コード例 #1
0
        /// <summary>
        /// Open project
        /// </summary>
        /// <param name="projectConfigPath">Project path</param>
        /// <returns>Opened project</returns>
        static public Project OpenProject(string projectConfigPath,
                                          IProjectSaveExceptionHandler logHandler)
        {
            WorkspaceHandler workspaceHandler = new WorkspaceHandler(logHandler);
            Project          project          = new Project(projectConfigPath, logHandler);

            workspaceHandler.Handled = true;

            return(project);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of the <c>Project</c> class.
        /// </summary>
        public Project(string projectConfigPath, IProjectSaveExceptionHandler handler)
        {
            _handler = handler;

            if (projectConfigPath == null)
            {
                throw new ArgumentNullException("projectConfigPath");
            }

            _OpenProject(projectConfigPath);
        }
コード例 #3
0
        internal Project(string projectConfigPath, CapacitiesInfo capacitiesInfo,
                         OrderCustomPropertiesInfo orderCustomPropertiesInfo,
                         IProjectSaveExceptionHandler handler)
        {
            _handler = handler;

            if (projectConfigPath == null)
            {
                throw new ArgumentNullException("projectConfigPath");
            }

            _CreateProject(projectConfigPath, capacitiesInfo, orderCustomPropertiesInfo);
        }
コード例 #4
0
        /// <summary>
        /// Creates project.
        /// </summary>
        /// <param name="name">Project's name.</param>
        /// <param name="folderPath">Project's folder path.</param>
        /// <param name="description">Proejct's description.</param>
        /// <returns>Created project</returns>
        static public Project CreateProject(string name, string folderPath, string description, CapacitiesInfo capacitiesInfo,
                                            OrderCustomPropertiesInfo orderCustomPropertiesInfo, FuelTypesInfo fuelTypesInfo /*serivces*/,
                                            IProjectSaveExceptionHandler logHandler)
        {
            WorkspaceHandler workspaceHandler = new WorkspaceHandler(logHandler);

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (folderPath == null)
            {
                throw new ArgumentNullException("folderPath");
            }
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            if (!CheckMaximumLengthConstraint(orderCustomPropertiesInfo))
            {
                throw new ApplicationException(Properties.Messages.Error_OrderCustomPropTooLong);
            }

            bool   isDBCreated = false;
            string dbPath      = "";

            try
            {
                name = name.Trim();

                // make project configuration path
                string projCfgPath = System.IO.Path.Combine(folderPath, name);
                projCfgPath += ProjectConfiguration.FILE_EXTENSION;

                string databasePath = ProjectConfiguration.GetDatabaseFileName(name);
                // create project configuration
                ProjectConfiguration projConfig = new ProjectConfiguration(name, folderPath, description,
                                                                           databasePath, null, DateTime.Now);

                projConfig.Validate();

                projConfig.Save();

                dbPath = projConfig.DatabasePath;

                DatabaseEngine.DeleteDatabase(dbPath);

                // create database
                DatabaseEngine.CreateDatabase(dbPath, SchemeVersion.CreationScript);
                isDBCreated = true;

                Project project = new Project(projCfgPath, capacitiesInfo,
                                              orderCustomPropertiesInfo, workspaceHandler);

                foreach (FuelTypeInfo fuelTypeInfo in fuelTypesInfo)
                {
                    FuelType projectFuelType = new FuelType();
                    projectFuelType.Name        = fuelTypeInfo.Name;
                    projectFuelType.Price       = fuelTypeInfo.Price;
                    projectFuelType.Co2Emission = fuelTypeInfo.Co2Emission;
                    project.FuelTypes.Add(projectFuelType);
                }

                project.Save();

                workspaceHandler.Handled = true;

                return(project);
            }
            catch (Exception ex)
            {
                Logger.Info(ex);
                if (isDBCreated)
                {
                    DatabaseEngine.DeleteDatabase(dbPath);
                }

                throw;
            }
        }
コード例 #5
0
        /// <summary>
        /// Open project
        /// </summary>
        /// <param name="projectConfigPath">Project path</param>
        /// <returns>Opened project</returns>
        public static Project OpenProject(string projectConfigPath,
            IProjectSaveExceptionHandler logHandler)
        {
            WorkspaceHandler workspaceHandler = new WorkspaceHandler(logHandler);
            Project project = new Project(projectConfigPath, logHandler);
            workspaceHandler.Handled = true;

            return project;
        }
コード例 #6
0
        /// <summary>
        /// Creates project.
        /// </summary>
        /// <param name="name">Project's name.</param>
        /// <param name="folderPath">Project's folder path.</param>
        /// <param name="description">Proejct's description.</param>
        /// <returns>Created project</returns>
        public static Project CreateProject(string name, string folderPath, string description, CapacitiesInfo capacitiesInfo,
            OrderCustomPropertiesInfo orderCustomPropertiesInfo, FuelTypesInfo fuelTypesInfo /*serivces*/,
                                     IProjectSaveExceptionHandler logHandler)
        {
            WorkspaceHandler workspaceHandler = new WorkspaceHandler(logHandler);

            if (name == null)
                throw new ArgumentNullException("name");
            if (folderPath == null)
                throw new ArgumentNullException("folderPath");
            if (description == null)
                throw new ArgumentNullException("description");

            if (!CheckMaximumLengthConstraint(orderCustomPropertiesInfo))
                throw new ApplicationException(Properties.Messages.Error_OrderCustomPropTooLong);

            bool isDBCreated = false;
            string dbPath = "";

            try
            {
                name = name.Trim();

                // make project configuration path
                string projCfgPath = System.IO.Path.Combine(folderPath, name);
                projCfgPath += ProjectConfiguration.FILE_EXTENSION;

                string databasePath = ProjectConfiguration.GetDatabaseFileName(name);
                // create project configuration
                ProjectConfiguration projConfig = new ProjectConfiguration(name, folderPath, description,
                    databasePath, null, DateTime.Now);

                projConfig.Validate();

                projConfig.Save();

                dbPath = projConfig.DatabasePath;

                DatabaseEngine.DeleteDatabase(dbPath);

                // create database
                DatabaseEngine.CreateDatabase(dbPath, SchemeVersion.CreationScript);
                isDBCreated = true;

                Project project = new Project(projCfgPath, capacitiesInfo,
                    orderCustomPropertiesInfo, workspaceHandler);

                foreach (FuelTypeInfo fuelTypeInfo in fuelTypesInfo)
                {
                    FuelType projectFuelType = new FuelType();
                    projectFuelType.Name = fuelTypeInfo.Name;
                    projectFuelType.Price = fuelTypeInfo.Price;
                    projectFuelType.Co2Emission = fuelTypeInfo.Co2Emission;
                    project.FuelTypes.Add(projectFuelType);
                }

                project.Save();

                workspaceHandler.Handled = true;

                return project;
            }
            catch(Exception ex)
            {
                Logger.Info(ex);
                if (isDBCreated)
                    DatabaseEngine.DeleteDatabase(dbPath);

                throw;
            }
        }
コード例 #7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="handler">Implementation of IProjectSaveExceptionHandler.</param>
 internal WorkspaceHandler(IProjectSaveExceptionHandler handler)
 {
     _handler = handler;
     Handled  = false;
 }
コード例 #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="handler">Implementation of IProjectSaveExceptionHandler.</param>
 internal WorkspaceHandler(IProjectSaveExceptionHandler handler)
 {
     _handler = handler;
     Handled = false;
 }