Example #1
0
            /// <summary>
            /// Deserializes a <see cref="Change"/> from the given byte array.
            /// </summary>
            /// <param name="serializedChange">Byte array containing a serialized change</param>
            /// <param name="factory">The <see cref="AbstractPersistedDataFactory"/> that must be associated with the deserialized change list</param>
            /// <returns>A <see cref="ChangeList"/></returns>
            private static ChangeList.Change Deserialize(byte[] serializedChange, AbstractPersistedDataFactory factory)
            {
                MemoryStream memoryStream = new MemoryStream(serializedChange);

                try
                {
                    using (var binaryReader = new BinaryReader(memoryStream))
                    {
                        memoryStream = null;

                        ChangeList.ChangeType changeType = (ChangeList.ChangeType)binaryReader.ReadInt32();
                        PersistedData         data       = new PersistedData(0);
                        data.ReadFrom(binaryReader);

                        return(new ChangeList.Change(changeType, data));
                    }
                }
                finally
                {
                    if (memoryStream != null)
                    {
                        memoryStream.Dispose();
                    }
                }
            }
Example #2
0
            public Task Remove(PersistedData data)
            {
                var change = new ChangeList.Change(ChangeList.ChangeType.Remove, data);

                this.serializedChanges.Add(Serialize(change));
                return(Task.FromResult <object>(null));
            }
Example #3
0
        /// <summary>
        /// Creates the new.
        /// </summary>
        /// <returns>IPersistedData.</returns>
        public IPersistedData CreateNew()
        {
            IPersistedData res = new PersistedData();

            this.RecordStatsDelta(1, 0);
            return(res);
        }
Example #4
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            PersistedData dataToBePersisted = new PersistedData();

            if (this.stackCharts.Children.Count > 1)
            {
                for (int i = this.stackCharts.Children.Count - 1; i > 0; i--)
                {
                    var        clusteredColumnChartSeriesData = ((ClusteredColumnChart)this.stackCharts.Children[i]).Series;
                    SeriesData seriesData = new SeriesData();

                    dataToBePersisted.Series.Add(seriesData);
                    seriesData.SeriesDisplayName = ((ClusteredColumnChart)this.stackCharts.Children[i]).ChartTitle;
                    seriesData.SubTitle          = ((ClusteredColumnChart)this.stackCharts.Children[i]).ChartSubTitle;


                    foreach (var x in clusteredColumnChartSeriesData[0].Items)
                    {
                        seriesData.Items.Add((ChartData)x);
                    }
                }
            }

            StreamWriter  streanWriter = new StreamWriter("SavedData.xml");
            XmlSerializer serializer   = new XmlSerializer(typeof(PersistedData));

            serializer.Serialize(streanWriter, dataToBePersisted);
            streanWriter.Flush();
            streanWriter.Close();
        }
    private static void SaveLocal(bool _isMember, bool _checkFailed, string _errorMessage)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(Application.persistentDataPath + "/member.dat", FileMode.OpenOrCreate);

        PersistedData data = new PersistedData();

        data.isMember     = _isMember;
        data.checkFailed  = _checkFailed;
        data.errorMessage = _errorMessage;
        bf.Serialize(file, data);
        file.Close();
    }
Example #6
0
            public async Task Remove(PersistedData value)
            {
                this.dataById = this.dataById ?? await this.factory.GetDataById(this.transaction);

                var key = (long)value.Id;

                ServiceFabricPersistenceEventSource.Log.Remove(this.transaction.TransactionId, key);
                var timer = Stopwatch.StartNew();

                await this.dataById.TryRemoveAsync(this.transaction, key);

                this.factory.instrumentation?.RemoveRequested(timer.Elapsed);
            }
Example #7
0
            public async Task Update(PersistedData value)
            {
                this.dataById = this.dataById ?? await this.factory.GetDataById(this.transaction);

                var key = (long)value.Id;

                ServiceFabricPersistenceEventSource.Log.Update(this.transaction.TransactionId, key, value?.Name);
                var timer = Stopwatch.StartNew();

                await this.dataById.SetAsync(this.transaction, key, new WinFabPersistence.PersistedData(value));

                this.factory.instrumentation?.UpdateRequested(timer.Elapsed);
            }
Example #8
0
        /// <summary>
        /// Deserializes a <see cref="WinFabPersistence.PersistedData"/> from the given <see cref="BinaryReader"/>.
        /// </summary>
        /// <param name="binaryReader">The <see cref="BinaryReader"/> to deserialize from</param>
        /// <returns>The deserialized <see cref="WinFabPersistence.PersistedData"/></returns>
        public WinFabPersistence.PersistedData Read(BinaryReader binaryReader)
        {
            if (binaryReader == null)
            {
                throw new ArgumentNullException(nameof(binaryReader));
            }

            var pd = new PersistedData(0);

            pd.ReadFrom(binaryReader);
            ServiceFabricPersistenceEventSource.Log.PersistedDataSerializer_Read(pd.Id, pd.Name);

            return(new WinFabPersistence.PersistedData(pd));
        }
Example #9
0
        /// <summary>
        /// Enumerates the stream and returns a collection of persisted data
        /// </summary>
        /// <param name="stream">Stream to read</param>
        /// <returns>collection of persisted data object</returns>
        public IEnumerable <PersistedData> EnumerateFrom(Stream stream)
        {
            InMemoryPersistenceEventSource.Log.LoadFromStream();
            using (var binaryReader = new BinaryReader(stream))
            {
                ulong itemCount = binaryReader.ReadUInt64();

                for (ulong i = 0; i < itemCount; i++)
                {
                    PersistedData data = new PersistedData(0);
                    data.ReadFrom(binaryReader);
                    yield return(data);
                }
            }
        }
    public static void LoadLocal()
    {
        if (File.Exists(Application.persistentDataPath + "/member.dat"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/member.dat", FileMode.Open);
            PersistedData   data = (PersistedData)bf.Deserialize(file);
            file.Close();

            isMember     = data.isMember;
            checkFailed  = data.checkFailed;
            errorMessage = data.errorMessage;
        }
        else
        {
            SaveLocal(false, false, "");
            isMember = false;
        }
    }
Example #11
0
 // Code to execute when the application is deactivated (sent to background)
 // This code will not execute when the application is closing
 private void Application_Deactivated(object sender, DeactivatedEventArgs e)
 {
     PersistedData data = new PersistedData(_currentDate.Year,
                                             _currentDate.Month,
                                             _currentDate.Day,
                                             _calendardata.CityToken,
                                             _calendardata.CityName,
                                             _calendardata.CityTimeZone,
                                             _calendardata.UseLocation);
     try
     {
         using (var store = IsolatedStorageFile.GetUserStoreForApplication())
         {
             IsolatedStorageFileStream stream = store.OpenFile("PersistedFile.xml", System.IO.FileMode.Create);
             DataContractSerializer ser = new DataContractSerializer(typeof(PersistedData));
             ser.WriteObject(stream, data);
             stream.Close();
         }
     }
     catch (Exception excep)
     {
         Debug.WriteLine("Isolated Storage exception " + excep.Message);
     }
 }