コード例 #1
0
        // throws if path, name is invalid, project directory already exists
        public void createNewProject(ModelAPI <ProjectModel> api, string path = null)
        {
            if (api.api_mode != ModelApiMode.MODE_CREATE)
            {
                throw new InvalidOperationException("api mode must be MODE_CREATE");
            }
            if (path is null)
            {
                path = programe_data_file.data.default_proj_dir;
            }
            path = Path.GetFullPath(path);
            api.model.id.value = DateTime.Now.Ticks;             // TODO: consider change in pk
            ProjectManager.singleton.createProjectTemplate(path, api);
            var client = Model.getModel(api.model.client_id.value, ModelType.MODEL_CLIENT) as ClientModel;

            programe_data_file.data.addProject(api.model.name.value, client.name.value, ProjectManager.singleton.project_file.path);
            programe_data_file.save();
            Directory.SetCurrentDirectory(Path.Combine(path, api.model.name.value));
            _is_proj_loaded = true;
        }
コード例 #2
0
 public ModeloController(ModelAPI modelAPI)
 {
     _modelAPI = modelAPI;
 }
コード例 #3
0
        public void createProjectTemplate(string path, ModelAPI <ProjectModel> api)
        {
            var    project_model = api.model;
            string project_name  = project_model.name.value;

            if (!Directory.Exists(path))
            {
                throw new DirectoryNotFoundException();
            }
            string project_dir = Path.Combine(path, project_name);             // TODO: project_name validation - throws illegal characters in path

            if (Directory.Exists(project_dir))
            {
                throw new AlreadyExistsError("project directory already exists");
            }
            Directory.CreateDirectory(project_dir);
            foreach (FileTreeItem item in getProjectTemplate(project_model.getProjectType()))
            {
                buildRecursiveDirectory(project_dir, item);
            }

            if (project_model.client_id.isNull())
            {
                throw new Exception("client must not be null for a project");
            }

            // project file
            var proj_file_path = Path.Combine(path, project_name, project_name + Reference.PROJECT_FILE_EXTENSION);

            project_file.path = proj_file_path;
            api.update();             // creates project file and save, upload cache

            var file_items = getProjectTemplate(project_model.getProjectType());

            if (has_progress_tracking is null)
            {
                throw new NullReferenceException("did you call Application.singleton.initialize()");
            }
            if (has_progress_tracking[project_model.getProjectType()])
            {
                var progress_pk = DateTime.Now.Ticks;

                // progress client
                progress_client.path = Path.Combine(path, project_name, Dirs.PROJECT_TRACKING, Files.PROGRESS_CLIENT);
                ModelAPI <ClientProgressModel> api_progress_client = new ModelAPI <ClientProgressModel>(null, ModelApiMode.MODE_CREATE);
                api_progress_client.model.id.value         = progress_pk;
                api_progress_client.model.project_id.value = api.model.id.value;
                api_progress_client.update();                 // create and save progress_client file
                project_file.data.dirs.getDir(Dirs.PROJECT_TRACKING).addFile(Files.PROGRESS_CLIENT);

                // progress supplier
                progress_supplier.path = Path.Combine(path, project_name, Dirs.PROJECT_TRACKING, Files.PROGRESS_SUPPLIER);
                ModelAPI <SupplierProgressModel> api_progress_supplier = new ModelAPI <SupplierProgressModel>(null, ModelApiMode.MODE_CREATE);
                api_progress_supplier.model.id.value         = progress_pk;
                api_progress_supplier.model.project_id.value = api.model.id.value;
                api_progress_supplier.update();                 // create and save progress_supplier file
                project_file.data.dirs.getDir(Dirs.PROJECT_TRACKING).addFile(Files.PROGRESS_SUPPLIER);

                // payments
                progress_payments.path = Path.Combine(path, project_name, Dirs.PROJECT_TRACKING, Files.PROGRESS_PAYMENTS);
                progress_payments.save();
                project_file.data.dirs.getDir(Dirs.PROJECT_TRACKING).addFile(Files.PROGRESS_PAYMENTS);
            }

            project_file.save();
        }