Esempio n. 1
0
        public void CloneProject(string projectName, string projectDir, string modelFileName)
        {
            CreateProject(projectName, projectDir);

            string modelName = string.IsNullOrEmpty(modelFileName) ?
                               vissim.Instance.GetInputFileName() : Path.GetFileName(modelFileName);
            string modelDir = string.IsNullOrEmpty(modelFileName) ?
                              vissim.Instance.GetWorkingDirectory() : Path.GetDirectoryName(modelFileName);
            string snapshotDataFileName = string.Format("{0}\\{1}", projectDir, project.Files.SnapshotDataFileName);

            var tree = new ExperimentsTree(string.Format("{0}\\{1}", projectDir, project.Files.SnapshotTreeFileName));

            DirectoryPacker.Pack(modelDir, snapshotDataFileName, tree.root.Id);

            modelDir = string.Format("{0}\\{1}", projectDir, project.Files.ModelDirectory);
            if (!Directory.Exists(modelDir))
            {
                Directory.CreateDirectory(modelDir);
            }
            DirectoryPacker.UnPack(modelDir, snapshotDataFileName, tree.root.Id);

            vissim.Instance.LoadNet(string.Format("{0}\\{1}{2}", modelDir, modelName,
                                                  modelName.EndsWith(".inp") ? string.Empty : ".inp"));

            CreateExperiment(projectDir, tree.root.Id);

            project.CurrentExperimentId = tree.root.Id;
            project.Save(projectDir);

            SaveProjectToSettings(project, projectDir);

            OnProjectLoaded(string.Format("{0}\\{1}{2}", projectDir, project.Name, project.FileExtension));
        }
Esempio n. 2
0
        public void Initialize(string projectName, string projectDir, ModelCreationMode modelMode, string model)
        {
            ThreadPool.QueueUserWorkItem(o =>
            {
                OnInitialization();

                Guid id = Guid.NewGuid();

                this.projectDir = projectDir;
                Project         = new Project(projectName, id);
                Project.Save(projectDir);
                SaveProjectToSettings();

                tree = new ExperimentsTree(TreeFileName, id);

                bool pack = false;

                switch (modelMode)
                {
                case ModelCreationMode.cmCreateNew:

                    pack = DirectoryPacker.Pack(ModelDir, SnapshotDataFileName, id);

                    CreateModel(model);
                    break;

                case ModelCreationMode.cmClone:

                    pack = DirectoryPacker.Pack(model, SnapshotDataFileName, id);
                    if (pack)
                    {
                        DirectoryPacker.UnPack(ModelDir, SnapshotDataFileName, id);
                    }

                    LoadModel();
                    break;
                }

                Experiment.Create(id, ExperimentFileName, MakeBackup(id), pack);

                OnInitialized();
            });
        }
Esempio n. 3
0
        public void TakeSnapshot(ExperimentsTree.ExperimentsTreeNode node)
        {
            node.Open();
            node.Load();
            Tree.Save(TreeFileName);

            if (Experiment.GetInstance(node.Id).HasSnapshot)
            {
                Experiment.GetInstance(node.Id).HasSnapshot = DirectoryPacker.UnPack(ModelDir, SnapshotDataFileName, node.Id);
            }
            if (Experiment.GetInstance(node.Id).HasBackup)
            {
                TakeBackup(node.Id);
            }

            LastSnapshotId = node.Id;
            SaveProject();

            //string modelName = vissim.Instance.GetInputFileName();
            //string modelDir = vissim.Instance.GetWorkingDirectory();

            LoadModel();
        }