internal static string Build(List<TestAttribute> Categories) { string source = ""; var list = new List<string>(); Categories .ToList() .ForEach(c => list.Add(c.GetName())); list.Sort(); var catParams = new string[] { ExtentFlag.GetPlaceHolder("testCategory"), ExtentFlag.GetPlaceHolder("testCategoryU") }; list.ForEach(c => { var catValues = new string[] { c, c.ToLower().Replace(" ", "") }; source += SourceBuilder.Build(CategoryFilterHtml.GetOptionSource(), catParams, catValues); }); return source; }
public void SortTest() { var episodes = new List<TvdbEpisode>(); episodes.Add(new TvdbEpisode { SeasonNumber = 2, EpisodeNumber = 1 }); episodes.Add(new TvdbEpisode { SeasonNumber = 1, EpisodeNumber = 1 }); episodes.Add(new TvdbEpisode { SeasonNumber = 1, EpisodeNumber = 5 }); episodes.Add(new TvdbEpisode { SeasonNumber = 3, EpisodeNumber = 12 }); episodes.Add(new TvdbEpisode { SeasonNumber = 2, EpisodeNumber = 12 }); episodes.Sort(new TvEpisodeComparer()); Assert.Equal(1, episodes[0].SeasonNumber); Assert.Equal(1, episodes[0].EpisodeNumber); Assert.Equal(1, episodes[1].SeasonNumber); Assert.Equal(5, episodes[1].EpisodeNumber); Assert.Equal(2, episodes[2].SeasonNumber); Assert.Equal(1, episodes[2].EpisodeNumber); Assert.Equal(2, episodes[3].SeasonNumber); Assert.Equal(12, episodes[3].EpisodeNumber); Assert.Equal(3, episodes[4].SeasonNumber); Assert.Equal(12, episodes[4].EpisodeNumber); }
public CategoryViewer(Category category) { Title = WindowTitle = "Category: " + category.Name; this.category = category; InitializeComponent(); Header.DataContext = category; posts = new List<Post>(category.Posts); posts.Sort(delegate(Post x, Post y) { return x.Modified.CompareTo(y.Modified); }); PostsView.ItemsSource = posts; }
public List<Tweet> GetRange(int count, decimal lastId) { List<Tweet> displayTweets = new List<Tweet>(); displayTweets = _tweets.Where(tweet => tweet.Id > lastId).ToList<Tweet>(); if (displayTweets.Count > count) { displayTweets = displayTweets.GetRange(0, count); } displayTweets.Sort(new TwitterComparer()); return displayTweets; }
public static string buildOptions(List<string> Categories) { string source = ""; Categories.Sort(); foreach (string c in Categories) { source += SourceBuilder.BuildSimple(CategoryHtml.GetOptionSource(), new string[] { ExtentFlag.GetPlaceHolder("testCategory"), ExtentFlag.GetPlaceHolder("testCategoryU") }, new string[] { c, c.ToLower().Replace(" ", "") }); } return source; }
public static List<string> ListaPaises() { List<string> ListaCultura = new List<string>(); CultureInfo[] SelecionarCultureInfo = CultureInfo.GetCultures(CultureTypes.SpecificCultures); foreach (CultureInfo SelecionarCultura in SelecionarCultureInfo) { RegionInfo SelecionarRegionInfo = new RegionInfo(SelecionarCultura.LCID); if (!(ListaCultura.Contains(SelecionarRegionInfo.DisplayName))) { ListaCultura.Add(SelecionarRegionInfo.DisplayName); } } ListaCultura.Sort(); return ListaCultura; }
/// <summary> /// Return a pair of random integers, where the first is always lower than /// the second, and there is not more than maxDistance between the returned integers. /// Keeping this interval close is because the main usecase is a musical interval test /// where a large distance would not help with aural training. /// It helps if the Random passed in has been used in previous calls, to help entropy. /// </summary> public List<int> GetRandomInterval(int lowerLimit, int upperLimit, int maxDistance, Random rand) { if (lowerLimit.Equals(upperLimit)) { return new List<int> {lowerLimit, upperLimit}; } const int MaxIterations = 100; var lowerAndUpperLimit = new List<int>{rand.Next(lowerLimit,upperLimit)}; var nextNote = rand.Next(lowerLimit, upperLimit); var count = 0; while (lowerAndUpperLimit[0] == nextNote || System.Math.Abs(lowerAndUpperLimit[0] - nextNote) > maxDistance) { if (count++ > MaxIterations) { throw new Exception("Too many iterations"); } nextNote = rand.Next(lowerLimit, upperLimit); } lowerAndUpperLimit.Add(nextNote); lowerAndUpperLimit.Sort(); return lowerAndUpperLimit; }
public static string buildOptions(List<string> Categories) { string source = ""; Categories.Sort(); var catFlags = new string[] { ExtentFlag.GetPlaceHolder("testCategory"), ExtentFlag.GetPlaceHolder("testCategoryU") }; Categories.ForEach(c => { var catValues = new string[] { c, c.ToLower().Replace(" ", "") }; source += SourceBuilder.Build(CategoryHtml.GetOptionSource(), catFlags, catValues); }); return source; }
/// <summary> /// Sorts the specified list. /// </summary> /// <param name="list">The list.</param> /// <param name="sortExpression">The sort expression.</param> /// <param name="sortDirection">The sort direction.</param> public static List<Resume> Sort(List<Resume> list, string sortExpression, string sortDirection) { if (!string.IsNullOrEmpty(sortExpression)) { list.Sort(new ListSorter<Resume>(sortExpression)); } if (sortDirection != null && sortDirection == "Desc") { list.Reverse(); } return list; }
protected async override void OnLaunched(LaunchActivatedEventArgs e) { List<MyLine> listLines = new List<MyLine>(); //int minSize = 40; //int maxSize = 2600; int wordTopRange = 25; StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile file = null; if (!string.IsNullOrEmpty(e.Arguments)) { try { OcrEngine ocrEngine = new OcrEngine(OcrLanguage.English); file = await folder.GetFileAsync(e.Arguments); ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync(); //if (imgProp.Height < minSize || imgProp.Height > maxSize || imgProp.Width < minSize || imgProp.Width > maxSize) //{ // await WriteToFile(folder, file.Name + ".txt", "Image size must be > 40 and < 2600 pixel"); //} //else //{ WriteableBitmap bitmap = null; using (IRandomAccessStream imgStream = await file.OpenAsync(FileAccessMode.Read)) { bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height); bitmap.SetSource(imgStream); } // This main API call to extract text from image. OcrResult ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray()); // If there is text. if (ocrResult.Lines != null) { StringBuilder builder = new StringBuilder(); // loop over recognized text. foreach (OcrLine line in ocrResult.Lines) { // Iterate over words in line. foreach (OcrWord word in line.Words) { // sort the word line by line bool isBelongToLine = false; foreach (MyLine myLine in listLines) { // if line exist, add word to line if (Between(myLine.lineNumber, word.Top - wordTopRange, word.Top + wordTopRange, true)) { myLine.listWords.Add(word); isBelongToLine = true; break; } } // if line does not exist, create new line, add word to line if (isBelongToLine == false) { MyLine myLine = new MyLine(); myLine.lineNumber = word.Top; myLine.listWords.Add(word); listLines.Add(myLine); } // sort the word line by line } } // sort the lines base on top position listLines.Sort(); // return data line by line foreach (MyLine myLine in listLines) { builder.Append(myLine.ToString()); } await WriteToFile(folder, file.Name + ".txt", builder.ToString()); } else // if no text { await WriteToFile(folder, file.Name + ".txt", "No Text"); } //} } catch (Exception ex) { await WriteToFile(folder, file.Name + ".txt", "Exception"); } App.Current.Exit(); } }
public MvcHtmlString AdminsList(string userEmail) { var user = userRepository.Find(u => u.Email == userEmail); var admins = redactorRepository.FindAll(r => r.UserId_Id == user.Id).GroupBy(u => u.Administrator_Id).Select(g => g.First()).ToList(); if (admins != null && admins.Count > 0) { List<string> adminsEmails = new List<string>(); foreach (var admin in admins) { var administrator = userRepository.Find(u => u.Id == admin.Administrator_Id); adminsEmails.Add(administrator.Email); } StringBuilder builder = new StringBuilder(); adminsEmails.Sort(); foreach (var adminEmail in adminsEmails) { builder.AppendLine("<li>" + adminEmail + "</li>"); } return new MvcHtmlString(builder.ToString()); } return null; }
private void SortViewModelsByDate(List<NewsDetailsViewModel> newsDetailsViewModels) { newsDetailsViewModels.Sort((first, second) => second.PublicationDate.CompareTo(first.PublicationDate)); }
protected override void LoadParameterData() { String IDAttribute = XmlSchemaConstants.Display.Component.Id; String NameAttribute = XmlSchemaConstants.Display.Component.Name; String LinkIDAttribute = "LinkID"; IXPathNavigable iNavigator = myController.GetComponentAndChildren(SelectedID, linkType, 2, false, true); XPathNavigator navigator = iNavigator.CreateNavigator(); //// Perform a CRC checksum on the data coming back, only update if it has changed //MD5CryptoServiceProvider x = new MD5CryptoServiceProvider(); //Byte[] bs = System.Text.Encoding.UTF8.GetBytes(navigator.OuterXml); //bs = x.ComputeHash(bs); //System.Text.StringBuilder s = new System.Text.StringBuilder(); //foreach (Byte b in bs) //{ // s.Append(b.ToString("x2").ToLower()); //} //String newCrc = s.ToString(); DrawingUtility.SuspendDrawing(this); //if (!crc.Equals(newCrc)) // otherwise update with the new data { //crc = newCrc; this.Columns.Clear(); pairInformation = new List<ComponentPair>(); if (navigator.HasChildren) { Dictionary<String, int> rowNameToIndex = new Dictionary<String, int>(); nodeNameToID = new Dictionary<string, int>(); XPathNodeIterator listOfNodes = navigator.Select(String.Format("/Components/Component/Component")); List<String> names = new List<String>(); foreach (XPathNavigator nodeNav in listOfNodes) { int nodeID = Int32.Parse(nodeNav.GetAttribute(IDAttribute, nodeNav.NamespaceURI)); String nodeName = nodeNav.GetAttribute(NameAttribute, nodeNav.NamespaceURI); names.Add(nodeName); nodeNameToID.Add(nodeName, nodeID); } names.Sort(); foreach (String aName in names) { int addedColumn = Columns.Add(aName, aName); int addedRow = this.Rows.Add(); Rows[addedRow].HeaderCell.Value = aName; rowNameToIndex.Add(aName, addedRow); } int fromID, toID; int rowIndex, linkID; String paramValue, columnName, rowName; String linkString = ""; //now, form links. foreach (XPathNavigator nodeNav in listOfNodes) { rowName = nodeNav.GetAttribute(NameAttribute, nodeNav.NamespaceURI); fromID = Int32.Parse(nodeNav.GetAttribute(IDAttribute, nodeNav.NamespaceURI)); rowIndex = rowNameToIndex[rowName]; if (nodeNav.HasChildren) { XPathNodeIterator listOfChildren = nodeNav.Select("Component"); foreach (XPathNavigator childNav in listOfChildren) { columnName = childNav.GetAttribute(NameAttribute, childNav.NamespaceURI); toID = Int32.Parse(childNav.GetAttribute(IDAttribute, childNav.NamespaceURI)); linkString = childNav.GetAttribute(LinkIDAttribute, childNav.NamespaceURI); if (linkString != null && linkString != "") { linkID = Int32.Parse(linkString); } else { linkID = -1; } pairInformation.Add(new ComponentPair(rowName, columnName, linkID)); XPathNavigator pnav = childNav.SelectSingleNode("LinkParameters/Parameter"); if (pnav != null) { paramValue = pnav.GetAttribute("Value", pnav.NamespaceURI); if (paramValue.Equals("")) { this[columnName, rowIndex].Value = "Link"; } else { this[columnName, rowIndex].Value = paramValue; } } else { this[columnName, rowIndex].Value = "Link"; } } } } } } }