private void InitDropDowns() { if (comboBox_SPLicense.Items.Count == 0 || comboBox_SPVersion.Items.Count == 0) { try { FileInfo fi = new FileInfo(Path.Combine(Application.StartupPath, Globals.SHAREPOINT_CONFIG)); if (fi.Exists) { using (var fileStream = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read)) { var serializer = new XmlSerializer(typeof(Model.SPSD)); Model.SPSD config = serializer.Deserialize(fileStream) as Model.SPSD; FillSPDropDowns(config); } } else { using (var stringStream = new StringReader(Resources.SharePointVersions)) { var serializer = new XmlSerializer(typeof(Model.SPSD)); Model.SPSD config = serializer.Deserialize(stringStream) as Model.SPSD; FillSPDropDowns(config); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void InitNewFile() { _spsd = new Model.SPSD(); _spsd.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); _control.LoadEnv(_spsd); _isReadonly = false; _filepath = null; _filename = null; MakeSingletonDirty(); }
public static Model.SPSD LoadFile(string filepath) { Model.SPSD file = null; try { FileInfo fi = new FileInfo(filepath); if (fi.Exists) { using (FileStream filestream = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read)) { string content; using (StreamReader reader = new StreamReader(filestream)) { content = reader.ReadToEnd(); reader.Close(); } // can be done better directly in the serializer but will to for now content = Regex.Replace(content, "\"true\"", "\"true\"", RegexOptions.IgnoreCase); content = Regex.Replace(content, "\"false\"", "\"false\"", RegexOptions.IgnoreCase); content = Regex.Replace(content, ">true<", ">true<", RegexOptions.IgnoreCase); content = Regex.Replace(content, ">false<", ">false<", RegexOptions.IgnoreCase); using (MemoryStream memStream = new MemoryStream(Encoding.ASCII.GetBytes(content))) { var serializer = new XmlSerializer(typeof(Model.SPSD)); file = serializer.Deserialize(memStream) as Model.SPSD; } } } else { MessageBox.Show(string.Format("The file \"{0}\" does not exist!", filepath), "File does not exist", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), string.Format( "Exception while loading \"{0}\". The file has to be a valid SPSD environment file.", filepath), MessageBoxButtons.OK, MessageBoxIcon.Error); } return(file); }
public static bool SaveFile(string filepath, Model.SPSD file) { try { using (var fileStream = new FileStream(filepath, FileMode.Create, FileAccess.ReadWrite)) { var serializer = new XmlSerializer(typeof(Model.SPSD)); serializer.Serialize(fileStream, file); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), string.Format("Exception while saving file \"{0}\"", filepath), MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
public bool Load(string filepath) { if (IsDirty) { if (MessageBox.Show( Resources.EnvironmentFileHandler_Load_UnsavedChanges, Resources.EnvironmentFileHandler_Load_UnsavedChangesTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } } if (string.IsNullOrEmpty(filepath)) { InitNewFile(); return(true); } FileInfo fi = new FileInfo(filepath); _spsd = LoadFile(filepath); if (_spsd != null) { if (!string.IsNullOrEmpty(_spsd.Version) && !_spsd.Version.Equals(Assembly.GetExecutingAssembly().GetName().Version.ToString())) { // Versions do not match _spsd.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); } _control.LoadEnv(_spsd); _filename = fi.Name; _filepath = fi.FullName; _isReadonly = fi.IsReadOnly; Clean(); return(true); } else { return(false); } }
private void FillSPDropDowns(Model.SPSD config) { if (config.SharePoint != null) { // fill licenses dropdown if (config.SharePoint.Licenses != null && config.SharePoint.Licenses.License.Count() > 0) { string[] licenseTypes = (from lic in config.SharePoint.Licenses.License select lic.Type).Distinct <string>().ToArray <string>(); comboBox_SPLicense.Items.AddRange(licenseTypes); } else { comboBox_SPLicense.Items.AddRange(new[] { "Foundation", "Standard", "Enterprise" }); } comboBox_SPLicense.SelectedIndex = 0; if (config.SharePoint.Versions != null && config.SharePoint.Versions.Version.Count() > 0) { // only show versions supported by SPSD, >= 14 Dictionary <string, string> versions = config.SharePoint.Versions.Version.Where( rel => new Version(rel.Number).Major >= 14) .ToDictionary(rel => rel.Number, rel => string.Format("{0} - {1}", rel.Number, rel.Name), StringComparer.OrdinalIgnoreCase); comboBox_SPVersion.DataSource = new BindingSource(versions, null); comboBox_SPVersion.DisplayMember = "Value"; comboBox_SPVersion.ValueMember = "Key"; } comboBox_SPLicense.SelectedIndex = 0; } }
public bool Load(string filepath) { if (IsDirty) { if (MessageBox.Show( Resources.EnvironmentFileHandler_Load_UnsavedChanges, Resources.EnvironmentFileHandler_Load_UnsavedChangesTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return false; } } if (string.IsNullOrEmpty(filepath)) { InitNewFile(); return true; } FileInfo fi = new FileInfo(filepath); _spsd = LoadFile(filepath); if (_spsd != null) { if (!string.IsNullOrEmpty(_spsd.Version) && !_spsd.Version.Equals(Assembly.GetExecutingAssembly().GetName().Version.ToString())) { // Versions do not match _spsd.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); } _control.LoadEnv(_spsd); _filename = fi.Name; _filepath = fi.FullName; _isReadonly = fi.IsReadOnly; Clean(); return true; } else { return false; } }