private void AddCompRepToRecord(CompRep _cr) { this.comp_rep_record.Add(_cr); this.UpdateFlatRecord(); this.RecordChanged = true; this.RecordChanged = false; }
private async Task RemoveCompanyRepFromProgram(CompRep compRep) { List <CompRep> repToRemove = new List <CompRep>(); repToRemove.Add(compRep); await ProgramContext.RemoveCompRepsFromProgram(repToRemove, ProgrammeId); StateHasChanged(); await GetCompanyReps(); }
private async Task RemoveCompRepFromCourse(CompRep compRep) { List <CompRep> repToRemove = new List <CompRep>(); repToRemove.Add(compRep); await CourseContext.RemoveCompRepsFromCourse(repToRemove, CourseId); StateHasChanged(); await GetCompanyReps(); }
private void ToggleSelectedCompRep(CompRep s) { if (selectedCompReps.Exists(x => x.Equals(s))) { selectedCompReps.Remove(s); } else { selectedCompReps.Add(s); } }
private EFContext Seed(EFContext context) { context.Course.Add(new Course { CourseName = "Tom_Kurs" }); context.SaveChanges(); context.Student.Add(new Student { FirstName = "Tom_Student" }); context.Programmes.Add(new Programme { ProgramName = "Tom_Utbildning" }); context.CompRep.Add(new CompRep { FirstName = "Tom_CompRep" }); context.Group.Add(new Group { Title = "Tom_Grupp" }); var student = new Student { FirstName = "Student" }; var utbildning = new Programme { ProgramName = "Utbildning" }; var grupp = new Group { Title = "Grupp" }; var comprep = new CompRep { FirstName = "CompRep" }; var course = new Course { CourseName = "Kurs" }; context.Student.Add(student); context.SaveChanges(); context.Programmes.Add(utbildning); context.Course.Add(course); context.CompRep.Add(comprep); context.Group.Add(grupp); context.SaveChanges(); utbildning.Students = new List <Student>(); utbildning.Students.Add(student); course.Students = new List <Student>(); grupp.Members = new List <Person>(); course.Students.Add(student); grupp.Members.Add(student); context.SaveChanges(); return(context); }
private bool RemoveCompRepFromRecord(CompRep _cr) { if (_cr == null) { return(false); } bool success = this.comp_rep_record.Remove(_cr); this.UpdateFlatRecord(); this.RecordChanged = true; this.RecordChanged = false; return(success); }
public List <ComponentMessage> ExtractMessagesFrom(CompRep _cr) { List <ComponentMessage> extracted = new List <ComponentMessage>(); if (_cr == null) { return(extracted); } CompRepInfo cri = _cr as CompRepInfo; if (cri == null) { return(extracted); } List <CompRepInfo> cr_subCRs = cri.GetFlatListOfSubCompReps(); int nrSub = cr_subCRs.Count; if (nrSub == 0) { ComponentMessage msg = cri.ExtractMessage(MessagePositionInSeq.SINGLE_MESSAGE); if (msg != null) { extracted.Add(msg); } } else { ComponentMessage msg = cri.ExtractMessage(MessagePositionInSeq.SEQUENCE_START_MESSAGE); if (msg != null) { extracted.Add(msg); } for (int i = 0; i < nrSub; i++) { MessagePositionInSeq pos_current = (i == (nrSub - 1)) ? MessagePositionInSeq.SEQUENCE_END_MESSAGE : MessagePositionInSeq.MESSAGE_INSIDE_SEQUENCE; ComponentMessage msg_i = cr_subCRs[i].ExtractMessage(pos_current); if (msg_i != null) { extracted.Add(msg_i); } } } return(extracted); }
public async Task <int> InsertCompRep(CompRep compRep) // ENDAST FÖR TESTNING { using var context = dbContextFactory.CreateDbContext(); //compRep.User = new User //{ // UserType = UserTypeEnum.Company //}; context.Add(compRep); //transaction.Commit(); await context.SaveChangesAsync(); context.Entry(compRep).GetDatabaseValues(); return(1); //fix }
private List <CompRep> GetParentChain(CompRepInfo _cri) { if (_cri == null) { return(new List <CompRep>()); } List <CompRep> chain = new List <CompRep>(); CompRep parent = (_cri.CR_Parent > -1) ? this.FindById(_cri.CR_Parent) : null; CompRepInfo parent_as_cri = (parent == null) ? null : (parent as CompRepInfo); while (parent_as_cri != null) { chain.Add(parent); parent = (parent_as_cri.CR_Parent > -1) ? this.FindById(parent_as_cri.CR_Parent) : null; parent_as_cri = (parent == null) ? null : (parent as CompRepInfo); } return(chain); }
// for a sequence of messages public void AddCompReps(List <ComponentMessage> _cmsgs) { if (_cmsgs == null) { return; } if (_cmsgs.Count == 0) { return; } // add all List <CompRep> added = new List <CompRep>(); foreach (ComponentMessage cmsg in _cmsgs) { CompRep cr_new = AddCompRep(cmsg); if (cr_new != null) { added.Add(cr_new); } } if (added.Count == 0) { // updates only of Component Ids, if any this.RecordChanged = false; this.RecordChanged = true; return; } // establish the relationships btw the component representations: // assign the parent ID // assing the representations of sub-components foreach (CompRep cr in added) { CompRepInfo cri = cr as CompRepInfo; if (cri == null) { continue; } if (cri.Comp_Parent > -1) { CompRepInfo parent = this.FindByCompId(cri.Comp_Parent); if (parent != null) { cri.CR_Parent = parent.CR_ID; parent.AddSubCompRep(cri); this.comp_rep_record.Remove(cri); } } } this.UpdateFlatRecord(); // establish connectivity List <CompRepContainedIn> connection_nodes = this.comp_rep_record_flat.Where(x => x is CompRepContainedIn).Select(x => x as CompRepContainedIn).ToList(); if (connection_nodes.Count > 0) { foreach (CompRep cr in this.comp_rep_record_flat) { if (cr is CompRepConnects) { CompRepConnects connection_edge = cr as CompRepConnects; connection_edge.RetrieveConnectionPoints(connection_nodes); } } } // re-associate with existing geometry (this causes information flow back to the ComponentBuilder) // NOTE: after the hierarchy has been established in the previous step foreach (CompRep cr in this.comp_rep_record_flat) { if (cr is CompRepDescirbes) { CompRepDescirbes crd = cr as CompRepDescirbes; if (crd.GR_State.IsRealized) { this.communcation_manager.ConnectCompRepToZonedVolume(crd); } } else if (cr is CompRepAlignedWith) { CompRepAlignedWith cra = cr as CompRepAlignedWith; this.communcation_manager.ConnectCompRepToMaterial(cra); } } // done this.RecordChanged = false; this.RecordChanged = true; }
public CompRepInfo FindByParentComponentId(long _parent_comp_id) { CompRep found = this.comp_rep_record_flat.FirstOrDefault(x => (x is CompRepInfo) && (x as CompRepInfo).Comp_Parent == _parent_comp_id); return(found as CompRepInfo); }
public CompRepInfo FindByCompId(long _id) { CompRep found = this.comp_rep_record_flat.FirstOrDefault(x => (x is CompRepInfo) && (x as CompRepInfo).Comp_ID == _id); return(found as CompRepInfo); }
public CompRep FindById(long _id) { CompRep found = this.comp_rep_record_flat.FirstOrDefault(x => x.CR_ID == _id); return(found); }
public List <ComponentMessage> ExtractMessagesForReferenceUpdateFrom(CompRep _cr) { List <ComponentMessage> extracted = new List <ComponentMessage>(); if (_cr == null) { return(extracted); } CompRepInfo cri = _cr as CompRepInfo; if (cri == null) { return(extracted); } // call 'ExtractMessage' to force synchronization with geometry ComponentMessage msg1 = cri.ExtractMessage(MessagePositionInSeq.SINGLE_MESSAGE); // ............................................................................. List <CompRepInfo> cr_subCRs = cri.GetFlatListOfSubCompReps(); List <CompRepInfo> cr_CRs_w_refs = cr_subCRs.Where(x => x.Comp_RefCompIDs.Count > 0).ToList(); if (cri.Comp_RefCompIDs.Count > 0) { cr_CRs_w_refs.Insert(0, cri); } int nrMsg = cr_CRs_w_refs.Count; if (nrMsg == 1) { ComponentMessage msg = cr_CRs_w_refs[0].ExtractMessage(MessagePositionInSeq.SINGLE_MESSAGE); if (msg != null) { extracted.Add(msg); } } else if (nrMsg > 1) { for (int i = 0; i < nrMsg; i++) { MessagePositionInSeq pos_current = MessagePositionInSeq.SEQUENCE_START_MESSAGE; if (i > 0 && i < (nrMsg - 1)) { pos_current = MessagePositionInSeq.MESSAGE_INSIDE_SEQUENCE; } else if (i == (nrMsg - 1)) { pos_current = MessagePositionInSeq.SEQUENCE_END_MESSAGE; } ComponentMessage msg_i = cr_CRs_w_refs[i].ExtractMessage(pos_current); if (msg_i != null) { extracted.Add(msg_i); } } } return(extracted); }
public CompRep AddCompRep(ComponentMessage _cmsg) { if (_cmsg == null) { return(null); } if (this.communcation_manager == null) { return(null); // unable to communicate... } // check for duplicate COMPONENT representations CompRep same_comp_id = this.FindByCompId(_cmsg.CompID); if (same_comp_id != null) { return(same_comp_id); } // check for component representations with duplicate content -> take the one with the VALID COMPONENT ID CompRepInfo same_comp_content = this.FindSameStructureNoCompId(_cmsg); if (same_comp_content != null) { // just transfer the comp id same_comp_content.AdoptCompId(_cmsg); return(null); } // creates a representation of a component that has been here before and looks for the referenced geometry // OR... // creates a representation of a component that is here for the first time switch (_cmsg.GeomType) { case InterProcCommunication.Specific.Relation2GeomType.DESCRIBES: CompRepDescirbes created_D = new CompRepDescirbes(_cmsg, this.communcation_manager); this.AddCompRepToRecord(created_D); return(created_D); case InterProcCommunication.Specific.Relation2GeomType.DESCRIBES_3D: CompRepDescirbes3D created_D3d = new CompRepDescirbes3D(_cmsg, this.communcation_manager); this.AddCompRepToRecord(created_D3d); return(created_D3d); case InterProcCommunication.Specific.Relation2GeomType.DESCRIBES_2DorLESS: CompRepDescribes2DorLess created_D2d = new CompRepDescribes2DorLess(_cmsg, this.communcation_manager); this.AddCompRepToRecord(created_D2d); return(created_D2d); case InterProcCommunication.Specific.Relation2GeomType.GROUPS: return(null); case InterProcCommunication.Specific.Relation2GeomType.CONTAINED_IN: CompRepContainedIn created_CI = new CompRepContainedIn(_cmsg, this.communcation_manager); this.AddCompRepToRecord(created_CI); return(created_CI); case InterProcCommunication.Specific.Relation2GeomType.CONNECTS: CompRepConnects created_CO = new CompRepConnects(_cmsg, this.communcation_manager); this.AddCompRepToRecord(created_CO); return(created_CO); case InterProcCommunication.Specific.Relation2GeomType.ALIGNED_WITH: CompRepAlignedWith created_A = new CompRepAlignedWith(_cmsg, this.communcation_manager); this.AddCompRepToRecord(created_A); return(created_A); case InterProcCommunication.Specific.Relation2GeomType.NONE: // this is for the parent of a geometry containing component CompRepInfo created_N = new CompRepInfo(_cmsg, this.communcation_manager); this.AddCompRepToRecord(created_N); return(created_N); default: return(null); } }