B2019-035 Added better memory management to the import procedure set functionality, with focus on importing Word documents and Library documents. Also, when a library document is added via an import, the modified date/time of the library document is appended to the library document name
This commit is contained in:
parent
c9c26d235a
commit
c16ebcf2ed
@ -709,6 +709,7 @@ namespace VEPROMS
|
|||||||
Old2NewItem = new Dictionary<int, int>();
|
Old2NewItem = new Dictionary<int, int>();
|
||||||
Old2NewContent = new Dictionary<int, int>();
|
Old2NewContent = new Dictionary<int, int>();
|
||||||
Old2NewLibDoc = new Dictionary<int, int>();
|
Old2NewLibDoc = new Dictionary<int, int>();
|
||||||
|
GetExistingLibDocsList(); // B2019-035 better memory management
|
||||||
PendingTransitions = new XmlDocument();
|
PendingTransitions = new XmlDocument();
|
||||||
XmlElement xe = PendingTransitions.CreateElement("transitions");
|
XmlElement xe = PendingTransitions.CreateElement("transitions");
|
||||||
PendingTransitions.AppendChild(xe);
|
PendingTransitions.AppendChild(xe);
|
||||||
@ -738,6 +739,7 @@ namespace VEPROMS
|
|||||||
Old2NewItem = new Dictionary<int, int>();
|
Old2NewItem = new Dictionary<int, int>();
|
||||||
Old2NewContent = new Dictionary<int, int>();
|
Old2NewContent = new Dictionary<int, int>();
|
||||||
Old2NewLibDoc = new Dictionary<int, int>();
|
Old2NewLibDoc = new Dictionary<int, int>();
|
||||||
|
GetExistingLibDocsList(); // B2019-035 better memory management
|
||||||
PendingTransitions = new XmlDocument();
|
PendingTransitions = new XmlDocument();
|
||||||
XmlElement xe = PendingTransitions.CreateElement("transitions");
|
XmlElement xe = PendingTransitions.CreateElement("transitions");
|
||||||
PendingTransitions.AppendChild(xe);
|
PendingTransitions.AppendChild(xe);
|
||||||
@ -777,6 +779,7 @@ namespace VEPROMS
|
|||||||
Old2NewItem = new Dictionary<int, int>();
|
Old2NewItem = new Dictionary<int, int>();
|
||||||
Old2NewContent = new Dictionary<int, int>();
|
Old2NewContent = new Dictionary<int, int>();
|
||||||
Old2NewLibDoc = new Dictionary<int, int>();
|
Old2NewLibDoc = new Dictionary<int, int>();
|
||||||
|
GetExistingLibDocsList(); // B2019-035 better memory management
|
||||||
PendingTransitions = new XmlDocument();
|
PendingTransitions = new XmlDocument();
|
||||||
XmlElement xe = PendingTransitions.CreateElement("transitions");
|
XmlElement xe = PendingTransitions.CreateElement("transitions");
|
||||||
PendingTransitions.AppendChild(xe);
|
PendingTransitions.AppendChild(xe);
|
||||||
@ -866,6 +869,7 @@ namespace VEPROMS
|
|||||||
DirectoryInfo[] dis = di.GetDirectories();
|
DirectoryInfo[] dis = di.GetDirectories();
|
||||||
for (int d = 0; d < dis.Length; d++)
|
for (int d = 0; d < dis.Length; d++)
|
||||||
dis[d].Delete(true);
|
dis[d].Delete(true);
|
||||||
|
di.Delete();
|
||||||
lblImportStatus.Text = "Updating Transitions";
|
lblImportStatus.Text = "Updating Transitions";
|
||||||
AddTransitions();
|
AddTransitions();
|
||||||
FixFloatingFoldouts();
|
FixFloatingFoldouts();
|
||||||
@ -1705,6 +1709,7 @@ namespace VEPROMS
|
|||||||
Old2NewItem = new Dictionary<int, int>();
|
Old2NewItem = new Dictionary<int, int>();
|
||||||
Old2NewContent = new Dictionary<int, int>();
|
Old2NewContent = new Dictionary<int, int>();
|
||||||
Old2NewLibDoc = new Dictionary<int, int>();
|
Old2NewLibDoc = new Dictionary<int, int>();
|
||||||
|
GetExistingLibDocsList(); // B2019-035 better memory management
|
||||||
PendingTransitions = new XmlDocument();
|
PendingTransitions = new XmlDocument();
|
||||||
FileInfo fi = new FileInfo(ofd.FileName);
|
FileInfo fi = new FileInfo(ofd.FileName);
|
||||||
string dn;
|
string dn;
|
||||||
@ -3336,6 +3341,7 @@ namespace VEPROMS
|
|||||||
private Dictionary<int, int> Old2NewItem;
|
private Dictionary<int, int> Old2NewItem;
|
||||||
private Dictionary<int, int> Old2NewContent;
|
private Dictionary<int, int> Old2NewContent;
|
||||||
private Dictionary<int, int> Old2NewLibDoc;
|
private Dictionary<int, int> Old2NewLibDoc;
|
||||||
|
private Dictionary<string, int> ExistingLibDocs; // B2019-035 better memory management
|
||||||
private XmlDocument PendingTransitions;
|
private XmlDocument PendingTransitions;
|
||||||
private RODb MyRODb = null;
|
private RODb MyRODb = null;
|
||||||
|
|
||||||
@ -3921,7 +3927,8 @@ namespace VEPROMS
|
|||||||
}
|
}
|
||||||
private void AddAnnotations(int itemID, XmlNode xn)
|
private void AddAnnotations(int itemID, XmlNode xn)
|
||||||
{
|
{
|
||||||
Item itm = Item.Get(itemID);
|
using (Item itm = Item.Get(itemID)) //B2019-035 better memory management
|
||||||
|
{
|
||||||
foreach (XmlNode nd in xn.SelectNodes("annotation"))
|
foreach (XmlNode nd in xn.SelectNodes("annotation"))
|
||||||
{
|
{
|
||||||
int typeid = int.Parse(nd.Attributes.GetNamedItem("typeid").InnerText);
|
int typeid = int.Parse(nd.Attributes.GetNamedItem("typeid").InnerText);
|
||||||
@ -3935,6 +3942,7 @@ namespace VEPROMS
|
|||||||
ann.Save();
|
ann.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void AddParts(XmlNode myNode, ItemInfo parentInfo)
|
private void AddParts(XmlNode myNode, ItemInfo parentInfo)
|
||||||
{
|
{
|
||||||
foreach (XmlNode xn in myNode.ChildNodes)
|
foreach (XmlNode xn in myNode.ChildNodes)
|
||||||
@ -4566,7 +4574,6 @@ namespace VEPROMS
|
|||||||
lblImportSection.Text = string.Format("{0} of {1} Sections", pbImportSection.Value.ToString(), pbImportSection.Maximum.ToString());
|
lblImportSection.Text = string.Format("{0} of {1} Sections", pbImportSection.Value.ToString(), pbImportSection.Maximum.ToString());
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
XmlNode xc = xn.SelectSingleNode("content");
|
XmlNode xc = xn.SelectSingleNode("content");
|
||||||
Section sect;
|
|
||||||
string number = xc.Attributes.GetNamedItem("number").InnerText;
|
string number = xc.Attributes.GetNamedItem("number").InnerText;
|
||||||
string text = xc.Attributes.GetNamedItem("text").InnerText;
|
string text = xc.Attributes.GetNamedItem("text").InnerText;
|
||||||
int sectiontype = int.Parse(xc.Attributes.GetNamedItem("type").InnerText);
|
int sectiontype = int.Parse(xc.Attributes.GetNamedItem("type").InnerText);
|
||||||
@ -4577,7 +4584,7 @@ namespace VEPROMS
|
|||||||
CheckForFloatingFoldout(contentid, config);
|
CheckForFloatingFoldout(contentid, config);
|
||||||
string userid = xc.Attributes.GetNamedItem("userid").InnerText;
|
string userid = xc.Attributes.GetNamedItem("userid").InnerText;
|
||||||
DateTime dts = DateTime.Parse(xc.Attributes.GetNamedItem("dts").InnerText);
|
DateTime dts = DateTime.Parse(xc.Attributes.GetNamedItem("dts").InnerText);
|
||||||
using (sect = Section.MakeSection(parentInfo, prevInfo, number, text, sectiontype))
|
using (Section sect = Section.MakeSection(parentInfo, prevInfo, number, text, sectiontype)) // B2019-035 better memory management
|
||||||
{
|
{
|
||||||
sect.DTS = dts;
|
sect.DTS = dts;
|
||||||
sect.UserID = userid;
|
sect.UserID = userid;
|
||||||
@ -4750,10 +4757,12 @@ namespace VEPROMS
|
|||||||
XmlNode nd = xc.SelectSingleNode("entry");
|
XmlNode nd = xc.SelectSingleNode("entry");
|
||||||
string userid = nd.Attributes.GetNamedItem("userid").InnerText;
|
string userid = nd.Attributes.GetNamedItem("userid").InnerText;
|
||||||
DateTime dts = DateTime.Parse(nd.Attributes.GetNamedItem("dts").InnerText);
|
DateTime dts = DateTime.Parse(nd.Attributes.GetNamedItem("dts").InnerText);
|
||||||
Document dd = AddDocument(nd.SelectSingleNode("document"));
|
using (Document dd = AddDocument(nd.SelectSingleNode("document"))) // B2019-035 better memory management
|
||||||
|
{
|
||||||
Entry ee = Entry.MakeEntry(content, dd, dts, userid);
|
Entry ee = Entry.MakeEntry(content, dd, dts, userid);
|
||||||
ee.Save();
|
ee.Save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// jsj 2016Feb16 - This appears to not be used
|
// jsj 2016Feb16 - This appears to not be used
|
||||||
//private void AddDocument(XmlReader xr, Dictionary<string, string> dic)
|
//private void AddDocument(XmlReader xr, Dictionary<string, string> dic)
|
||||||
//{
|
//{
|
||||||
@ -4772,37 +4781,58 @@ namespace VEPROMS
|
|||||||
// userid = dic["userid"];
|
// userid = dic["userid"];
|
||||||
// Entry ee = Entry.MakeEntry(content, dd, dts, userid);
|
// Entry ee = Entry.MakeEntry(content, dd, dts, userid);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
// B2019-035 This is called only once to get the existing library document info.
|
||||||
|
// when it was in the AddDocument() logic, it would use up (and not free up) memory each time
|
||||||
|
// a Word section was added during the import
|
||||||
|
private void GetExistingLibDocsList()
|
||||||
|
{
|
||||||
|
ExistingLibDocs = new Dictionary<string,int>();
|
||||||
|
using (DocumentInfoList dil = DocumentInfoList.GetLibraries(true))
|
||||||
|
{
|
||||||
|
foreach (DocumentInfo di in dil)
|
||||||
|
{
|
||||||
|
string keystr = di.LibTitle+"_"+di.DTS.ToString();
|
||||||
|
if (!ExistingLibDocs.ContainsKey(keystr))
|
||||||
|
ExistingLibDocs.Add(keystr, di.DocID);
|
||||||
|
di.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
private Document AddDocument(XmlNode xn)
|
private Document AddDocument(XmlNode xn)
|
||||||
{
|
{
|
||||||
Document d;
|
Document d=null;
|
||||||
int docid = int.Parse(xn.Attributes.GetNamedItem("docid").InnerText);
|
int docid = int.Parse(xn.Attributes.GetNamedItem("docid").InnerText);
|
||||||
if (Old2NewLibDoc.ContainsKey(docid))
|
if (Old2NewLibDoc.ContainsKey(docid))
|
||||||
{
|
{
|
||||||
docid = Old2NewLibDoc[docid];
|
docid = Old2NewLibDoc[docid];
|
||||||
d = Document.Get(docid);
|
d = Document.Get(docid);
|
||||||
}
|
}
|
||||||
else
|
else // see if it is in the existing database
|
||||||
{
|
{
|
||||||
string libtitle = xn.Attributes.GetNamedItem("libtitle").InnerText;
|
string libtitle = xn.Attributes.GetNamedItem("libtitle").InnerText;
|
||||||
DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").InnerText);
|
DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").InnerText);
|
||||||
if (libtitle != "")
|
if (libtitle != "")
|
||||||
{
|
{
|
||||||
DocumentInfoList dil = DocumentInfoList.GetLibraries(true);
|
// B2019-035 better memory management. Prior logic would eat up memory (and not free it).
|
||||||
foreach (DocumentInfo di in dil)
|
string libkey = libtitle + "_" + dts.ToString();
|
||||||
|
if (ExistingLibDocs.ContainsKey(libkey))
|
||||||
|
d = Document.Get(ExistingLibDocs[libkey]); // found library document in existing database
|
||||||
|
}
|
||||||
|
if (d == null) // not found in existing database, create it
|
||||||
{
|
{
|
||||||
if (di.LibTitle == libtitle && di.DTS == dts)
|
|
||||||
return di.Get(); // found library document in exiting database
|
|
||||||
}
|
|
||||||
}
|
|
||||||
byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText);
|
byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText);
|
||||||
string docascii = xn.Attributes.GetNamedItem("docascii").InnerText;
|
string docascii = xn.Attributes.GetNamedItem("docascii").InnerText;
|
||||||
string config = xn.Attributes.GetNamedItem("config").InnerText;
|
string config = xn.Attributes.GetNamedItem("config").InnerText;
|
||||||
string userid = xn.Attributes.GetNamedItem("userid").InnerText;
|
string userid = xn.Attributes.GetNamedItem("userid").InnerText;
|
||||||
string fileextension = xn.Attributes.GetNamedItem("fileextension").InnerText;
|
string fileextension = xn.Attributes.GetNamedItem("fileextension").InnerText;
|
||||||
|
if (libtitle != "") libtitle = libtitle + "_" + dts.ToString(); // if a lib document, append the date/time to the title incase there are duplicate titles
|
||||||
d = Document.MakeDocument(libtitle, doccontent, docascii, config, dts, userid, fileextension);
|
d = Document.MakeDocument(libtitle, doccontent, docascii, config, dts, userid, fileextension);
|
||||||
d.Save();
|
d.Save();
|
||||||
Old2NewLibDoc.Add(docid, d.DocID);
|
Old2NewLibDoc.Add(docid, d.DocID);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user