public bool StartImport(TimeSeriesImporterParams impParams)
        {
            if (CurrentState == EImportState.Idle)
            {
                _tickersProcessed.Clear();
                _isRunning = true;
                _impParams = impParams;

                _importStart = DateTime.UtcNow;
                _errorsLog.Clear();

                _importTask = new Task(ImportThread);
                _importTask.Start();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        public object Any(ForceRunImportTimeSeries request)
        {
            _logger.Log(EErrorType.Info, " ****** Call start: ForceRunImport");

            ForceRunImportResponse response = new ForceRunImportResponse();

            try
            {
                TransferHeader(request, response);

                if (IsValidSessionToken(request))
                {
                    if (Global.Importer.CurrentState == TimeSeriesImporter.EImportState.Idle)
                    {
                        string sCompanies = string.Empty;

                        // preparing parameters for import
                        TimeSeriesImporterParams impParams = new TimeSeriesImporterParams();
                        if (request.DaysBack != null)
                        {
                            impParams.DateEnd   = DateTime.UtcNow;
                            impParams.DateStart = impParams.DateEnd - TimeSpan.FromDays((double)request.DaysBack);
                        }
                        else
                        {
                            impParams.DateStart = request.DateStart != null ? (DateTime)request.DateStart : DateTime.Parse(ConfigurationManager.AppSettings["UpdateFromDate"]);
                            impParams.DateEnd   = request.DateEnd != null ? (DateTime)request.DateEnd : DateTime.UtcNow;
                        }
                        impParams.Tickers    = request.SymbolCodes != null ? new System.Collections.Generic.HashSet <string>(request.SymbolCodes) : null;
                        impParams.TimeFrame  = request.Timeframe ?? ETimeFrame.Daily;
                        impParams.AgencyCode = request.AgencyCode;


                        // starting import process
                        response.Success = Global.Importer.StartImport(impParams);
                    }
                    else
                    {
                        response.Errors.Add(new Interfaces.Error()
                        {
                            Code = Interfaces.EErrorCodes.ImporterBusy, Type = Interfaces.EErrorType.Error, Message = string.Format("Importing is running, current state - {0}", Global.Importer.CurrentState)
                        });
                        response.Success = false;
                    }
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.InvalidSession, Type = EErrorType.Error, Message = "Invalid session token"
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code    = EErrorCodes.GeneralError,
                    Type    = EErrorType.Error,
                    Message = string.Format("Unpexcted error: {0}", ex.Message)
                });
            }

            _logger.Log(EErrorType.Info, " ****** Call end: ForceRunImport");

            return(response);
        }