Пример #1
0
 //--construction--//
 internal Report(string name, string userFullName, string userID, CaseFile caseFile) : base(name)
 {
     this.caseFile     = caseFile;
     this.licensorName = userFullName;
     this.licensorID   = userID;
     this.lastModified = new DateTime(1999, 12, 12);
 }
Пример #2
0
        //--merging--//
        /// <summary>
        /// merges a local slave casefile into the master casefile held on the server. The casefile instance
        /// that calls this method is considered the master, and the local copy isn't changed. This should only be
        /// called by the master version and then merged into the server.
        ///
        /// If a the same report exists on both copies, the more recentlly updated one will be prioritized.
        /// If a report exists only on the local copy, it will be added to the master copy.
        ///
        /// If the local copy's ID doesn't match the ID of the master copy, an exception will be thrown
        /// as that just doesn't make any sense.
        /// </summary>
        /// <param name="other">local case file to merge into this one.</param>
        public void MergeIntoSelf(CaseFile other)
        {
            if (!this.name.Equals(other.name))
            {
                throw new ArgumentException("ERROR case file " + name + "does not match " + other.name + ". They cannot be merged.");
            }

            foreach (Report report in other.reports)
            {
                Report localCopy = this.elementList.Find(x => x.name.Equals(report.name));
                if (localCopy == null)
                {
                    this.AddElementInternal(report);
                }
                else if (report.lastModified > localCopy.lastModified)
                {
                    this.RemoveElementInternal(localCopy);
                    this.AddElementInternal(report);
                }
            }
        }
Пример #3
0
        //--save/load--//
        /// <summary>
        /// saves a casefile, including the all-important checksum!
        /// </summary>
        /// <param name="caseFile"></param>
        /// <param name="filename"></param>
        public static void SaveCaseFile(CaseFile caseFile, string filename)
        {
            //save the casefile to a string so we can get its char data, but do NOT
            //save it to a file yet. We want to keep it in memory until we can find the checksum
            //and make sure nobody messes with this that they shouldn't.
            StringBuilder sb  = new StringBuilder();
            XmlSerializer ser = new XmlSerializer(typeof(CaseFile));

            using (StringWriter writer = new StringWriter(sb))
            {
                ser.Serialize(writer, caseFile);
            }

            //create a temp XML document.
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(sb.ToString());


            //use that to find the char count of the case file's XML SANS <?xml.... tag at the top
            int checksum = doc.DocumentElement.OuterXml.Length;

            XmlNode checksumNode = doc.CreateNode("element", CHECKSUM_NODE_NAME, "");

            checksumNode.InnerText = checksum.ToString();
            doc.DocumentElement.AppendChild(checksumNode);



            doc.Save(filename);
            caseFile.hasUnsavedData = false;
            if (caseFile.onCaseFileSaved != null)
            {
                caseFile.onCaseFileSaved.Invoke();
            }
        }