public void InitFromSetupFile() { string setupFullPath = Application.StartupPath + @"\" + setupFileName; JsonFileService jfs = new JsonFileService(); if (File.Exists(setupFullPath)) // Если файл установок существует, то { try { CProperties instance = jfs.LoadInstanceFromFile <CProperties>(setupFullPath); // загружаем его содержимое if (instance != null) { if (((CProperties)instance).SelfIntersectionCheck.GetType().Equals(typeof(bool))) { properties.SelfIntersectionCheck = ((CProperties)instance).SelfIntersectionCheck; } for (int i = 0; i < 3; i++) { if (((CProperties)instance).opProperty[i].StrokeWeight.GetType().Equals(typeof(int))) { properties.opProperty[i].StrokeWeight = ((CProperties)instance).opProperty[i].StrokeWeight; } if (((CProperties)instance).opProperty[i].StrokeColor.GetType().Equals(typeof(string))) { properties.opProperty[i].StrokeColor = ((CProperties)instance).opProperty[i].StrokeColor; } if (((CProperties)instance).opProperty[i].FillColor.GetType().Equals(typeof(string))) { properties.opProperty[i].FillColor = ((CProperties)instance).opProperty[i].FillColor; } } if (((CProperties)instance).FileLocation != null) { if (Directory.Exists(((CProperties)instance).FileLocation)) { properties.FileLocation = ((CProperties)instance).FileLocation; } else { SavePropities(); //MessageBox.Show("The path specified in the files location property is missing, the default path will be used!"); } } else { MessageBox.Show("Could not read property of the shape-files location path, default path will be used!"); } if (!Directory.Exists(properties.FileLocation)) // Если нет дефолтной директории сохранения файлов { Directory.CreateDirectory(properties.FileLocation); // создаем ее } if (((CProperties)instance).UserLogin.GetType().Equals(typeof(string))) { properties.UserLogin = ((CProperties)instance).UserLogin; } if (((CProperties)instance).UserPassword.GetType().Equals(typeof(string))) { properties.UserPassword = ((CProperties)instance).UserPassword; } if (((CProperties)instance).RemoteUsed.GetType().Equals(typeof(bool))) { properties.RemoteUsed = ((CProperties)instance).RemoteUsed; } if (((CProperties)instance).RemoteHost.GetType().Equals(typeof(string))) { properties.RemoteHost = ((CProperties)instance).RemoteHost; } if (((CProperties)instance).RemotePort.GetType().Equals(typeof(string))) { properties.RemotePort = ((CProperties)instance).RemotePort; } if (((CProperties)instance).LocalHost.GetType().Equals(typeof(string))) { properties.LocalHost = ((CProperties)instance).LocalHost; } if (((CProperties)instance).LocalPort.GetType().Equals(typeof(string))) { properties.LocalPort = ((CProperties)instance).LocalPort; } /********** Прописать этот блок если получится сконфигурировать портативный сервер MongoDB *************** * if (((CProperties)instance).LocalDataBaseLocation != null) * { * if (Directory.Exists(((CProperties)instance).LocalDataBaseLocation)) * { * properties.LocalDataBaseLocation = ((CProperties)instance).LocalDataBaseLocation; * } * else * { * MessageBox.Show("The path specified in the files location property is missing, the default path will be used!"); * } * } * else * { * MessageBox.Show("Could not read property of the shape-files location path, default path will be used!"); * } * /*if (!Directory.Exists(properties.LocalDataBaseLocation)) // Если нет дефолтной директории для БД * { * Directory.CreateDirectory(properties.LocalDataBaseLocation); // создаем ее **************** }************************************************************************/ } else { //MessageBox.Show("Could not read Properties from the Setup File, Default Properties will be used!!"); SavePropities(); } } catch (ApplicationException ex) { MessageBox.Show("PropertiesService.InitFromSetupFile()" + ex.Message, "ApplicationException!"); } catch (Exception ex) { MessageBox.Show("PropertiesService.InitFromSetupFile()" + ex.Message, "Exeption!"); } } }
public void SavePropities() { JsonFileService jfs = new JsonFileService(); jfs.SaveToFile(Application.StartupPath + "\\" + setupFileName, properties); // записываем существующие установки }