Beispiel #1
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());
        }
Beispiel #2
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());
        }