small bugfix?

Mar 6, 2011 at 10:26 PM
Edited Mar 6, 2011 at 10:27 PM

Hi Sergey,

Many thanks for this very useful library. In my local copy I've made a small change that I would like to share with you:

In Table.cs I added the line below in Save(..) to avoid IsolatedStorageExceptions I was getting otherwise.



        public void Save(IsolatedStorageFile store)
        {
            lock (_lock)
            {
                if (!string.IsNullOrEmpty(_databaseName))
                {
                    try
                    {
                        string fileName = string.Concat(_databaseName, ".", typeof(T).FullName);
                        if (store.FileExists(fileName))
                        {
                            store.DeleteFile(fileName);
                        }
                        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, store))
                        {
                            WriteDTableToStream(stream);
                            stream.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new SaveException(ex);
                    }

                }
                else
                {
                    throw new TableCannotBeSavedException(DatabaseResources.TableWithoutDatabaseCannotBeSaved);
                }
            }
        }
I hope you find this helpful. By the way: I am using Windows Phone 7 database a lot here: http://bit.ly/hkTkxK
Coordinator
Mar 8, 2011 at 12:54 AM

Hey, Kalus,

Thanks for the suggestion. This is really not needed because Dispose will automatically close the stream if it is open, releasing all the resources. This is typical pattering for usage of using{} statement with all the classes that implement IDisposable.

 

 

Mar 10, 2011 at 11:11 AM

Hey Sergey, thanks and apologies for overlooking the obvious. Of course you are right. I must have been too desperate with the IsolatedStorageExceptions.