public void IsValidTimePeriod_IsValid_InRange()
        {
            var          dateTime   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 9, 5, 0);
            const string timePeriod = "08:00-22:00";

            Assert.True(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
        public void IsValidTimePeriod_IsInValid()
        {
            var          dateTime   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 51, 0);
            const string timePeriod = "00:00-23:50";

            Assert.False(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
Esempio n. 3
0
        private static async Task Run(ILogger logger, TimeSpan interval, string timePeriod, Executor executor,
                                      CancellationToken cancel)
        {
            try
            {
                while (!cancel.IsCancellationRequested)
                {
                    // In valid time period?
                    var currentState = Interlocked.CompareExchange(ref _lockState, SqlConfig.Locked, SqlConfig.Available);
                    if (TimePeriodHelper.IsValidTimePeriod(DateTime.Now, timePeriod) &&
                        currentState == SqlConfig.Available)
                    {
                        await executor.Start();
                    }

                    // ReSharper disable once RedundantAssignment
                    currentState = Interlocked.CompareExchange(ref _lockState, SqlConfig.Available, SqlConfig.Locked);
                    await Task.Delay(interval, cancel);
                }
            }
            catch (OperationCanceledException)
            {
                logger.Information("The executor task was canceled.");
            }
            catch (Exception ex)
            {
                logger.Fatal(ex, "The executor task threw an unhandled exception.");
            }
        }
        public void IsValidTimePeriod_IsValid_OnPoint()
        {
            var          dateTime   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 22, 0, 0);
            const string timePeriod = "10:00-22:00";

            Assert.True(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
Esempio n. 5
0
        public void GetTimePeriod_WithKnownDateTime_ReturnsCorrectPeriodId(string period1, string period2, int expectedPeriodIdDiff)
        {
            var result1 = TimePeriodHelper.GetTimePeriod(DateTime.Parse(period1), (60 * 60));
            var result2 = TimePeriodHelper.GetTimePeriod(DateTime.Parse(period2), (60 * 60));

            Assert.AreEqual(expectedPeriodIdDiff, result2.PeriodId - result1.PeriodId);
        }
Esempio n. 6
0
        public void Start(TextWriter inputWriter)
        {
            var settingsFileInfo = new FileInfo(Path.Combine(App.StoragePath, "lastScan.txt"));
            var query            = $"SELECT * FROM {TableOrViewName}";
            var stringBuilder    = new SqlConnectionStringBuilder()
            {
                DataSource     = ServerInstance,
                InitialCatalog = InitialCatalog
            };

            if (IntegratedSecurity)
            {
                stringBuilder.IntegratedSecurity = true;
            }
            else
            {
                stringBuilder.UserID   = DatabaseUsername;
                stringBuilder.Password = DatabasePassword;
            }

            if (!TimePeriodHelper.IsStringValid(TimePeriod))
            {
                Log.Warning("Defined TimePeriod {TimePeriod} is not valid. Use default {DefaultValue}.", TimePeriod, DefaultTimePeriod);
                TimePeriod = DefaultTimePeriod;
            }

            var executor = new Executor(Log, inputWriter, settingsFileInfo, stringBuilder.ToString(), query, AdditionalFilterClause, ColumnNameTimeStamp, ColumnNameMessage, ColumnNamesInclude, ApplicationName, LogEventLevel);

            _executorTask = new ExecutorTask(Log, TimeSpan.FromSeconds(QueryEverySeconds), TimePeriod, executor);
        }
        public void GivenIAddTheTimePeriodParametersforDaysStartingTomorrowWithStartEndPrefix(int days, string startDatePrefix, string endDatePrefix)
        {
            var val = TimePeriodHelper.GetTimePeriodStartDateTomorrowEndDateDays(days);

            Given($"I add the parameter \"start\" with the value \"{startDatePrefix}{val.Start}\"");
            Given($"I add the parameter \"end\" with the value \"{endDatePrefix}{val.End}\"");
        }
Esempio n. 8
0
        /// <summary>
        /// Returns the Index view
        /// </summary>
        /// <param name="Period">Text representation of the date time period. eg: Today, Yesterday, Last Week etc.</param>
        /// <param name="LoggerProviderName">Elmah, Log4Net, NLog, Health Monitoring etc</param>
        /// <param name="LogLevel">Debug, Info, Warning, Error, Fatal</param>
        /// <param name="page">The current page index (0 based)</param>
        /// <param name="PageSize">The number of records per page</param>
        /// <returns></returns>
        public ActionResult Index(string Period, string LoggerProviderName, string LogLevel, int?page, int?PageSize)
        {
            // Set up our default values
            string defaultPeriod   = Session["Period"] == null ? "Today" : Session["Period"].ToString();
            string defaultLogType  = Session["LoggerProviderName"] == null ? "All" : Session["LoggerProviderName"].ToString();
            string defaultLogLevel = Session["LogLevel"] == null ? "Error" : Session["LogLevel"].ToString();

            // Set up our view model
            LoggingIndexModel model = new LoggingIndexModel();

            model.Period             = (Period == null) ? defaultPeriod : Period;
            model.LoggerProviderName = (LoggerProviderName == null) ? defaultLogType : LoggerProviderName;
            model.LogLevel           = (LogLevel == null) ? defaultLogLevel : LogLevel;
            model.CurrentPageIndex   = page.HasValue ? page.Value - 1 : 0;
            model.PageSize           = PageSize.HasValue ? PageSize.Value : 20;

            TimePeriod timePeriod = TimePeriodHelper.GetUtcTimePeriod(model.Period);

            // Grab the data from the database
            model.LogEvents = loggingRepository.GetByDateRangeAndType(model.CurrentPageIndex, model.PageSize, timePeriod.Start, timePeriod.End, model.LoggerProviderName, model.LogLevel);

            // Put this into the ViewModel so our Pager can get at these values
            ViewData["Period"]             = model.Period;
            ViewData["LoggerProviderName"] = model.LoggerProviderName;
            ViewData["LogLevel"]           = model.LogLevel;
            ViewData["PageSize"]           = model.PageSize;

            // Put the info into the Session so that when we browse away from the page and come back that the last settings are rememberd and used.
            Session["Period"]             = model.Period;
            Session["LoggerProviderName"] = model.LoggerProviderName;
            Session["LogLevel"]           = model.LogLevel;

            return(View(model));
        }
        public void GivenIAddTheTimePeriodParametersforDaysStartingToday(int days)
        {
            var val = TimePeriodHelper.GetTimePeriodStartDateTodayEndDateDays(days);

            Given($"I add the parameter \"start\" with the value \"{val.Start}\"");
            Given($"I add the parameter \"end\" with the value \"{val.End}\"");
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Period"></param>
        /// <param name="LoggerProviderName"></param>
        /// <param name="LogLevel"></param>
        /// <returns></returns>
        public FeedResult RssFeed(string Period, string LoggerProviderName, string LogLevel)
        {
            string defaultPeriod             = Session["Period"] == null ? "This Week" : Session["Period"].ToString();
            string defaultLoggerProviderName = Session["LoggerProviderName"] == null ? "All" : Session["LoggerProviderName"].ToString();
            string defaultLogLevel           = Session["LogLevel"] == null ? "Error" : Session["LogLevel"].ToString();

            Period             = (Period == null) ? defaultPeriod : Period;
            LoggerProviderName = (LoggerProviderName == null) ? defaultLoggerProviderName : LoggerProviderName;
            LogLevel           = (LogLevel == null) ? defaultLogLevel : LogLevel;

            TimePeriod timePeriod = TimePeriodHelper.GetUtcTimePeriod(Period);

            // Grab ALL entries for the feed (DO NOT PAGE feed DATA!!!)
            IPagedList <LogEvent> chartEntries = loggingRepository.GetByDateRangeAndType(0, Int32.MaxValue, timePeriod.Start, timePeriod.End, LoggerProviderName, LogLevel);

            var postItems = chartEntries.Select(p => new SyndicationItem(string.Format("{0} - {1} - {2}", p.LogDate, p.Level, p.LoggerProviderName), p.Message, new Uri(Url.AbsoluteAction("Details", new { LoggerProviderName = p.LoggerProviderName, Id = p.Id }))));

            Uri feedAlternateLink = Url.ActionFull("Index", "Logging");

            var feed = new SyndicationFeed("MVC Logging Demo -> Log Reporting", string.Format("Log Provider: {0}, Log Level : {1}, From {2} to {3} ({4})", LoggerProviderName, LogLevel, timePeriod.Start.ToShortDateString(), timePeriod.End.ToShortDateString(), Period), feedAlternateLink, postItems)
            {
                Language = "en-US"
            };

            return(new FeedResult(new Rss20FeedFormatter(feed)));
        }
Esempio n. 11
0
        public void GetTimePeriod_WithKnownDateTime_ReturnsCorrectPeriodId()
        {
            var result1 = TimePeriodHelper.GetTimePeriod(DateTime.Parse("01 January 2013 03:14:23"), (60 * 60));
            var result2 = TimePeriodHelper.GetTimePeriod(DateTime.Parse("01 January 2013 04:44:23"), (60 * 60));

            Assert.AreEqual(1, result2 - result1);
        }
        public void IsValidTimePeriod_IsValid_InRange()
        {
            var dateTime   = new DateTime(2020, 1, 22, 9, 5, 0);
            var timePeriod = "08:00-22:00";

            Assert.True(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
        public void IsValidTimePeriod_IsInValid()
        {
            var dateTime   = new DateTime(2020, 1, 22, 23, 51, 0);
            var timePeriod = "00:00-23:50";

            Assert.False(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
        public void IsValidTimePeriod_IsValid_OnPoint()
        {
            var dateTime   = new DateTime(2020, 1, 22, 22, 0, 0);
            var timePeriod = "10:00-22:00";

            Assert.True(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
        public void GivenIAddTheStartTimePeriodParametersforDaysStartingTodayUsingThePrefixes(int days, string startDatePrefix, string endDatePrefix, string startDateFormat, string endDateFormat)
        {
            var val = TimePeriodHelper.GetTimePeriodStartDateFormatEndDateFormat(startDateFormat, endDateFormat, days);

            Given($"I add the parameter \"start\" with the value \"{startDatePrefix}{val.Start}\"");
            Given($"I add the parameter \"start\" with the value \"{endDatePrefix}{val.End}\"");
        }
        public void GivenIAddTheTimePeriodParametersforDaysStartingTodayWithStartEndFormats(int days, string startFormat, string endFormat)
        {
            var val = TimePeriodHelper.GetTimePeriodStartDateFormatEndDateFormat(startFormat, endFormat, days);


            Given($"I add the parameter \"start\" with the value \"{FhirConst.Prefixs.kGreaterThanOrEqualTo}{val.Start}\"");
            Given($"I add the parameter \"end\" with the value \"{FhirConst.Prefixs.kLessThanOrEqualTo}{val.End}\"");
        }
        public void IAddTheMedicationsDatePeriodPartParameter()
        {
            ParameterComponent param = new ParameterComponent();

            param.Name  = FhirConst.GetStructuredRecordParams.kMedicationDatePeriod;
            param.Value = TimePeriodHelper.GetTimePeriodFormatted("yyyy-MM-dd");
            _httpContext.HttpRequestConfiguration.BodyParameters.Parameter.Add(param);
        }
Esempio n. 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Period"></param>
        /// <param name="LoggerProviderName"></param>
        /// <param name="logLevel"></param>
        /// <param name="keyFormatString"></param>
        /// <param name="groupByClause"></param>
        /// <returns></returns>
        public JsonResult ChartDataByTimePeriod(string Period, string LoggerProviderName, string logLevel, string keyFormatString, Func <LogEvent, Object> groupByClause)
        {
            TimePeriod timePeriod = TimePeriodHelper.GetUtcTimePeriod(Period);

            // Grab ALL entries for the chart (DO NOT PAGE REPORTING DATA!!!)
            IPagedList <LogEvent> chartEntries = loggingRepository.GetByDateRangeAndType(0, Int32.MaxValue, timePeriod.Start, timePeriod.End, LoggerProviderName, logLevel);

            var groupedByDate = chartEntries.GroupBy(groupByClause).OrderBy(y => y.Key);

            var groupedByDateAndThenName = groupedByDate.Select(group => new { Key = group.Key, NestedGroup = group.ToLookup(result => result.LoggerProviderName, result => result.Id) });

            var LoggerNames = (from logEvent in chartEntries
                               select new { Name = logEvent.LoggerProviderName }
                               ).Distinct().OrderBy(item => item.Name);

            ChartData chartData = new ChartData();

            // Add columns
            chartData.AddColumn(new ChartColumn("0", "Period", "string"));
            int columnIndex = 1;

            foreach (var name in LoggerNames)
            {
                chartData.AddColumn(new ChartColumn(columnIndex.ToString(), name.Name.ToString(), "number"));
                columnIndex++;
            }

            // add row data
            foreach (var myDate in groupedByDateAndThenName)
            {
                ChartRow row = new ChartRow();

                string dateString = (myDate.Key is DateTime) ? ((DateTime)myDate.Key).ToString(keyFormatString) : myDate.Key.ToString();
                row.AddCellItem(new ChartCellItem(dateString, ""));

                foreach (var name in LoggerNames)
                {
                    bool valueFound = false;
                    foreach (var myLogger in myDate.NestedGroup)
                    {
                        if (myLogger.Key == name.Name.ToString())
                        {
                            row.AddCellItem(new ChartCellItem(myLogger.Count(), ""));
                            valueFound = true;
                        }
                    }
                    if (!valueFound)
                    {
                        row.AddCellItem(new ChartCellItem(0, ""));
                    }
                }

                chartData.AddRow(row);
            }

            return(Json(chartData, "text/x-json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet));
        }
        public void GivenIAddTheAllergiesParameterWithAnEndPeriod()
        {
            IEnumerable <Tuple <string, Base> > tuples = new Tuple <string, Base>[] {
                Tuple.Create(FhirConst.GetStructuredRecordParams.kTimePeriod, (Base)TimePeriodHelper.GetTimePeriodEndDateOnly()),
                Tuple.Create(FhirConst.GetStructuredRecordParams.kResolvedAllergies, (Base) new FhirBoolean(false))
            };

            _httpContext.HttpRequestConfiguration.BodyParameters.Add(FhirConst.GetStructuredRecordParams.kAllergies, tuples);
        }
        public void GivenIAddTheTimePeriodParameterThatIsDaysInTheFuture(int days)
        {
            var dateStart = DateTime.UtcNow.AddDays(days);
            var dateEnd   = dateStart.AddDays(1);
            var val       = TimePeriodHelper.GetTimePeriod(dateStart.ToString("yyyy-MM-dd"), dateEnd.ToString("yyyy-MM-dd"));

            Given($"I add the parameter \"start\" with the value \"{FhirConst.Prefixs.kGreaterThanOrEqualTo}{val.Start}\"");
            Given($"I add the parameter \"end\" with the value \"{FhirConst.Prefixs.kLessThanOrEqualTo}{val.End}\"");
        }
Esempio n. 21
0
        public void GivenTimePeriodInput_ThenCorrectDateRangeIsReturned(DateTime currentDateTime, TimePeriod inputTimePeriod, DateRange expectedDateRange)
        {
            var expectedDateTimeUtcNow = new DateTimeOffset(currentDateTime);

            _mockSystemClock.Setup(clock => clock.UtcNow).Returns(expectedDateTimeUtcNow);
            var helper = new TimePeriodHelper(_mockSystemClock.Object);

            var returnedDateRange = helper.ResolveDateRange(inputTimePeriod);

            Assert.Equal(expectedDateRange, returnedDateRange);
        }
Esempio n. 22
0
        public void GetTimePeriod_WithKnownDateTime_ReturnsCorrectDates()
        {
            var result1 = TimePeriodHelper.GetTimePeriod(DateTime.Parse("09 June 2013 03:14:23"));

            Assert.AreEqual(9, result1.From.Day, "From Day");
            Assert.AreEqual(6, result1.From.Month, "From Month");
            Assert.AreEqual(2013, result1.From.Year, "From Month");

            Assert.AreEqual(9, result1.To.Day, "To Day");
            Assert.AreEqual(6, result1.To.Month, "To Month");
            Assert.AreEqual(2013, result1.To.Year, "To Month");
        }
Esempio n. 23
0
        private List <FilterDropdownElement> getMonthDropdownList()
        {
            List <FilterDropdownElement> temp = new List <FilterDropdownElement>();

            foreach (var Id in TimePeriodHelper.GetMonthsAsIdList())
            {
                temp.Add(new FilterDropdownElement()
                {
                    Id   = Id,
                    Name = TimePeriodHelper.GetMonthName(Id)
                });
            }

            return(temp);
        }
Esempio n. 24
0
        /// <summary>
        /// Returns the Index view
        /// </summary>
        /// <param name="Period">Text representation of the date time period. eg: Today, Yesterday, Last Week etc.</param>
        /// <param name="LoggerProviderName">Elmah, Log4Net, NLog, Health Monitoring etc</param>
        /// <param name="LogLevel">Debug, Info, Warning, Error, Fatal</param>
        /// <param name="page">The current page index (0 based)</param>
        /// <param name="PageSize">The number of records per page</param>
        /// <returns></returns>
        public ActionResult List(string Period, string LoggerProviderName, string LogLevel, int PageSize = 20, int page = 1)
        {
            // Set up our default values
            string     defaultPeriod   = Session["Period"] == null ? "Today" : Session["Period"].ToString();
            TimePeriod timePeriod      = TimePeriodHelper.GetUtcTimePeriod(Period);
            string     defaultLogType  = Session["LoggerProviderName"] == null ? "All" : Session["LoggerProviderName"].ToString();
            string     defaultLogLevel = Session["LogLevel"] == null ? "Error" : Session["LogLevel"].ToString();

            // Set up our view model
            LoggingIndexModel model = new LoggingIndexModel();

            model.LogLevel           = (LogLevel == null) ? defaultLogLevel : LogLevel;
            model.LoggerProviderName = (LoggerProviderName == null) ? defaultLogType : LoggerProviderName;
            IEnumerable <LogEvent> events = loggingRepository.GetByDateRangeAndType(timePeriod.Start, timePeriod.End, model.LoggerProviderName, model.LogLevel);

            model.Period = (Period == null) ? defaultPeriod : Period;

            model.PagingInfo = new PagingInfo
            {
                CurrentPage  = page,
                ItemsPerPage = PageSize,
                TotalItems   = events.Count()
            };
            model.LogEvents = events.Skip((page - 1) * PageSize)
                              .Take(PageSize);
            // Grab the data from the database


            // Put this into the ViewModel so our Pager can get at these values
            ViewData["Period"]             = model.Period;
            ViewData["LoggerProviderName"] = model.LoggerProviderName;
            ViewData["LogLevel"]           = model.LogLevel;
            ViewData["PageSize"]           = model.PagingInfo.ItemsPerPage;

            // Put the info into the Session so that when we browse away from the page and come back that the last settings are rememberd and used.
            Session["Period"]             = model.Period;
            Session["LoggerProviderName"] = model.LoggerProviderName;
            Session["LogLevel"]           = model.LogLevel;
            Session["PageSize"]           = PageSize;
            return(View(model));
        }
        public List <Entities.StockPrice> GetStockPrices()
        {
            var timePeriod = TimePeriodHelper.GetTimePeriod(DateTime.UtcNow);

            var stockPrices = new List <StockPrice>();

            Parallel.ForEach <string>(GetPageUrls(), url =>
            {
                var stock = ReadStockPrices(url, timePeriod);

                if (stock != null)
                {
                    lock (stockPrices)
                    {
                        stockPrices.Add(stock);
                    }
                }
            });

            return(stockPrices);
        }
Esempio n. 26
0
        public void Start(TextWriter inputWriter)
        {
            var settingsFileInfo = new FileInfo(Path.Combine(App.StoragePath, "lastScan.txt"));
            var query            = $"SELECT * FROM {TableOrViewName}";
            var stringBuilder    = new SqlConnectionStringBuilder
            {
                DataSource      = SqlConfig.ServerInstance,
                InitialCatalog  = SqlConfig.InitialCatalog,
                ConnectTimeout  = SqlConfig.ConnectTimeout,
                CommandTimeout  = SqlConfig.CommandTimeout,
                ApplicationName = SqlConfig.ApplicationName
            };

            if (SqlConfig.Encrypt)
            {
                stringBuilder.Encrypt = SqlConfig.Encrypt;
                stringBuilder.TrustServerCertificate = SqlConfig.TrustCertificate;
            }

            if (SqlConfig.IntegratedSecurity)
            {
                stringBuilder.IntegratedSecurity = true;
            }
            else
            {
                stringBuilder.UserID   = DatabaseUsername;
                stringBuilder.Password = DatabasePassword;
            }

            if (!TimePeriodHelper.IsStringValid(TimePeriod))
            {
                Log.Warning("Defined TimePeriod {TimePeriod} is not valid. Use default {DefaultValue}.", TimePeriod,
                            DefaultTimePeriod);
                TimePeriod = DefaultTimePeriod;
            }

            var executor = new Executor(Log, inputWriter, settingsFileInfo, stringBuilder.ToString(), query);

            _executorTask = new ExecutorTask(Log, TimeSpan.FromSeconds(QueryEverySeconds), TimePeriod, executor);
        }
Esempio n. 27
0
 private static async Task Run(ILogger logger, TimeSpan interval, string timePeriod, Executor executor, CancellationToken cancel)
 {
     try
     {
         while (!cancel.IsCancellationRequested)
         {
             // In valid time period?
             if (TimePeriodHelper.IsValidTimePeriod(DateTime.Now, timePeriod))
             {
                 await executor.Start();
             }
             await Task.Delay(interval, cancel);
         }
     }
     catch (OperationCanceledException)
     {
         logger.Information("The executor task was canceled.");
     }
     catch (Exception ex)
     {
         logger.Fatal(ex, "The executor task threw an unhandled exception.");
     }
 }
Esempio n. 28
0
 public void AddATimePeriodParameterWithstartDateFormatAndEndDateFormat(string startDateFormat, string endDateFormat)
 {
     _httpContext.HttpRequestConfiguration.BodyParameters.Add(FhirConst.GetCareRecordParams.kTimePeriod, TimePeriodHelper.GetTimePeriodStartDateFormatEndDateFormat(startDateFormat, endDateFormat, -10));
 }
        private StockPrice ExtractStockData(string content)
        {
            var nameExp = "(?ismx)" +
                          "<h2[^>]*?class\\s?=\\s?[\\\"\\']title[\\\"\\'][^>]*?>[^<]*?" +
                          "(?:<a[^>]*?>)?" +
                          "\\s*(?<val>[^<]*?)\\s*<";

            var name = Regex.Match(content, nameExp).Groups["val"].Value;

            var symExp = "(?ismx)" +
                         "symbol[^<]*?" +
                         "<span[^>]*?class\\s?=\\s?[\\\"\\']shares_one[^>]*?>\\s*" +
                         "(?:<a[^>]*?>[^<]*?)?" +
                         "(?<val>[^<]*?)\\s*<";

            var symb = Regex.Match(content, symExp).Groups["val"].Value;

            var midExp = "(?ismx)" +
                         "share\\sprice[^<]*?" +
                         "<span[^>]*?class\\s?=\\s?[\\\"\\']shares_one[^>]*?>\\s*" +
                         "(?<val>[\\d\\,\\.]+)";

            var mid = Regex.Match(content, midExp).Groups["val"].Value;

            var valExp = "(?ismx)" +
                         "<th[^>]*?>[^<]*?{0}[^<]*?</\\s?th>[^<]*?" +
                         "<td[^>]*?>\\s*(?:<a[^>]*?>)?(?<value>.*?)\\s*</\\s?(?:a|td)>";

            var bid      = Regex.Match(content, string.Format(valExp, "bid")).Groups["value"].Value;
            var offer    = Regex.Match(content, string.Format(valExp, "offer")).Groups["value"].Value;
            var security = Regex.Match(content, string.Format(valExp, "security")).Groups["value"].Value;

            var changeDateExp = "(?ismx)" +
                                "<th[^>]*?>\\s*last\\schange[^<]*</\\s?th>[^<]*?<td[^>]*?>" +
                                "(?<month>\\d+)\\s*.\\s*" +
                                "(?<day>\\d+)\\s*.\\s*" +
                                "(?<hour>\\d+)\\s*.\\s*" +
                                "(?<min>\\d+)";

            var changeDateMatch = Regex.Match(content, changeDateExp);
            var dateTime        = new DateTime(DateTime.Now.Year,
                                               int.Parse(changeDateMatch.Groups["month"].Value),
                                               int.Parse(changeDateMatch.Groups["day"].Value),
                                               int.Parse(changeDateMatch.Groups["hour"].Value),
                                               int.Parse(changeDateMatch.Groups["min"].Value),
                                               0);

            var period = TimePeriodHelper.GetTimePeriod(dateTime);

            var stock = new Stock {
                Identifier = symb, Name = name, Security = security
            };

            return(new StockPrice
            {
                Period = period,
                UpdatedAt = DateTime.UtcNow,
                Stock = stock,
                Price = new Price
                {
                    Bid = decimal.Parse(bid),
                    Offer = decimal.Parse(offer),
                    UpdatedAt = DateTime.Now
                }
            });
        }
Esempio n. 30
0
 public void AddATimePeriodParameterWithStartDateTodayAndEndDateInDays(int days)
 {
     _httpContext.HttpRequestConfiguration.BodyParameters.Add(FhirConst.GetCareRecordParams.kStartDate, TimePeriodHelper.GetTimePeriodStartDateTodayEndDateDays(days));
 }