Beispiel #1
0
        /// <summary>
        /// Clones fuel types info and makes it read-only.
        /// </summary>
        public object Clone()
        {
            FuelTypesInfo obj = new FuelTypesInfo();

            FuelTypeInfo[] fuelTypes = new FuelTypeInfo[_fuelTypes.Count];
            this._fuelTypes.CopyTo(fuelTypes, 0);
            obj._fuelTypes.AddRange(fuelTypes);

            // clonned object is ReadOnly
            obj._isReadOnly = true;

            return(obj);
        }
Beispiel #2
0
        // Load fueltype defaults
        private FuelTypesInfo _LoadFuelTypesDefaults(FuelTypesDefaults fuelTypesConfig)
        {
            FuelTypesInfo fuelTypesInfo = new FuelTypesInfo();

            StringCollection uniqueNames = new StringCollection();

            foreach (FuelTypeConfig fuelTypeConfig in fuelTypesConfig.FuelTypeConfig)
            {
                if (!uniqueNames.Contains(fuelTypeConfig.Name))
                {   // added only unique named types
                    FuelTypeInfo fuelTypeInfo = new FuelTypeInfo(fuelTypeConfig.Name, fuelTypeConfig.Price, fuelTypeConfig.Co2Emission);
                    fuelTypesInfo.Add(fuelTypeInfo);
                    uniqueNames.Add(fuelTypeConfig.Name);
                }
            }

            return(fuelTypesInfo);
        }
Beispiel #3
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;
            }
        }