Exemple #1
0
        public void BackupCurrentDb(Dictionary <string, MixerClip> db, ClipMine adder, int currentDbVersion)
        {
            adder.SetStatus("Backing up to historian...");

            try
            {
                // Convert the current map to a list.
                List <MixerClip> clips = new List <MixerClip>();
                foreach (KeyValuePair <string, MixerClip> k in db)
                {
                    clips.Add(k.Value);
                }

                // Seralize our current database.
                HistorianBackup backup = new HistorianBackup()
                {
                    database = clips,
                    Version  = currentDbVersion
                };
                string json = JsonConvert.SerializeObject(backup);

                // Try to get the history file
                CloudBlockBlob blob = GetHistoryFile();
                if (blob == null)
                {
                    Logger.Info("Failed to get history blob.");
                    return;
                }

                // Write the json to the file.
                blob.UploadText(json);
            }
            catch (Exception e)
            {
                Logger.Error("Exception in historian write db", e);
            }
        }
Exemple #2
0
        public void AttemptToRestore(ClipMine adder, int currentDbVersion)
        {
            adder.SetStatus("Attempting to restore from historian...");
            DateTime start = DateTime.Now;

            try
            {
                // Look for a history file
                CloudBlockBlob cloudBlockBlob = GetHistoryFile();
                if (cloudBlockBlob == null)
                {
                    adder.SetStatus("Failed to get history file...");
                    Logger.Info($"Failed to get history file.");
                    return;
                }

                if (!cloudBlockBlob.Exists())
                {
                    Logger.Info($"No history file exits.");
                    return;
                }

                adder.SetStatus("Found history, downloading...");

                // Download and deseralize.
                HistorianBackup backup = null;
                using (var stream = new MemoryStream())
                {
                    cloudBlockBlob.DownloadToStream(stream);
                    stream.Position = 0;
                    var serializer = new JsonSerializer();
                    using (var sr = new StreamReader(stream))
                    {
                        using (var jsonTextReader = new JsonTextReader(sr))
                        {
                            backup = serializer.Deserialize <HistorianBackup>(jsonTextReader);
                        }
                    }
                }

                if (backup == null)
                {
                    Logger.Info("Failed to get or deseralize old history file.");
                    return;
                }

                if (backup.Version != currentDbVersion)
                {
                    Logger.Info("History file found, but the verison doesn't match ours.");
                    return;
                }

                adder.SetStatus("History is good, restoring...");

                // Push the database in!
                adder.AddToClipMine(backup.database, (DateTime.Now - start), true);
            }
            catch (Exception e)
            {
                Logger.Error("Exception thrown in historian restore.", e);
            }
        }