/// <summary> /// Import data from loaded flow file to new Flow entity /// </summary> /// <param name="ilcdDb">Database context wrapper object</param> /// <returns>true iff data was imported</returns> private bool SaveFlow(DbContextWrapper ilcdDb) { bool isSaved = false; int? fpID; string dataSetInternalID = "0"; string uuid = GetCommonUUID(); int flowId = 0; if (ilcdDb.IlcdEntityAlreadyExists<Flow>(uuid)) ilcdDb.FindRefIlcdEntityID<Flow>(uuid, out flowId); else { XElement fpElement; Flow flow = new Flow(); SaveIlcdEntity(ilcdDb, flow, DataTypeEnum.Flow); // TODO : generate name from classification/category flow.Name = GetElementValue(ElementName("baseName")); flow.CASNumber = GetElementValue(ElementName("CASNumber")); flow.FlowTypeID = ilcdDb.GetFlowTypeID(GetElementValue(ElementName("typeOfDataSet"))); // Get Reference Flow Property dataSetInternalID = GetElementValue(ElementName("referenceToReferenceFlowProperty")); fpElement = GetElementWithInternalId(ElementName("flowProperty"), dataSetInternalID); fpID = GetFlowPropertyID(ilcdDb, fpElement); flow.ReferenceFlowProperty = (int)fpID; if (ilcdDb.AddIlcdEntity(flow, uuid)) { isSaved = true; flowId = flow.FlowID; } } if (flowId != 0) // successful import or existing object { // add flow properties that don't already exist var ffp = CreateFFPList(ilcdDb, flowId); ilcdDb.AddEntities<FlowFlowProperty>(ffp); // add classification data if it is not already present var cs = CreateClassificationList(ilcdDb, uuid); ilcdDb.AddEntities<Classification>(cs); Program.Logger.InfoFormat("Added {0} FlowFlowProperty entries and {1} Classification entries", ffp.Count(), cs.Count()); } return isSaved; }
/// <summary> /// This is bound to be super-slooooow /// </summary> /// <param name="repository"></param> /// <param name="f"></param> /// <returns></returns> private static FlowResource ToResource(this IRepository<Flow> repository, Flow f) { int? maxHL; string categoryName; //IEnumerable<Classification> classes = _ClassificationService.Query() // .Include(c => c.Category) // .Filter(c => c.ILCDEntityID == f.ILCDEntityID); IEnumerable<Classification> classes = repository.GetRepository<Classification>() .Query(c => c.ILCDEntityID == f.ILCDEntityID) .Include(c => c.Category) .Select(); maxHL = classes.Max(c => c.Category.HierarchyLevel); categoryName = classes.Where(c => c.Category.HierarchyLevel == maxHL).FirstOrDefault().Category.Name; return new FlowResource { FlowID = f.FlowID, Name = f.Name, FlowTypeID = f.FlowTypeID, ReferenceFlowPropertyID = f.ReferenceFlowProperty, CASNumber = f.CASNumber, Category = categoryName, UUID = f.ILCDEntity.UUID, Version = f.ILCDEntity.Version }; }