Index: xword/XWord/Login.cs
===================================================================
--- xword/XWord/Login.cs (revision 19428)
+++ xword/XWord/Login.cs (working copy)
@@ -22,16 +22,50 @@
/// True if the operation is uscessfull. False otherwise.
public bool WriteCredentials(String[] credentials)
{
- IsolatedStorageFile isFile = IsolatedStorageFile.GetUserStoreForAssembly();
- IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Create, isFile);
- StreamWriter writer = new StreamWriter(stream);
- foreach (String s in credentials)
+ IsolatedStorageFile isFile = null;
+ IsolatedStorageFileStream stream = null;
+ StreamWriter writer = null;
+
+ bool successfulWrite = false;
+
+ try
{
- writer.WriteLine(s);
+
+ isFile = IsolatedStorageFile.GetUserStoreForAssembly();
+ stream = new IsolatedStorageFileStream(filename, FileMode.Create, isFile);
+ writer = new StreamWriter(stream);
+ foreach (String s in credentials)
+ {
+ writer.WriteLine(s);
+ }
+ successfulWrite = true;
}
- writer.Close();
- stream.Close();
- return true;
+ catch (IOException ioException)
+ {
+ Log.Exception(ioException);
+ }
+ catch (Exception exception)
+ {
+ Log.Exception(exception);
+ }
+ finally
+ {
+ if (writer != null)
+ {
+ writer.Close();
+ }
+ if (stream != null)
+ {
+ stream.Close();
+ }
+ if (isFile != null)
+ {
+ isFile.Dispose();
+ isFile.Close();
+ }
+ }
+
+ return successfulWrite;
}
///
/// Gets the last used credentials.
@@ -39,26 +73,46 @@
/// Array of strings containing the last used credentials
public String[] GetCredentials()
{
+ String[] credentials = new String[3];
+ IsolatedStorageFile isFile=null;
+ IsolatedStorageFileStream stream = null;
+ StreamReader reader = null;
try
{
- String[] credentials = new String[3];
- IsolatedStorageFile isFile = IsolatedStorageFile.GetUserStoreForAssembly();
- IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Open, isFile);
- StreamReader reader = new StreamReader(stream);
- int i=0;
+ isFile = IsolatedStorageFile.GetUserStoreForAssembly();
+ stream = new IsolatedStorageFileStream(filename, FileMode.Open, isFile);
+ reader = new StreamReader(stream);
+ int i = 0;
while (!reader.EndOfStream)
{
String s = reader.ReadLine();
credentials[i] = s;
i++;
}
- return credentials;
}
- catch(Exception ex)
+ catch (Exception ex)
{
Log.ExceptionSummary(ex);
- return null;
+ credentials = null;
}
+ finally
+ {
+ if (reader != null)
+ {
+ reader.Close();
+ }
+ if (stream != null)
+ {
+ stream.Close();
+ }
+ if (isFile != null)
+ {
+ isFile.Dispose();
+ isFile.Close();
+ }
+
+ }
+ return credentials;
}
///
@@ -66,15 +120,24 @@
///
public void ClearCredentials()
{
+ IsolatedStorageFile isFile=null;
try
{
- IsolatedStorageFile isFile = IsolatedStorageFile.GetUserStoreForAssembly();
+ isFile = IsolatedStorageFile.GetUserStoreForAssembly();
isFile.DeleteFile(filename);
}
catch (IsolatedStorageException ex)
{
Log.ExceptionSummary(ex);
}
+ finally
+ {
+ if (isFile != null)
+ {
+ isFile.Dispose();
+ isFile.Close();
+ }
+ }
}
///
@@ -83,8 +146,28 @@
///
public bool CanAutoLogin()
{
- IsolatedStorageFile isFile = IsolatedStorageFile.GetUserStoreForAssembly();
- return (isFile.GetFileNames(filename).Length > 0);
+ IsolatedStorageFile isFile=null;
+ bool canAutoLogin = false;
+
+ try
+ {
+ isFile = IsolatedStorageFile.GetUserStoreForAssembly();
+ canAutoLogin = (isFile.GetFileNames(filename).Length > 0);
+ }
+ catch (Exception exception)
+ {
+ Log.Exception(exception);
+ }
+ finally
+ {
+ if (isFile != null)
+ {
+ isFile.Dispose();
+ isFile.Close();
+ }
+ }
+
+ return canAutoLogin;
}
}
}
Index: xword/XWord/Repositories.cs
===================================================================
--- xword/XWord/Repositories.cs (revision 19428)
+++ xword/XWord/Repositories.cs (working copy)
@@ -24,11 +24,33 @@
/// True if the operation succeded. False if the operation failed.
public static bool WriteRepositorySettings(RepositorySettings settings)
{
- IsolatedStorageFile isFile = IsolatedStorageFile.GetUserStoreForAssembly();
- IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Create, isFile);
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize(stream, settings);
- stream.Close();
+ IsolatedStorageFile isFile=null;
+ IsolatedStorageFileStream stream = null;
+ BinaryFormatter formatter = null;
+
+ try
+ {
+ isFile = IsolatedStorageFile.GetUserStoreForAssembly();
+ stream = new IsolatedStorageFileStream(filename, FileMode.Create, isFile);
+ formatter = new BinaryFormatter();
+ formatter.Serialize(stream, settings);
+ }
+ catch (IOException ioException)
+ {
+ Log.Exception(ioException);
+ }
+ finally
+ {
+ if (stream != null)
+ {
+ stream.Close();
+ }
+ if (isFile != null)
+ {
+ isFile.Dispose();
+ isFile.Close();
+ }
+ }
return true;
}
@@ -38,14 +60,16 @@
/// A instance containing the repository settings.
public static RepositorySettings GetRepositorySettings()
{
+ RepositorySettings settings=new RepositorySettings();
+ IsolatedStorageFile isFile=null;
+ IsolatedStorageFileStream stream=null;
+ BinaryFormatter formatter;
try
{
- RepositorySettings settings = new RepositorySettings();
- IsolatedStorageFile isFile = IsolatedStorageFile.GetUserStoreForAssembly();
- IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Open, isFile);
- BinaryFormatter formatter = new BinaryFormatter();
+ isFile = IsolatedStorageFile.GetUserStoreForAssembly();
+ stream = new IsolatedStorageFileStream(filename, FileMode.Open, isFile);
+ formatter = new BinaryFormatter();
settings = (RepositorySettings)formatter.Deserialize(stream);
- return settings;
}
catch (InvalidCastException ce)
{
@@ -57,6 +81,19 @@
Log.ExceptionSummary(ex);
return null;
}
+ finally
+ {
+ if (stream != null)
+ {
+ stream.Close();
+ }
+ if (isFile != null)
+ {
+ isFile.Dispose();
+ isFile.Close();
+ }
+ }
+ return settings;
}
///
@@ -68,8 +105,27 @@
///
public static bool HasRepositorySettings()
{
- IsolatedStorageFile isFile = IsolatedStorageFile.GetUserStoreForAssembly();
- return (isFile.GetFileNames(filename).Length > 0);
+ IsolatedStorageFile isFile=null;
+ bool hasRepositorySettings=false;
+ try
+ {
+ isFile = IsolatedStorageFile.GetUserStoreForAssembly();
+ hasRepositorySettings = (isFile.GetFileNames(filename).Length > 0);
+ }
+ catch (IOException ioException)
+ {
+ Log.Exception(ioException);
+ }
+ finally
+ {
+ if (isFile != null)
+ {
+ isFile.Dispose();
+ isFile.Close();
+ }
+ }
+
+ return hasRepositorySettings;
}
}
}