Exemplo n.º 1
0
 private static ProcessResource ToResource(this IRepositoryAsync<Process> repository, Process p)
 {
     return new ProcessResource
     {
         ProcessID = p.ProcessID,
         Name = p.Name,
         Geography = p.Geography,
         //ProcessTypeID = TransformNullable(p.ProcessTypeID, "Process.ProcessTypeID"),
         ReferenceTypeID = p.ReferenceTypeID,
         ReferenceFlowID = p.ReferenceFlowID,
         CompositionFlowID = repository.GetRepository<ProcessComposition>().Queryable()
             .Where(pc => pc.ProcessID == p.ProcessID)
             .Select(pc => pc.CompositionModel.FlowID).FirstOrDefault(),
         ReferenceYear = p.ReferenceYear,
         UUID = p.ILCDEntity.UUID,
         Version = p.ILCDEntity.Version,
         DataSource = p.ILCDEntity.DataSource.Name,
         isPrivate = (p.ILCDEntity.DataSource.VisibilityID == 2),
         hasElementaryFlows = repository.GetRepository<ProcessFlow>().Queryable()
             .Where(pf => pf.ProcessID == p.ProcessID)
             .Where(pf => pf.Flow.FlowTypeID == 2).Any()
     };
 }
Exemplo n.º 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;
        }