예제 #1
0
        public String createProject(EditorResourceProvider resourceProvider, string projectName)
        {
            EmbeddedResourceHelpers.CopyResourceToStream(EmbeddedTemplateNames.SimpleMvcContext_mvc, MvcContextName, resourceProvider, Assembly.GetExecutingAssembly());

            DDAtlasPlugin ddPlugin = new DDAtlasPlugin();

            ddPlugin.PluginName      = projectName;
            ddPlugin.PluginNamespace = projectName;
            StartAnomalousMvcTask mvcTask = new StartAnomalousMvcTask("Task", projectName, "", "Apps");

            mvcTask.ContextFile = MvcContextName;
            ddPlugin.addTask(mvcTask);
            saveObject(ddPlugin, resourceProvider, "Plugin.ddp");

            resourceProvider.createDirectory("", "Timeline");
            resourceProvider.createDirectory("", "Resources");

            Assembly editorAssembly = Assembly.GetExecutingAssembly();

            EmbeddedResourceHelpers.CopyResourceToStream(EmbeddedTemplateNames.MasterTemplate_trml, "MasterTemplate.trml", resourceProvider, Assembly.GetExecutingAssembly());

            using (StreamWriter streamWriter = new StreamWriter(resourceProvider.openWriteStream("Index.rml")))
            {
                streamWriter.Write(indexRml, projectName);
            }

            return(null);
        }
예제 #2
0
        private bool addDataDrivenPlugin(String path)
        {
            bool   loadedPlugin    = false;
            String pluginDirectory = null;
            String fullPath;

            //Try to load from virtual file system first
            if (VirtualFileSystem.Instance.directoryExists(path))
            {
                fullPath = path;
                String directoryName = Path.GetFileName(Path.GetDirectoryName(path));
                if (!loadedPluginNames.Contains(directoryName))
                {
                    loadedPluginNames.Add(directoryName);

                    pluginDirectory = String.Format("Plugins/{0}/", directoryName);
                }
                else
                {
                    Log.Error("Cannot plugin file '{0}' from virtual file system because a plugin named '{1}' is already loaded.", path, directoryName);
                }
            }
            else
            {
                fullPath = Path.GetFullPath(path);
                if (!Directory.Exists(fullPath) && !File.Exists(fullPath))
                {
                    fullPath = Path.Combine(additionalSearchPath, path);
                }

                if (File.Exists(fullPath))
                {
                    String dataFileName = Path.GetFileNameWithoutExtension(fullPath);
                    try
                    {
                        if (!loadedPluginNames.Contains(dataFileName))
                        {
                            //Add the archive to the VirtualFileSystem if needed
                            if (!VirtualFileSystem.Instance.containsRealAbsolutePath(fullPath))
                            {
                                VirtualFileSystem.Instance.addArchive(fullPath);
                            }
                            pluginDirectory = String.Format("Plugins/{0}/", Path.GetFileNameWithoutExtension(path));

                            loadedPluginNames.Add(dataFileName);
                        }
                        else
                        {
                            Log.Error("Cannot load data file '{0}' from '{1}' because a plugin named '{2}' is already loaded.", path, fullPath, dataFileName);
                        }
                    }
                    catch (ZipAccess.ZipIOException e)
                    {
                        firePluginLoadError(String.Format("There was an error loading the plugin '{0}'.", dataFileName));
                        Log.Error("Cannot load data file '{0}' from '{1}' because of a zip read error: {2}. Deleting corrupted plugin.", path, fullPath, e.Message);
                        try
                        {
                            File.Delete(fullPath);
                        }
                        catch (Exception deleteEx)
                        {
                            Log.Error("Error deleting data file '{0}' from '{1}' because: {2}.", path, fullPath, deleteEx.Message);
                        }
                    }
                }
                else if (Directory.Exists(fullPath))
                {
                    String directoryName = Path.GetFileName(Path.GetDirectoryName(fullPath));
                    if (!loadedPluginNames.Contains(directoryName))
                    {
                        loadedPluginNames.Add(directoryName);

                        pluginDirectory = String.Format("Plugins/{0}/", directoryName);
                        String rootPluginPath = fullPath.Replace("\\", "/");
                        if (!rootPluginPath.EndsWith("/"))
                        {
                            rootPluginPath += "/";
                        }
                        rootPluginPath = rootPluginPath.Replace(pluginDirectory, "");

                        //Add the archive to the VirtualFileSystem if needed
                        if (!VirtualFileSystem.Instance.containsRealAbsolutePath(rootPluginPath))
                        {
                            VirtualFileSystem.Instance.addArchive(rootPluginPath);
                        }
                    }
                    else
                    {
                        Log.Error("Cannot load data file '{0}' from '{1}' because a plugin named '{2}' is already loaded.", path, fullPath, directoryName);
                    }
                }
                else
                {
                    Log.Error("Cannot load data file '{0}' from '{0}' or '{1}' because it was not found.", path, fullPath, Path.GetFullPath(path));
                }
            }

            if (pluginDirectory != null)
            {
                String pluginDefinitionFile = pluginDirectory + "Plugin.ddp";

                if (VirtualFileSystem.Instance.exists(pluginDefinitionFile))
                {
                    using (Stream pluginStream = VirtualFileSystem.Instance.openStream(pluginDefinitionFile, Engine.Resources.FileMode.Open, Engine.Resources.FileAccess.Read))
                    {
                        try
                        {
                            DDAtlasPlugin plugin = SharedXmlSaver.Load <DDAtlasPlugin>(pluginStream);
                            if (plugin != null)
                            {
                                plugin.Location         = fullPath;
                                plugin.PluginRootFolder = pluginDirectory;
                                addPlugin(plugin, false);
                                loadedPlugin = true;
                            }
                            else
                            {
                                throw new Exception(String.Format("Error loading '{0}' in path '{1}' from '{2}' because it was null.", pluginDefinitionFile, path, fullPath));
                            }
                        }
                        catch (Exception ex)
                        {
                            firePluginLoadError(String.Format("There was an error loading the plugin '{0}'.", Path.GetFileName(fullPath)));
                            Log.Error(ex.Message);
                            try
                            {
                                File.Delete(fullPath);
                            }
                            catch (Exception deleteEx)
                            {
                                Log.Error("Error deleting data file '{0}' from '{1}' because: {2}.", path, fullPath, deleteEx.Message);
                                managePluginInstructions.addFileToDelete(fullPath);
                                managePluginInstructions.savePersistantFile();
                            }
                        }
                    }
                }

                if (!loadedPlugin)
                {
                    String dependencyDefinitionFile = pluginDirectory + "Dependency.ddd";
                    if (VirtualFileSystem.Instance.fileExists(dependencyDefinitionFile))
                    {
                        using (Stream stream = VirtualFileSystem.Instance.openStream(dependencyDefinitionFile, Engine.Resources.FileMode.Open, Engine.Resources.FileAccess.Read))
                        {
                            try
                            {
                                DDAtlasDependency dependency = SharedXmlSaver.Load <DDAtlasDependency>(stream);
                                if (dependency != null)
                                {
                                    dependency.Location   = fullPath;
                                    dependency.RootFolder = pluginDirectory;
                                    addDependency(dependency);
                                    loadedPlugin = true;
                                }
                                else
                                {
                                    throw new Exception(String.Format("Error loading '{0}' in path '{1}' from '{2}' because it was null.", dependencyDefinitionFile, path, fullPath));
                                }
                            }
                            catch (Exception ex)
                            {
                                firePluginLoadError(String.Format("There was an error loading the plugin '{0}'.", Path.GetFileName(fullPath)));
                                Log.Error(ex.Message);
                                try
                                {
                                    File.Delete(fullPath);
                                }
                                catch (Exception deleteEx)
                                {
                                    Log.Error("Error deleting data file '{0}' from '{1}' because: {2}.", path, fullPath, deleteEx.Message);
                                    managePluginInstructions.addFileToDelete(fullPath);
                                    managePluginInstructions.savePersistantFile();
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Error("Error loading '{0}' or '{1}' in path '{2}' from '{3}' because it does not exist.", pluginDefinitionFile, dependencyDefinitionFile, path, fullPath);
                    }
                }
            }

            return(loadedPlugin);
        }
예제 #3
0
 /// <summary>
 /// Set the plugin for this task. DO NOT TOUCH if you are not DDAtlasPlugin.
 /// </summary>
 /// <param name="plugin">The DDAtlasPlugin that loaded this task.</param>
 internal void _setPlugin(DDAtlasPlugin plugin)
 {
     this.plugin = plugin;
     UniqueName  = String.Format("DDPlugin.{0}.{1}", plugin.PluginNamespace, TaskUniqueName);
 }
예제 #4
0
        public String createProject(EditorResourceProvider resourceProvider, string projectName)
        {
            AnomalousMvcContext mvcContext = new AnomalousMvcContext();

            mvcContext.StartupAction  = "Common/Startup";
            mvcContext.ShutdownAction = "Common/Shutdown";

            RmlView view = new RmlView("Index");

            view.RmlFile     = "Index.rml";
            view.ElementName = new BorderLayoutElementName(GUILocationNames.ContentArea, BorderLayoutLocations.Left);
            view.Buttons.add(new CloseButtonDefinition("Close", "Common/ExitApp"));
            mvcContext.Views.add(view);

            mvcContext.Controllers.add(new MvcController("Common",
                                                         new RunCommandsAction("Startup",
                                                                               new SaveCameraPositionCommand(),
                                                                               new SaveLayersCommand(),
                                                                               new SaveMusclePositionCommand(),
                                                                               new SaveMedicalStateCommand(),
                                                                               new HideMainInterfaceCommand(),
                                                                               new RunActionCommand("Index/Show")),
                                                         new RunCommandsAction("Shutdown",
                                                                               new RestoreCameraPositionCommand(),
                                                                               new RestoreLayersCommand(),
                                                                               new RestoreMusclePositionCommand(),
                                                                               new RestoreMedicalStateCommand(),
                                                                               new ShowMainInterfaceCommand()
                                                                               ),
                                                         new RunCommandsAction("ExitApp",
                                                                               new ShutdownCommand())
                                                         ));

            mvcContext.Controllers.add(new MvcController("Index",
                                                         new RunCommandsAction("Show",
                                                                               new PlayTimelineCommand(TimelineName),
                                                                               new ShowViewCommand("Index")
                                                                               )
                                                         ));

            saveObject(mvcContext, resourceProvider, MvcContextName);

            DDAtlasPlugin ddPlugin = new DDAtlasPlugin();

            ddPlugin.PluginName      = projectName;
            ddPlugin.PluginNamespace = projectName;
            StartAnomalousMvcTask mvcTask = new StartAnomalousMvcTask("Task", projectName, "", "Apps");

            mvcTask.ContextFile = MvcContextName;
            ddPlugin.addTask(mvcTask);
            saveObject(ddPlugin, resourceProvider, "Plugin.ddp");

            Timeline mainTimeline = new Timeline();

            saveObject(mainTimeline, resourceProvider, TimelineName);

            resourceProvider.createDirectory("", "Resources");

            EmbeddedResourceHelpers.CopyResourceToStream(EmbeddedTemplateNames.MasterTemplate_trml, "MasterTemplate.trml", resourceProvider, Assembly.GetExecutingAssembly());

            using (StreamWriter streamWriter = new StreamWriter(resourceProvider.openWriteStream("Index.rml")))
            {
                streamWriter.Write(indexRml, projectName);
            }

            return(null);
        }
        public PluginEditorContext(DDAtlasPlugin plugin, String file, PluginTypeController pluginTypeController, EditorController editorController, GuiFrameworkUICallback uiCallback, StandaloneController standaloneController)
        {
            this.pluginTypeController = pluginTypeController;
            this.currentFile          = file;
            this.plugin               = plugin;
            this.editorController     = editorController;
            this.standaloneController = standaloneController;

            mvcContext = new AnomalousMvcContext();
            mvcContext.StartupAction = "Common/Start";
            mvcContext.FocusAction   = "Common/Focus";
            mvcContext.BlurAction    = "Common/Blur";
            mvcContext.SuspendAction = "Common/Suspended";
            mvcContext.ResumeAction  = "Common/Resumed";

            mvcContext.Models.add(new EditMenuManager());

            GenericPropertiesFormView genericPropertiesView = new GenericPropertiesFormView("MvcContext", plugin.EditInterface, editorController, uiCallback, true);

            genericPropertiesView.ElementName = new MDILayoutElementName(GUILocationNames.MDI, DockLocation.Left);
            mvcContext.Views.add(genericPropertiesView);

            EditorTaskbarView taskbar = new EditorTaskbarView("InfoBar", currentFile, "Editor/Close");

            taskbar.addTask(new CallbackTask("SaveAll", "Save All", "Editor/SaveAllIcon", "", 0, true, item =>
            {
                saveAll();
            }));
            taskbar.addTask(new RunMvcContextActionTask("Save", "Save Plugin Definition File", "CommonToolstrip/Save", "File", "Editor/Save", mvcContext));
            taskbar.addTask(new CallbackTask("FindDependencies", "Find Dependencies", "EditorFileIcon/.ddp", "", item =>
            {
                findDependencies();
            }));
            mvcContext.Views.add(taskbar);

            mvcContext.Controllers.add(new MvcController("Editor",
                                                         new RunCommandsAction("Show",
                                                                               new ShowViewCommand("MvcContext"),
                                                                               new ShowViewCommand("InfoBar")),
                                                         new RunCommandsAction("Close", new CloseAllViewsCommand()),
                                                         new CallbackAction("Save", context =>
            {
                save();
            })));

            mvcContext.Controllers.add(new MvcController("Common",
                                                         new RunCommandsAction("Start", new RunActionCommand("Editor/Show")),
                                                         new CallbackAction("Focus", context =>
            {
                GlobalContextEventHandler.setEventContext(eventContext);
                if (Focus != null)
                {
                    Focus.Invoke(this);
                }
            }),
                                                         new CallbackAction("Blur", context =>
            {
                GlobalContextEventHandler.disableEventContext(eventContext);
                if (Blur != null)
                {
                    Blur.Invoke(this);
                }
            }),
                                                         new RunCommandsAction("Suspended", new SaveViewLayoutCommand()),
                                                         new RunCommandsAction("Resumed", new RestoreViewLayoutCommand())));

            eventContext = new EventContext();
            ButtonEvent saveEvent = new ButtonEvent(EventLayers.Gui);

            saveEvent.addButton(KeyboardButtonCode.KC_LCONTROL);
            saveEvent.addButton(KeyboardButtonCode.KC_S);
            saveEvent.FirstFrameUpEvent += eventManager =>
            {
                saveAll();
            };
            eventContext.addEvent(saveEvent);
        }