예제 #1
0
 /// <summary>
 /// Import data from loaded unitgroup file to new UnitGroup entity
 /// </summary>
 /// <param name="ilcdDb">Database context wrapper object</param>
 /// <returns>true iff data was imported</returns>
 private bool SaveUnitGroup(DbContextWrapper ilcdDb)
 {
     bool isSaved = false;
     string dataSetInternalID = "0";
     string uuid = GetCommonUUID();
     if (!ilcdDb.IlcdEntityAlreadyExists<UnitGroup>(uuid)) {
         UnitGroup unitGroup = new UnitGroup();
         SaveIlcdEntity(ilcdDb, unitGroup, DataTypeEnum.UnitGroup);
         unitGroup.Name = GetCommonName();
         // Get Reference Flow Property
         dataSetInternalID = GetElementValue(ElementName("referenceToReferenceUnit"));
         if (ilcdDb.AddIlcdEntity(unitGroup, uuid)) {
             ilcdDb.AddEntities<UnitConversion>(CreateUnitConversionList(unitGroup, dataSetInternalID));
             isSaved = true;
         }
     }
     return isSaved;
 }
예제 #2
0
        private bool SaveProcess(DbContextWrapper ilcdDb)
        {
            bool isSaved = false;
            string lookupName;
            string uuid = GetCommonUUID();
            string version = GetCommonVersion();
            if (!ilcdDb.IlcdEntityAlreadyExists<LcaDataModel.Process>(uuid, version)) {
                Program.Logger.InfoFormat("Importing process with uuid {0}", uuid);
                LcaDataModel.Process process = new LcaDataModel.Process();
                SaveIlcdEntity(ilcdDb, process, DataTypeEnum.Process);
                process.Name = GetElementValue(ElementName("baseName"));
                process.ReferenceYear = GetElementValue(_CommonNamespace + "referenceYear");
                string geog = GetElementAttributeValue(ElementName("locationOfOperationSupplyOrProduction"), "location");
                if (geog.Length > 15)
                    geog = geog.Substring(0, 15);
                process.Geography = geog;
                lookupName = GetElementAttributeValue(ElementName("quantitativeReference"), "type");
                if (lookupName != null) {
                    process.ReferenceTypeID = ilcdDb.LookupEntityID<ReferenceType>(lookupName);
                }
                lookupName = GetElementValue(ElementName("typeOfDataSet"));
                if (lookupName != null) {
                    process.ProcessTypeID = ilcdDb.LookupEntityID<ProcessType>(lookupName);
                }
                if (ilcdDb.AddIlcdEntity(process, uuid, version)) {
                    List<ProcessFlow> pfList =
                        LoadedDocument.Root.Descendants(ElementName("exchanges")).Elements(ElementName("exchange")).Select(f =>
                            CreateProcessFlow(ilcdDb, f, process.ID)).ToList();
                    ilcdDb.AddEntities<ProcessFlow>(pfList);

                    isSaved = true;
                }
            }
            return isSaved;
        }
예제 #3
0
        /// <summary>
        /// Import data from loaded flowproperty file to new FlowProperty entity
        /// </summary>
        /// <param name="ilcdDb">Database context wrapper object</param>
        /// <returns>true iff data was imported</returns>
        private bool SaveFlowProperty(DbContextWrapper ilcdDb)
        {
            bool isSaved = false;
            string ugUUID;
            string uuid = GetCommonUUID();
            if (!ilcdDb.IlcdEntityAlreadyExists<FlowProperty>(uuid)) {
                FlowProperty flowProperty = new FlowProperty();
                SaveIlcdEntity(ilcdDb, flowProperty, DataTypeEnum.FlowProperty);
                flowProperty.Name = GetCommonName();
                ugUUID = GetElementAttributeValue(ElementName("referenceToReferenceUnitGroup"), "refObjectId");
                if (ugUUID == null) {
                    Program.Logger.WarnFormat("Unable to find referenceToReferenceUnitGroup in flow property {0}",
                        flowProperty.ILCDEntity.UUID);
                }
                else {
                    int ugID;
                    if (ilcdDb.FindRefIlcdEntityID<UnitGroup>(ugUUID, out ugID)) {
                        flowProperty.UnitGroupID = ugID;
                    }
                }

                isSaved = ilcdDb.AddIlcdEntity(flowProperty, uuid);
            }

            return isSaved;
        }
예제 #4
0
        private bool SaveLciaMethod(DbContextWrapper ilcdDb)
        {
            bool isSaved = false;
            string lookupName;
            string refUUID;
            string uuid = GetCommonUUID();
            if (!ilcdDb.IlcdEntityAlreadyExists<LCIAMethod>(uuid)) {
                LCIAMethod lciaMethod = new LCIAMethod();
                SaveIlcdEntity(ilcdDb, lciaMethod, DataTypeEnum.LCIAMethod);
                lciaMethod.Name = GetCommonName();
                lciaMethod.Methodology = GetElementValue(ElementName("methodology"));
                lookupName = GetElementValue(ElementName("impactCategory"));
                if (lookupName != null) {
                    lciaMethod.ImpactCategoryID = (int)ilcdDb.LookupEntityID<ImpactCategory>(lookupName);
                }
                lciaMethod.ImpactIndicator = GetElementValue(ElementName("impactIndicator"));
                lookupName = GetElementValue(ElementName("typeOfDataSet"));
                if (lookupName != null) {
                    lciaMethod.IndicatorTypeID = ilcdDb.LookupEntityID<IndicatorType>(lookupName);
                }
                lciaMethod.ReferenceYear = GetElementValue(ElementName("referenceYear"));
                lciaMethod.Duration = GetElementValue(ElementName("duration"));
                lciaMethod.ImpactLocation = GetElementValue(ElementName("impactLocation"));
                lciaMethod.Normalization = Convert.ToBoolean(GetElementValue(ElementName("normalisation")));
                lciaMethod.Weighting = Convert.ToBoolean(GetElementValue(ElementName("weighting")));
                lciaMethod.UseAdvice = GetElementValue(ElementName("useAdviceForDataSet"));
                refUUID = GetElementAttributeValue(ElementName("referenceQuantity"), "refObjectId");
                Debug.Assert(refUUID != null);
                int refID;
                if (ilcdDb.FindRefIlcdEntityID<FlowProperty>(refUUID, out refID)) {
                    lciaMethod.ReferenceFlowPropertyID = refID;
                }
                if (ilcdDb.AddIlcdEntity(lciaMethod, uuid)) {
                    List<LCIA> lciaList =
                        LoadedDocument.Root.Descendants(ElementName("characterisationFactors")).Elements(ElementName("factor")).Select(f =>
                            CreateLCIA(ilcdDb, f, lciaMethod.ID, uuid)).ToList();
                    ilcdDb.AddEntities<LCIA>(lciaList);

                    isSaved = true;

                }
            }
            return isSaved;
        }
예제 #5
0
        /// <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;
        }