/// <summary> /// Распарсить. /// </summary> /// <param name="source">Источник.</param> /// <returns>Результат.</returns> public IThreadUpdatesInfo Parse(CheckUpdatesDataWithLink source) { return(new MakabaThreadUpdatesInfo() { Link = source.Link, LastPost = source.Link.GetPostLink(source.Data.LastNum), LastUpdate = DatesHelper.FromUnixTime(source.Data.TimeStamp), NumberOfPosts = source.Data.Posts }); }
public void GetCandlesticks_Should_RespondWithCandlesticksArray() { // arrange var candles = new[] { new SwitcheoCandlestick() { Time = DatesHelper.FromTimestamp(1531215240), Open = 0.00049408m, Close = 0.00049238m, High = 0.000497m, Low = 0.00048919m, Volume = 110169445, QuoteVolume = 222900002152 }, new SwitcheoCandlestick() { Time = DatesHelper.FromTimestamp(1531219800), Open = 0.00050366m, Close = 0.00049408m, High = 0.00050366m, Low = 0.00049408m, Volume = 102398958, QuoteVolume = 205800003323 }, }; var client = PrepareClient(JsonConvert.SerializeObject(candles)); // act var result = client.GetCandlesticks("SWTH_NEO", DateTime.Now.AddDays(-1), DateTime.Now, CandlestickInterval.ThirtyMinutes); // assert Assert.AreEqual(true, result.Success); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(candles[0], result.Data[0])); Assert.IsTrue(Compare.PublicInstancePropertiesEqual(candles[1], result.Data[1])); }
public void CompleteInventory() { var completeInventory = DatesHelper.CompleteInventoryWithRandom(); Assert.IsNotNull(completeInventory); }
public void CompleteCustomers() { var completeCustomer = DatesHelper.CompleteCustomerWithRandom(); Assert.IsNotNull(completeCustomer); }
/// <summary> /// Распарсить. /// </summary> /// <param name="source">Источник.</param> /// <returns>Результат.</returns> public IBoardPost Parse(BoardPost2WithParentLink source) { var data = source.Post; var link = source.ParentLink; var isPreview = source.EntityType != PostStoreEntityType.Post; var ipIdRegex = RegexCache.CreateRegex(IpIdRegexText); var ipIdRegex2 = RegexCache.CreateRegex(IpIdRegexText2); var colorRegex = RegexCache.CreateRegex(ColorRegexText); var flags = new HashSet <Guid>(); if (data.Banned != "0" && !string.IsNullOrWhiteSpace(data.Banned)) { flags.Add(BoardPostFlags.Banned); } if (data.Closed != "0" && !string.IsNullOrWhiteSpace(data.Closed)) { flags.Add(BoardPostFlags.Closed); } if (data.Sticky != "0" && !string.IsNullOrWhiteSpace(data.Sticky)) { flags.Add(BoardPostFlags.Sticky); } if (isPreview) { flags.Add(BoardPostFlags.ThreadPreview); } if (source.Counter == 1) { flags.Add(BoardPostFlags.ThreadOpPost); } if (data.Op != "0" && !string.IsNullOrWhiteSpace(data.Op)) { flags.Add(BoardPostFlags.Op); } if ("mailto:sage".Equals((data.Email ?? "").Trim(), StringComparison.OrdinalIgnoreCase)) { flags.Add(BoardPostFlags.Sage); } if (data.Edited != "0" && !string.IsNullOrWhiteSpace(data.Edited)) { flags.Add(BoardPostFlags.IsEdited); } if ((data.Endless ?? 0) != 0) { flags.Add(BoardPostFlags.Endless); } string admName = null; if (data.Tripcode != null) { if (data.Tripcode.StartsWith("!!%") && data.Tripcode.EndsWith("%!!")) { if ("!!%mod%!!".Equals(data.Tripcode)) { admName = "## Mod ##"; } else if ("!!%adm%!!".Equals(data.Tripcode)) { admName = "## Abu ##"; } else if ("!!%Inquisitor%!!".Equals(data.Tripcode)) { admName = "## Applejack ##"; } else if ("!!%coder%!!".Equals(data.Tripcode)) { admName = "## Кодер ##"; } else { admName = data.Tripcode.Replace("!!%", "## ").Replace("%!!", " ##"); } flags.Add(BoardPostFlags.AdminTrip); } } var number = data.Number.TryParseWithDefault(); var thisLink = new PostLink() { Engine = MakabaConstants.MakabaEngineId, Board = link.Board, OpPostNum = link.OpPostNum, PostNum = number }; var postDocument = _htmlParser.ParseHtml(data.Comment ?? "", thisLink); var name = admName != null && string.IsNullOrWhiteSpace(data.Name) ? admName : WebUtility.HtmlDecode(data.Name ?? string.Empty).Replace(" ", " "); string nameColor = null; Color? color = null; var match = ipIdRegex.Match(name); var match2 = ipIdRegex2.Match(name); if (match.Success) { name = match.Groups["id"].Captures[0].Value; } else if (match2.Success) { name = match2.Groups["id"].Captures[0].Value; nameColor = match2.Groups["style"].Captures[0].Value; var cmatch = colorRegex.Match(nameColor); if (cmatch.Success) { try { var r = byte.Parse(cmatch.Groups["r"].Captures[0].Value, CultureInfo.InvariantCulture.NumberFormat); var g = byte.Parse(cmatch.Groups["g"].Captures[0].Value, CultureInfo.InvariantCulture.NumberFormat); var b = byte.Parse(cmatch.Groups["b"].Captures[0].Value, CultureInfo.InvariantCulture.NumberFormat); color = Color.FromArgb(255, r, g, b); } catch (Exception) { color = null; } } } else if (name.StartsWith("Аноним ID:", StringComparison.OrdinalIgnoreCase)) { name = name.Remove(0, "Аноним ID:".Length).Trim(); } PosterInfo posterInfo = null; if (!string.IsNullOrEmpty(name) || !string.IsNullOrWhiteSpace(data.Tripcode)) { posterInfo = new PosterInfo() { Name = HtmlToText(name ?? ""), NameColor = color, NameColorStr = nameColor, Tripcode = data.Tripcode }; } var iconAndFlag = ParseFlagAndIcon(data.Icon); BoardPostTags tags = null; if (!string.IsNullOrWhiteSpace(data.Tags)) { tags = new BoardPostTags() { TagStr = data.Tags, Tags = new List <string>() { data.Tags } }; } BoardPostLikes likes = null; if (data.Likes != null || data.Dislikes != null) { likes = new BoardPostLikes() { Likes = data.Likes ?? 0, Dislikes = data.Dislikes ?? 0 }; } Core.Models.Posts.BoardPost result; if (source.EntityType == PostStoreEntityType.CatalogPost) { result = new CatalogBoardPost() { OnPageSequence = source.Counter }; } else { result = new Core.Models.Posts.BoardPost(); } result.Link = thisLink; result.Comment = postDocument; result.ParentLink = link; result.Subject = WebUtility.HtmlDecode(data.Subject ?? string.Empty); result.BoardSpecificDate = data.Date; result.Date = DatesHelper.FromUnixTime(data.Timestamp.TryParseWithDefault()); result.Flags = flags.ToList(); result.Quotes = new List <ILink>(); result.Hash = data.Md5; result.Email = data.Email; result.MediaFiles = new List <IPostMedia>(); result.Counter = source.Counter; result.Poster = posterInfo; result.Icon = iconAndFlag.Icon; result.Country = iconAndFlag.Country; result.Tags = tags; result.UniqueId = Guid.NewGuid().ToString(); result.Likes = likes; result.LoadedTime = source.LoadedTime; result.OnServerCounter = source.Post.CountNumber; if (data.Files != null) { foreach (var f in data.Files) { BoardLinkBase mediaLink, tnLink; if (IsBoardLink(f.Path, link.Board)) { mediaLink = new BoardMediaLink() { Engine = MakabaConstants.MakabaEngineId, Board = link.Board, Uri = RemoveBoardFromLink(f.Path), }; tnLink = new BoardMediaLink() { Engine = MakabaConstants.MakabaEngineId, Board = link.Board, Uri = RemoveBoardFromLink(f.Thumbnail), }; } else { mediaLink = new EngineMediaLink() { Engine = MakabaConstants.MakabaEngineId, Uri = f.Path, }; tnLink = new EngineMediaLink() { Engine = MakabaConstants.MakabaEngineId, Uri = f.Thumbnail, }; } var media = new PostMediaWithThumbnail() { MediaLink = mediaLink, FileSize = (ulong)(f.Size * 1024), Height = f.Heigth, Width = f.Width, Name = f.Name, MediaType = f.Type == MakabaMediaTypes.Webm ? PostMediaTypes.WebmVideo : PostMediaTypes.Image, DisplayName = f.DisplayName, FullName = f.FullName, Nsfw = f.NotSafeForWork != 0, Hash = f.Md5, Duration = f.Duration, Thumbnail = new PostMediaWithSize() { MediaLink = tnLink, Height = f.TnHeight, Width = f.TnWidth, FileSize = null, MediaType = PostMediaTypes.Image }, }; result.MediaFiles.Add(media); } } if (source.Counter == 1 && string.IsNullOrWhiteSpace(result.Subject)) { try { var lines = result.Comment.ToPlainText(); if (lines.Count > 0) { var s = lines.FirstOrDefault(l => !string.IsNullOrWhiteSpace(l)); if (s != null) { if (s.Length >= 50) { s = s.Substring(0, 50 - 3) + "..."; } result.Subject = s; } } } catch { } } return(result); }
public void CompleteOrders() { var completeOrders = DatesHelper.CompleteOrdersWithRandom(); Assert.IsNotNull(completeOrders); }
public ActionResult Index() { #region Code to redirect with a slash by Raju @ 30th Sept, 2013 var url = Na.Core.Configuration.NaConfig.Url.DomainUrl + Request.RawUrl; if (!Request.IsAjaxRequest() && CheckUrlForRediract(url)) { Response.Status = "301 Moved Permanently"; Response.AddHeader("Location", url + "/"); } #endregion var model = new BrowseResultsModel(); model.resultDetails = new System.Collections.Generic.List<Na.Website.Models.Browse.BrowseResultsDetailsModel>(); if (String.IsNullOrWhiteSpace(model.SearchString)) { model.SearchString = string.Empty; } fcnClearCookie(); #region Date Section var _DateHelper = new DatesHelper(_cacheManager); Dates[] enums = { Dates.AvailableStartYears, Dates.AvailableStartMonths, Dates.AvailableStartDays, Dates.AvailableEndMonths, Dates.AvailableEndDays }; _DateHelper.SetDates(model.Dates, _dateService, enums); #endregion return View(model); }
public void DatesDropDownPopulate(BrowseResultsModel model) { #region Value Set into Date Filters From BrowseLocation Cookie HttpCookie hcBrowse = null; if ((Request.Cookies[_config.GetStringValueFromConfig("cookiePrefix", "NewspaperARCHIVE.com") + ".BrowseLocation"] != null && Request.Cookies[_config.GetStringValueFromConfig("cookiePrefix", "NewspaperARCHIVE.com") + ".BrowseLocation"].HasKeys)) { hcBrowse = Request.Cookies[_config.GetStringValueFromConfig("cookiePrefix", "NewspaperARCHIVE.com") + ".BrowseLocation"]; } if (hcBrowse != null) { _startyear = _common.GetStringValue(hcBrowse.Values["year"], ""); _startmonth = _common.GetStringValue(hcBrowse.Values["month"], ""); _startday = _common.GetStringValue(hcBrowse.Values["day"], ""); _endyear = _common.GetStringValue(hcBrowse.Values["endyear"], ""); _endmonth = _common.GetStringValue(hcBrowse.Values["endmonth"], ""); _endday = _common.GetStringValue(hcBrowse.Values["endday"], ""); } if (!string.IsNullOrWhiteSpace(_startmonth)) { if (_common.GetStringValue(_startmonth, "0").StartsWith("0")) { _startmonth = _common.GetStringValue(_startmonth, "0").Replace(_common.GetStringValue(_startmonth, "0").Substring(0, 1), ""); } else { _startmonth = _common.GetStringValue(_startmonth, "0"); } } if (!string.IsNullOrWhiteSpace(_startday)) { if (_common.GetStringValue(_startday, "0").StartsWith("0")) { _startday = _common.GetStringValue(_startday, "").Replace(_common.GetStringValue(_startday, "0").Substring(0, 1), ""); } else { _startday = _common.GetStringValue(_startday, ""); } } if (!string.IsNullOrWhiteSpace(_endmonth)) { if (_common.GetStringValue(_endmonth, "0").StartsWith("0")) { _endmonth = _common.GetStringValue(_endmonth, "0").Replace(_common.GetStringValue(_endmonth, "0").Substring(0, 1), ""); } else { _endmonth = _common.GetStringValue(_endmonth, "0"); } } if (!string.IsNullOrWhiteSpace(_endday)) { if (_common.GetStringValue(_endday, "0").StartsWith("0")) { _endday = _common.GetStringValue(_endday, "").Replace(_common.GetStringValue(_endday, "0").Substring(0, 1), ""); } else { _endday = _common.GetStringValue(_endday, ""); } } #endregion #region Reset Date DropDowns from Date Filters // Commented by Vishal Tyagi as //model.Dates.AvailableStartYears.Clear(); //foreach (var c in _dateService.GetAllYears()) // model.Dates.AvailableStartYears.Add(new SelectListItem() { Text = c.startYear, Value = c.yearID.ToString() }); //model.Dates.AvailableStartMonths.Clear(); //foreach (var c in _dateService.GetAllMonths()) // model.Dates.AvailableStartMonths.Add(new SelectListItem() { Text = c.startMonthName, Value = c.startMonth.ToString() }); //model.Dates.AvailableStartDays.Clear(); //foreach (var c in _dateService.GetAllDays()) // model.Dates.AvailableStartDays.Add(new SelectListItem() { Text = c.startDay, Value = c.dayID.ToString() }); //model.Dates.AvailableEndMonths.Clear(); //foreach (var c in _dateService.GetAllMonths()) // model.Dates.AvailableEndMonths.Add(new SelectListItem() { Text = c.startMonthName, Value = c.startMonth.ToString() }); //model.Dates.AvailableEndDays.Clear(); //foreach (var c in _dateService.GetAllDays()) // model.Dates.AvailableEndDays.Add(new SelectListItem() { Text = c.startDay, Value = c.dayID.ToString() }); #region Reset Date DropDowns from Date Filters model.Dates.AvailableStartYears.Clear(); model.Dates.AvailableStartMonths.Clear(); model.Dates.AvailableStartDays.Clear(); model.Dates.AvailableEndMonths.Clear(); model.Dates.AvailableEndDays.Clear(); var _DateHelper = new DatesHelper(_cacheManager); Dates[] enums = { Dates.AvailableStartYears, Dates.AvailableStartMonths, Dates.AvailableStartDays, Dates.AvailableEndMonths, Dates.AvailableEndDays }; _DateHelper.SetDates(model.Dates, _dateService, enums); #endregion //****************Dates Populates Ended********************** if (!string.IsNullOrWhiteSpace(_startyear)) { model.Dates.StartYear = _common.GetStringValue(_startyear, ""); model.Dates.BetweenStartYear = _common.GetStringValue(_startyear, ""); model.Dates.BetweenDatesYear = _common.GetStringValue(_startyear, ""); model.Dates.IsPublicationDate = true; model.Dates.AvailableEndYears.Clear(); foreach (var c in _dateService.GetAllEndYears(_common.GetIntegerValue(model.Dates.StartYear, 0))) model.Dates.AvailableEndYears.Add(new SelectListItem() { Text = c.endYear, Value = c.endYear.ToString() }); } if (!String.IsNullOrWhiteSpace(_startyear) && !String.IsNullOrWhiteSpace(_startmonth) && !String.IsNullOrWhiteSpace(_endyear)) { model.Dates.IsBetweenDates = true; } else if (!String.IsNullOrWhiteSpace(_startyear) && !String.IsNullOrWhiteSpace(_startmonth) && String.IsNullOrWhiteSpace(_endyear)) { model.Dates.IsExactDate = true; } else if (!String.IsNullOrWhiteSpace(_startyear) && String.IsNullOrWhiteSpace(_startmonth) && !String.IsNullOrWhiteSpace(_endyear)) { model.Dates.IsBetweenYears = true; } //if (model.Dates.IsExactDate) //{ // if (!string.IsNullOrWhiteSpace(_startmonth)) { model.Dates.StartMonth = _common.GetStringValue(_startmonth, ""); } // if (!string.IsNullOrWhiteSpace(_startday)) { model.Dates.StartDay = _common.GetStringValue(_startday, ""); } // model.Dates.BetweenStartYear = ""; // model.Dates.BetweenDatesYear = ""; // model.Dates.BetweenDatesMonth = ""; // model.Dates.BetweenDatesDay = ""; //} //if (model.Dates.IsBetweenYears) //{ // if (!string.IsNullOrWhiteSpace(_endyear)) { model.Dates.BetweenEndYear = _common.GetStringValue(_endyear, ""); } // model.Dates.StartYear = ""; // model.Dates.BetweenDatesYear = ""; // model.Dates.EndYear = ""; //} //if (model.Dates.IsBetweenDates) //{ // if (!string.IsNullOrWhiteSpace(_startmonth)) { model.Dates.BetweenDatesMonth = _common.GetStringValue(_startmonth, ""); } // if (!string.IsNullOrWhiteSpace(_startday)) { model.Dates.BetweenDatesDay = _common.GetStringValue(_startday, ""); } // if (!string.IsNullOrWhiteSpace(_endyear)) { model.Dates.EndYear = _common.GetStringValue(_endyear, ""); } // if (!string.IsNullOrWhiteSpace(_endmonth)) { model.Dates.EndMonth = _common.GetStringValue(_endmonth, ""); } // if (!string.IsNullOrWhiteSpace(_endday)) { model.Dates.EndDay = _common.GetStringValue(_endday, ""); } // model.Dates.StartYear = ""; // model.Dates.BetweenStartYear = ""; //} //Updated by : Amit Kumar Srivastava //Updated Date : 18 september 2013. //Purpose : Task No. 252, commented above section due to blank all other Dates rather then selected in model. //Start if (model.Dates.IsExactDate) { if (!string.IsNullOrWhiteSpace(_startyear)) { model.Dates.StartYear = _common.GetStringValue(_startyear, ""); } if (!string.IsNullOrWhiteSpace(_startmonth)) { model.Dates.StartMonth = _common.GetStringValue(_startmonth, ""); } if (!string.IsNullOrWhiteSpace(_startday)) { model.Dates.StartDay = _common.GetStringValue(_startday, ""); } model.Dates.BetweenStartYear = ""; model.Dates.BetweenEndYear = ""; model.Dates.BetweenDatesYear = ""; model.Dates.BetweenDatesMonth = ""; model.Dates.BetweenDatesDay = ""; model.Dates.EndYear = ""; model.Dates.EndMonth = ""; model.Dates.EndDay = ""; } else if (model.Dates.IsBetweenYears) { if (!string.IsNullOrWhiteSpace(_startyear)) { model.Dates.BetweenStartYear = _common.GetStringValue(_startyear, ""); } if (!string.IsNullOrWhiteSpace(_endyear)) { model.Dates.BetweenEndYear = _common.GetStringValue(_endyear, ""); } model.Dates.StartYear = ""; model.Dates.StartMonth = ""; model.Dates.StartDay = ""; model.Dates.BetweenDatesYear = ""; model.Dates.BetweenDatesMonth = ""; model.Dates.BetweenDatesDay = ""; model.Dates.EndYear = ""; model.Dates.EndMonth = ""; model.Dates.EndDay = ""; } else if (model.Dates.IsBetweenDates) { if (!string.IsNullOrWhiteSpace(_startyear)) { model.Dates.BetweenDatesYear = _common.GetStringValue(_startyear, ""); } if (!string.IsNullOrWhiteSpace(_startmonth)) { model.Dates.BetweenDatesMonth = _common.GetStringValue(_startmonth, ""); } if (!string.IsNullOrWhiteSpace(_startday)) { model.Dates.BetweenDatesDay = _common.GetStringValue(_startday, ""); } if (!string.IsNullOrWhiteSpace(_endyear)) { model.Dates.EndYear = _common.GetStringValue(_endyear, ""); } if (!string.IsNullOrWhiteSpace(_endmonth)) { model.Dates.EndMonth = _common.GetStringValue(_endmonth, ""); } if (!string.IsNullOrWhiteSpace(_endday)) { model.Dates.EndDay = _common.GetStringValue(_endday, ""); } model.Dates.StartYear = ""; model.Dates.StartMonth = ""; model.Dates.StartDay = ""; model.Dates.BetweenStartYear = ""; model.Dates.BetweenEndYear = ""; } else { model.Dates.BetweenStartYear = ""; model.Dates.BetweenEndYear = ""; model.Dates.StartYear = ""; model.Dates.StartMonth = ""; model.Dates.StartDay = ""; model.Dates.BetweenDatesYear = ""; model.Dates.BetweenDatesMonth = ""; model.Dates.BetweenDatesDay = ""; model.Dates.EndYear = ""; model.Dates.EndMonth = ""; model.Dates.EndDay = ""; } //End #endregion }