Exemplo n.º 1
0
        /// <summary>
        /// Adds error to our Errors list by error code.
        /// </summary>
        /// <param name="code"></param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public ErrorResponse AddError(EErrorCodes code)
        {
            var errorMessage = messages.GetErrorMessage(code);

            this.Errors.Add(new Error((int)code, errorMessage));

            return(this);
        }
        public object Any(GetRegulators request)
        {
            DateTime dtStart = DateTime.UtcNow;

            _logger.Log(EErrorType.Info, " ****** Call start: GetRegulators");
            GetRegulatorsResponse response = new GetRegulatorsResponse();

            TransferHeader(request, response);

            _logger.Log(EErrorType.Info, string.Format("ValidateSession({0})", request.SessionToken));

            EErrorCodes valSession = ValidateSession(request.SessionToken);

            if (valSession == EErrorCodes.Success)
            {
                try
                {
                    var regulators = _dal.GetRegulators();;

                    foreach (var reg in regulators.Regulators)
                    {
                        DTO.RegulatorInfo regulatorInfo = new DTO.RegulatorInfo()
                        {
                            Name        = reg.Name,
                            Code        = reg.Code,
                            CountryCode = reg.CountryCode
                        };

                        response.Payload.Regulators.Add(regulatorInfo);
                    }

                    response.Success = true;
                }
                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)
                    });
                }
            }
            else
            {
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code = valSession, Type = EErrorType.Error, Message = string.Format("Invalid session")
                });
            }

            DateTime dtEnd = DateTime.UtcNow;

            _logger.Log(EErrorType.Info, string.Format(" ****** Call end: GetRegulators\tTime: {0}", dtEnd - dtStart));

            return(response);
        }
Exemplo n.º 3
0
        public void CloseSession_Success()
        {
            var         client = CreateClient();
            EErrorCodes result = client.InitSession(_host, _accountKey);

            result = client.CloseSession();

            Assert.IsTrue(result == EErrorCodes.Success);
        }
        public string GetErrorMsg(EErrorCodes eError)
        {
            if (m_vErrMsg == null)
            {
                Init();
            }

            return(m_vErrMsg.ContainsKey(eError) ? m_vErrMsg[eError] : String.Empty);
        }
Exemplo n.º 5
0
        public static ISimplygon InitSimplygon(out EErrorCodes errorCode, out string errorMessage)
        {
            string sdkPath = GetSDKPath();

            errorCode    = 0;
            errorMessage = string.Empty;

            if (string.IsNullOrEmpty(sdkPath))
            {
                errorCode    = EErrorCodes.DLLOrDependenciesNotFound;
                errorMessage = "Simplygon.dll not found";
                return(null);
            }

            try
            {
                var simplygon = Simplygon.InitializeSimplygon(sdkPath);
                errorCode = Simplygon.GetLastInitializationError();
                if (errorCode != EErrorCodes.NoError)
                {
                    throw new Exception(string.Format("Failed to load Simplygon from {0}\nErrorCode: {1}", sdkPath, errorCode));
                }
                return(simplygon);
            }
            catch (NotSupportedException ex)
            {
                errorCode = EErrorCodes.AlreadyInitialized;

                string exceptionMessage = string.Format($"Failed to load Simplygon from {sdkPath}\nErrorCode: {errorCode}\nMessage: {ex.Message}");
                Console.Error.WriteLine(exceptionMessage);

                errorMessage = exceptionMessage;
            }
            catch (SEHException ex)
            {
                string exceptionMessage = string.Format($"Failed to load Simplygon from {sdkPath}\nErrorCode: {errorCode}\nMessage: {ex.Message}");
                Console.Error.WriteLine(exceptionMessage);

                errorCode    = EErrorCodes.DLLOrDependenciesNotFound;
                errorMessage = exceptionMessage;
            }
            catch (Exception ex)
            {
                errorCode    = EErrorCodes.DLLOrDependenciesNotFound;
                errorMessage = ex.Message;
                Console.Error.WriteLine(errorMessage);
            }
            finally
            {
                if (errorCode != 0)
                {
                    string errorMessageEx = string.Format("Failed to load Simplygon from {0}\nErrorCode: {1}", sdkPath, errorCode);
                    Console.Error.WriteLine(errorMessageEx);
                }
            }
            return(null);
        }
Exemplo n.º 6
0
        public ErrorResponse AddError(EErrorCodes code, string additionalDetails)
        {
            var errorMessage = messages.GetErrorMessage(code);
            var error        = new Error((int)code, errorMessage, additionalDetails);

            this.Errors.Add(error);

            return(this);
        }
Exemplo n.º 7
0
        public void AddError(EErrorCodes code, EErrorType type, string message)
        {
            Error err = new Error()
            {
                Code = code, Message = message, Type = type
            };

            AddError(err);
        }
Exemplo n.º 8
0
 public ErrorContext(EErrorCodes a_iErrc, int a_iPos, string a_sIdent, char cType1, char cType2, int nArg)
 {
     Expr  = "";
     Ident = a_sIdent;
     Hint  = "";
     Errc  = a_iErrc;
     Type1 = cType1;
     Type2 = cType2;
     Arg   = nArg;
     Pos   = a_iPos;
 }
Exemplo n.º 9
0
 public string GetErrorMsg(EErrorCodes eError)
 {
     if (m_pInstance == null)
     {
         return("");
     }
     else
     {
         return(m_pInstance.GetErrorMsg(eError));
     }
 }
Exemplo n.º 10
0
        public string GetErrorMessage(EErrorCodes errorCode)
        {
            string error = this.errorCodes[errorCode];

            if (string.IsNullOrEmpty(error))
            {
                throw new System.Exception("Could not find error");
            }

            return(error);
        }
Exemplo n.º 11
0
 // Used by by DefineVar and DefineConst methods
 // for better checking of var//oprt/fun existence.
 private void CheckForEntityExistence(string ident, EErrorCodes error_code)
 {
     if (IsVarDefined(ident) ||
         IsConstDefined(ident) ||
         IsFunDefined(ident) ||
         IsOprtDefined(ident) ||
         IsPostfixOprtDefined(ident) ||
         IsInfixOprtDefined(ident))
     {
         throw new ParserError(new ErrorContext(error_code, 0, ident));
     }
 }
Exemplo n.º 12
0
 private ParserError Error(EErrorCodes code, string ident   = "", bool isLen = false,
                           [CallerFilePath] string file     = "",
                           [CallerMemberName] string member = "",
                           [CallerLineNumber] int line      = 0)
 {
     return(new ParserError(
                new ErrorContext
     {
         Errc = code,
         Ident = ident,
         Expr = m_sExpr,
         Pos = isLen ? m_nPos - m_sExpr.Length : m_nPos
     }, null, file, member, line));
 }
Exemplo n.º 13
0
        private EErrorCodes ValidateSession(string sessionToken)
        {
            EErrorCodes result = EErrorCodes.InvalidSession;


            if (sessionToken == ConfigurationManager.AppSettings["ServiceSessionToken"])
            {
                result = EErrorCodes.Success;
            }
            else
            {
                eventRespReceived = new AutoResetEvent(false); // this event will be raised when response received

                sinfo = new GetSessionInfo();
                sinfo.SessionToken = sessionToken;
                sinfo.CheckActive  = true;


                int waitTimeout = Int32.Parse(ConfigurationManager.AppSettings["MQWaitTimeout"]);
                // sending message to queue
                string payload = JsonSerializer.SerializeToString(sinfo);
                string type    = "GetSessionInfo";

                Global.MQClient.NewChannelMessages += NewMessagesHandlerSender;
                Global.MQClient.Push(Global.AccountsChannel, type, payload);

                _logger.Log(EErrorType.Info, string.Format("GetSessionInfo: {0}", sinfo.RequestID));

                // receiving message
                eventRespReceived.WaitOne(waitTimeout);
                Global.MQClient.NewChannelMessages -= NewMessagesHandlerSender;

                if (sinfoResponse != null)
                {
                    if (!sinfoResponse.Success)
                    {
                        _logger.Log(EErrorType.Warning, string.Format("sinfoResponse error: {0}, {1}", sinfo.RequestID, sinfoResponse.Errors[0].Code));
                    }
                    result = sinfoResponse.Success ? EErrorCodes.Success : sinfoResponse.Errors[0].Code;
                }
                else
                {
                    _logger.Log(EErrorType.Warning, string.Format("MQCommunicationError: {0}", sinfo.RequestID));
                    result = EErrorCodes.MQCommunicationError;
                }
            }

            return(result);
        }
        public EErrorCodes GetTimeSeriesInfo(string country, string ticker)
        {
            EErrorCodes result = EErrorCodes.GeneralError;

            try
            {
                if (Client != null && SessionToken != null)
                {
                    GetTimeSeriesInfo reqGetTSInfo = new GetTimeSeriesInfo();
                    reqGetTSInfo.SessionToken = SessionToken;
                    reqGetTSInfo.Ticker       = ticker;
                    reqGetTSInfo.CountryCode  = country;

                    GetTimeSeriesInfoResponse resGetTSInfo = Post <GetTimeSeriesInfo, GetTimeSeriesInfoResponse>("/api/timeseries/GetTimeSeriesInfo", reqGetTSInfo);
                    if (resGetTSInfo.Success)
                    {
                        IndicatorData indData = null;
                        if (!Indicators.TryGetValue(ticker, out indData))
                        {
                            indData      = new IndicatorData();
                            indData.Name = resGetTSInfo.Payload.Name;
                            indData.Code = resGetTSInfo.Payload.Ticker;
                            Indicators.Add(ticker, indData);
                        }

                        indData.SetColumns(resGetTSInfo.Payload.Columns);

                        result = EErrorCodes.Success;
                    }
                    else
                    {
                        result = resGetTSInfo.Errors[0].Code;
                    }
                }
                else
                {
                    return(EErrorCodes.SessionClosed);
                }
            }
            catch (Exception ex)
            {
                _lastError = ex;
                result     = EErrorCodes.GeneralError;
            }

            return(result);
        }
Exemplo n.º 15
0
        private SubmissionFile LoadFromStorage(string regulatorCode, string companyCode, string filingName, string name)
        {
            SubmissionFile file = null;

            if (_storage != null)
            {
                List <byte> content = new List <byte>();
                EErrorCodes loadRes = _storage.Load(regulatorCode, companyCode, filingName, name, content);
                if (loadRes == EErrorCodes.Success)
                {
                    file         = new SubmissionFile(name);
                    file.Content = content;
                }
            }

            return(file);
        }
        public EErrorCodes InitSession(string host, string accountKey)
        {
            EErrorCodes result = EErrorCodes.GeneralError;

            try
            {
                if (Client == null)
                {
                    Host   = host;
                    Client = new JsonServiceClient(Host);
                }

                if (SessionToken == null || AccountKey != accountKey)
                {
                    AccountKey = accountKey;
                    InitSession reqInit = new InitSession();
                    reqInit.RequestID  = System.Guid.NewGuid().ToString();
                    reqInit.AccountKey = AccountKey;

                    InitSessionResponse resInit = Post <InitSession, InitSessionResponse>("/api/accounts/InitSession", reqInit);

                    if (resInit.Success)
                    {
                        SessionToken = resInit.SessionToken;
                        Indicators   = new Dictionary <string, IndicatorData>();
                        result       = EErrorCodes.Success;
                    }
                    else
                    {
                        result = resInit.Errors[0].Code;
                    }
                }
                else
                {
                    return(EErrorCodes.Success);
                }
            }
            catch (Exception ex)
            {
                _lastError = ex;
                result     = EErrorCodes.GeneralError;
            }

            return(result);
        }
Exemplo n.º 17
0
        private EErrorCodes ValidateSession(string sessionToken)
        {
            EErrorCodes result = EErrorCodes.InvalidSession;

            if (sessionToken == ConfigurationManager.AppSettings["ServiceSessionToken"])
            {
                result = EErrorCodes.Success;
            }
            else
            {
                GetSessionInfo sinfo = new GetSessionInfo();
                sinfo.SessionToken = sessionToken;
                sinfo.CheckActive  = true;

                DMFX.Client.Accounts.ServiceClient accnts    = new Client.Accounts.ServiceClient();
                GetSessionInfoResponse             sInfoResp = accnts.PostGetSessionInfo(sinfo);

                result = sInfoResp.Success ? EErrorCodes.Success : sInfoResp.Errors[0].Code;
            }

            return(result);
        }
        public EErrorCodes CloseSession()
        {
            EErrorCodes result = EErrorCodes.GeneralError;

            try
            {
                if (SessionToken != null)
                {
                    CloseSession reqInit = new CloseSession();
                    reqInit.RequestID    = System.Guid.NewGuid().ToString();
                    reqInit.SessionToken = SessionToken;

                    CloseSessionResponse resInit = Post <CloseSession, CloseSessionResponse>("/api/accounts/CloseSession", reqInit);

                    if (resInit.Success)
                    {
                        SessionToken = null;
                        result       = EErrorCodes.Success;
                    }
                    else
                    {
                        result = resInit.Errors[0].Code;
                    }
                }
                else
                {
                    result = EErrorCodes.Success;
                }
            }
            catch (Exception ex)
            {
                _lastError = ex;
                result     = EErrorCodes.GeneralError;
            }

            return(result);
        }
Exemplo n.º 19
0
 [DataRow("a+0x", EErrorCodes.ecUNASSIGNABLE_TOKEN)] // incomplete hex value
 public void test_value_recognition(string s, EErrorCodes e) => Tester.ThrowTest(s, e);
Exemplo n.º 20
0
 public void test_missing_params(string s, EErrorCodes e) => Tester.ThrowTest(s, e);
        protected override void Initialize()
        {
            try
            {
                Print("Initialize");

                _cotCode = COTCode;
                _ticker  = DMFX.Constants.GetTicker(COTCode);

                Print(_ticker);

                EErrorCodes result = EErrorCodes.Success;

                if (_dmfxClient == null)
                {
                    _dmfxClient = new DMFXClient();
                }

                result = _dmfxClient.InitSession(Host, AccountKey);


                if (result == EErrorCodes.Success)
                {
                    Print("InitSession OK");

                    result = _dmfxClient.GetTimeSeriesInfo(_country, _ticker);
                    if (result == EErrorCodes.Success)
                    {
                        Print("GetTimeSeriesInfo OK");

                        DateTime periodStart = DateTime.UtcNow - TimeSpan.FromDays(Math.Max(WeeksBack, 52) * 7);
                        DateTime periodEnd   = DateTime.UtcNow;

                        result = _dmfxClient.GetTimeSeries(_country, _ticker, ETimeFrame.Weekly, periodStart, periodEnd);

                        if (result == EErrorCodes.Success)
                        {
                            Print("GetTimeSeries - data loaded OK");
                        }
                        else
                        {
                            Print("GetTimeSeries failed: " + result);
                            Exception ex = _dmfxClient.GetLastError();
                            if (ex != null)
                            {
                                Print("LastError:" + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        Print("GetTimeSeriesInfo failed: " + result);
                        Exception ex = _dmfxClient.GetLastError();
                        if (ex != null)
                        {
                            Print("LastError:" + ex.Message);
                        }
                    }
                }
                else
                {
                    Print("InitSession failed: " + result);
                    Exception ex = _dmfxClient.GetLastError();
                    if (ex != null)
                    {
                        Print("LastError:" + ex.Message);
                    }
                }
            } catch (Exception ex)
            {
                Print("Error in Initialize(): " + ex.Message);
            }
        }
Exemplo n.º 22
0
 public void test_unassignable_token(string s, EErrorCodes e) => Tester.ThrowTest(s, e);
Exemplo n.º 23
0
 public void test_unexpected_parens(string s, EErrorCodes e) => Tester.ThrowTest(s, e);
Exemplo n.º 24
0
 public void test_unexpected_end_of_expression(string s, EErrorCodes e) => Tester.ThrowTest(s, e);
Exemplo n.º 25
0
 public void test_binary_op_type_conflicts(string s, EErrorCodes e, int i) => Tester.ThrowTest(s, e, i);
Exemplo n.º 26
0
 public void test_invalid_unary_operator_arguments(string s, EErrorCodes e, int p) => Tester.ThrowTest(s, e, p);
Exemplo n.º 27
0
 public void test_invalid_function_arguments(string s, EErrorCodes e, int i) => Tester.ThrowTest(s, e, i);
Exemplo n.º 28
0
 public void test_index_out_of_bounds(string s, EErrorCodes e) => Tester.ThrowTest(s, e);
Exemplo n.º 29
0
 public void test_error_detection(string s, EErrorCodes e) => Tester.ThrowTest(s, e);
Exemplo n.º 30
0
 public void test_basic_error_throwing(string s, EErrorCodes e) => Tester.ThrowTest(s, e);