/// <summary> /// Clones CapacitiesInfo and makes it read-only. /// </summary> public object Clone() { CapacitiesInfo obj = new CapacitiesInfo(); CapacityInfo[] capacities = new CapacityInfo[_capacities.Count]; this._capacities.CopyTo(capacities, 0); obj._capacities.AddRange(capacities); return(obj); }
internal Project(string projectConfigPath, CapacitiesInfo capacitiesInfo, OrderCustomPropertiesInfo orderCustomPropertiesInfo, IProjectSaveExceptionHandler handler) { _handler = handler; if (projectConfigPath == null) { throw new ArgumentNullException("projectConfigPath"); } _CreateProject(projectConfigPath, capacitiesInfo, orderCustomPropertiesInfo); }
// Load capacity defaults private CapacitiesInfo _LoadCapacitiesDefaults(CapacitiesDefaults capacitiesConfig) { CapacitiesInfo capacitiesInfo = new CapacitiesInfo(); StringCollection uniqueNames = new StringCollection(); foreach (CapacityConfig capacity in capacitiesConfig.Capacity) { if (!uniqueNames.Contains(capacity.Name)) { // added only unique named capacities capacitiesInfo.Add(new CapacityInfo(capacity.Name, capacity.DisplayUnitUS, capacity.DisplayUnitMetric)); uniqueNames.Add(capacity.Name); } } return(capacitiesInfo); }
private void _CreateProject(string projectConfigPath, CapacitiesInfo capacitiesInfo, OrderCustomPropertiesInfo orderCustomPropertiesInfo) { try { // TODO : add advanced error reporting _projectCfg = ProjectConfiguration.Load(projectConfigPath); _dataContext = DatabaseOpener.OpenDatabase(_projectCfg.DatabasePath); _dataContext.PostInit(capacitiesInfo, orderCustomPropertiesInfo); _CreateCollections(); // TODO: DataObjectManager workaround _dataContext.SaveChangesCompleted += new SaveChangesCompletedEventHandler(_dataContext_SaveChangesCompleted); _dataContext.PostSavingChanges += new SavingChangesEventHandler(_dataContext_PostSavingChanges); this.DeletionCheckingService = new DeletionCheckingService(_dataContext); _isOpened = true; } catch (Exception) { _Clean(); throw; } }
/// <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; } }