protected override void Because_of()
 {
     //save to file
     BinaryStateSerializer.Save();
     //create new serializer, and get loaded state
     BinaryStateSerializer = new BinaryStateSerializer(Logger.Object);
     //save loaded state
     restoredState = BinaryStateSerializer.CurrentState;
 }
        protected override void Establish_context()
        {
            base.Establish_context();
            if (File.Exists(BinaryStateSerializer.STATE_FILE_NAME))
            {
                File.Delete(BinaryStateSerializer.STATE_FILE_NAME);
            }

            createdByDefaultState = BinaryStateSerializer.CurrentState;
            createdByDefaultState.CurrentUri = uriInStateToSave;
        }
Esempio n. 3
0
        private void load()
        {
            DownloaderState deserialized = null;
            if (File.Exists(STATE_FILE_NAME))
            {
                try
                {

                    using (var stream = File.OpenRead(STATE_FILE_NAME))
                    {
                        deserialized = netDataContractSerializer.Deserialize(stream)
                            as DownloaderState;
                        stream.Close();
                    }
                }
                catch (XmlException e)
                {
                    deserialized = null;
                    logger.LogException(e);
                }
            }
            if (deserialized != null)
            {
                CurrentState = deserialized;
            }
            else
            {
                CurrentState = new DownloaderState();
            }
        }