Esempio n. 1
0
        private void UpdateChartsOfOwner(IContainerOwner owner)
        {
            InformationContext.Current.Owner = owner;
            var inputCollection = InformationInputCollection.RetrieveFromOwnerContent(owner, "MasterCollection");

            if (inputCollection == null || inputCollection.CollectionContent == null)
            {
                return;
            }
            var input = inputCollection.CollectionContent.FirstOrDefault(x => x.LocationURL.Contains("table.csv"));

            if (input == null)
            {
                return;
            }
            var coll = StockCompanyCollection.RetrieveFromOwnerContent(InformationContext.Current.Owner, "default");

            foreach (var company in coll.CollectionContent)
            {
                try
                {
                    FetchInputInformation.Execute(new FetchInputInformationParameters
                    {
                        InformationInputID = input.ID,
                        Owner           = owner,
                        QueryParameters = GetChartInputParameters(company.Symbol, 'd', DateTime.Now.AddMonths(-1))
                    });
                    ProcessFetchedInputs.Execute(new ProcessFetchedInputsParameters
                    {
                        InformationInputID = input.ID,
                        Owner = owner,
                        ProcessingOperationName = "UpdateChart_Days;" + company.ID,
                    });
                    FetchInputInformation.Execute(new FetchInputInformationParameters
                    {
                        InformationInputID = input.ID,
                        Owner           = owner,
                        QueryParameters = GetChartInputParameters(company.Symbol, 'w', DateTime.Now.AddYears(-1))
                    });
                    ProcessFetchedInputs.Execute(new ProcessFetchedInputsParameters
                    {
                        InformationInputID = input.ID,
                        Owner = owner,
                        ProcessingOperationName = "UpdateChart_Months;" + company.ID,
                    });
                    FetchInputInformation.Execute(new FetchInputInformationParameters
                    {
                        InformationInputID = input.ID,
                        Owner           = owner,
                        QueryParameters = GetChartInputParameters(company.Symbol, 'm', DateTime.Now.AddYears(-5))
                    });
                    ProcessFetchedInputs.Execute(new ProcessFetchedInputsParameters
                    {
                        InformationInputID = input.ID,
                        Owner = owner,
                        ProcessingOperationName = "UpdateChart_Years;" + company.ID,
                    });
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Updating charts for " + company.Symbol + " failed. " + ex.Message);
                }
            }
        }
Esempio n. 2
0
        private void RefreshStockCompaniesOfOwner(IContainerOwner owner)
        {
            InformationContext.Current.Owner = owner;
            var inputCollection = InformationInputCollection.RetrieveFromOwnerContent(owner, "MasterCollection");

            if (inputCollection == null || inputCollection.CollectionContent == null)
            {
                return;
            }
            var coll = StockCompanyCollection.RetrieveFromOwnerContent(owner, "default");

            if (coll == null)
            {
                coll = new StockCompanyCollection();
                if (coll.CollectionContent == null)
                {
                    coll.CollectionContent = new List <StockCompany>();
                }
                coll.SetLocationAsOwnerContent(owner, "default");
                coll.StoreInformation();
            }
            if (coll.CollectionContent.Count < 10)
            {
                var input = inputCollection.CollectionContent.FirstOrDefault(x => x.LocationURL.Contains("Lookup"));
                if (input == null)
                {
                    return;
                }
                //Load the stock companies
                var letters = new[]
                {
                    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
                    'U', 'V', 'W', 'X', 'Y', 'Z'
                };
                foreach (var letter in letters)
                {
                    FetchInputInformation.Execute(new FetchInputInformationParameters
                    {
                        InformationInputID = input.ID,
                        Owner           = owner,
                        QueryParameters = "?input=" + letter
                    });
                    ProcessFetchedInputs.Execute(new ProcessFetchedInputsParameters
                    {
                        InformationInputID = input.ID,
                        Owner = owner,
                        ProcessingOperationName = "AddNewStockCompanies"
                    });
                }
            }
            else
            {
                var input = inputCollection.CollectionContent.FirstOrDefault(x => x.LocationURL.Contains("quotes.csv"));
                if (input == null)
                {
                    return;
                }
                foreach (var group in coll.CollectionContent.Select((x, i) => new { Index = i, Value = x })
                         .GroupBy(x => x.Index / 190))
                {
                    var parameters = new StringBuilder("?s=");
                    parameters = group.Aggregate(parameters,
                                                 (current, stockCompany) => current.Append(stockCompany.Value.Symbol + ","));
                    parameters = parameters.Remove(parameters.Length - 1, 1);
                    parameters.Append("&d=t&f=snl1ohgc1p2m5m6v");
                    FetchInputInformation.Execute(new FetchInputInformationParameters
                    {
                        InformationInputID = input.ID,
                        Owner           = owner,
                        QueryParameters = parameters.ToString()
                    });
                    ProcessFetchedInputs.Execute(new ProcessFetchedInputsParameters
                    {
                        InformationInputID = input.ID,
                        Owner = owner,
                        ProcessingOperationName = "UpdateStockCompanies"
                    });
                }
            }
        }