Пример #1
0
        public static async Task <List <PortfolioItem> > GetAllListings(this StockXAccount login)
        {
            List <PortfolioItem> OutputItems = new List <PortfolioItem>();
            StockXApiResult <GetPagedPortfolioItemsResponse> GetListings;

            try
            {
                GetListings = await login.GetCurrentListings(login.CustomerID.ToString(), 1);
            }
            catch (Exception ex)
            {
                AuditExtensions.CreateAudit(login.Id, "StockXApi", "GetAllListings", "Error", ex.Message, ex.StackTrace);
                return(null);
            }
            if ((int)GetListings.Code > 399 && (int)GetListings.Code < 500)
            {
                throw new NeedsVerificaitonException(login);
            }
            GetPagedPortfolioItemsResponse Items = GetListings.RO;

            if (Items.PortfolioItems.Count == 0)
            {
                return(OutputItems);
            }
            if (Items.PortfolioItems == null)
            {
                return(null);
            }
            OutputItems.AddRange(Items.PortfolioItems);
            var i = 2;

            while (Items.Pagination != null && Items.Pagination.NextPage != null)
            {
                GetListings = await login.GetCurrentListings(login.CustomerID.ToString(), i ++);

                if ((int)GetListings.Code > 399 && (int)GetListings.Code < 500)
                {
                    throw new NeedsVerificaitonException(login);
                }
                Items = GetListings.RO;
                if (Items.PortfolioItems == null || Items.PortfolioItems.Count == 0)
                {
                    break;
                }
                OutputItems.AddRange(Items.PortfolioItems);
            }
            return(OutputItems);
        }
Пример #2
0
        public static async Task <StockXApiResult <LoginCookieToken> > GetLogin(this StockXAccount stockAuth)
        {
            var tmpdr = Path.GetTempFileName();
            var Json  = Base64Encode(JsonConvert.SerializeObject(stockAuth));
            ProcessStartInfo Processstartinfo;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Processstartinfo = new ProcessStartInfo("/usr/bin/xvfb-run", $" /usr/bin/node --require ts-node/register StockLoginator.ts --BaseJson={Json} --JobID={tmpdr}   ")
                {
                    UseShellExecute = false,

                    WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory + "NodeStuff"
                };
            }
            else
            {
                string arguments = $"--require ts-node/register StockLoginator.ts --BaseJson={Json} --JobID={tmpdr} ";
                Processstartinfo = new ProcessStartInfo("node", arguments)
                {
                    UseShellExecute = true,

                    WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "NodeStuff"
                };
            }

            string jsontxt   = "";
            string outputtxt = "";

            try
            {
                var Proc = new Process
                {
                    StartInfo = Processstartinfo
                };
                Proc.Start();

                //Error = Proc.StandardError.ReadToEnd();
                //   Output = Proc.StandardOutput.ReadToEnd();
                var MaxWait = 40;
                while (!Proc.WaitForExit(5000) && MaxWait-- > 0)
                {
                    await Task.Delay(500);
                }
                if (MaxWait == 0)
                {
                    try
                    {
                        Proc.Kill();
                        AuditExtensions.CreateAudit(stockAuth.Id, "StockXApi", "GetLogin", "Killed Process");
                    }
                    catch (Exception ex)
                    {
                        AuditExtensions.CreateAudit(stockAuth.Id, "StockXApi", "GetLogin", "Error Killing Process", ex.Message, ex.StackTrace);
                    }
                }
                if (File.Exists(tmpdr + ".txt"))
                {
                    outputtxt = File.ReadAllText(tmpdr + ".txt");
                    File.Delete(tmpdr + ".txt");
                }
                if (File.Exists(tmpdr))
                {
                    jsontxt = File.ReadAllText(tmpdr);
                    File.Delete(tmpdr);
                    var settings = new JsonSerializerSettings
                    {
                        NullValueHandling     = NullValueHandling.Ignore,
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    };
                    var JsonObj = JsonConvert.DeserializeObject <LoginCookieToken>(jsontxt, settings);

                    if (JsonObj != null && JsonObj.error == null)
                    {
                        return new StockXApiResult <LoginCookieToken>()
                               {
                                   Code       = HttpStatusCode.OK,
                                   ResultText = jsontxt + outputtxt,
                                   RO         = JsonObj
                               }
                    }
                    ;
                }
                else
                {
                    using (var Db = HostContext.Resolve <IDbConnectionFactory>().Open())
                    {
                        AuditExtensions.CreateAudit(Db, stockAuth.Id, "FunBoy/GetLogin", "Login Attempt", "Login Failed: " + jsontxt + outputtxt);
                    }
                }
                return(new StockXApiResult <LoginCookieToken>()
                {
                    Code = HttpStatusCode.Ambiguous,
                    ResultText = jsontxt + outputtxt + tmpdr,
                });
            }
            catch (Exception ex)
            {
                using (var Db = HostContext.Resolve <IDbConnectionFactory>().Open())
                {
                    AuditExtensions.CreateAudit(Db, stockAuth.Id, "FunBoy/GetLogin", "Login Attempt", "Login Failed: " + jsontxt + outputtxt, ex.Message, ex.StackTrace);
                }
                return(new StockXApiResult <LoginCookieToken>()
                {
                    Code = HttpStatusCode.InternalServerError,
                    ResultText = AppDomain.CurrentDomain.BaseDirectory + "NodeStuff" + ex.Message + ex.StackTrace + outputtxt + jsontxt + tmpdr,
                });
            }
        }