public void InsertAt(int index, ResearchTeam team) { if (index <= 0 || index > _list.Count()) { _list.Add(team); } else { _list.Add(team); for (int i = 1; i < _list.Count() - 1 - index; ++i) { _list[_list.Count() - i] = _list[_list.Count() - 1 - i]; } _list[index] = team; TeamListHandlerEventArgs argss = new TeamListHandlerEventArgs(); argss.Name = "Inserted"; argss.Info = "ResearchTeam inserted"; argss.Index = index; if (ResearchTeamInserted != null) { ResearchTeamInserted(this, argss); } } TeamListHandlerEventArgs args = new TeamListHandlerEventArgs(); args.Name = "Inserted"; args.Info = "ResearchTeam added"; args.Index = index; if (ResearchTeamAdded != null) { ResearchTeamAdded(this, args); } }
public static void Main(string[] args) { ResearchTeamCollection col1 = new ResearchTeamCollection(); ResearchTeamCollection col2 = new ResearchTeamCollection(); TeamsJournal j1 = new TeamsJournal(); TeamsJournal j2 = new TeamsJournal(); col1.ResearchTeamAdded += j1.Handler; col1.ResearchTeamInserted += j1.Handler; col1.ResearchTeamAdded += j2.Handler; col1.ResearchTeamInserted += j2.Handler; col2.ResearchTeamAdded += j2.Handler; col2.ResearchTeamInserted += j2.Handler; ResearchTeam team = new ResearchTeam(); col1.AddDefaults(); col1.InsertAt(0, team); col2.InsertAt(0, team); col2.InsertAt(0, team); Console.WriteLine(j1.ToString()); Console.WriteLine(j2.ToString()); }
public void AddDefaults(int n) { for (int i = 0; i < n; i++) { ResearchTeam tTeam = new ResearchTeam("A" + i, "C" + i, i, "T" + i, TimeFrame.Long); AddResearchTeams(tTeam); } }
public TestCollections(int elementsCount) { foreach (var num in Enumerable.Range(1, elementsCount).RandomShuffle()) { ResearchTeam newObject = GenElement(num); teamList.Add(newObject.Team); strList.Add(newObject.Name); resTeamDict.Add(newObject.Team, newObject); resTeamDict2.Add(newObject.Name, newObject); } }
public static ResearchTeam GenElement(int num) { var result = new ResearchTeam("ResName" + num, "CompName" + num, num, "TeamName" + num, TimeFrame.Long); int artNum = new Random(Seed: DateTime.Now.Millisecond).Next(10); for (int i = 0; i < artNum; i++) { result.AddPapers(new Paper("ArtName" + num, new Person("Author" + num, "Surname" + num, new DateTime(2000, 1, 1)), new DateTime(2020, 10, 10))); } return(result); }
static void Main(string[] args) { ResearchTeam pz = new ResearchTeam("Family", "409 Production", 1234, TimeFrame.Year); ResearchTeam px = new ResearchTeam("Help", "Me", 103, TimeFrame.Long); ResearchTeam pxx = new ResearchTeam("Help", "Me", 505, TimeFrame.Long); Paper[] newPapers = //Список новых публикаций { new Paper("Goddess of Math", new Person(), new DateTime(2015, 02, 02)), new Paper("FSB", new Person("Alina", "Ruchinskaya", new DateTime(1999, 12, 03)), new DateTime(2017, 11, 06)), new Paper("Kotja", new Person("Eugene", "Gerasimov", new DateTime(2000, 01, 30)), new DateTime(2016, 03, 20)) }; Person[] newPerson = { new Person(), new Person("Alina", "Ruchinskaya", new DateTime(1999, 12, 03)), new Person("Eugene","Gerasimov", new DateTime(2000, 01, 30)), new Person("Lina", "Antonenko", new DateTime(2000, 07, 19)) }; pz.AddPapers(newPapers); //Добавляем новые публикации и учасников pz.AddMembers(newPerson); ResearchTeamCollection <string> rtc1 = new ResearchTeamCollection <string> { CollectionName = "First collection" }; ResearchTeamCollection <string> rtc2 = new ResearchTeamCollection <string> { CollectionName = "Second collection" }; TeamsJournal <string> tg1 = new TeamsJournal <string>(); rtc1.ResearchTeamsChanged += tg1.TeamChanged; //подписка rtc2.ResearchTeamsChanged += tg1.TeamChanged; rtc1.AddDefaults("150"); // добавление элементов rtc2.AddResearchTeams("120", pxx); rtc1.AddResearchTeams("17", pz); rtc1.AddResearchTeams("188", px); rtc2.AddResearchTeams("18", px); rtc1.resTeam["17"].Topic = "NEW TOPIC"; //изменение отдельных свойств 1 rtc2.resTeam["120"].Time = TimeFrame.Year; //2 rtc2.Remove(px); // удаление 3 px.Topic = "VERY NEW TOPIC"; //4 rtc1.Replace(pz, pxx); //5 pz.Time = TimeFrame.TwoYears; Console.WriteLine("TEAM JOURNAL:\n" + tg1.ToString()); Console.WriteLine("Count of journals: " + rtc1.CountOfJournals(0, 2000)); Console.ReadLine(); }
public void Search(int k) { int x, y, res; bool ch = false; ResearchTeam rt = AutoGeneric(k); x = Environment.TickCount; ch = teamList.Contains(rt.Team); y = Environment.TickCount; res = y - x; Console.WriteLine("List<Team> = {0} ms", res); Console.WriteLine("Found? " + ch); x = Environment.TickCount; ch = stringList.Contains(rt.Team.ToString()); y = Environment.TickCount; res = y - x; Console.WriteLine("List<string> = {0} ms", res); Console.WriteLine("Found? " + ch); x = Environment.TickCount; ch = teamDic.ContainsKey(rt.Team); y = Environment.TickCount; res = y - x; Console.WriteLine("Key - Dictionary<Team, ResearchTeam> = {0} ms", res); Console.WriteLine("Found? " + ch); x = Environment.TickCount; ch = teamDic.ContainsValue(rt); y = Environment.TickCount; res = y - x; Console.WriteLine("Key - Dictionary<Team, ResearchTeam> = {0} ms", res); Console.WriteLine("Found? " + ch); x = Environment.TickCount; ch = stringDic.ContainsKey(rt.Team.ToString()); y = Environment.TickCount; res = y - x; Console.WriteLine("Dictionary<string, ResearchTeam> = {0} ms", res); Console.WriteLine("Found? " + ch); x = Environment.TickCount; ch = stringDic.ContainsValue(rt); y = Environment.TickCount; res = y - x; Console.WriteLine("Dictionary<string, ResearchTeam> = {0} ms", res); Console.WriteLine("Found? " + ch); }
public bool Remove(ResearchTeam rt) { if (!resTeam.ContainsValue(rt)) { return(false); } else { foreach (var item in resTeam.Where(kpv => kpv.Value.Equals(rt)).ToList()) { resTeam.Remove(item.Key); item.Value.PropertyChanged -= ResearchTeamChangedInto; ResearchTeamsChanged?.Invoke(this, new ResearchTeamsChangedEventArgs <TKey>(CollectionName, Revision.Remove, " ", rt.ReNumber)); } return(true); } }
public bool Replace(ResearchTeam rtold, ResearchTeam rtnew) { if (!resTeam.ContainsValue(rtold)) { return(false); } else { foreach (var item in resTeam.Where(kpv => kpv.Value.Equals(rtold)).ToArray()) { resTeam[item.Key] = rtnew; rtold.PropertyChanged -= ResearchTeamChangedInto; rtnew.PropertyChanged += ResearchTeamChangedInto; ResearchTeamsChanged?.Invoke(this, new ResearchTeamsChangedEventArgs <TKey>(CollectionName, Revision.Replace, " ", rtnew.ReNumber)); } return(true); } }
public bool Remove(ResearchTeam rt) { if (!resTeamDict.Values.Contains(rt)) { return(false); } foreach (var pair in resTeamDict) { if (pair.Value == rt) { pair.Value.PropertyChanged -= ControlPropertyChanging; resTeamDict.Remove(pair.Key); ResearchTeamsChanged.Invoke(this, new ResearchTeamsChangedEventArgs <Tkey>(CollectionName, Revision.Remove, "", rt.LicenceNumber)); break; } } return(true); }
public static void Main() { ResearchTeamCollection <string> firstCollection = new ResearchTeamCollection <string>(team => team.Name) { CollectionName = "FirstCollection" }; ResearchTeamCollection <string> secondCollection = new ResearchTeamCollection <string>(team => team.Name) { CollectionName = "SecondCollection" }; TeamsJournal <string> journal = new TeamsJournal <string>(); firstCollection.ResearchTeamsChanged += journal.ChangesEventController; secondCollection.ResearchTeamsChanged += journal.ChangesEventController; ResearchTeam tTeam1 = new ResearchTeam("First", "OAO", 1, "TSquad1", TimeFrame.Long); ResearchTeam tTeam2 = new ResearchTeam("Second", "OAO", 2, "TSquad2", TimeFrame.TwoYears); ResearchTeam tTeam3 = new ResearchTeam("Third", "PAR", 3, "Ppp1", TimeFrame.TwoYears); ResearchTeam tTeam4 = new ResearchTeam("Fourth", "PAR", 4, "Ppp2", TimeFrame.Long); firstCollection.AddResearchTeams(tTeam1, tTeam2); secondCollection.AddResearchTeams(tTeam3, tTeam4); tTeam1.ResearchName = "New name"; tTeam2.ResearchDuration = TimeFrame.Long; tTeam3.ResearchName = "Reser Name123"; tTeam4.ResearchDuration = TimeFrame.Year; firstCollection.Remove(tTeam2); secondCollection.Remove(tTeam4); tTeam2.ResearchDuration = TimeFrame.TwoYears; tTeam4.ResearchName = "Old Research Name"; firstCollection.Replace(tTeam1, tTeam3); tTeam1.ResearchName = "TTeam11 new ResName"; Console.WriteLine(journal); }
public bool Replace(ResearchTeam rold, ResearchTeam rnew) { if (!resTeamDict.Values.Contains(rold)) { return(false); } Tkey tempKey = default(Tkey); foreach (var pair in resTeamDict) { if (pair.Value == rold) { pair.Value.PropertyChanged -= ControlPropertyChanging; tempKey = pair.Key; rnew.PropertyChanged += ControlPropertyChanging; } } resTeamDict[tempKey] = rnew; ResearchTeamsChanged.Invoke(this, new ResearchTeamsChangedEventArgs <Tkey>(CollectionName, Revision.Replace, "", rold.LicenceNumber)); return(true); }
public int GetTiming() { SetDefaults(); Console.WriteLine("\n\n--------List-------\n"); Team team = this[0]; var taskBegin = Environment.TickCount; _a.Contains(team); var taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for first: {0}", taskEnd - taskBegin); team = this[1]; taskBegin = Environment.TickCount; _a.Contains(team); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for second: {0}", taskEnd - taskBegin); team = this[2]; taskBegin = Environment.TickCount; _a.Contains(team); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for third: {0}", taskEnd - taskBegin); team = this[3]; taskBegin = Environment.TickCount; _a.Contains(team); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for fourth: {0}", taskEnd - taskBegin); Console.WriteLine("\n\n----Dictionary Keys----\n"); Team[] keys = new Team[4]; _c.Keys.CopyTo(keys, 0); taskBegin = Environment.TickCount; _c.ContainsKey(keys[0]); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for first: {0}", taskEnd - taskBegin); taskBegin = Environment.TickCount; _c.ContainsKey(keys[1]); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for second: {0}", taskEnd - taskBegin); taskBegin = Environment.TickCount; _c.ContainsKey(keys[2]); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for third: {0}", taskEnd - taskBegin); taskBegin = Environment.TickCount; _c.ContainsKey(keys[3]); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for fourth: {0}", taskEnd - taskBegin); Console.WriteLine("\n\n----Dictionary Values----\n"); ResearchTeam[] values = new ResearchTeam[4]; _c.Values.CopyTo(values, 0); taskBegin = Environment.TickCount; _c.ContainsValue(values[0]); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for first: {0}", taskEnd - taskBegin); taskBegin = Environment.TickCount; _c.ContainsValue(values[1]); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for second: {0}", taskEnd - taskBegin); taskBegin = Environment.TickCount; _c.ContainsValue(values[2]); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for third: {0}", taskEnd - taskBegin); taskBegin = Environment.TickCount; _c.ContainsValue(values[3]); taskEnd = Environment.TickCount; Console.WriteLine("\nSearch for fourth: {0}", taskEnd - taskBegin); return(0); }
public void AddResearchTeams(TKey key, ResearchTeam newteam) { resTeam.Add(key, newteam); newteam.PropertyChanged += ResearchTeamChangedInto; }
static ResearchTeam AutoGeneric(int k) //инициализация элементов { ResearchTeam rs = new ResearchTeam($"Topic{k}", $"Team{k}", k, TimeFrame.TwoYears); return(rs); }