private async void ExecuteOpen(object param) { ObservableModelPrediction.Clear(); AvailableClasses.Clear(); FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { try { IsRunning = true; (var OldImages, var NewImages) = await client.PostOld(fbd.SelectedPath, cts); OldImages.ForEach(delegate(PredictionResponse prs) { AddPrecomputedPrediction(new ModelPrediction(prs.ClassName, prs.Proba, prs.FilePath, Convert.FromBase64String(prs.Image))); }); var NewImagesResults = await client.GetNew(NewImages, cts); NewImagesResults.ForEach(delegate(PredictionResult pr) { AddPrediction(pr); }); IsRunning = false; } catch (TaskCanceledException tce) { MessageBox.Show("Tasks were cancelled"); } catch (Exception e) { MessageBox.Show("Prediction failed!"); } } }
public void Initialize(Person connectedPerson) { ConnectedPerson = connectedPerson; ResetAll(); if (HasRequiredPermissions) { // Get the school data and use to it to populate this View Model's data SchoolEntities schoolData = new SchoolEntities(); // Create a list of all the classes in the school schoolData.Classes.ToList().ForEach(currClass => AvailableClasses.Add(currClass.classID, currClass.className)); AvailableHomeroomClasses.Add(FIELD_NOT_SET, "לא מוגדר"); schoolData.Classes.Where(currClass => currClass.Teachers.Count() == 0).ToList() .ForEach(currClass => AvailableHomeroomClasses.Add(currClass.classID, currClass.className)); // Create a list of all the parents in the school AvailableParents.Add(FIELD_NOT_SET, "לא מוגדר"); schoolData.Persons.Where(p => p.isParent).ToList() .ForEach(parent => AvailableParents.Add(parent.personID, parent.firstName + " " + parent.lastName)); // Create a list of all the students in the school schoolData.Persons.Where(p => p.isStudent).ToList() .ForEach(student => AvailableStudents.Add(student.personID, student.firstName + " " + student.lastName)); // Create a list of all the courses in the school schoolData.Courses.Where(course => course.isHomeroomTeacherOnly == false).ToList() .ForEach(course => AvailableCoursesMustChoose.Add(course.courseID, course.courseName)); AvailableCourses.Add(FIELD_NOT_SET, "לא מוגדר"); AvailableCoursesMustChoose.ToList().ForEach(course => AvailableCourses.Add(course.Key, course.Value)); } }
public void Write(Packet packet) { packet.Write(VirtualRealmAddress); packet.Write(VirtualRealms.Count); packet.Write(TimeRemain); packet.Write(TimeOptions); packet.Write(TimeRested); packet.Write(ActiveExpansionLevel); packet.Write(AccountExpansionLevel); packet.Write(TimeSecondsUntilPCKick); packet.Write(AvailableRaces.Count); packet.Write(AvailableClasses.Count); packet.Write(Templates.Count); packet.Write(CurrencyID); VirtualRealms.ForEach(vr => vr.Write(packet)); AvailableRaces.ForEach(ar => ar.Write(packet)); AvailableClasses.ForEach(ac => ac.Write(packet)); Templates.ForEach(t => t.Write(packet)); packet.PutBit(IsExpansionTrial); packet.PutBit(ForceCharacterTemplate); packet.PutBit(NumPlayersHorde); packet.PutBit(NumPlayersAlliance); packet.PutBit(IsVeteranTrial); packet.Flush(); }
// Clears all the data in this View Model private void ResetAll() { // Reset all of the lists AvailableClasses.Clear(); AvailableParents.Clear(); AvailableStudents.Clear(); AvailableCourses.Clear(); AvailableCoursesMustChoose.Clear(); AvailableHomeroomClasses.Clear(); // Reset all properties Username = ""; FirstName = ""; LastName = ""; Email = ""; Phone = ""; Birthdate = new DateTime(); IsNewStudent = false; IsNewTeacher = false; IsNewParent = false; IsNewSecretary = false; SelectedHomeroomClass = null; SelectedParent = null; SelectedStudent = null; SelectedClass = null; SelectedCourse1 = null; SelectedCourse2 = null; SelectedCourse3 = null; SelectedCourse4 = null; }
/// <summary> /// Choose a specific room and view its information. /// </summary> /// <param name="selectedRoom">The room's data</param> private void UseSelectedRoom(RoomData selectedRoom) { // Cleanup previous selections SelectedClass = NO_ASSIGNED_CLASS; RoomName = string.Empty; LessonsInSelectedRoom = new ObservableCollection <LessonsInRoom>(); // Remove the previous room choice's class from the available classes list (as it is already assigned to that room) if (_previousRoomClass != null) { AvailableClasses.Remove(_previousRoomClass.Value); } // Update the properties per the selected room if (selectedRoom != null) { RoomName = selectedRoom.Name; // If the room has an homeroom, add it first to the available classes list if (selectedRoom.HomeroomClassID != null) { AvailableClasses.Add(selectedRoom.HomeroomClassID.Value, selectedRoom.HomeroomClassName); SelectedClass = selectedRoom.HomeroomClassID.Value; } // Save this room class ID so it can be removed from the available classes when we select another room _previousRoomClass = selectedRoom.HomeroomClassID; // Create the list of lessons in the current room if (selectedRoom.LessonsInThisRoom != null) { LessonsInSelectedRoom = new ObservableCollection <LessonsInRoom>(selectedRoom.LessonsInThisRoom); } } }
public void DeliverPendingClasses(IContext context, IMailSender sender) { var classroomClasses = GetDeliveryPlanClassesInfo(); if (Concluded && AvailableClasses.Count != classroomClasses.Count()) { return; } foreach (var classroomClass in classroomClasses) { if (classroomClass.DeliveryDate <= DateTime.Today && AvailableClasses.All(ac => ac.ClassId != classroomClass.Class.Id)) { DeliverClass(context, sender, classroomClass); } } if (AvailableClasses.Count != classroomClasses.Count()) { return; } Concluded = true; context.Save(); }
public void Clear() { AvailableClasses.Clear(); ClassesImages.Clear(); SelectedClassInfo.Clear(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AvailableCLasses")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CLassesImages")); }
public void Initialize(Person connectedPerson) { // Reset all information ConnectedPerson = connectedPerson; AvailableUserTypes.Clear(); AvailableUsers.Clear(); AvailableClasses.Clear(); AvailableParents.Clear(); AvailableStudents.Clear(); AvailableCourses.Clear(); AvailableCoursesMustChoose.Clear(); AvailableHomeroomClasses.Clear(); if (HasRequiredPermissions) { _schoolData = new SchoolEntities(); // Create a list of all the editable user types if (!CanEditManagement) { AvailableUserTypes.AddRange(new List <string>() { Globals.USER_TYPE_STUDENT, Globals.USER_TYPE_TEACHERS, Globals.USER_TYPE_PARENTS }); } else { AvailableUserTypes.AddRange(new List <string>() { Globals.USER_TYPE_STUDENT, Globals.USER_TYPE_TEACHERS, Globals.USER_TYPE_PARENTS, Globals.USER_TYPE_SECRETARIES, Globals.USER_TYPE_PRINCIPAL }); } SelectedUserType = AvailableUserTypes[0]; // Create a list of all the classes in the school _schoolData.Classes.ToList().ForEach(currClass => AvailableClasses.Add(currClass.classID, currClass.className)); AvailableHomeroomClasses.Add(FIELD_NOT_SET, "לא מוגדר"); _schoolData.Classes.Where(currClass => currClass.Teachers.Count() == 0).ToList() .ForEach(currClass => AvailableHomeroomClasses.Add(currClass.classID, currClass.className)); // Create a list of all the parents in the school AvailableParents.Add(FIELD_NOT_SET, "לא מוגדר"); _schoolData.Persons.Where(p => p.isParent).ToList() .ForEach(parent => AvailableParents.Add(parent.personID, parent.firstName + " " + parent.lastName)); // Create a list of all the students in the school _schoolData.Persons.Where(p => p.isStudent).ToList() .ForEach(student => AvailableStudents.Add(student.personID, student.firstName + " " + student.lastName)); // Create a list of all the courses in the school _schoolData.Courses.Where(course => course.isHomeroomTeacherOnly == false).ToList() .ForEach(course => AvailableCoursesMustChoose.Add(course.courseID, course.courseName)); AvailableCourses.Add(FIELD_NOT_SET, "לא מוגדר"); AvailableCoursesMustChoose.ToList().ForEach(course => AvailableCourses.Add(course.Key, course.Value)); } }
private async void PostRequest() { try { var content = new StringContent(JsonConvert.SerializeObject(imageDirectory), Encoding.UTF8, "application/json"); HttpResponseMessage httpResponse; try { httpResponse = await client.PostAsync(url, content, cts.Token); } catch (HttpRequestException) { await disp.BeginInvoke(new Action(() => { MessageBox.Show("NO CONNECTION", "Warning"); Stop(); })); return; } if (httpResponse.IsSuccessStatusCode) { var items = JsonConvert.DeserializeObject <List <RecognitionInfo> >(httpResponse.Content.ReadAsStringAsync().Result); foreach (var item in items) { await disp.BeginInvoke(new Action(() => //await ??? { ClassesImages.Add(item); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ClassesImages")); Pair <string, int> p; try { p = AvailableClasses.Single(i => i.Item1 == item.Class); p.Item2 += 1; } catch (InvalidOperationException) { AvailableClasses.Add(new Pair <string, int>(item.Class, 1)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AvailableClasses")); } })); } isRunning = false; } } catch (OperationCanceledException) { await disp.BeginInvoke(new Action(() => { MessageBox.Show("RECOGNITION STOPPED", "Warning"); })); } }
public Employee(string name, string myClass) { Name = name; AvailableClasses classEnum; if (!Enum.TryParse(myClass, true, out classEnum)) { classEnum = AvailableClasses.Other; } Class = classEnum; }
private void ExecuteClear(object param) { ObservableModelPrediction.Clear(); AvailableClasses.Clear(); try { client.Delete(); } catch (Exception e) { MessageBox.Show("Clearing DataBase failed!"); } }
internal void DeliverClass(IContext context, IMailSender sender, ClassDeliveryPlan classDeliveryPlan) { classDeliveryPlan.DeliveryDate = DateTime.Now; AvailableClasses.Add(classDeliveryPlan); context.GetList <Notice>().Add(new Notice { Text = $@"New <a href='Class/Watch/{classDeliveryPlan.ClassId}'>{Resource.ClassName} {classDeliveryPlan.Class.Name}</a> available! <br /> <a href='Class/Index/{classDeliveryPlan.Class.Course.Id}'>{Resource.CourseName} {classDeliveryPlan.Class.Course.Name}</a> <br />", DateTime = DateTime.Now, DeliveryPlan = this }); context.Save(); SendDeliveringClassEmail(context, sender, classDeliveryPlan.Class, Students); }
private void AddPrediction(PredictionResult pr) { dispatcher.BeginInvoke(new Action(() => { ObservableModelPrediction.Add(new ModelPrediction(pr)); var buf = AvailableClasses.Where(x => x.Item1 == pr.ClassName).FirstOrDefault(); if (buf != null) { AvailableClasses[AvailableClasses.IndexOf(buf)] = new Tuple <string, int>(buf.Item1, buf.Item2 + 1); } else { AvailableClasses.Add(new Tuple <string, int>(pr.ClassName, 1)); } })); }
/// <summary> /// Assistant method that clears all the ViewModel properties /// </summary> private void ResetData() { AvailableSearchChoices.Clear(); LessonsTableData.Clear(); AvailableClasses.Clear(); AvailableCourses.Clear(); AvailableTeachers.Clear(); AvailableRooms.Clear(); SelectedLesson = null; SelectedSearchChoice = NOT_ASSIGNED; SelectedTeacher = NOT_ASSIGNED; SelectedClass = NOT_ASSIGNED; LessonFirstDay = NOT_ASSIGNED; LessonSecondDay = NOT_ASSIGNED; LessonThirdDay = NOT_ASSIGNED; LessonFourthDay = NOT_ASSIGNED; LessonFirstHour = NOT_ASSIGNED; LessonSecondHour = NOT_ASSIGNED; LessonThirdHour = NOT_ASSIGNED; LessonFourthHour = NOT_ASSIGNED; }
public void Initialize(Person connectedPerson) { ConnectedPerson = connectedPerson; // Get the list of existing rooms RoomsTableData = new ObservableCollection <RoomData>(_schoolData.Rooms.AsEnumerable().Select(room => ModelRoomToRoomData(room)).ToList()); // Create the basic list of available classes AvailableClasses.Clear(); // Add a 'No class' option, as not all rooms are assigned to a specific class AvailableClasses.Add(NO_ASSIGNED_CLASS, "אין כיתה משויכת"); // Create the list of classes that don't have an homeroom already _schoolData.Classes.Where(schoolClass => schoolClass.roomID == null).ToList() .ForEach(schoolClass => AvailableClasses.Add(schoolClass.classID, schoolClass.className)); SelectedClass = NO_ASSIGNED_CLASS; // For some reason, after re-initializing this view, the SelectedClass is not updated properly in the view unless called again OnPropertyChanged("SelectedClass"); }
public void Initialize(Person connectedPerson) { ConnectedPerson = connectedPerson; ResetData(); // Create the lists of possible classes, courses, teachers _schoolData.Classes.ToList().ForEach(schoolClass => AvailableClasses.Add(schoolClass.classID, schoolClass.className)); _schoolData.Courses.ToList().ForEach(course => AvailableCourses.Add(course.courseID, course.courseName)); _schoolData.Teachers.Where(teacher => !teacher.Person.User.isDisabled).ToList() .ForEach(teacher => AvailableTeachers.Add(teacher.teacherID, teacher.Person.firstName + " " + teacher.Person.lastName)); // Initialize the rooms list. Note that a room is optional and therefore has a NOT_ASSIGNED option AvailableRooms.Add(NOT_ASSIGNED, "ללא"); _schoolData.Rooms.ToList().ForEach(room => AvailableRooms.Add(room.roomID, room.roomName)); SearchingByClass = true; // For some reason, after re-initializing this view, the selections are not updated properly in the view unless called again OnPropertyChanged("SelectedClass"); OnPropertyChanged("SelectedCourse"); OnPropertyChanged("SelectedTeacher"); OnPropertyChanged("SelectedRoom"); }
public static T Parse <T>(GameBoxReader r, uint?classID = null, GameBox <T> gbx = null, IProgress <GameBoxReadProgress> progress = null) where T : Node { var stopwatch = Stopwatch.StartNew(); if (!classID.HasValue) { classID = r.ReadUInt32(); } if (classID == uint.MaxValue) { return(null); } classID = Remap(classID.Value); if (!AvailableClasses.TryGetValue(classID.Value, out Type type)) { throw new NotImplementedException($"Node ID 0x{classID.Value:X8} is not implemented. ({Names.Where(x => x.Key == Chunk.Remap(classID.Value)).Select(x => x.Value).FirstOrDefault() ?? "unknown class"})"); } T node = null; if (gbx == null) { node = (T)Activator.CreateInstance(type); } else { node = gbx.MainNode; } IGameBoxBody body; if (r.Lookbackable is Chunk ch) { body = (IGameBoxBody)ch.Part; } else { body = (IGameBoxBody)r.Lookbackable; } node.Body = body; var chunks = new ChunkSet { Node = node }; node.Chunks = chunks; uint?previousChunk = null; while (r.BaseStream.Position < r.BaseStream.Length) { if (r.BaseStream.Position + 4 > r.BaseStream.Length) { Debug.WriteLine($"Unexpected end of the stream: {r.BaseStream.Position}/{r.BaseStream.Length}"); var bytes = r.ReadBytes((int)(r.BaseStream.Length - r.BaseStream.Position)); break; } var chunkID = r.ReadUInt32(); if (chunkID == 0xFACADE01) // no more chunks { break; } else if (chunkID == 0) { // weird case after ending node reference } else { var logChunk = $"[{node.ClassName}] 0x{chunkID:X8} ({(float)r.BaseStream.Position / r.BaseStream.Length:0.00%})"; if (node.Body?.GBX.ClassID.HasValue == true && Remap(node.Body.GBX.ClassID.Value) == node.ID) { Log.Write(logChunk); } else { Log.Write($"~ {logChunk}"); } } Type chunkClass = null; Chunk chunk = null; var chunkRemapped = Chunk.Remap(chunkID); var reflected = ((chunkRemapped & 0xFFFFF000) == node.ID || AvailableInheritanceClasses[type].Contains(chunkRemapped & 0xFFFFF000)) && (AvailableChunkClasses[type].TryGetValue(chunkRemapped, out chunkClass) || AvailableChunkClasses[type].TryGetValue(chunkID & 0xFFF, out chunkClass)); var skippable = reflected && chunkClass.BaseType.GetGenericTypeDefinition() == typeof(SkippableChunk <>); if (!reflected || skippable) { var skip = r.ReadUInt32(); if (skip != 0x534B4950) { if (chunkID != 0 && !reflected) { node.FaultyChunk = chunkID; var logChunkError = $"[{node.ClassName}] 0x{chunkID:X8} ERROR (wrong chunk format or unknown unskippable chunk)"; if (node.Body?.GBX.ClassID.HasValue == true && Remap(node.Body.GBX.ClassID.Value) == node.ID) { Log.Write(logChunkError, ConsoleColor.Red); } else { Log.Write($"~ {logChunkError}", ConsoleColor.Red); } throw new Exception($"Wrong chunk format or unskippable chunk: 0x{chunkID:X8} (" + $"{Names.Where(x => x.Key == Chunk.Remap(chunkID & 0xFFFFF000)).Select(x => x.Value).FirstOrDefault() ?? "unknown class"})" + $"\nPrevious chunk: 0x{previousChunk ?? 0:X8} (" + $"{(previousChunk.HasValue ? (Names.Where(x => x.Key == Chunk.Remap(previousChunk.Value & 0xFFFFF000)).Select(x => x.Value).FirstOrDefault() ?? "unknown class") : "not a class")})"); /* Usually breaks in the current state and causes confusion * * var buffer = BitConverter.GetBytes(chunkID); * using (var restMs = new MemoryStream(ushort.MaxValue)) * { * restMs.Write(buffer, 0, buffer.Length); * * while (r.PeekUInt32() != 0xFACADE01) * restMs.WriteByte(r.ReadByte()); * * node.Rest = restMs.ToArray(); * } * Debug.WriteLine("FACADE found.");*/ } break; } var chunkDataSize = r.ReadInt32(); var chunkData = new byte[chunkDataSize]; if (chunkDataSize > 0) { r.Read(chunkData, 0, chunkDataSize); } if (reflected && chunkClass.GetCustomAttribute <IgnoreChunkAttribute>() == null) { ISkippableChunk c; var constructor = chunkClass.GetConstructors().First(); var constructorParams = constructor.GetParameters(); if (constructorParams.Length == 0) { c = (ISkippableChunk)constructor.Invoke(new object[0]); c.Node = node; c.Part = (GameBoxPart)body; c.Stream = new MemoryStream(chunkData, 0, chunkData.Length, false); if (chunkData == null || chunkData.Length == 0) { c.Discovered = true; } c.OnLoad(); } else if (constructorParams.Length == 2) { c = (ISkippableChunk)constructor.Invoke(new object[] { node, chunkData }); } else { throw new ArgumentException($"{type.FullName} has an invalid amount of parameters."); } chunks.Add((Chunk)c); if (chunkClass.GetCustomAttribute <ChunkAttribute>().ProcessSync) { c.Discover(); } chunk = (Chunk)c; } else { Debug.WriteLine("Unknown skippable chunk: " + chunkID.ToString("X")); chunk = (Chunk)Activator.CreateInstance(typeof(SkippableChunk <>).MakeGenericType(type), node, chunkRemapped, chunkData); chunks.Add(chunk); } } if (reflected && !skippable) { if (skippable) // Does it ever happen? { var skip = r.ReadUInt32(); var chunkDataSize = r.ReadInt32(); } IChunk c; var constructor = chunkClass.GetConstructors().First(); var constructorParams = constructor.GetParameters(); if (constructorParams.Length == 0) { c = (IChunk)constructor.Invoke(new object[0]); c.Node = node; } else if (constructorParams.Length == 1) { c = (IChunk)constructor.Invoke(new object[] { node }); } else { throw new ArgumentException($"{type.FullName} has an invalid amount of parameters."); } c.Part = (GameBoxPart)body; c.OnLoad(); chunks.Add((Chunk)c); r.Chunk = (Chunk)c; // Set chunk temporarily for reading var posBefore = r.BaseStream.Position; GameBoxReaderWriter gbxrw = new GameBoxReaderWriter(r); try { if (chunkClass.GetCustomAttribute <IgnoreChunkAttribute>() == null) { if (chunkClass.GetCustomAttribute <AutoReadWriteChunkAttribute>() == null) { c.ReadWrite(node, gbxrw); } else { var unknown = new GameBoxWriter(((Chunk)c).Unknown, r.Lookbackable); var unknownData = r.ReadTillFacade(); unknown.Write(unknownData, 0, unknownData.Length); } } else { throw new Exception($"Chunk 0x{chunkID & 0xFFF:x3} from class {node.ClassName} is known but its content is unknown to read."); } } catch (EndOfStreamException) { Debug.WriteLine($"Unexpected end of the stream while reading the chunk."); } c.Progress = (int)(r.BaseStream.Position - posBefore); r.Chunk = null; chunk = (Chunk)c; } progress?.Report(new GameBoxReadProgress(GameBoxReadProgressStage.Body, (float)r.BaseStream.Position / r.BaseStream.Length, gbx, chunk)); previousChunk = chunkID; } stopwatch.Stop(); var logNodeCompletion = $"[{node.ClassName}] DONE! ({stopwatch.Elapsed.TotalMilliseconds}ms)"; if (node.Body?.GBX.ClassID.HasValue == true && Remap(node.Body.GBX.ClassID.Value) == node.ID) { Log.Write(logNodeCompletion, ConsoleColor.Green); } else { Log.Write($"~ {logNodeCompletion}", ConsoleColor.Green); } return(node); }
private static void DefineTypes() { var watch = Stopwatch.StartNew(); var assembly = Assembly.GetExecutingAssembly(); IEnumerable <Type> types; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException e) { types = e.Types.Where(x => x is not null) !; } var engineRelatedTypes = types.Where(t => t?.IsClass == true && t.Namespace?.StartsWith("GBX.NET.Engines") == true); var availableClassesByType = new Dictionary <Type, uint>(); foreach (var type in engineRelatedTypes) { if (!type.IsSubclassOf(typeof(CMwNod)) && type != typeof(CMwNod)) // Engine types { continue; } var id = type.GetCustomAttribute <NodeAttribute>()?.ID; if (!id.HasValue) { throw new Exception($"{type.Name} misses NodeAttribute."); } AvailableClasses.Add(id.Value, type); availableClassesByType.Add(type, id.Value); } foreach (var typePair in AvailableClasses) { var id = typePair.Key; var type = typePair.Value; var classes = new List <uint>(); Type currentType = type.BaseType !; while (currentType != typeof(object)) { classes.Add(availableClassesByType[currentType]); currentType = currentType.BaseType !; } AvailableInheritanceClasses[type] = classes; var chunks = type.GetNestedTypes().Where(x => x.IsSubclassOf(typeof(Chunk))); var baseType = type.BaseType !; while (baseType !.IsSubclassOf(typeof(CMwNod))) { chunks = chunks.Concat(baseType.GetNestedTypes().Where(x => x.IsSubclassOf(typeof(Chunk)))); baseType = baseType.BaseType; } var availableChunkClasses = new Dictionary <uint, Type>(); var availableHeaderChunkClasses = new Dictionary <uint, Type>(); foreach (var chunk in chunks) { var chunkAttribute = chunk.GetCustomAttribute <ChunkAttribute>(); if (chunkAttribute == null) { throw new Exception($"Chunk {chunk.FullName} doesn't have ChunkAttribute."); } if (chunk.GetInterface(nameof(IHeaderChunk)) == null) { availableChunkClasses.Add(chunkAttribute.ID, chunk); } else { availableHeaderChunkClasses.Add(chunkAttribute.ID, chunk); } } AvailableChunkClasses.Add(type, availableChunkClasses); AvailableHeaderChunkClasses.Add(type, availableHeaderChunkClasses); } foreach (var idClassPair in AvailableClasses) { var id = idClassPair.Key; var classType = idClassPair.Value; AvailableClassAttributes.Add(classType, classType.GetCustomAttributes()); } foreach (var classChunksPair in AvailableHeaderChunkClasses.Concat(AvailableChunkClasses)) { var attributeDictionary = new Dictionary <uint, IEnumerable <Attribute> >(); foreach (var chunkClassIdTypePair in classChunksPair.Value) { var id = chunkClassIdTypePair.Key; var chunkClass = chunkClassIdTypePair.Value; var attributes = chunkClass.GetCustomAttributes(); attributeDictionary[id] = attributes; AvailableChunkAttributesByType[chunkClass] = attributes; } AvailableChunkAttributes[classChunksPair.Key] = attributeDictionary; } foreach (var idClassPair in AvailableClasses) { var id = idClassPair.Key; var classType = idClassPair.Value; var privateConstructor = classType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Array.Empty <Type>(), null); if (privateConstructor is null) { throw new PrivateConstructorNotFoundException(classType); } var newExp = Expression.New(privateConstructor); var lambda = Expression.Lambda <Func <CMwNod> >(newExp); var compiled = lambda.Compile(); AvailableClassConstructors.Add(id, compiled); } foreach (var classChunksPair in AvailableChunkClasses) { var constructors = GetChunkConstructors(classChunksPair); if (constructors != null) { AvailableChunkConstructors[classChunksPair.Key] = constructors; } } foreach (var classChunksPair in AvailableHeaderChunkClasses) { var constructors = GetChunkConstructors(classChunksPair); if (constructors != null) { AvailableHeaderChunkConstructors[classChunksPair.Key] = constructors; } } Debug.WriteLine("Types defined in " + watch.Elapsed.TotalMilliseconds + "ms"); }
public static List <FitnessClass> GetClassList() { //creating and adding our classes Strength_Class StrengthClass1 = new Strength_Class { Name = "Pump", Duration = 60, Level = "Intermediate", WeightType = "Barbells, Bar" }; Strength_Class StrengthClass2 = new Strength_Class() { Name = "Combat", Duration = 45, Level = "Beginner", WeightType = "Body Weight", }; Cardio_Class CardioClass1 = new Cardio_Class { Name = "Attack", Duration = 60, Level = "Intermediate", FitnessLevelRequired = "High fitness Level Required" }; Cardio_Class CardioClass2 = new Cardio_Class { Name = "Zumba", Duration = 45, Level = "Beginner", FitnessLevelRequired = "No fitness Level Required" }; Balance_Class BalanceClass1 = new Balance_Class { Name = "Easy Yoga", Duration = 30, Level = "Beginner", Type = "Yoga" }; Balance_Class BalanceClass2 = new Balance_Class { Name = "Master Pilates", Duration = 90, Level = "Advanced", Type = "Pilates" }; Balance_Class BalanceClass3 = new Balance_Class { Name = "Zen", Duration = 60, Level = "Intermediate", Type = "Thai Chi" }; if (AvailableClasses.Count == 0) { AvailableClasses.Add(StrengthClass1); AvailableClasses.Add(StrengthClass2); AvailableClasses.Add(CardioClass1); AvailableClasses.Add(CardioClass2); AvailableClasses.Add(BalanceClass1); AvailableClasses.Add(BalanceClass2); AvailableClasses.Add(BalanceClass3); } //returning our class list return(AvailableClasses); }
private async void PostRequest() { try { //MessageBox.Show(imageDirectory); var images = from file in Directory.GetFiles(imageDirectory) // пустой путь - throw exception where file.Contains(".jpg") || file.Contains(".jpeg") || file.Contains(".png") select file; Dictionary <string, string> ToServer = new Dictionary <string, string>(); foreach (var i in images) { ToServer.Add(i, Convert.ToBase64String(File.ReadAllBytes(i))); } var content = new StringContent(JsonConvert.SerializeObject(ToServer), Encoding.UTF8, "application/json"); HttpResponseMessage httpResponse; try { httpResponse = await client.PostAsync(url, content, cts.Token); } catch (HttpRequestException) { await disp.BeginInvoke(new Action(() => { MessageBox.Show("NO CONNECTION", "Warning"); Stop(); })); return; } if (httpResponse.IsSuccessStatusCode) { var items = JsonConvert.DeserializeObject <List <RecognitionContract> >(httpResponse.Content.ReadAsStringAsync().Result); foreach (var item in items) { await disp.BeginInvoke(new Action(() => //await ??? { ClassesImages.Add(item); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ClassesImages")); Pair <string, int> p; try { p = AvailableClasses.Single(i => i.Item1 == item.Class); p.Item2 += 1; } catch (InvalidOperationException) { AvailableClasses.Add(new Pair <string, int>(item.Class, 1)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("AvailableClasses")); } })); } isRunning = false; } } catch (OperationCanceledException) { await disp.BeginInvoke(new Action(() => { MessageBox.Show("RECOGNITION STOPPED", "Warning"); })); } }
private static void DefineTypes() { var watch = Stopwatch.StartNew(); var assembly = Assembly.GetExecutingAssembly(); IEnumerable <Type> types; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException e) { types = e.Types; } var engineRelatedTypes = types.Where(t => t?.IsClass == true && t.Namespace?.StartsWith("GBX.NET.Engines") == true); var availableClassesByType = new Dictionary <Type, uint>(); foreach (var type in engineRelatedTypes) { if (type.IsSubclassOf(typeof(CMwNod)) || type == typeof(CMwNod)) // Engine types { var id = type.GetCustomAttribute <NodeAttribute>()?.ID; if (id.HasValue) { AvailableClasses.Add(id.Value, type); availableClassesByType.Add(type, id.Value); } else { throw new Exception($"{type.Name} misses NodeAttribute."); } } } var availableInheritanceTypes = new Dictionary <Type, List <Type> >(); foreach (var typePair in AvailableClasses) { var id = typePair.Key; var type = typePair.Value; List <uint> classes = new List <uint>(); List <Type> inheritedTypes = new List <Type>(); Type currentType = type.BaseType; while (currentType != typeof(object)) { classes.Add(availableClassesByType[currentType]); inheritedTypes.Add(currentType); currentType = currentType.BaseType; } AvailableInheritanceClasses[type] = classes; availableInheritanceTypes[type] = inheritedTypes; var chunks = type.GetNestedTypes().Where(x => x.IsSubclassOf(typeof(Chunk))); var availableChunkClasses = new Dictionary <uint, Type>(); var availableHeaderChunkClasses = new Dictionary <uint, Type>(); foreach (var chunk in chunks) { var chunkAttribute = chunk.GetCustomAttribute <ChunkAttribute>(); if (chunkAttribute == null) { throw new Exception($"Chunk {chunk.FullName} doesn't have ChunkAttribute."); } if (chunk.GetInterface(nameof(IHeaderChunk)) == null) { availableChunkClasses.Add(chunkAttribute.ID, chunk); } else { availableHeaderChunkClasses.Add(chunkAttribute.ID, chunk); } } AvailableChunkClasses.Add(type, availableChunkClasses); AvailableHeaderChunkClasses.Add(type, availableHeaderChunkClasses); } foreach (var typePair in availableInheritanceTypes) { var mainType = typePair.Key; foreach (var type in typePair.Value) { foreach (var chunkType in AvailableChunkClasses[type]) { AvailableChunkClasses[mainType][chunkType.Key] = chunkType.Value; } } } Debug.WriteLine("Types defined in " + watch.Elapsed.TotalMilliseconds + "ms"); }
public static ClassNode GetClass(AvailableClasses cType) { switch (cType) { /* Human */ case AvailableClasses.HumanBaseMage: return(new HumanBaseMage()); /* lvl 2 */ case AvailableClasses.HumanIWarlockClass: return(new HumanIWarlockClass()); case AvailableClasses.HumanTechnomancerClass: return(new HumanTechnomancerClass()); /* lvl 3 */ case AvailableClasses.HumanWizardClass: return(new HumanWizardClass()); case AvailableClasses.HumanGeniusClass: return(new HumanGeniusClass()); case AvailableClasses.HumanTinkererClass: return(new HumanTinkererClass()); case AvailableClasses.HumanArchMageClass: return(new HumanArchMageClass()); /* lvl 4 */ case AvailableClasses.HumanGigaWizardClass: return(new HumanGigaWizardClass()); case AvailableClasses.HumanIceWizardClass: return(new HumanIceWizardClass()); case AvailableClasses.HumanGrandMageClass: return(new HumanGrandMageClass()); case AvailableClasses.HumanMetalmancerClass: return(new HumanMetalmancerClass()); case AvailableClasses.HumanBramblelockClass: return(new HumanBramblelockClass()); case AvailableClasses.HumanKootClass: return(new HumanKootClass()); case AvailableClasses.HumanAstronautClass: return(new HumanAstronautClass()); case AvailableClasses.HumanDoctorClass: return(new HumanDoctorClass()); case AvailableClasses.HumanBaseScout: return(new HumanBaseScout()); /* lvl 2 */ case AvailableClasses.HumanCorporalClass: return(new HumanCorporalClass()); case AvailableClasses.HumanFSergeantClass: return(new HumanFSergeantClass()); /* lvl 3 */ case AvailableClasses.HumanMSergeantClass: return(new HumanMSergeantClass()); case AvailableClasses.HumanCSergeantClass: return(new HumanCSergeantClass()); case AvailableClasses.HumanLieutenantClass: return(new HumanLieutenantClass()); case AvailableClasses.HumanCaptainClass: return(new HumanCaptainClass()); /* lvl 4 */ case AvailableClasses.HumanGeneralClass: return(new HumanGeneralClass()); case AvailableClasses.HumanFlankCaptainClass: return(new HumanFlankCaptainClass()); case AvailableClasses.HumanArcaneCommanderClass: return(new HumanArcaneCommanderClass()); case AvailableClasses.HumanTankCommanderClass: return(new HumanTankCommanderClass()); case AvailableClasses.HumanPKnightClass: return(new HumanPKnightClass()); case AvailableClasses.HumanMineSweeperClass: return(new HumanMineSweeperClass()); case AvailableClasses.HumanPMarineClass: return(new HumanPMarineClass()); case AvailableClasses.HumanQEngineerClass: return(new HumanQEngineerClass()); case AvailableClasses.HumanBaseSoldier: return(new HumanBaseSoldier()); /* lvl 2 */ case AvailableClasses.HumanBerserkerClass: return(new HumanBerserkerClass()); case AvailableClasses.HumanPaladinClass: return(new HumanPaladinClass()); /* lvl 3 */ case AvailableClasses.HumanGPaladinClass: return(new HumanGPaladinClass()); case AvailableClasses.HumanIPaladinClass: return(new HumanIPaladinClass()); case AvailableClasses.HumanGDancerClass: return(new HumanGDancerClass()); case AvailableClasses.HumanFMarineClass: return(new HumanFMarineClass()); /* lvl 4 */ case AvailableClasses.HumanBloodBenderClass: return(new HumanBloodBenderClass()); case AvailableClasses.HumanDMercenaryClass: return(new HumanDMercenaryClass()); case AvailableClasses.HumanGNinjaClass: return(new HumanGNinjaClass()); case AvailableClasses.HumanRSamuraiClass: return(new HumanRSamuraiClass()); case AvailableClasses.HumanInquisitorClass: return(new HumanInquisitorClass()); case AvailableClasses.HumanTormentorClass: return(new HumanTormentorClass()); case AvailableClasses.HumanCCrusaderClass: return(new HumanCCrusaderClass()); case AvailableClasses.HumanDCrusaderClass: return(new HumanDCrusaderClass()); /* Egypt */ case AvailableClasses.EgyptBaseMage: return(new EgyptBaseMage()); /* lvl 2 */ case AvailableClasses.EgyptConjurerClass: return(new EgyptConjurerClass()); case AvailableClasses.EgyptDjinnClass: return(new EgyptDjinnClass()); /* lvl 3 */ case AvailableClasses.EgyptGenieClass: return(new EgyptGenieClass()); case AvailableClasses.EgyptElementalistClass: return(new EgyptElementalistClass()); case AvailableClasses.EgyptGeomancerClass: return(new EgyptGeomancerClass()); case AvailableClasses.EgyptKoboldClass: return(new EgyptKoboldClass()); /* lvl 4 */ case AvailableClasses.EgyptVWhispererClass: return(new EgyptVWhispererClass()); case AvailableClasses.EgyptTConduitClass: return(new EgyptTConduitClass()); case AvailableClasses.EgyptEMoverClass: return(new EgyptEMoverClass()); case AvailableClasses.EgyptHSpeakerClass: return(new EgyptHSpeakerClass()); case AvailableClasses.EgyptWMasterClass: return(new EgyptWMasterClass()); case AvailableClasses.EgyptRSpectreClass: return(new EgyptRSpectreClass()); case AvailableClasses.EgyptBKoboldClass: return(new EgyptBKoboldClass()); case AvailableClasses.EgyptTGoblinClass: return(new EgyptTGoblinClass()); case AvailableClasses.EgyptBaseScout: return(new EgyptBaseScout()); /* lvl 2 */ case AvailableClasses.EgyptManglerClass: return(new EgyptManglerClass()); case AvailableClasses.EgyptWhispererClass: return(new EgyptWhispererClass()); /* lvl 3 */ case AvailableClasses.EgyptSSenseiClass: return(new EgyptSSenseiClass()); case AvailableClasses.EgyptFBenderClass: return(new EgyptFBenderClass()); case AvailableClasses.EgyptArsonistClass: return(new EgyptArsonistClass()); case AvailableClasses.EgyptRChosenClass: return(new EgyptRChosenClass()); /* lvl 4 */ case AvailableClasses.EgyptPorcupineClass: return(new EgyptPorcupineClass()); case AvailableClasses.EgyptFEnforcerClass: return(new EgyptFEnforcerClass()); case AvailableClasses.EgyptCWalkerClass: return(new EgyptCWalkerClass()); case AvailableClasses.EgyptDCarrierClass: return(new EgyptDCarrierClass()); case AvailableClasses.EgyptPChannelerClass: return(new EgyptPChannelerClass()); case AvailableClasses.EgyptNSpeakerClass: return(new EgyptNSpeakerClass()); case AvailableClasses.EgyptFelonClass: return(new EgyptFelonClass()); case AvailableClasses.EgyptFirefighterClass: return(new EgyptFirefighterClass()); case AvailableClasses.EgyptBaseSoldier: return(new EgyptBaseSoldier()); /* lvl 2 */ case AvailableClasses.EgyptNomadClass: return(new EgyptNomadClass()); case AvailableClasses.EgyptScionClass: return(new EgyptScionClass()); /* lvl 3 */ case AvailableClasses.EgyptAshClass: return(new EgyptAshClass()); case AvailableClasses.EgyptAnukeClass: return(new EgyptAnukeClass()); case AvailableClasses.EgyptBesClass: return(new EgyptBesClass()); case AvailableClasses.EgyptHapyClass: return(new EgyptHapyClass()); /* lvl 4 */ case AvailableClasses.EgyptAMessiahClass: return(new EgyptAMessiahClass()); case AvailableClasses.EgyptSActorClass: return(new EgyptSActorClass()); case AvailableClasses.EgyptAnMessiahClass: return(new EgyptAnMessiahClass()); case AvailableClasses.EgyptMSandsClass: return(new EgyptMSandsClass()); case AvailableClasses.EgyptBMessiahClass: return(new EgyptBMessiahClass()); case AvailableClasses.EgyptOracleClass: return(new EgyptOracleClass()); case AvailableClasses.EgyptHMessiahClass: return(new EgyptHMessiahClass()); case AvailableClasses.EgyptAConduitClass: return(new EgyptAConduitClass()); /* Cthulhu */ case AvailableClasses.CthulhuBaseMage: return(new CthulhuBaseMage()); /* lvl 2 */ case AvailableClasses.CthulhuLesserDemonClass: return(new CthulhuLesserDemonClass()); case AvailableClasses.CthulhuNecromancerClass: return(new CthulhuNecromancerClass()); /* lvl 3 */ case AvailableClasses.CthulhuLichClass: return(new CthulhuLichClass()); case AvailableClasses.CthulhuPitLordClass: return(new CthulhuPitLordClass()); case AvailableClasses.CthulhuFurymancerClass: return(new CthulhuFurymancerClass()); case AvailableClasses.CthulhuGrandDemonClass: return(new CthulhuGrandDemonClass()); /* lvl 4 */ case AvailableClasses.CthulhuDevilClass: return(new CthulhuDevilClass()); case AvailableClasses.CthulhuFaustusClass: return(new CthulhuFaustusClass()); case AvailableClasses.CthulhuJudasClass: return(new CthulhuJudasClass()); case AvailableClasses.CthulhuVirgilClass: return(new CthulhuVirgilClass()); case AvailableClasses.CthulhuUReaperClass: return(new CthulhuUReaperClass()); case AvailableClasses.CthulhuPApostleClass: return(new CthulhuPApostleClass()); case AvailableClasses.CthulhuPGoblinClass: return(new CthulhuPGoblinClass()); case AvailableClasses.CthulhuGDispatcherClass: return(new CthulhuGDispatcherClass()); case AvailableClasses.CthulhuBaseScout: return(new CthulhuBaseScout()); /* lvl 2 */ case AvailableClasses.CthulhuStolisClass: return(new CthulhuStolisClass()); case AvailableClasses.CthulhuTrollClass: return(new CthulhuTrollClass()); /* lvl 3 */ case AvailableClasses.CthulhuHTotemClass: return(new CthulhuHTotemClass()); case AvailableClasses.CthulhuApparitionClass: return(new CthulhuApparitionClass()); case AvailableClasses.CthulhuPBeastClass: return(new CthulhuPBeastClass()); case AvailableClasses.CthulhuDEaterClass: return(new CthulhuDEaterClass()); /* lvl 4 */ case AvailableClasses.CthulhuPRiderClass: return(new CthulhuPRiderClass()); case AvailableClasses.CthulhuNyarlathotepClass: return(new CthulhuNyarlathotepClass()); case AvailableClasses.CthulhuDRiderClass: return(new CthulhuDRiderClass()); case AvailableClasses.CthulhuPBearerClass: return(new CthulhuPBearerClass()); case AvailableClasses.CthulhuFRiderClass: return(new CthulhuFRiderClass()); case AvailableClasses.CthulhuYigClass: return(new CthulhuYigClass()); case AvailableClasses.CthulhuAzathothClass: return(new CthulhuAzathothClass()); case AvailableClasses.CthulhuYogsothothClass: return(new CthulhuYogsothothClass()); case AvailableClasses.CthulhuBaseWisp: return(new CthulhuBaseWisp()); case AvailableClasses.CthulhuBaseSoldier: return(new CthulhuBaseSoldier()); /* lvl 2 */ case AvailableClasses.CthulhuVamprossClass: return(new CthulhuVamprossClass()); case AvailableClasses.CthulhuGoliathClass: return(new CthulhuGoliathClass()); /* lvl 3 */ case AvailableClasses.CthulhuAVamprossClass: return(new CthulhuAVamprossClass()); case AvailableClasses.CthulhuSuccubusClass: return(new CthulhuSuccubusClass()); case AvailableClasses.CthulhuSBehemothClass: return(new CthulhuSBehemothClass()); case AvailableClasses.CthulhuRGiantClass: return(new CthulhuRGiantClass()); /* lvl 4 */ case AvailableClasses.CthulhuVampireClass: return(new CthulhuVampireClass()); case AvailableClasses.CthulhuEssilexClass: return(new CthulhuEssilexClass()); case AvailableClasses.CthulhuLilithClass: return(new CthulhuLilithClass()); case AvailableClasses.CthulhuEveClass: return(new CthulhuEveClass()); case AvailableClasses.CthulhuGodzillaClass: return(new CthulhuGodzillaClass()); case AvailableClasses.CthulhuThingClass: return(new CthulhuThingClass()); case AvailableClasses.CthulhuWRiderClass: return(new CthulhuWRiderClass()); case AvailableClasses.CthulhuADeathClass: return(new CthulhuADeathClass()); /* Final */ case AvailableClasses.FinalBaseAntichrist: return(new FinalBaseAntichrist()); case AvailableClasses.FinalBaseApocalypse: return(new FinalBaseApocalypse()); case AvailableClasses.FinalBaseChaos: return(new FinalBaseChaos()); case AvailableClasses.FinalBaseCollapse: return(new FinalBaseCollapse()); case AvailableClasses.FinalBaseDarkness: return(new FinalBaseDarkness()); case AvailableClasses.FinalBaseDireOmen: return(new FinalBaseDireOmen()); case AvailableClasses.FinalBaseDisorder: return(new FinalBaseDisorder()); case AvailableClasses.FinalBaseEternalDarkness: return(new FinalBaseEternalDarkness()); case AvailableClasses.FinalBaseEvening: return(new FinalBaseEvening()); case AvailableClasses.FinalBaseIMessiah: return(new FinalBaseIMessiah()); case AvailableClasses.FinalBaseOmen: return(new FinalBaseOmen()); case AvailableClasses.FinalBaseTwilight: return(new FinalBaseTwilight()); default: return(new HumanBaseSoldier()); } }