예제 #1
0
        private ScenarioModel CreateScenarioWithMethods(
            [NotNull] ScenarioModel baseScenario,
            [NotNull, ItemNotNull] IEnumerable <MethodActionModel> methods,
            [NotNull] ModelContainer container)
        {
            const string uniqueIdDef = "UniqueId";

            var precedingActionTypes = new[]
            {
                typeof(BarrierActionModel),
                typeof(RebootActionModel)
            };

            var newScenario = (ScenarioModel)baseScenario.Clone();

            newScenario.Id      = container.NextId();
            newScenario.Name    = Api.GetAssemblyAndMethod(methods.First().Method.Expr).Field1.Name;
            newScenario.Actions = new List <BaseActionModel>();

            var originalActions = baseScenario.Actions;

            foreach (var method in methods)
            {
                var index = originalActions.FindIndex(m => m == method);
                var i     = index;
                while (--i >= 0 && precedingActionTypes.Contains(originalActions[i].GetType()))
                {
                }

                while (++i < index)
                {
                    newScenario.Actions.Add(originalActions[i]);
                }

                newScenario.Actions.Add(method);

                if (index < originalActions.Count - 2 &&
                    originalActions[index + 1].GetType() == typeof(WaitForRebootActionModel))
                {
                    newScenario.Actions.Add(originalActions[index + 1]);
                }
            }

            UpdateScenarioDefinitionModel(newScenario, uniqueIdDef, Guid.NewGuid().ToString());
            newScenario.Init(container);
            UpdateReference(newScenario);

            container.Add(newScenario);

            return(newScenario);
        }
예제 #2
0
        public IModel GetModel(Type t, string key)
        {
            if (key != null)
            {
                ModelObj it = CML.ComUtility.QueryFirst <ModelObj>(
                    from x in ModelMap where x.key == key where x.cls == t.FullName select x, null);

                if (it == null)
                {
                    ModelObj tmp = new ModelObj(this)
                    {
                        key = key,
                        asm = t.Assembly.GetName().Name,

                        cls   = t.FullName,
                        model = GetModel(t),
                        //local = true,
                    };
                    ModelMap.Add(tmp);
                    return(tmp.model);
                }
                else
                {
                    if (it.model == null)
                    {
                        it.asm   = t.Assembly.GetName().Name;
                        it.model = GetModel(t);
                    }

                    return(it.model);
                }
            }
            else
            {
                return(GetModel(t));
            }
        }
예제 #3
0
        public void FromZip(byte[] buff)
        {
            using (ZipArchive zip = new ZipArchive(new MemoryStream(buff)))
            {
                ZipArchiveEntry iConfig = zip.GetEntry("config.json");
                if (iConfig != null)
                {
                    using (Stream s = iConfig.Open())
                        using (StreamReader sr = new StreamReader(s, Encoding.UTF8))
                        {
                            Config = new Configuration();
                            Config.FromJson(sr.ReadToEnd());
                        }
                }

                AsmMap = new AsmContainer(this);
                for (int i = 0; i < Config.AssemblyCount; i++)
                {
                    ZipArchiveEntry it = zip.GetEntry("assemblies/" + i.ToString() + ".dll");
                    if (it != null)
                    {
                        using (Stream s = it.Open())
                        {
                            byte[] buffer = new byte[it.Length];
                            s.Read(buffer, 0, buffer.Length);

                            AsmObj add = new AsmObj();
                            add.load(buffer);
                            AsmMap.Add(add);
                        }
                    }
                }

                TypeMap = new TypeContainer();
                foreach (AsmObj it in AsmMap)
                {
                    TypeMap.Merge(it);
                }

                ModelMap = new ModelContainer(this);
                for (int i = 0; i < Config.ModelCount; i++)
                {
                    ZipArchiveEntry it = zip.GetEntry("models/" + i.ToString() + ".json");
                    if (it != null)
                    {
                        using (Stream s = it.Open())
                            using (StreamReader sr = new StreamReader(s, Encoding.UTF8))
                            {
                                ModelObj add = new ModelObj(this);
                                add.FromJson(sr.ReadToEnd());
                                ModelMap.Add(add);
                            }
                    }
                }
            }

            //ZipArchiveEntry iModels = zip.GetEntry("models");
            //if (iModels != null)
            //{
            //    using (MemoryStream ms = iModels.Open() as MemoryStream)
            //    {
            //        ModelMap = new ModelContainer(this);
            //        ModelMap.FromZip(ms.ToArray());
            //    }
            //}

            //ZipArchiveEntry iAssemblies = zip.GetEntry("assemblies");
            //if (iAssemblies != null)
            //{
            //    using (MemoryStream ms = iAssemblies.Open() as MemoryStream)
            //    {
            //        AsmMap = new AsmContainer(this);
            //        AsmMap.FromZip(ms.ToArray());
            //    }
            //}
        }