Esempio n. 1
0
        public InstanceFileInterface(String name, Object iconReferenceTag, String filename, InstanceGroup parentGroup)
            : base(name, iconReferenceTag)
        {
            this.parentGroup = parentGroup;
            GenericClipboardEntry clipboardEntry = new GenericClipboardEntry(typeof(SimObjectDefinition));

            clipboardEntry.CopyFunction  = copy;
            clipboardEntry.PasteFunction = paste;
            clipboardEntry.CutFunction   = cut;
            clipboardEntry.SupportsPastingTypeFunction = supportsPastingType;
            editInterface.ClipboardEntry = clipboardEntry;
            editInterface.addCommand(new EditInterfaceCommand("Toggle Display", toggleHidden));
            Deleted       = false;
            this.filename = filename;
            if (File.Exists(filename))
            {
                try
                {
                    using (var stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        instance = saver.restoreObject <Instance>(stream);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Could not load Instance {0} because {1}", filename, ex.Message);
                    instance = new Instance(name, new GenericSimObjectDefinition(name));
                }
            }
        }
Esempio n. 2
0
        public void scanForFiles(InstanceGroup group)
        {
            String path = group.FullPath;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            String[] groups = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly);
            foreach (String groupPath in groups)
            {
                String dir = Path.GetFileName(groupPath);
                if ((File.GetAttributes(path + Path.DirectorySeparatorChar + dir) & FileAttributes.Hidden) != FileAttributes.Hidden)
                {
                    InstanceGroup subGroup = new InstanceGroup(dir, groupPath);
                    group.addGroup(subGroup);
                    scanForFiles(subGroup);
                }
            }

            String[] instances = Directory.GetFiles(path, "*.ins", SearchOption.TopDirectoryOnly);
            foreach (String instanceFile in instances)
            {
                group.addInstanceFile(Path.GetFileNameWithoutExtension(instanceFile));
            }
        }
Esempio n. 3
0
 public void removeGroup(InstanceGroup group)
 {
     group.parent = null;
     groups.Remove(group.name);
     group.Dispose();
     deletedGroups.Add(group);
     if (editInterface != null)
     {
         editInterface.removeSubInterface(group);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Add a template group to the target.
 /// </summary>
 /// <param name="group">The template group to add.</param>
 public void addInstanceGroup(InstanceGroup group)
 {
     try
     {
         String path = group.FullPath;
         Directory.CreateDirectory(path);
     }
     catch (Exception e)
     {
         Log.Default.sendMessage("Could not create directory for template group {0} because of {1}", LogLevel.Error, "Anomaly", group.Name, e.Message);
     }
 }
Esempio n. 5
0
 public void addGroup(InstanceGroup group)
 {
     group.parent = this;
     groups.Add(group.name, group);
     if (instancesDisplayed)
     {
         group.showInstances(simObjectController);
     }
     if (editInterface != null)
     {
         addGroupSubInterface(group);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Remove a template group from the target.
        /// </summary>
        /// <param name="group">The template group to remove.</param>
        public void removeInstanceGroup(InstanceGroup group)
        {
            try
            {
                String path = group.FullPath;

                DirectoryUtility.ForceDirectoryDelete(path);
            }
            catch (Exception e)
            {
                Log.Default.sendMessage("Could not remove directory for template group {0} because of {1}.", LogLevel.Error, "Anomaly", group.Name, e.Message);
            }
        }
Esempio n. 7
0
 /// <summary>
 /// The method that actually searches for the instance name. Called only by findInstanceGroup.
 /// </summary>
 /// <param name="instanceName">The instance name to search for.</param>
 /// <returns>The group containing the instance or null if it does not exist.</returns>
 private InstanceGroup doFindInstanceGroup(String instanceName)
 {
     if (instanceFiles.ContainsKey(instanceName))
     {
         return(this);
     }
     else
     {
         foreach (InstanceGroup group in groups.Values)
         {
             InstanceGroup foundGroup = group.doFindInstanceGroup(instanceName);
             if (foundGroup != null)
             {
                 return(foundGroup);
             }
         }
     }
     return(null);
 }
Esempio n. 8
0
        private void createGroupCallback(EditUICallback callback)
        {
            callback.getInputString("Enter a name.", delegate(String input, ref String errorPrompt)
            {
                if (input == null || input == "")
                {
                    errorPrompt = "Please enter a non empty name.";
                    return(false);
                }
                if (this.groups.ContainsKey(input))
                {
                    errorPrompt = "That name is already in use. Please provide another.";
                    return(false);
                }

                InstanceGroup group = new InstanceGroup(input, Path.Combine(path, input));
                this.addGroup(group);
                return(true);
            });
        }
Esempio n. 9
0
 private void doImportTemplates(String directory)
 {
     foreach (String template in Directory.GetFiles(directory, "*.tpl", SearchOption.TopDirectoryOnly))
     {
         createInstance(InstanceWriter.Instance.loadTemplate(template));
     }
     foreach (String groupDir in Directory.GetDirectories(directory, "*", SearchOption.TopDirectoryOnly))
     {
         DirectoryInfo dirInfo = new DirectoryInfo(groupDir);
         if ((dirInfo.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
         {
             String name = dirInfo.Name;
             if (!groups.ContainsKey(groupDir))
             {
                 InstanceGroup group = new InstanceGroup(name, Path.Combine(path, name));
                 addGroup(group);
             }
             groups[name].doImportTemplates(groupDir);
         }
     }
 }
Esempio n. 10
0
        private void createSimObjectCallback(EditUICallback callback)
        {
            callback.getInputString("Enter a name.", delegate(String input, ref String errorPrompt)
            {
                if (input == null || input == "")
                {
                    errorPrompt = "Please enter a non empty name.";
                    return(false);
                }
                InstanceGroup groupWithInstance = findInstanceGroup(input);
                if (groupWithInstance != null)
                {
                    errorPrompt = String.Format("The name {0} is already in use in group {1}. Please provide another.", input, groupWithInstance.Name);
                    return(false);
                }

                SimObjectDefinition simObject = new GenericSimObjectDefinition(input);
                createInstance(simObject);
                return(true);
            });
        }
Esempio n. 11
0
 private void addGroupSubInterface(InstanceGroup group)
 {
     editInterface.addSubInterface(group, group.getEditInterface());
 }
Esempio n. 12
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);
        }
Esempio n. 13
0
 public InstanceFileInterface(String name, Object iconReferenceTag, String filename, InstanceGroup parentGroup, Instance instance)
     : this(name, iconReferenceTag, filename, parentGroup)
 {
     this.instance = instance;
 }
Esempio n. 14
0
 public String getInstanceFileName(InstanceGroup group, String instanceName)
 {
     return(group.FullPath + Path.DirectorySeparatorChar + instanceName + ".ins");
 }