public void SaveRectangleIfNotInDb(DbRectangle r) { if (Rectangles.Where(x => x.Rows == r.Rows) .Where(x => x.Cols == r.Cols) .Where(x => x.Symbols == r.Symbols) .Where(x => x.Count == r.Count) .Where(x => x.Type == r.Type) .Any(x => x.Content == r.Content)) { return; } Rectangles.Add(r); SaveChanges(); }
internal static void SaveRectanlgeToDb(string content, string type) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { try { using (ApplicationDbContext db = new ApplicationDbContext()) { var contentRows = content.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);; int rows = contentRows.Count(); int cols = contentRows[0].Split(' ').Count(); int[] symbolsArr = new int[SYMBOLS.Count()]; int count = rows * cols; foreach (var contentRow in contentRows) { for (int i = 0; i < contentRow.Length; i++) { if (contentRow[i].ToString() == Rectangle.EMPTY) { count--; } if (Char.IsLetterOrDigit(contentRow[i])) { symbolsArr[Array.FindIndex(SYMBOLS, x => x == contentRow[i].ToString())]++; } } } int symbols = symbolsArr.Where(x => x > 0).Count(); DbRectangle r = new DbRectangle() { Rows = rows, Cols = cols, Symbols = symbols, Count = count, Type = type, Content = content }; db.SaveRectangleIfNotInDb(r); } } catch (Exception) { } }, null); }
internal static void SaveRectanlgeToDb(Rectangle sq, int rows, int cols, int symbols, int count, string type) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { try { using (ApplicationDbContext db = new ApplicationDbContext()) { DbRectangle r = new DbRectangle() { Rows = rows, Cols = cols, Symbols = symbols, Count = count, Type = type, Content = sq.GetPlainTextString() }; db.SaveRectangleIfNotInDb(r); } } catch (Exception) { } }, null); }