<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tag 'ObjectStorageHelper'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=ObjectStorageHelper&amp;orTags=0</link><description>Search results matching tag 'ObjectStorageHelper'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>ObjectStorageHelper now available via nuget</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/11/20/objectstoragehelper-now-available-via-nuget.aspx</link><pubDate>Tue, 20 Nov 2012 09:17:20 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46299</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;One of my numerous little side projects has recently been &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/tags/ObjectStorageHelper/default.aspx" target="_blank"&gt;ObjectStorageHelper&lt;/a&gt;, a library that makes it easy to read/write files in WinRT (aka Windows 8) applications. This is a short post to let you know that ObjectStorageHelper is now &lt;a href="https://nuget.org/packages/ObjectStorageHelper" target="_blank"&gt;available in the nuget gallery&lt;/a&gt; and hence can easily be added to your WinRT applications by running the following command in the nuget &lt;a href="http://docs.nuget.org/docs/start-here/using-the-package-manager-console" target="_blank"&gt;Package Manager Console&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_48BB6B56.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_436C84A5.png" width="527" height="54" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Massive thanks to Scott Lovegrove (&lt;a href="https://twitter.com/scottisafool" target="_blank"&gt;@scottisafool&lt;/a&gt;) for &lt;strike&gt;helping me with this&lt;/strike&gt; making this happen.&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;To read more about ObjectStorageHelper and what it can do for you please visit &lt;a href="http://winrtstoragehelper.codeplex.com/"&gt;Generic Object Storage Helper for WinRT&lt;/a&gt; on Codeplex. I know of four apps in the Windows Store that are currently making use of ObjectStorageHelper, they are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://apps.microsoft.com/webpdp/en-us/app/myscoreboard-pro/8f4d5173-2f8a-4ff5-9f8a-99097154aaec/m/row"&gt;myScoreboard pro&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://apps.microsoft.com/webpdp/en-US/app/bo2-create-a-class/ada6f477-6cd8-4a9c-a065-de8f8087c249"&gt;BO2 Create-a-Class&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://apps.microsoft.com/webpdp/en-US/app/mw3-create-a-class/4b30923a-f988-4db6-90f7-cc01d85a7589"&gt;MW3 Create-a-Class&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://apps.microsoft.com/webpdp/en-US/app/ctrl-alt-del/775964e3-8372-4dbd-af95-d8ca79b4b4fa"&gt;Ctrl-Alt-Del&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following code shows how easy it is to store files using ObjectStorageHelper:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_76EA5161.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_377C7804.png" width="539" height="203" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;and subsequently retrieve them:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_60576740.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_0EED7023.png" width="537" height="168" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;</description></item><item><title>ObjectStorageHelper&amp;lt;T&amp;gt; now available for Windows 8 RTM</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/08/28/objectstoragehelper-t-now-available-for-windows-8-rtm.aspx</link><pubDate>Tue, 28 Aug 2012 22:20:19 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44891</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;In October 2011 I wrote a blog post entitled &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2011/10/21/objectstoragehelper-t-a-winrt-utility-for-windows-8.aspx" target="_blank"&gt;ObjectStorageHelper&amp;lt;T&amp;gt; – A WinRT utility for Windows 8&lt;/a&gt; where I introduced a little utility class called &lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#4bacc6"&gt;ObjectStorageHelper&lt;/font&gt;&amp;lt;T&amp;gt;&lt;/strong&gt;&lt;/font&gt; that I had been working on while noodling around on the Developer Preview of Windows 8. &lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#4bacc6"&gt;ObjectStorageHelper&lt;/font&gt;&amp;lt;T&amp;gt;&lt;/strong&gt;&lt;/font&gt; makes it easy for anyone building apps for Windows 8 to save data to files. How easy? As easy as this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; myPoco = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#4bacc6"&gt;Poco&lt;/font&gt;() { IntProp = 1, StringProp = &amp;quot;one&amp;quot; };           &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; objectStorageHelper = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#4bacc6"&gt;ObjectStorageHelper&lt;/font&gt;&amp;lt;&lt;font color="#4bacc6"&gt;Poco&lt;/font&gt;&amp;gt;(&lt;font color="#4bacc6"&gt;StorageType&lt;/font&gt;.Local);           &lt;br /&gt;&lt;font color="#0000ff"&gt;await&lt;/font&gt; objectStorageHelper.SaveAsync(myPoco);&lt;/strong&gt;&lt;/font&gt;       &lt;br /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Compare that to the plumbing code that you would have to write otherwise:&lt;/p&gt;  &lt;blockquote&gt;&lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; Obj = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#4bacc6"&gt;Poco&lt;/font&gt;() { IntProp = 1, StringProp = &amp;quot;one&amp;quot; };        &lt;br /&gt;&lt;font color="#0000ff"&gt;var &lt;/font&gt;filename = “SomeFileName”;&amp;#160; &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#4bacc6"&gt;StorageFile&lt;/font&gt; file = &lt;font color="#0000ff"&gt;null&lt;/font&gt;;         &lt;br /&gt;&lt;font color="#4bacc6"&gt;StorageFolder&lt;/font&gt; folder = GetFolder(storageType);         &lt;br /&gt;file = await folder.CreateFileAsync(filename, &lt;font color="#4bacc6"&gt;CreationCollisionOption&lt;/font&gt;.ReplaceExisting);         &lt;br /&gt;&lt;font color="#4bacc6"&gt;IRandomAccessStream&lt;/font&gt; writeStream = &lt;font color="#0000ff"&gt;await&lt;/font&gt; file.OpenAsync(&lt;font color="#4bacc6"&gt;FileAccessMode&lt;/font&gt;.ReadWrite);         &lt;br /&gt;using (&lt;font color="#4bacc6"&gt;Stream&lt;/font&gt; outStream = &lt;font color="#4bacc6"&gt;Task&lt;/font&gt;.Run(() =&amp;gt; writeStream.AsStreamForWrite()).Result)         &lt;br /&gt;{         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; serializer.Serialize(outStream, Obj);         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;await&lt;/font&gt; outStream.FlushAsync();         &lt;br /&gt;}&lt;/strong&gt;&lt;/font&gt;&lt;/blockquote&gt;  &lt;p&gt;and you can see how &lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#4bacc6"&gt;ObjectStorageHelper&lt;/font&gt;&amp;lt;T&amp;gt;&lt;/strong&gt;&lt;/font&gt; can help save a Windows 8 developer quite a few headaches. &lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#4bacc6"&gt;ObjectStorageHelper&lt;/font&gt;&amp;lt;T&amp;gt;&lt;/strong&gt;&lt;/font&gt; simply requires you to pass it an object to be saved, tell it where to save it (Roaming, Local or Temporary), and you’re done. You don’t even need to give it a filename.&lt;/p&gt;  &lt;p&gt;Retrieving an object from storage is equally as simple:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; objectStorageHelper = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#4bacc6"&gt;ObjectStorageHelper&lt;/font&gt;&amp;lt;&lt;font color="#4bacc6"&gt;Poco&lt;/font&gt;&amp;gt;(&lt;font color="#4bacc6"&gt;StorageType&lt;/font&gt;.Local);           &lt;br /&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; myPoco = &lt;font color="#0000ff"&gt;await&lt;/font&gt; objectStorageHelper.LoadAsync();&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Please check the homepage for the project at &lt;a title="http://winrtstoragehelper.codeplex.com/" href="http://winrtstoragehelper.codeplex.com/"&gt;http://winrtstoragehelper.codeplex.com/&lt;/a&gt; for (much) more info.&lt;/p&gt;    &lt;hr /&gt;    &lt;p&gt;A number of people have used and tested &lt;font face="Consolas"&gt;&lt;strong&gt;&lt;font color="#4bacc6"&gt;ObjectStorageHelper&lt;/font&gt;&amp;lt;T&amp;gt;&lt;/strong&gt;&lt;/font&gt; since those early days and one of those folks in particular, &lt;a href="https://twitter.com/DavidBurela/" target="_blank"&gt;David Burela&lt;/a&gt;, was good enough to submit a couple of bugs:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://winrtstoragehelper.codeplex.com/workitem/22826" target="_blank"&gt;Saving Asynchronously&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://winrtstoragehelper.codeplex.com/workitem/22821" target="_blank"&gt;Save fails when class is in another project&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;As a result of David’s bug reports and some more extensive testing on my side I have overhauled the initial code that I wrote last October and am confident that it is now much more robust and ready for primetime (check the &lt;a href="http://winrtstoragehelper.codeplex.com/SourceControl/list/changesets" target="_blank"&gt;commit history&lt;/a&gt; if you’re interested). The source code (which, again, you can find on Codeplex at &lt;a title="http://winrtstoragehelper.codeplex.com/" href="http://winrtstoragehelper.codeplex.com/"&gt;http://winrtstoragehelper.codeplex.com/&lt;/a&gt;) includes a suite of unit tests to test all of the basic use cases (if you can think of any more please let me know).&lt;/p&gt;  &lt;p&gt;If you use this in any of your Windows 8 projects then please let me know. I love getting feedback and I’d also love to know if this is actually being used anywhere.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;</description></item><item><title>ObjectStorageHelper&amp;lt;T&amp;gt; – A WinRT utility for Windows 8</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/10/21/objectstoragehelper-t-a-winrt-utility-for-windows-8.aspx</link><pubDate>Fri, 21 Oct 2011 19:51:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:39308</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;&lt;i&gt;[Disclaimer: This blog post was written in the Developer Preview timeframe and the code has since been heavily updated. Please visit my &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/tags/ObjectStorageHelper/default.aspx" target="_blank"&gt;ObjectStorageHelper feed&lt;/a&gt; to see the most up to date information.]&amp;nbsp;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;A heads up – this blog post has nothing to do with SQL Server. You have been warned.&lt;/i&gt;&lt;/p&gt;  &lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;Last month Microsoft announced the next version of Windows and along with it a new programming model called Windows Runtime (WinRT). Given my long-time interest in the &lt;a href="http://consultingblogs.emc.com/jamiethomson/archive/tags/Live+Framework/default.aspx" target="_blank"&gt;Live Framework API&lt;/a&gt; which has re-emerged (sort of) in WinRT I decided to have poke around in what it had to offer. I discovered that any application written for WinRT will have access to three sandboxed folders:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;LocalFolder &lt;/li&gt;    &lt;li&gt;TemporaryFolder &lt;/li&gt;    &lt;li&gt;RoamingFolder &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;LocalFolder and TemporaryFolder are fairly self-explanatory. RoamingFolder is where the remnants of the Live Framework API rears its head – the contents of that folder gets synced to any device on which the app is installed – thus providing the ability to sync application data between those different devices; I’m not going to go into the scenarios that this feature makes possible but I will say that I think this is one of the most exciting features about Windows 8.&lt;/p&gt;  &lt;p&gt;As I poked and prodded at the WinRT classes provided to enable interaction with these three folders I concluded that it wasn’t exactly straightforward and figured I’d have a go at writing something a bit friendlier and hence ObjectStorageHelper&amp;lt;T&amp;gt; was born. It is, in short, a simple class that provides three basic methods:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;void DeleteASync() &lt;/li&gt;    &lt;li&gt;void SaveASync(T Object) &lt;/li&gt;    &lt;li&gt;Task&amp;lt;T&amp;gt; LoadASync() &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Saving an object&lt;/h2&gt;  &lt;p&gt;They simply allow you to manage storage of nearly any object (basically anything that can be serialized as XML). Here’s the code to save an object, its only two lines of code:&lt;/p&gt;    &lt;div style="margin:0px;padding:0px;float:none;display:inline;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:4732cb61-083c-4b1c-93f0-afd6717f5100" class="wlWriterEditableSmartContent"&gt;&lt;pre style="overflow:auto;background-color:white;"&gt;&lt;span&gt;[TestMethod]
&lt;/span&gt;&lt;span&gt;public&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;void&lt;/span&gt;&lt;span&gt; SaveObject()
{
  &lt;/span&gt;&lt;span&gt;//&lt;/span&gt;&lt;span&gt;Instantiate an object that we want to save&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;  var myPoco &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;new&lt;/span&gt;&lt;span&gt; Poco() { IntProp &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;, StringProp &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;"&lt;/span&gt;&lt;span&gt;one&lt;/span&gt;&lt;span&gt;"&lt;/span&gt;&lt;span&gt; };
  &lt;/span&gt;&lt;span&gt;//&lt;/span&gt;&lt;span&gt;new up ObjectStorageHelper specifying that we want to interact with the Local storage folder&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;  var objectStorageHelper &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;new&lt;/span&gt;&lt;span&gt; ObjectStorageHelper&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Poco&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(StorageType.Local);
  &lt;/span&gt;&lt;span&gt;//&lt;/span&gt;&lt;span&gt;Save the object (via XML Serialization) to the specified folder, asynchronously&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;  objectStorageHelper.SaveASync(myPoco);
}
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;p&gt;The name of the file that gets stored is determined by the name of the type T specified in ObjectStorageHelper&amp;lt;T&amp;gt; and this in turn means that only one object of type T can be stored in each of the three folders; this is by design. 
  &lt;br&gt;If you have a need to store multiple objects of T then you could use a List instead like this: ObjectStorageHelper&amp;lt;List&amp;lt;T&amp;gt;&amp;gt; or simply adjust the code herein so that it allows you to specify a filename.&lt;/p&gt;

&lt;h2&gt;Retrieving an object&lt;/h2&gt;

&lt;p&gt;Retrieving that object thereafter is equally as easy, just two lines of code&lt;/p&gt;

&lt;div style="margin:0px;padding:0px;float:none;display:inline;" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c0fcb89c-ad17-4a45-989a-adae97ba4779" class="wlWriterEditableSmartContent"&gt;&lt;pre style="overflow:auto;"&gt;&lt;span&gt;[TestMethod]
&lt;/span&gt;&lt;span&gt;public&lt;/span&gt;&lt;span&gt; async &lt;/span&gt;&lt;span&gt;void&lt;/span&gt;&lt;span&gt; LoadObject()
{
  &lt;/span&gt;&lt;span&gt;//&lt;/span&gt;&lt;span&gt;new up ObjectStorageHelper specifying that we want to interact with the Local storage folder&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;  var objectStorageHelper &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;new&lt;/span&gt;&lt;span&gt; ObjectStorageHelper&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;Poco&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(StorageType.Local);
  &lt;/span&gt;&lt;span&gt;//&lt;/span&gt;&lt;span&gt;Get the object from the storage folder&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;  Poco myPoco &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; await objectStorageHelper.LoadASync();
}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;Get the goods&lt;/h2&gt;

&lt;p&gt;If you want to have a play then the code or compiled assembly is available under the MS-PL license on Codeplex at &lt;a title="http://winrtstoragehelper.codeplex.com/" href="http://bit.ly/omUBsA"&gt;http://winrtstoragehelper.codeplex.com/&lt;/a&gt;. Feedback is welcome!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@jamiet&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>