/// <summary> /// Updates project's custom order properties info. /// </summary> /// <param name="projectConfig">Project configuration.</param> /// <param name="propertiesInfo">Order custom properties info.</param> /// <exception cref="DataException">Failed to update database.</exception> public static void UpdateProjectCustomOrderPropertiesInfo(ProjectConfiguration projectConfig, OrderCustomPropertiesInfo propertiesInfo) { Debug.Assert(projectConfig != null); Debug.Assert(propertiesInfo != null); DataObjectContext dataContext = null; try { // Open database. dataContext = DatabaseOpener.OpenDatabase(projectConfig.DatabasePath); // Update custom order properties info in database. dataContext.UpdateCustomOrderPropertiesInfo(propertiesInfo); } catch (Exception ex) { // Failed to update database. throw new DataException(Properties.Messages.Error_DatabaseUpdate, ex, DataError.DatabaseUpdateError); } finally { if (dataContext != null) { dataContext.Dispose(); } } }
internal Project(string projectConfigPath, CapacitiesInfo capacitiesInfo, OrderCustomPropertiesInfo orderCustomPropertiesInfo, IProjectSaveExceptionHandler handler) { _handler = handler; if (projectConfigPath == null) { throw new ArgumentNullException("projectConfigPath"); } _CreateProject(projectConfigPath, capacitiesInfo, orderCustomPropertiesInfo); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Clone properties info and made it read-only /// </summary> public object Clone() { OrderCustomPropertiesInfo obj = new OrderCustomPropertiesInfo(); OrderCustomProperty[] property = new OrderCustomProperty[_properies.Count]; this._properies.CopyTo(property, 0); obj._properies.AddRange(property); obj._totalLength = this._totalLength; // NOTE: clonned object is ReadOnly obj._isReadOnly = true; return(obj); }
/// <summary> /// Converts OrderCustomPropertiesInfo to CustomOrderProperties. /// </summary> /// <param name="customOrderPropertiesInfo">OrderCustomPropertiesInfo object to convert.</param> /// <returns>Converted object.</returns> private CustomOrderProperties _ConvertToCustomOrderProperties(OrderCustomPropertiesInfo customOrderPropertiesInfo) { Debug.Assert(customOrderPropertiesInfo != null); // Create custom order properties. CustomOrderProperties customOrderProperties = new CustomOrderProperties(); // Create array of CustomOrderProperty objects. customOrderProperties.CustomOrderProperty = new CustomOrderProperty[customOrderPropertiesInfo.Count]; // Convert each object of collection customOrderPropertiesInfo to OrderCustomProperty and store to array. for (int i = 0; i < customOrderPropertiesInfo.Count; i++) { OrderCustomProperty orderCustomProperty = customOrderPropertiesInfo[i]; customOrderProperties.CustomOrderProperty[i] = _ConvertToCustomOrderProperty(orderCustomProperty); } return(customOrderProperties); }
/// <summary> /// Checks maximum length constraint for list of custom order properties. /// </summary> /// <param name="propertiesInfo">Order custom properties info.</param> /// <returns>Maximum length constraint.</returns> public static bool CheckMaximumLengthConstraint(OrderCustomPropertiesInfo propertiesInfo) { Debug.Assert(propertiesInfo != null); bool checkMaxLengthConstraint = false; // Serialize order custom properties info to XML. string customOrderPropertiesSerialized = ConfigDataSerializer.SerializeOrderCustomPropertiesInfo(propertiesInfo); // Maximum length needed to store values of cusom order properties. int maxLengthOfPropertiesValuesString = OrderCustomProperties.CalculateMaximumLengthOfDBString(propertiesInfo); // Check constraint. checkMaxLengthConstraint = customOrderPropertiesSerialized.Length <= MAX_DB_FIELD_LENGTH && maxLengthOfPropertiesValuesString <= MAX_DB_FIELD_LENGTH; return(checkMaxLengthConstraint); }
// Load order custom properties defaults private OrderCustomPropertiesInfo _LoadOrderCustomPropertiesDefaults(CustomOrderProperties customOrderProperties) { OrderCustomPropertiesInfo propertiesInfo = new OrderCustomPropertiesInfo(); StringCollection uniqueNames = new StringCollection(); foreach (CustomOrderProperty customOrderProperty in customOrderProperties.CustomOrderProperty) { if (!uniqueNames.Contains(customOrderProperty.Name)) { // added only unique named properties OrderCustomProperty property = new OrderCustomProperty(customOrderProperty.Name, customOrderProperty.Type, customOrderProperty.MaxLength, customOrderProperty.Description, customOrderProperty.OrderPairKey); propertiesInfo.Add(property); uniqueNames.Add(customOrderProperty.Name); } } return(propertiesInfo); }
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; } }