Example #1
0
        private void BackupMonitor()
        {
            Running = true;

            while (Running)
            {
                BackupEntry entry = new BackupEntry(-1, "", "");

                // Check the queue to see if we need to do another backup?
                lock (BackupQueue)
                {
                    // Are there any entries in the queue?
                    if (BackupQueue.Count > 0)
                    {
                        // Yes! Grab the first one
                        entry = BackupQueue.Dequeue();
                    }
                }
                // Did we get a backup request from the queue?
                if (entry.ServerHostID > -1)
                {
                    // Yup, let's get this done...
                    PerformBackup(entry);
                }

                Thread.Sleep(10);
            }

            Running = false;
        }
Example #2
0
        /// <summary>
        /// Adds file to backup storage
        /// </summary>
        public void BackupFile(string filePath, string modId)
        {
            // Check settings
            if (!Settings.Stager.Current.UseBackup)
            {
                return;
            }

            // File must exist
            if (!File.Exists(filePath))
            {
                return;
            }

            // Find entry or create new
            var entry = Find(filePath, modId);

            if (entry == null)
            {
                long installOrder = GetNextFreeInstallOrder(filePath);
                entry = new BackupEntry(filePath, installOrder, modId);
                Store(entry);
            }

            // Copy file
            string backupFilePath = Path.Combine(FileSystem.BackupStorageDirectory, entry.BackupFileName);

            Ext.MakeDirectoryAtPath(backupFilePath);
            File.Copy(filePath, backupFilePath, true);

            // Logging
            Logger.Record($"Made backup of file: {filePath}");
        }
Example #3
0
        /// <summary>
        /// Serialize object and add one to backup
        /// </summary>
        /// <param name="backupEntry"></param>
        /// <param name="zipStream"></param>
        private void AddToBackup(BackupEntry backupEntry, ZipOutputStream zipStream)
        {
            // Serialize BackupEntry
            using (var memoryStream = new MemoryStream())
            {
                using (var streamWriter = new StreamWriter(memoryStream)
                {
                    AutoFlush = true
                })
                {
                    var type = backupEntry.BackupObject.GetType();

                    // Prepare ignored properties
                    var xmlOver    = GetIgnoreProperties(backupEntry);
                    var serializer = new XmlSerializer(type, xmlOver);
                    serializer.Serialize(streamWriter, backupEntry.BackupObject);

                    //Add result to zip
                    memoryStream.Position = 0;
                    var newEntry = new ZipEntry(backupEntry.EntryName)
                    {
                        DateTime = DateTime.Now
                    };
                    zipStream.PutNextEntry(newEntry);
                    StreamUtils.Copy(memoryStream, zipStream, new byte[4096]);
                    zipStream.CloseEntry();
                    _extpactMap.Add(new ExtractEntry {
                        BackupObjectTypeName = type.AssemblyQualifiedName, IgnoreProperties = backupEntry.IgnoreProperties, EntryName = backupEntry.EntryName
                    });
                }
            }
        }
Example #4
0
        private static string GetPath(BackupEntry entry)
        {
            if (entry == null)
            {
                return(null);
            }

            return(GetPath(entry.Parent) + "/" + entry.Name);
        }
Example #5
0
 /// <summary>
 /// Stores entry to database
 /// </summary>
 private void Store(BackupEntry entry)
 {
     // Check if already exists
     if (Find(entry.OriginalFilePath, entry.ModId) != null)
     {
         return;
     }
     _databaseService.DB.Insert(entry);
 }
 public void RemoveInstalledMod(BackupEntry entry)
 {
     foreach (BackupEntry listEntry in this._installedModsList)
     {
         if (entry == listEntry)
         {
             this._installedModsList.Remove(listEntry);
             break;
         }
     }
 }
Example #7
0
        private void PerformBackup(BackupEntry entry)
        {
            OnBackupStarting(entry.ServerHostID);

            if (Directory.Exists(entry.ServerLevelPath))
            {
                string[] folders = Directory.GetDirectories(entry.ServerLevelPath);
                string[] files   = Directory.GetFiles(entry.ServerLevelPath);

                if (folders.Length > 0 && files.Length > 0)
                {
                    // Does the backup path exist?
                    if (!Directory.Exists(entry.BackupPath))
                    {
                        // Nope, let's try to create it
                        try
                        {
                            Directory.CreateDirectory(entry.BackupPath);
                        }
                        catch { }
                    }

                    // Does the backup path exist?
                    if (Directory.Exists(entry.BackupPath))
                    {
                        // Yup, the backup path exists and we've got data to back up...
                        // Fetch an available filename for the zip archive
                        string zipFilePathName = GetArchiveFilePathName(entry.BackupPath);
                        // Do the backup...
                        ZipFile.CreateFromDirectory(entry.ServerLevelPath, zipFilePathName);
                        // Finally raise the completed event.
                        OnBackupCompleted(entry.ServerHostID);
                        // We are done, so let's just return
                        return;
                    }
                }
            }

            OnBackupFailed(entry.ServerHostID);
        }
Example #8
0
        protected override TimeSpan OnProcess()
        {
            IBackupService service;

            switch (_settings.Service)
            {
            case BackupServices.AwsS3:
                service = new AmazonS3Service(AmazonExtensions.GetEndpoint(_settings.Address), _settings.ServiceRepo, _settings.Login, _settings.Password.To <string>());
                break;

            case BackupServices.AwsGlacier:
                service = new AmazonGlacierService(AmazonExtensions.GetEndpoint(_settings.Address), _settings.ServiceRepo, _settings.Login, _settings.Password.To <string>());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var hasSecurities = false;

            this.AddInfoLog(LocalizedStrings.Str2306Params.Put(_settings.StartFrom));

            var startDate = _settings.StartFrom;
            var endDate   = DateTime.Today - TimeSpan.FromDays(_settings.Offset);

            var allDates = startDate.Range(endDate, TimeSpan.FromDays(1)).ToArray();

            var pathEntry = ToEntry(new DirectoryInfo(_settings.Drive.Path));

            var workingSecurities = GetWorkingSecurities().ToArray();

            foreach (var date in allDates)
            {
                foreach (var security in workingSecurities)
                {
                    hasSecurities = true;

                    if (!CanProcess())
                    {
                        break;
                    }

                    var dateEntry = new BackupEntry
                    {
                        Name   = date.ToString("yyyy_MM_dd"),
                        Parent = new BackupEntry
                        {
                            Parent = new BackupEntry
                            {
                                Name   = security.Security.Id.Substring(0, 1),
                                Parent = pathEntry
                            },
                            Name = security.Security.Id,
                        }
                    };

                    var dataTypes = _settings.Drive.GetAvailableDataTypes(security.Security.ToSecurityId(), _settings.StorageFormat);

                    foreach (var dataType in dataTypes)
                    {
                        var storage = StorageRegistry.GetStorage(security.Security, dataType.MessageType, dataType.Arg, _settings.Drive, _settings.StorageFormat);

                        var drive = storage.Drive;

                        var stream = drive.LoadStream(date);

                        if (stream == Stream.Null)
                        {
                            continue;
                        }

                        var entry = new BackupEntry
                        {
                            Name   = LocalMarketDataDrive.GetFileName(dataType.MessageType, dataType.Arg) + LocalMarketDataDrive.GetExtension(StorageFormats.Binary),
                            Parent = dateEntry,
                        };

                        service.Upload(entry, stream, p => { });

                        this.AddInfoLog(LocalizedStrings.Str1580Params, GetPath(entry));
                    }
                }

                if (CanProcess())
                {
                    _settings.StartFrom += TimeSpan.FromDays(1);
                    SaveSettings();
                }
            }

            if (!hasSecurities)
            {
                this.AddWarningLog(LocalizedStrings.Str2292);
                return(TimeSpan.MaxValue);
            }

            if (CanProcess())
            {
                this.AddInfoLog(LocalizedStrings.Str2300);
            }

            return(base.OnProcess());
        }
Example #9
0
 /// <summary>
 /// Removes an entry from the database
 /// </summary>
 private void Remove(BackupEntry entry)
 {
     _databaseService.DB.Delete(entry);
 }
 public void AddInstalledMod(BackupEntry entry)
 {
     this._installedModsList.Add(entry);
 }
Example #11
0
        protected override TimeSpan OnProcess()
        {
            IBackupService service;

            switch (_settings.Service)
            {
            case BackupServices.AwsS3:
                service = new AmazonS3Service(AmazonExtensions.GetEndpoint(_settings.Address), _settings.ServiceRepo, _settings.Login, _settings.Password.To <string>());
                break;

            case BackupServices.AwsGlacier:
                service = new AmazonGlacierService(AmazonExtensions.GetEndpoint(_settings.Address), _settings.ServiceRepo, _settings.Login, _settings.Password.To <string>());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var hasSecurities = false;

            this.AddInfoLog(LocalizedStrings.Str2306Params.Put(_settings.StartFrom));

            var startDate = _settings.StartFrom;
            var endDate   = DateTime.Today - TimeSpan.FromDays(_settings.Offset);

            var allDates = startDate.Range(endDate, TimeSpan.FromDays(1)).ToArray();

            var pathEntry = ToEntry(new DirectoryInfo(_settings.Drive.Path));

            IEnumerable <Tuple <Type, object> > dataTypes = new[]
            {
                Tuple.Create(typeof(ExecutionMessage), (object)ExecutionTypes.Tick),
                Tuple.Create(typeof(ExecutionMessage), (object)ExecutionTypes.OrderLog),
                Tuple.Create(typeof(ExecutionMessage), (object)ExecutionTypes.Order),
                Tuple.Create(typeof(ExecutionMessage), (object)ExecutionTypes.Trade),
                Tuple.Create(typeof(QuoteChangeMessage), (object)null),
                Tuple.Create(typeof(Level1ChangeMessage), (object)null),
                Tuple.Create(typeof(NewsMessage), (object)null)
            };

            var workingSecurities = GetWorkingSecurities().ToArray();

            foreach (var date in allDates)
            {
                foreach (var security in workingSecurities)
                {
                    hasSecurities = true;

                    if (!CanProcess())
                    {
                        break;
                    }

                    var dateEntry = new BackupEntry
                    {
                        Name   = date.ToString("yyyy_MM_dd"),
                        Parent = new BackupEntry
                        {
                            Parent = new BackupEntry
                            {
                                Name   = security.Security.Id.Substring(0, 1),
                                Parent = pathEntry
                            },
                            Name = security.Security.Id,
                        }
                    };

                    var candleTypes = _settings.Drive.GetCandleTypes(security.Security.ToSecurityId(), _settings.StorageFormat);

                    var secDataTypes = dataTypes.Concat(candleTypes.SelectMany(t => t.Item2.Select(a => Tuple.Create(t.Item1, a))));

                    foreach (var tuple in secDataTypes)
                    {
                        var storage = StorageRegistry.GetStorage(security.Security, tuple.Item1, tuple.Item2, _settings.Drive, _settings.StorageFormat);

                        var drive = storage.Drive;

                        var stream = drive.LoadStream(date);

                        if (stream == Stream.Null)
                        {
                            continue;
                        }

                        var entry = new BackupEntry
                        {
                            Name   = LocalMarketDataDrive.CreateFileName(tuple.Item1, tuple.Item2) + LocalMarketDataDrive.GetExtension(StorageFormats.Binary),
                            Parent = dateEntry,
                        };

                        service.Upload(entry, stream, p => { });

                        this.AddInfoLog(LocalizedStrings.Str1580Params, GetPath(entry));
                    }
                }

                if (CanProcess())
                {
                    _settings.StartFrom += TimeSpan.FromDays(1);
                    SaveSettings();
                }
            }

            if (!hasSecurities)
            {
                this.AddWarningLog(LocalizedStrings.Str2292);
                return(TimeSpan.MaxValue);
            }

            if (CanProcess())
            {
                this.AddInfoLog(LocalizedStrings.Str2300);
            }

            return(base.OnProcess());
        }
Example #12
0
 public BackupModel(BackupsModule module, BackupEntry backup)
 {
     // the filename has all the info to make a BackupModel
     Module = module;
     ObjectSupport.CopyData(backup, this);
 }
 public void AddInstalledMod(BackupEntry entry)
 {
     this._installedModsList.Add(entry);
 }
 public void RemoveInstalledMod(BackupEntry entry)
 {
     foreach (BackupEntry listEntry in this._installedModsList)
     {
         if (entry == listEntry)
         {
             this._installedModsList.Remove(listEntry);
             break;
         }
     }
 }