Exemplo n.º 1
0
        public static IEnumerable<ParamResource> GetParamResource(this IRepository<Param> repository,
            Param p)
        {
            var PR = new List<ParamResource>();
            switch (p.ParamTypeID)
            {
                case 1:
                case 2:
                    {   // DependencyParam: TODO- mark conservation flow ?
                        PR = repository.GetRepository<DependencyParam>()
                            .Query(k => k.ParamID == p.ParamID)
                            .Select(k => new ParamResource()
                        {
                            ParamID = p.ParamID,
                            ParamTypeID = p.ParamTypeID,
                            ScenarioID = p.ScenarioID,
                            Name = p.Name,
                            FragmentFlowID = k.FragmentFlowID,
                            Value = k.Value
                        }).ToList();
                        foreach (var PRi in PR)
                            PRi.DefaultValue = repository.GetRepository<FragmentFlow>()
                                .GetDefaultValue((int)PRi.FragmentFlowID, p.ScenarioID);

                        break;
                    }
                case 4:
                    {   // FlowPropertyParam
                        PR = repository.GetRepository<FlowPropertyParam>()
                            .Query(k => k.ParamID == p.ParamID)
                            .Select(k => new ParamResource()
                        {
                            ParamID = p.ParamID,
                            ParamTypeID = p.ParamTypeID,
                            ScenarioID = p.ScenarioID,
                            Name = p.Name,
                            FlowID = k.FlowFlowProperty.FlowID,
                            FlowPropertyID = k.FlowFlowProperty.FlowPropertyID,
                            Value = k.Value,
                            DefaultValue = k.FlowFlowProperty.MeanValue
                        }).ToList();
                        break;
                    }
                case 5:
                    {   // CompositionParam -- this is a valid type for a Param but not for a ParamResource, because of schema design errors
                        // (CompositionData shouldn't even exist)
                        // CompositionData masquerade as FlowPropertyMagnitudes in the Real World
                        // CompositionParams masquerade as FlowPropertyParams in the Real World
                        PR = repository.GetRepository<CompositionParam>()
                            .Query(k => k.ParamID == p.ParamID)
                            .Select(k => new ParamResource()
                        {
                            ParamID = p.ParamID,
                            ParamTypeID = 4,
                            ScenarioID = p.ScenarioID,
                            Name = p.Name,
                            FlowID = k.CompositionData.CompositionModel.FlowID,
                            FlowPropertyID = k.CompositionData.FlowPropertyID,
                            //CompositionDataID = k.CompositionDataID,
                            Value = k.Value,
                            DefaultValue = k.CompositionData.Value
                        }).ToList();
                        break;
                    }
                case 6:
                    {   // ProcessDissipationParam
                        PR = repository.GetRepository<ProcessDissipationParam>()
                            .Query(k => k.ParamID == p.ParamID)
                            .Select(k => new ParamResource()
                        {
                            ParamID = p.ParamID,
                            ParamTypeID = p.ParamTypeID,
                            ScenarioID = p.ScenarioID,
                            Name = p.Name,
                            FlowID = k.ProcessDissipation.FlowPropertyEmission.FlowID,
                            ProcessID = k.ProcessDissipation.ProcessID,
                            Value = k.Value,
                            DefaultValue = k.ProcessDissipation.EmissionFactor
                        }).ToList();
                        break;
                    }
                case 8:
                    {   // ProcessEmissionParam
                        PR = repository.GetRepository<ProcessEmissionParam>()
                            .Query(k => k.ParamID == p.ParamID)
                            .Select(k => new ParamResource()
                        {
                            ParamID = p.ParamID,
                            ParamTypeID = p.ParamTypeID,
                            ScenarioID = p.ScenarioID,
                            Name = p.Name,
                            FlowID = k.ProcessFlow.FlowID,
                            ProcessID = k.ProcessFlow.ProcessID,
                            Value = k.Value,
                            DefaultValue = k.ProcessFlow.Result
                        }).ToList();
                        break;
                    }
                case 10:
                    {   // CharacterizationParam
                        PR = repository.GetRepository<CharacterizationParam>()
                            .Query(k => k.ParamID == p.ParamID)
                            .Select(k => new ParamResource()
                        {
                            ParamID = p.ParamID,
                            ParamTypeID = p.ParamTypeID,
                            ScenarioID = p.ScenarioID,
                            Name = p.Name,
                            FlowID = k.LCIA.FlowID,
                            LCIAMethodID = k.LCIA.LCIAMethodID,
                            Value = k.Value,
                            DefaultValue = k.LCIA.Factor
                        }).ToList();
                        break;
                    }
            }
            return PR;
        }
Exemplo n.º 2
0
        private static Param NewParam(this IRepository<Param> repository,
            int scenarioId, ParamResource post, ref CacheTracker cacheTracker)
        {
            // this creates a new param, only after confirming that a matching one does not exist
            Param P = new Param()
            {
                ScenarioID = scenarioId,
                ParamTypeID = post.ParamTypeID,
                Name = String.IsNullOrEmpty(post.Name)
                        ? repository.GetCanonicalName(post)
                        : post.Name,
            };
            switch (post.ParamTypeID)
            {
                case 1:
                case 2:
                    {
                        DependencyParam DP = new DependencyParam()
                        {
                            FragmentFlowID = (int)post.FragmentFlowID,
                            Value = (double)(post.Value == null
                                ? repository.GetRepository<FragmentFlow>()
                                    .GetDefaultValue((int)post.FragmentFlowID, post.ScenarioID)
                                : post.Value),
                            ObjectState = ObjectState.Added
                        };
                        /* no more conservation param
                        if (post.ParamTypeID == 2)
                        {
                            FragmentFlow c = repository.GetRepository<FragmentFlow>()
                                .Query(k => k.FragmentFlowID == post.FragmentFlowID)
                                .Include(k => k.Flow).Select().First();
                            DP.ConservationParam = new ConservationParam()
                            {
                                FragmentFlowID = (int)c.ParentFragmentFlowID,
                                FlowPropertyID = c.Flow.ReferenceFlowProperty,
                                DirectionID = c.DirectionID,
                                ObjectState = ObjectState.Added
                            };
                        }
                         * */
                        P.DependencyParams.Add(DP);
                        cacheTracker.FragmentFlowsTraverse.Add(DP.FragmentFlowID);
                        break;
                    }
                case 4:
                    {
                        var ffp = repository.GetRepository<FlowFlowProperty>().Queryable()
                            .Where(k => k.FlowID == post.FlowID)
                            .Where(k => k.FlowPropertyID == post.FlowPropertyID)
                            .First();
                        FlowPropertyParam fp = new FlowPropertyParam()
                        {
                            FlowFlowPropertyID = ffp.FlowFlowPropertyID,
                            Value = post.Value == null ? ffp.MeanValue : (double)post.Value,
                            ObjectState = ObjectState.Added
                        };
                        P.FlowPropertyParams.Add(fp);
                        cacheTracker.NodeCacheStale = true; // nothing to do about this- no way to tell when flow property conversion is required
                        break;
                    }
                case 5:
                    {
                        var cp = repository.GetRepository<CompositionData>().Queryable()
                            .Where(cd => cd.FlowPropertyID == (int)post.FlowPropertyID)
                            .Where(cd => cd.CompositionModel.FlowID == (int)post.FlowID)
                            .First();

                        P.CompositionParams.Add(new CompositionParam()
                        {
                            CompositionDataID = cp.CompositionDataID,
                            Value = post.Value == null ? cp.Value : (double)post.Value,
                            ObjectState = ObjectState.Added
                        });
                        cacheTracker.ScoreCacheStale = true;
                        break;
                    }
                case 6:
                    {
                        var pdp = repository.GetRepository<ProcessDissipation>().Queryable()
                            .Where(k => k.FlowPropertyEmission.FlowID == post.FlowID)
                            .Where(k => k.ProcessID == post.ProcessID)
                            .First();
                        ProcessDissipationParam pd = new ProcessDissipationParam()
                        {
                            ProcessDissipationID = pdp.ProcessDissipationID,
                            Value = post.Value == null ? pdp.EmissionFactor : (double)post.Value,
                            ObjectState = ObjectState.Added
                        };
                        P.ProcessDissipationParams.Add(pd);
                        cacheTracker.FragmentFlowsStale.AddRange(repository.FragmentFlowsAffected(scenarioId, (int)post.ProcessID));
                        break;
                    }
                case 8:
                    {
                        var pfp = repository.GetRepository<ProcessFlow>().Queryable()
                            .Where(k => k.FlowID == post.FlowID)
                            .Where(k => k.ProcessID == post.ProcessID)
                            .First();
                        ProcessEmissionParam pe = new ProcessEmissionParam()
                        {
                            ProcessFlowID = pfp.ProcessFlowID,
                            Value = post.Value == null ? pfp.Result : (double)post.Value,
                            ObjectState = ObjectState.Added
                        };
                        P.ProcessEmissionParams.Add(pe);
                        cacheTracker.FragmentFlowsStale.AddRange(repository.FragmentFlowsAffected(scenarioId, (int)post.ProcessID));
                        break;
                    }
                case 10:
                    {
                        var cfp = repository.GetRepository<LCIA>().Queryable()
                            .Where(k => k.FlowID == post.FlowID)
                            .Where(k => k.LCIAMethodID == post.LCIAMethodID)
                            .Where(k => String.IsNullOrEmpty(k.Geography) )
                            .First();
                        CharacterizationParam cp = new CharacterizationParam()
                            {
                                LCIAID = cfp.LCIAID,
                                Value = post.Value == null ? cfp.Factor : (double)post.Value,
                                ObjectState = ObjectState.Added
                            };
                        P.CharacterizationParams.Add(cp);
                        cacheTracker.LCIAMethodsStale.Add((int)post.LCIAMethodID);
                        break;
                    }
            }
            P.ObjectState = ObjectState.Added;
            return P;
        }