Example #1
0
        public void loadExternalFiles(AnomalyController controller)
        {
            if (File.Exists(solutionFile))
            {
                try
                {
                    using (var stream = File.Open(solutionFile, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
                    {
                        solutionData = saver.restoreObject <SolutionData>(stream);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Could not load solution data file {0} because:\n{1}", solutionFile, e.Message);
                }
            }
            if (solutionData == null)
            {
                solutionData = new SolutionData();
            }

            this.anomalyController = controller;
            String globalResourcesFile = Path.Combine(workingDirectory, "Resources.xml");

            if (!File.Exists(globalResourcesFile))
            {
                ResourceManager globalResources = controller.PluginManager.createScratchResourceManager();
                using (var stream = File.Open(globalResourcesFile, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None))
                {
                    saver.saveObject(globalResources, stream);
                }
            }

            resourceFileInterface = new ResourceManagerFileInterface("Global Resources", EngineIcons.Resource, globalResourcesFile, anomalyController.ResourceController.GlobalResources);
            anomalyController.ResourceController.GlobalResources.addResources(resourceFileInterface.getFileObject());
            anomalyController.ResourceController.GlobalResources.initializeResources();

            foreach (String projectFile in Directory.GetFiles(workingDirectory, "*.prj", SearchOption.AllDirectories))
            {
                Project project = new Project(this, Path.GetFileNameWithoutExtension(projectFile), Path.GetDirectoryName(projectFile));
                addProject(project);
                if (currentProject == null)
                {
                    currentProject = project;
                }
            }
        }
Example #2
0
        public Project(Solution solution, String name, String workingDirectory)
        {
            this.solution         = solution;
            this.name             = name;
            this.workingDirectory = workingDirectory;
            String instancesPath = Path.Combine(workingDirectory, "Instances");

            instanceGroup = new InstanceGroup("Instances", instancesPath);
            if (!Directory.Exists(instancesPath))
            {
                InstanceWriter.Instance.addInstanceGroup(instanceGroup);
            }
            else
            {
                InstanceWriter.Instance.scanForFiles(instanceGroup);
            }

            projectFile = Path.Combine(WorkingDirectory, Name + ".prj");
            if (File.Exists(projectFile))
            {
                try
                {
                    using (var stream = File.Open(projectFile, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
                    {
                        projectData = saver.restoreObject <ProjectData>(stream);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("Could not load project references file {0} because:\n{1}", projectFile, e.Message);
                }
            }
            if (projectData == null)
            {
                projectData = new ProjectData();
                projectData.SceneFileName = name + ".sim.xml";
            }

            String resourcesFile = Path.Combine(workingDirectory, "Resources.xml");

            if (!File.Exists(resourcesFile))
            {
                ResourceManager resources = PluginManager.Instance.createScratchResourceManager();
                using (var stream = File.Open(resourcesFile, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None))
                {
                    saver.saveObject(resources, stream);
                }
            }

            String sceneDefinitionFile = Path.Combine(workingDirectory, "SceneDefinition.xml");

            if (!File.Exists(sceneDefinitionFile))
            {
                SimSceneDefinition sceneDefinition = new SimSceneDefinition();
                using (var stream = File.Open(sceneDefinitionFile, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None))
                {
                    saver.saveObject(sceneDefinition, stream);
                }
            }

            resourceFileInterface = new ResourceManagerFileInterface("Resources", EngineIcons.Resource, resourcesFile, solution.GlobalResources);
            sceneFileInterface    = new SimSceneFileInterface("Scene Definition", EngineIcons.Scene, sceneDefinitionFile);
        }