public static SolutionConfig GetSolutionConfig() { SolutionConfig solutionConfig = null; var path = GetConfigPath(); if (File.Exists(path)) { solutionConfig = Utils.LoadFromXml <SolutionConfig>(File.ReadAllText(path)); } return(solutionConfig); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (VSIDEHelper.VisualStudioInstance.Solution.IsOpen) { if (0 == _reviewRepo.GetCount()) { return; } SolutionConfig solutionConfig = SolutionConfig.GetSolutionConfig(); if (solutionConfig == null) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "html file (*.html)|*.html"; saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { _fileLocation = saveFileDialog1.FileName; // save user selected file location the solution config file solutionConfig = new SolutionConfig { ReviewPalFileLocation = _fileLocation}; solutionConfig.Save(); } } XmlSerializer s = new XmlSerializer(typeof(CodeReview)); string tmpFile = Path.GetTempFileName(); TextWriter w = new StreamWriter(tmpFile); _reviewRepo.AdjustReviewId(); s.Serialize(w, _reviewRepo.CodeReview); w.Close(); //load the Xml doc XPathDocument xPathDoc = new XPathDocument(tmpFile); File.Delete(tmpFile); XslCompiledTransform xslTrans = new XslCompiledTransform(); //load the Xsl xslTrans.Load(Utils.AssemblyPath + "\\" + "ReviewPal.xsl"); //create the output stream XmlTextWriter xmlWriter = new XmlTextWriter(_fileLocation, null); //do the actual transform of Xml xslTrans.Transform(xPathDoc, null, xmlWriter); xmlWriter.Close(); string xml = Utils.GetSerializedXml(_reviewRepo.CodeReview); // save the xml data as well within the html XmlDocument reviewHtml = new XmlDocument(); reviewHtml.Load(_fileLocation); XmlNode dataNode = CodeReview.GetDataNode(reviewHtml); dataNode.InnerXml = xml; reviewHtml.Save(_fileLocation); VSIDEHelper.VisualStudioInstance.StatusBar.Text = "Review List saved at " + _fileLocation + " successfully"; } else { MessageBox.Show(SolutionNotOpen); } } catch (Exception ex) { Utils.HandleException(ex); } }
private void btnOpen_Click(object sender, RoutedEventArgs e) { try { if (VSIDEHelper.VisualStudioInstance.Solution.IsOpen) { OpenFileDialog fDialog = new OpenFileDialog(); fDialog.Title = "Open Review"; fDialog.Filter = "html file (*.html)|*.html"; //fDialog.InitialDirectory = @"C:\"; if (fDialog.ShowDialog() == DialogResult.OK) { _fileLocation = fDialog.FileName; LoadDataFromReviewPalFile(); var solutionConfig = SolutionConfig.GetSolutionConfig(); if(solutionConfig == null) solutionConfig = new SolutionConfig(); solutionConfig.ReviewPalFileLocation = _fileLocation; solutionConfig.Save(); } } else { MessageBox.Show(SolutionNotOpen); } } catch (Exception ex) { Utils.HandleException(ex); } }