public static RecipeCollection Deserialize() { RecipeCollection rc = new RecipeCollection(); rc.Deserialize(); return(rc); }
public static void Serialize() { Random rand = new Random(DateTime.Now.Millisecond); RecipeCollection rc = new RecipeCollection(); rc.Recipe = new List <Recipe>(); rc.Recipe.Add(new Recipe(1, rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString())); rc.Recipe.Add(new Recipe(2, rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString())); rc.Recipe.Add(new Recipe(3, rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString(), rand.Next().ToString())); rc.Serialize(); }
public void Deserialize() { string path = "final_may_be_3.xml"; DataContractSerializer xmlDeserializer = new DataContractSerializer(this.GetType()); XmlReader xmlR = XmlReader.Create(path); try { RecipeCollection serialize = (RecipeCollection)xmlDeserializer.ReadObject(xmlR); Recipe = serialize.Recipe; } catch (Exception ex) { Console.WriteLine(ex.Message + " " + ex.StackTrace); } finally { xmlR.Close(); } }
public static void MongoWriting(RecipeCollection rc) { MongoClient client = new MongoClient("mongodb://*****:*****@" [\d-\/]+[ ]{0,3}", string.Empty); str = Regex.Replace(str, @"[\-]", string.Empty); str = Regex.Replace(str, @"шт", string.Empty); str = Regex.Replace(str, @" ", " "); str = Regex.Replace(str, @"г", string.Empty); str = Regex.Replace(str, @" ", " "); str = str.ToLower(); if (str[str.Length - 1] == ' ' || str[str.Length - 1] == '.') { str = str.Remove(str.Length - 1); } if (str[0] == ' ') { str = str.Remove(0, 1); } //s = str.Split(", ".ToCharArray()); s = str.Split(new string[] { ", ", "; ", ";", " и ", "., " }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in s) { spl = item.Split(' '); if (spl.Length > 0) { for (int zz = 0; zz < spl.Length; zz++) { if (string.IsNullOrEmpty(spl[zz])) { continue; } if (!char.IsDigit(spl[zz].First()) && spl[zz].First() != '.') { e = zz; break; } } } s_.Add(spl[e]); } //newS = new string[s.Length]; if (s != null && s.Length > 0) { //foreach (var item in s) // if (item[item.Length - 1] == ' ') // newS[i++] = item.Remove(item.Length - 1); collection.Insert(new BsonDocument { { "name", r.ARecept }, { "description", r.Description }, { "ingredients", new BsonArray(s_.ToArray()) }, { "dishType", r.DishType }, { "typeKitchen", r.ICuisine }, { "minutes", r.Minutes }, { "picture", r.Picture } }); } s_.Clear(); } } }