Tuesday, December 14, 2010

Intentionally fill up isolated storage in Silverlight

I came across a bug in my application which required me to fill the IsolatedStorageFile to reproduce. I thought I would share this snippet for any of you out there that need to quickly fill your isolated storage in your app to reproduce a full isolated storage environment.

private static void FillUpISO()
{

int loopCount = 600;

string content = "al;jd fkjasdklfj alks;djf lkajsd klfjlkdasj fklj alsdjfk jadlkjflk;ajsd;lfkj kldsjf lk;jdkljldjglkjdgk dghkd fjkl dlk;fj l;kdj sfk asd " +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj" +
"alkdjf l;asjd fk;lj dsakl;fj klajds flkjds alkfjl;ksadj fkljdlk;fj lkadsj fl;kj adslkfj lkd jflk jdlkf jkld asjkl;f jkl;adsj fkljdlksa jfl;kajsd ;lfkjaskdfj";


if (!IsolatedStorageFile.IsEnabled)
return;

using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForSite())
{
using (IsolatedStorageFileStream isfs
= new IsolatedStorageFileStream("Whatever",
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
isf))
{
using (StreamWriter writer = new StreamWriter(isfs))
{
writer.WriteLine(content);
writer.Close();
}
isfs.Close();
}
}
try
{

for (int i = 0; i < loopCount; i++)
{

using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForSite())
{
using (IsolatedStorageFileStream isfs
= new IsolatedStorageFileStream("Whatever",
FileMode.Append,
FileAccess.Write,
isf))
{
using (StreamWriter writer = new StreamWriter(isfs))
{

writer.WriteLine(content);
writer.Close();
}
isfs.Close();
}
}
}
}
catch (IsolatedStorageException isex)
{
var i = isex.Message;
}
}




Simply add the method from my sample app, or above, to one of your classes in your application and make the call to it. Here is the sample app.

http://cid-ab80127ae39f5a1e.office.live.com/self.aspx/.Public/fillIsolatedStorageHelper.zip

Cheers,

Bryon

Wednesday, August 18, 2010

WPF Modal Dialog when owner is IWin32Window

Today I was working on a plugin for Windows Live Photo Gallery, using WPF, and ran into an issue where I could not seem to set up modal dialog behavior. When a user opened up my plugin the task bar would have two entries, Windows Live Photo Gallery (WLPG), and my plugin. If a user selected the WLPG our plugin would be hidden behind the WLPG window.

However, I noticed other plugins made the border flash when trying to go back to WLPG without closing the plugin. I wanted the modal behavior in my plugin also. Simply using a WPF Window's .ShowDialog does not do the trick. This is because the WLPG is a IWin32Window, not a System.Windows.Window. WindowInteropHelper to the rescue!!!

GET TO THE POINT OF HOW TO DO IT! OK, OK, I hear you. So to make this simple make the following assumption. You have a WPF window named wpfWindow. You want to show wpfWindow as a modal dialog of the IWin32Window. Code the following:

//BEGIN CODE Snippet
//Use WindowInteropHelper to the wpfWindow
WindowInteropHelper helper = new WindowInteropHelper(wpfWindow);

//Get the process containing the IWin32Window
Process procs = Process.GetCurrentProcess();
IntPtr hwnd = procs.MainWindowHandle;

//Set the owner so it behaves like a true Modal Dialog
helper.Owner = hwnd;
wpfWindow.ShowDialog();

//End code snippet


That is all.
Cheers!
Bryon

Friday, June 25, 2010

JetBrains ReSharper 4.5 screen refresh issue and workaround

Problem:
I have ran across an issue with Visual Studio 2008 and JetBrains ReSharper 4.5 which prevents part of the screen from refreshing properly. This is frustrating at times because it even affects the scrollbar from functioning forcing you to use the keyboard to scroll through your code.

Workaround
To work around this you can DISABLE and ENABLE JetBrains ReSharper 4.5 in the Add-in Manager of Visual Studio.

Disable:
Open up Add-In Manager from the menu Tools->Add-in Manager.
Uncheck JetBrains ReSharper 4.5 and click OK.
It is good to disable before checking code into TFS or when reviewing existing code.

Enable:
Open up Add-In Manager from the menu Tools->Add-in Manager.
Check JetBrains ReSharper 4.5 and click OK.
It is good to enable when you are writing new code or doing any refactoring.


I have not seen any fix for this bug yet, but until then this workaround is not too time consuming.

Cheers!