コード例 #1
0
        private void LoadDataFromReviewPalFile()
        {
            XmlDocument reviewHtml = new XmlDocument();

            if (File.Exists(_fileLocation))
            {
                reviewHtml.Load(_fileLocation);
                XmlNode dataNode = CodeReview.GetDataNode(reviewHtml);
                if (dataNode == null)
                {
                    MessageBox.Show("Please select a valid ReviewPal file.");
                }
                else
                {
                    string xml = dataNode.InnerXml;
                    _reviewRepo.CodeReview = Utils.LoadFromXml <CodeReview>(xml);
                    _reviewRepo.AdjustReviewId();
                    RefreshReviewList();
                }
            }
            else
            {
                MessageBox.Show(string.Format("Previously saved ReviewPal file not found at \n {0}.", _fileLocation));
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles the Click event of the tbtnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void tbtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (VisualStudioInstance.Solution.IsOpen)
                {
                    if (0 == _reviewRepo.GetCount())
                    {
                        return;
                    }

                    SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                    saveFileDialog1.Filter           = "html file (*.html)|*.html";
                    saveFileDialog1.FilterIndex      = 2;
                    saveFileDialog1.RestoreDirectory = true;
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        _fileLocation = saveFileDialog1.FileName;

                        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 + "\\" + Utils.AssemblyTitle + ".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);

                        VisualStudioInstance.StatusBar.Text = "Review List saved at " + _fileLocation + " successfully";
                    }
                }
                else
                {
                    MessageBox.Show(SolutionNotOpen);
                }
            }
            catch (Exception ex)
            {
                Utils.HandleException(ex);
            }
        }