static void Main(string[] args) { CopywriterCollection collection1 = new CopywriterCollection("Collection 1"); CopywriterCollection collection2 = new CopywriterCollection("Collection 2"); Journal journal1 = new Journal(); Journal journal2 = new Journal(); collection1.CopywriterCountChanged += journal1.CopywriterCountChanged; collection1.CopywriterReferenceChanged += journal1.CopywriterReferenceChanged; collection1.CopywriterReferenceChanged += journal2.CopywriterReferenceChanged; collection2.CopywriterReferenceChanged += journal2.CopywriterReferenceChanged; collection1.AddDefaults(); collection1.AddDefaults(); collection1.AddDefaults(); collection1.Remove(1); collection1[0].Nickname = "Arkos"; collection1[0] = new Copywriter(new Person(), "Ortem", new Level(), 1000); collection1.AddCopywriters(new Copywriter()); collection2.AddDefaults(); collection2.AddDefaults(); collection2.Remove(0); collection2[0].Nickname = "ArkosLUL"; collection2.AddCopywriters(new Copywriter(new Person(), "ArkosOmegaLUL", new Level(), 150)); collection2[1] = new Copywriter(new Person(), "ArkosLUL", new Level(), 200); Console.WriteLine(journal1.ToString()); Console.WriteLine(journal2.ToString()); Console.ReadKey(); }
public static Copywriter CollectionAvtoGeneration(int n) { Copywriter c = new Copywriter(); c.Name += String.Format("askjdklajs{0}", n); return(c); }
static void Main(string[] args) { CopywriterCollection <string> dictionary1 = new CopywriterCollection <string>("First collection"); CopywriterCollection <string> dictionary2 = new CopywriterCollection <string>("Second collection"); Journal <string> journal = new Journal <string>(); dictionary1.CopywritersChanged += journal.CopywritersChanged; dictionary2.CopywritersChanged += journal.CopywritersChanged; Copywriter Mark = new Copywriter(new Person("Mark", "Wolf", new DateTime(1967, 01, 01)), "Boss of this gym", Level.MidLevel, 4); Copywriter Van = new Copywriter(new Person("Van", "Darkholme", new DateTime(1972, 10, 24)), "Dungeon Master", (Level)2, 3); Copywriter Aniki = new Copywriter(new Person("Billy", "Herrington", new DateTime(1969, 07, 14)), "Big Brother", (Level)2, 1); Copywriter Arkos = new Copywriter(new Person("Artem", "Kosogov", new DateTime(2000, 05, 26)), "Arkos", (Level)2, 2); dictionary1.AddCopywritersToDictionary("111", Arkos); dictionary1.AddCopywritersToDictionary("112", Aniki); dictionary1.AddCopywritersToDictionary("113", Van); dictionary2.AddCopywritersToDictionary("111", Mark); dictionary1["112"].Nickname = "Aniki"; dictionary1["111"].Rating = 3; dictionary1.Remove(Arkos); Arkos.Rating = 4; Console.WriteLine(journal.ToString()); List <Copywriter> sortedList = dictionary1.GetSortedListOfCopywriters(); foreach (var cw in sortedList) { Console.WriteLine(cw.ToString()); } Console.ReadKey(); }
public void AddCopywritersToDictionary(TKey key, Copywriter copywriter) { if (CopywriterDictionary == null) { CopywriterDictionary = new Dictionary <TKey, Copywriter>(); } CopywriterDictionary.Add(key, copywriter); copywriter.PropertyChanged += DictionaryHandler; CopywritersChanged?.Invoke(this, new CopywritersChangedEventArgs <TKey>(CopywriterCollectionName, Action.Add, "", key)); }
public TestCollections(int n) { for (int i = 0; i <= n; i++) { Copywriter c = CollectionAvtoGeneration(i); TestPersonList.Add(c as Person); TestStringList.Add(c.ToString()); TestPersonDictionary.Add(c as Person, c); TestStringDictionary.Add(c.ToString(), c); } }
public string Time(int n) { //Copywriter c = new Copywriter() { Name = String.Format("askjdklajs{0}", n) }; Copywriter c = CollectionAvtoGeneration(n); string info = ""; bool temp; System.Diagnostics.Stopwatch time = new System.Diagnostics.Stopwatch(); time.Start(); Person temp1 = c as Person; temp = TestPersonList.Contains(temp1); time.Stop(); info += String.Format("Element searching time in List<Team> - {0} {1}\n", time.Elapsed, temp); time.Reset(); time.Start(); string temp2 = c.ToString(); temp = TestStringList.Contains(c.Person.ToString()); time.Stop(); info += String.Format("Element searching time in List<string> - {0} {1}\n", time.Elapsed, temp); time.Reset(); time.Start(); temp = TestPersonDictionary.ContainsKey(c.Person); time.Stop(); info += String.Format("Element searching time by key in Dictionary<Person,Copywriter> - {0} {1}\n", time.Elapsed, temp); time.Reset(); time.Start(); temp = TestPersonDictionary.ContainsValue(c); time.Stop(); info += String.Format("Element searching time by value in Dictionary<Person,Copywriter> - {0} {1}\n", time.Elapsed, temp); time.Reset(); time.Start(); temp = TestStringDictionary.ContainsKey(c.Person.ToString()); time.Stop(); info += String.Format("Element searching time by key in Dictionary<string,Copywriter> - {0} {1}\n", time.Elapsed, temp); time.Reset(); time.Start(); temp = TestStringDictionary.ContainsValue(c); time.Stop(); info += String.Format("Element searching time by value in Dictionary<string,Copywriter> - {0} {1}\n", time.Elapsed, temp); return(info); }
public void AddDefaults() { if (ListOfCopywriters == null) { ListOfCopywriters = new List <Copywriter>(); } Copywriter copywriter = new Copywriter(); ListOfCopywriters.Add(copywriter); if (CopywriterCountChanged != null) { CopywriterListHandlerEventArgs e = new CopywriterListHandlerEventArgs(CopywriterCollectionName, " A default element was added to the collection ", copywriter); CopywriterCountChanged(this, e); } }
public override object DeepCopy() { Copywriter copy = new Copywriter(new Person(this.Name, this.Last_Name, this.Birth_Date), this.Nickname, this.Rang, this.Rating); copy.ListInformationAboutCopywriterArticles = new List <Article>(); foreach (Article p in this.ListInformationAboutCopywriterArticles) { copy.AddArticles((Article)(p.DeepCopy())); } copy.OrderList = new List <Order>(); foreach (Order p in this.OrderList) { copy.AddOrders((Order)(p.DeepCopy())); } return(copy); }
public bool Remove(Copywriter cw) { TKey key; if (CopywriterDictionary == null) { Console.WriteLine("The dictionary is empty "); return(false); } else { if (CopywriterDictionary.ContainsValue(cw) == false) { return(false); } else { key = CopywriterDictionary.First(x => x.Value == cw).Key; cw.PropertyChanged -= DictionaryHandler; CopywritersChanged?.Invoke(this, new CopywritersChangedEventArgs <TKey>(CopywriterCollectionName, Action.Remove, "", key)); return(CopywriterDictionary.Remove(key)); } } }
public CopywriterListHandlerEventArgs(string collectionWithChangesName, string collectionChangesTypeInfo, Copywriter referenceProperty) { CollectionWithChangesName = collectionWithChangesName; CollectionChangesTypeInfo = collectionChangesTypeInfo; ReferenceProperty = referenceProperty; }
public CopywriterListHandlerEventArgs() { CollectionWithChangesName = "Default CollectionWithChangesName"; CollectionChangesTypeInfo = "Default CollectionChangesTypeInfo"; ReferenceProperty = null; }
static void Main(string[] args) { Copywriter C1 = new Copywriter(); Console.WriteLine(C1.ToShortString()); Console.WriteLine(C1.ToString()); Copywriter C2 = new Copywriter(); Console.WriteLine(C1.Equals(C2)); Console.WriteLine(ReferenceEquals(C1, C2)); Console.WriteLine("\n Hash code 1 " + Convert.ToString(C1.GetHashCode()) + " Hash code 2 " + Convert.ToString(C2.GetHashCode())); C1 = new Copywriter(new Person("Artem", "Kosogov", new DateTime(2000, 05, 26)), "Arkos", 0, 3); C1.AddArticles(new Article[2] { new Article("kas_charp_lr_3", 35, new DateTime(2018, 04, 20)), new Article("kas_charp_lr_4", 75, new DateTime(2018, 03, 15)) }); C1.AddOrders(new Order[2] { new Order("Flowers", new DateTime(2018, 05, 21), 8), new Order("Cleaning", new DateTime(2018, 05, 21), 4) }); Console.WriteLine(" asd" + C1.Person.ToString()); object obj = C1.DeepCopy(); Copywriter C3 = obj as Copywriter; C1.Name = "Artur"; C1.ListInformationAboutCopywriterArticles[0].Article_name = "000000000000000000000000000000000000000000000"; Console.WriteLine("DEEP COPY OBJECT &&&&&&&&&&&&\n"); Console.WriteLine(C3.ToString()); Console.WriteLine("ORIGINAL OBJECT ^^^^^^^^^^^^^\n"); Console.WriteLine(C1.ToString()); Console.WriteLine(obj); Console.WriteLine("ADDED ORDERS AND ARTICLES ***********\n"); Console.WriteLine(C1.ToString()); C1.ListInformationAboutCopywriterArticles[0] = new Article("Article 1", 50, new DateTime(2000, 10, 01)); Console.WriteLine("All orders and articles\n "); foreach (var p in C1.GetArticleAndOrder()) { Console.WriteLine(p); } Console.WriteLine("All orders lower than 10 hours\n"); foreach (var p in C1.GetOrders(10)) { Console.WriteLine(p); } try { C1.Rating = 10; } catch (InvalidOperationException ex) { Console.WriteLine("Error " + ex.Message); } Console.WriteLine("Average quantity of sings ={0}", C1.AverageQuantityOfSings + "\n"); // string str; // str = Console.ReadLine(); // string[] substring; Console.WriteLine("Enter the array dimension you can write it trough that delims , . / _ ! ? : \n"); int[] size = Console.ReadLine().Split(new char[] { ',', '.', '/', '_', '!', ' ', '?', ':' }, StringSplitOptions.RemoveEmptyEntries).Select(i => int.Parse(i)).ToArray <int>(); // substring = str.Split(',', ':', '.', '#', '?', '!', '*'); int n, m; n = size[0]; m = size[1]; // n = Convert.ToInt32(substring[0]); //m = Convert.ToInt32(substring[1]); Article[] dimension1 = new Article[n * m]; Article[,] dimension2 = new Article[n, m]; Article[][] dimension3 = new Article[n][]; for (int i = 0; i < n; i++) { dimension3[i] = new Article[m]; } for (int i = 0; i < n * m; i++) { dimension1[i] = new Article(); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { dimension2[i, j] = new Article(); } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { dimension3[i][j] = new Article(); } } int t1 = Environment.TickCount; for (int i = 0; i < n * m; i++) { dimension1[i].Quantity_of_sings = 10; } int t2 = Environment.TickCount; Console.WriteLine("Time for one dimension array = " + (t2 - t1) + " quantity of row = " + n + " quantity of columns = " + m + "\n"); int t3 = Environment.TickCount; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { dimension2[i, j].Quantity_of_sings = 10; } } int t4 = Environment.TickCount; Console.WriteLine("Time for two dimension array = " + (t4 - t3) + " quantity of row = " + n + " quantity of columns = " + m + "\n"); int t5 = Environment.TickCount; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { dimension3[i][j].Quantity_of_sings = 10; } } int t6 = Environment.TickCount; Console.WriteLine("Time for stepped dimension array = " + (t6 - t5) + " quantity of row = " + n + " quantity of columns = " + m + "\n"); CopywriterCollection cc = new CopywriterCollection(); cc.AddCopywriters(C1, C3); cc.AddDefaults(); cc.SortByLastName(); Console.WriteLine(cc.ToShortString()); cc.SortByBirthDate(); cc.SortByAveregeQuantityOfSings(); Console.WriteLine(cc.ToString()); //try //{ Person person = new Person(); TestCollections tc = new TestCollections(1000); Console.WriteLine(String.Format("First element:\n" + tc.Time(1) + "Central element:\n" + tc.Time(500) + "Last element:\n" + tc.Time(1000) + "Element not in collection: \n" + tc.Time(2000))); //} //catch (InvalidOperationException) { Console.WriteLine( " NWn " ); } Console.WriteLine(cc.ToShortString()); Console.ReadKey(); }