Ejemplo n.º 1
0
        //private void LogRunEnd(DateTime startOfRun)
        //{
        //    Type t = typeof (RunTracker);
        //    MethodInfo method = t.GetMethod("RunCompleted", BindingFlags.Public | BindingFlags.Static);

        //    try
        //    {
        //        method.Invoke(null, new object[] {Scenario.Project, Scenario, startOfRun});
        //    }
        //    catch(Exception)
        //    {
        //        method.Invoke(null, new object[] { Scenario.Project, startOfRun });
        //    }
        //}

        private void ApplyRunParameters(RunParameters parameters)
        {
            HashSet <string> skipKeys = new HashSet <string>(new [] { RUN_NAME_KEY });

            RunningConfiguration configuration = Scenario.CurrentConfiguration;
            Type configType = configuration.GetType();

            foreach (var entry in parameters.Params.Where(kvp => !skipKeys.Contains(kvp.Key)))
            {
                var ri  = ReflectedItem.NewItem(entry.Key, configuration);
                var val = entry.Value;

                if (ri.itemType == typeof(DateTime))
                {
                    val = DateTime.ParseExact(entry.Value.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }
                else if (ri.itemType == typeof(InputSet))
                {
                    val = Scenario.Network.InputSets.FirstOrDefault(ipSet => ipSet.Name == (string)entry.Value);
                }
                else if (ri.itemType == typeof(TimeStep))
                {
                    val = TimeStep.FromName((string)entry.Value);
                }

                ri.itemValue = val;
            }
        }
Ejemplo n.º 2
0
        private static void SetPrivateRunProperty(object run, string field, object value)
        {
            var mi = run.GetType().GetMember(field, BindingFlags.NonPublic | BindingFlags.Instance)[0];
            var ri = ReflectedItem.NewItem(mi, run);

            ri.itemValue = value;
        }
Ejemplo n.º 3
0
        private TimeSeries FindTimeSeries()
        {
            ReflectedItem ri      = ReflectedItem.NewItem("Value", Variable);
            string        gddName = Scenario.Network.DataManager.GetUsageFullName(ri);

            if (String.IsNullOrEmpty(gddName))
            {
                return(null);
            }

            string[] split = gddName.Split('.');
            if (split.Length <= 1)
            {
                return(null);
            }

            string             groupName = string.Join(".", split.Take(split.Length - 1));
            GenericDataDetails GDD       =
                Scenario.Network.DataManager.DataGroups.Where(g => g.Name == groupName)
                .Select(@group => @group.GetUsage(split.Last()))
                .FirstOrDefault(gdd => gdd != null);

//                        DataUsage DU = GDD.Usages.First(x => x.ReflectedItem.Equals(ri));
            return(GDD.AssociatedData.FirstOrDefault(d => d.DataInformation.Name.Replace(".", "_") == split.Last())
                   .Data.TimeSeries);
        }
        public ReflectedParameter(AccessorMemberInfo key, object obj, string name, double factor)
        {
            var r = (ReflectedAccessor)ReflectedItem.NewItem(key.member, obj);

            Init(r);
            Factor = factor;
            Name   = name;
        }
Ejemplo n.º 5
0
        public void removeUsagesForSpecificModel(Model theModel)
        {
            if (theModel == null)
            {
                return;
            }

            foreach (MemberInfo MI in GetFieldsAndProperties(theModel.GetType()))
            {
                ReflectedItem RI = ReflectedItem.NewItem(MI, theModel);

                //Need this to 'ignore' redundant AggregatedConstituentModels
                //if (typeof(Model).IsAssignableFrom(RI.itemType) && RI.itemValue != null)
                if (RI.itemValue != null)
                {
                    if (RI.itemValue is Model)
                    {
                        //This member is a model itself
                        removeUsagesForSpecificModel((Model)RI.itemValue);
                        continue;
                    }
                }

                string GDDName = Scenario.Network.DataManager.GetUsageFullName(RI);
                if (!String.IsNullOrEmpty(GDDName))//Will be "" if no usages for this RI
                {
                    string[] split = GDDName.Split(new[] { '.' });
                    if (split.Count() <= 1)
                    {
                        return;
                    }
                    string groupName = string.Join(".", split.Take(split.Count() - 1));

                    bool removeTS          = true;
                    GenericDataDetails GDD = Scenario.Network.DataManager.DataGroups.Where(g => g.Name == groupName).Select(@group => @group.GetUsage(split.Last())).FirstOrDefault(gdd => gdd != null);
                    //GenericDataDetails GDD = Scenario.Network.DataManager.GetDetails(GDDName);
                    if (GDD.Usages.Count > 1)
                    {
                        //Other items need this timeseries, don't remove
                        removeTS = false;
                    }

                    DataUsage DU = GDD.Usages.First(x => x.ReflectedItem.Equals(RI));

                    GDD.Usages.Remove(DU);

                    if (removeTS)
                    {
                        string        DGName = GDDName.Split('.')[0];
                        DataGroupItem DGI    = Scenario.Network.DataManager.DataGroups.FirstOrDefault(x => x.Name == DGName);

                        DGI.RemoveItem(GDD);
                        Scenario.Network.DataManager.Refresh();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static ReflectedItem GetReflectedItem(object target, string element)
        {
            if (element.Contains("."))
            {
                var bits = element.Split('.');
                target  = Deref(target, String.Join(".", bits.Take(bits.Length - 1)));
                element = bits[bits.Length - 1];
            }

            Type t       = target.GetType();
            var  members = t.GetMember(element, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            if (members.Length == 0)
            {
                throw new Exception("No type member found");
            }
            var member = members[0];

            return(ReflectedItem.NewItem(member, target));
        }
Ejemplo n.º 7
0
        static Task <Dictionary <string, ReflectedItem> > ModifiedMembersAsync(string oldAssemblyPath, string newAssemblyPath)
        {
            return(Task.Run(() =>
            {
                var oldDict = AssemblyItems(oldAssemblyPath);
                var newDict = AssemblyItems(newAssemblyPath);

                Dictionary <string, ReflectedItem> modifiedItems = new Dictionary <string, ReflectedItem>();
                foreach (var kvp in newDict)
                {
                    string key = kvp.Key;
                    bool isObsolete = kvp.Value;
                    ReflectedItem item = new ReflectedItem();

                    // if the item is not in oldDict, then it is new
                    if (!oldDict.ContainsKey(key))
                    {
                        item.AddedInNewVersion = true;
                        item.ObsoletedInNewVersion = kvp.Value;
                    }
                    else if (isObsolete)
                    {
                        bool obsoleteInOld = oldDict[key];
                        if (!obsoleteInOld)
                        {
                            item.ObsoletedInNewVersion = true;
                        }
                    }

                    if (item.ObsoletedInNewVersion || item.AddedInNewVersion)
                    {
                        modifiedItems.Add(key, item);
                    }
                }
                return modifiedItems;
            }));
        }
Ejemplo n.º 8
0
 public static string GetFullPath(this DataGroupItem dgi, ReflectedItem ri,InputSet inputSet)
 {
     var gdd = dgi.DataDetails.FirstOrDefault(dd => dd.Usages.Any(u => u.ReflectedItem.Equals(ri)));
     return gdd == null ? "" : SimpleDataGroupItem.MakeID(dgi) + "/" + inputSet.Name + "/" + SourceService.URLSafeString(gdd.Name);
 }
Ejemplo n.º 9
0
        public static string GetFullPath(this DataGroupItem dgi, ReflectedItem ri, InputSet inputSet)
        {
            var gdd = dgi.DataDetails.FirstOrDefault(dd => dd.Usages.Any(u => u.ReflectedItem.Equals(ri)));

            return(gdd == null ? "" : SimpleDataGroupItem.MakeID(dgi) + "/" + inputSet.Name + "/" + SourceService.URLSafeString(gdd.Name));
        }