/// <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); }
/// <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; } }
/// <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; }
/// <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; } }