/// <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; }