コード例 #1
0
        private void Run()
        {
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            };

            try
            {
                BehaviourConfiguration configuration = JsonConvert.DeserializeObject <BehaviourConfiguration>(File.ReadAllText(Project.ProjectFolder + "\\Behaviours.dat"), settings);
                Project.BehaviourConfiguration = configuration;
                List <ActionPack> buildInActionPacks = studio.ProjectTypeProvider.GetBuildInActionPacks();
                if (buildInActionPacks != null)
                {
                    Project.BehaviourConfiguration.InternalWebActionPacks.AddRange(buildInActionPacks);
                }
            }
            catch (Exception ex)
            {
                Dialog.CancelAllTasks("Could not load web behaviour configuration:\n" + ex.Message);
            }

            List <string> assembliesToLoad = Project.BehaviourConfiguration.WebActionpacks.FindAll(pack => pack != "BasicWebActionsPack");

            if (assembliesToLoad.Count > 0)
            {
                List <LoadedAssembly> loadedAssemblies = studio.GetDLLManager().LoadAssemblies(assembliesToLoad, Studio.extensionRepresentingStudio);
                foreach (LoadedAssembly assembly in loadedAssemblies)
                {
                    try
                    {
                        Type       packType = assembly.Assembly.GetExportedTypes().First(ass => ass.BaseType.Name == "WebActionPack");
                        ActionPack pack     = Activator.CreateInstance(packType) as ActionPack;
                        Project.BehaviourConfiguration.InternalWebActionPacks.Add(pack);
                    }
                    catch (Exception ex)
                    {
                        Dialog.CancelAllTasks($"Could not load web action pack from assembly {assembly.Path}:\n\n{ex.Message}");
                    }
                }
            }
            Project.BehaviourConfiguration.Behaviours = JsonConvert.DeserializeObject <List <Behaviour> >(Project.BehaviourConfiguration.BehavioursJson, settings);
        }