Compare commits

..

2 Commits

2 changed files with 223 additions and 210 deletions

View File

@@ -111,10 +111,6 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\3rdPartyLibraries\DotNetBar\DotNetBar4.6Build\DevComponents.DotNetBar2.dll</HintPath> <HintPath>..\..\..\..\3rdPartyLibraries\DotNetBar\DotNetBar4.6Build\DevComponents.DotNetBar2.dll</HintPath>
</Reference> </Reference>
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\3rdPartyLibraries\Ionic\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="Itenso.Rtf.Interpreter"> <Reference Include="Itenso.Rtf.Interpreter">
<HintPath>..\..\..\..\3rdPartyLibraries\RtfConverter\bin\Debug\Itenso.Rtf.Interpreter.dll</HintPath> <HintPath>..\..\..\..\3rdPartyLibraries\RtfConverter\bin\Debug\Itenso.Rtf.Interpreter.dll</HintPath>
</Reference> </Reference>
@@ -133,6 +129,8 @@
<Reference Include="System.Deployment" /> <Reference Include="System.Deployment" />
<Reference Include="System.Design" /> <Reference Include="System.Design" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Runtime.Remoting" /> <Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Web" /> <Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" /> <Reference Include="System.Web.Extensions" />

View File

@@ -7,7 +7,7 @@ using Volian.Controls.Library;
using Volian.Base.Library; using Volian.Base.Library;
using System.Xml; using System.Xml;
using System.IO; using System.IO;
using Ionic.Zip; using System.IO.Compression;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using JR.Utils.GUI.Forms; using JR.Utils.GUI.Forms;
using System.Linq; using System.Linq;
@@ -193,8 +193,7 @@ namespace VEPROMS
txtExport.Text = sfd.FileName; txtExport.Text = sfd.FileName;
if (File.Exists(txtExport.Text)) if (File.Exists(txtExport.Text))
File.Delete(txtExport.Text); File.Delete(txtExport.Text);
MyExpxZipFile = new ZipFile(txtExport.Text, Encoding.UTF8); MyExpZipFileName = txtExport.Text;
MyExpxZipFile.Save();
} }
} }
else if (MyProcedure != null) else if (MyProcedure != null)
@@ -211,8 +210,8 @@ namespace VEPROMS
else else
lblExportStatus.Text = "Awaiting Export File Name:"; lblExportStatus.Text = "Awaiting Export File Name:";
} }
private ZipFile MyExpxZipFile = null; private string MyExpZipFileName = null;
private ZipFile MyImpxZipFile = null; private string MyImpZipFileName = null;
private DateTime MyStart; private DateTime MyStart;
private bool successfullExport = true; private bool successfullExport = true;
@@ -891,11 +890,17 @@ namespace VEPROMS
return true; return true;
} }
private bool LoadImportDataDocument() private bool LoadImportDataDocument()
{
using (FileStream zipToOpen = new FileStream(MyExpZipFileName, FileMode.OpenOrCreate))
{
using (ZipArchive MyExpxZipFile = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{ {
floatFoldout = new Dictionary<int, int>(); floatFoldout = new Dictionary<int, int>();
ZipEntry ze = MyExpxZipFile[0]; ZipArchiveEntry ze = MyExpxZipFile.Entries[0];
string fn = PEIPath + @"\" + ze.FileName; if (!Directory.Exists(Path.Combine(PEIPath, "folder")))
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently); Directory.CreateDirectory(Path.Combine(PEIPath, "folder"));
string fn = Path.Combine(PEIPath, "folder", ze.Name);
ze.ExtractToFile(fn, true);
XmlDocument xd = new XmlDocument(); XmlDocument xd = new XmlDocument();
xd.Load(fn); xd.Load(fn);
bool didImp = LoadFormats(xd, "folder/formats/format"); bool didImp = LoadFormats(xd, "folder/formats/format");
@@ -951,11 +956,13 @@ namespace VEPROMS
ProcedureInfo pi = null; ProcedureInfo pi = null;
pbImportProcedure.Value = 0; pbImportProcedure.Value = 0;
pbImportProcedure.Maximum = MyExpxZipFile.Entries.Count - 1; pbImportProcedure.Maximum = MyExpxZipFile.Entries.Count - 1;
if (!Directory.Exists(Path.Combine(PEIPath, "procedures")))
Directory.CreateDirectory(Path.Combine(PEIPath, "procedures"));
for (int i = 1; i < MyExpxZipFile.Entries.Count; i++) for (int i = 1; i < MyExpxZipFile.Entries.Count; i++)
{ {
ze = MyExpxZipFile[i]; ze = MyExpxZipFile.Entries[i];
fn = PEIPath + @"\" + ze.FileName; fn = Path.Combine(PEIPath, "procedures", ze.Name);
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently); ze.ExtractToFile(fn, true);
xd = new XmlDocument(); xd = new XmlDocument();
xd.Load(fn); xd.Load(fn);
pi = AddProcedure(xd.DocumentElement, dvi, pi); pi = AddProcedure(xd.DocumentElement, dvi, pi);
@@ -971,6 +978,8 @@ namespace VEPROMS
SaveTransitionAndItemContentIDs(); SaveTransitionAndItemContentIDs();
return true; return true;
} }
}
}
private void FixSectionStart(ProcedureInfo pi) private void FixSectionStart(ProcedureInfo pi)
{ {
Content c = Content.Get(pi.MyContent.ContentID); Content c = Content.Get(pi.MyContent.ContentID);
@@ -1253,6 +1262,10 @@ namespace VEPROMS
// This will create and save the ItemIDs (old and new), ContentIDs (old andnew), library document IDs (old and new), and pending transitions each in their own xml file // This will create and save the ItemIDs (old and new), ContentIDs (old andnew), library document IDs (old and new), and pending transitions each in their own xml file
// the xml files are then added (or replaced) in the .impx file. // the xml files are then added (or replaced) in the .impx file.
private void SaveTransitionAndItemContentIDs() private void SaveTransitionAndItemContentIDs()
{
using (FileStream zipToOpen = new FileStream(MyImpZipFileName, FileMode.OpenOrCreate))
{
using (ZipArchive MyImpxZipFile = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{ {
XmlDocument xd = new XmlDocument(); XmlDocument xd = new XmlDocument();
XmlElement xe = xd.CreateElement("items"); XmlElement xe = xd.CreateElement("items");
@@ -1266,11 +1279,9 @@ namespace VEPROMS
xd.DocumentElement.AppendChild(xe); xd.DocumentElement.AppendChild(xe);
} }
xd.Save(fn); xd.Save(fn);
ZipEntry ze = MyImpxZipFile["items.xml"]; ZipArchiveEntry ze = MyImpxZipFile.GetEntry("items.xml");
MyImpxZipFile.RemoveEntry(ze); ze.Delete();
MyImpxZipFile.Save(); _ = MyImpxZipFile.CreateEntryFromFile(fn, Path.GetFileName(fn));
MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
xd = new XmlDocument(); xd = new XmlDocument();
xe = xd.CreateElement("contents"); xe = xd.CreateElement("contents");
@@ -1284,11 +1295,9 @@ namespace VEPROMS
xd.DocumentElement.AppendChild(xe); xd.DocumentElement.AppendChild(xe);
} }
xd.Save(fn); xd.Save(fn);
ze = MyImpxZipFile["contents.xml"]; ze = MyImpxZipFile.GetEntry("contents.xml");
MyImpxZipFile.RemoveEntry(ze); ze.Delete();
MyImpxZipFile.Save(); _ = MyImpxZipFile.CreateEntryFromFile(fn, Path.GetFileName(fn));
MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
xd = new XmlDocument(); xd = new XmlDocument();
xe = xd.CreateElement("transitions"); xe = xd.CreateElement("transitions");
@@ -1303,36 +1312,36 @@ namespace VEPROMS
} }
} }
xd.Save(fn); xd.Save(fn);
ze = MyImpxZipFile["transitions.xml"]; ze = MyImpxZipFile.GetEntry("transitions.xml");
MyImpxZipFile.RemoveEntry(ze); ze.Delete();
MyImpxZipFile.Save(); _ = MyImpxZipFile.CreateEntryFromFile(fn, Path.GetFileName(fn));
MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
} }
}
}
// This is called only when we are importing an entire folder and there is a .impx file (a zip file) // This is called only when we are importing an entire folder and there is a .impx file (a zip file)
// the name of the .impx file is based on the folder name containing the export file being imported // the name of the .impx file is based on the folder name containing the export file being imported
// This will read in the saved ItemIDs (old and new), ContentIDs (old andnew), library document IDs (old and new), and pending transitions // This will read in the saved ItemIDs (old and new), ContentIDs (old andnew), library document IDs (old and new), and pending transitions
private void ReadTransitionAndItemContentIDs() private void ReadTransitionAndItemContentIDs(ZipArchive MyImpxZipFile)
{ {
ZipEntry ze = MyImpxZipFile["items.xml"]; ZipArchiveEntry ze = MyImpxZipFile.GetEntry("items.xml");
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
string fn = PEIPath + @"\items.xml"; string fn = PEIPath + @"\items.xml";
ze.ExtractToFile(fn, true);
XmlDocument xd = new XmlDocument(); XmlDocument xd = new XmlDocument();
xd.Load(fn); xd.Load(fn);
// B2016-176, B2016-197 Transitions were no always properly resolved - don't load in the old item ids // B2016-176, B2016-197 Transitions were no always properly resolved - don't load in the old item ids
File.Delete(fn); File.Delete(fn);
ze = MyImpxZipFile["contents.xml"]; ze = MyImpxZipFile.GetEntry("contents.xml");
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\contents.xml"; fn = PEIPath + @"\contents.xml";
ze.ExtractToFile(fn, true);
xd = new XmlDocument(); xd = new XmlDocument();
xd.Load(fn); xd.Load(fn);
// B2016-176, B2016-197 Transitions were no always properly resolved - don't load in the old content ids // B2016-176, B2016-197 Transitions were no always properly resolved - don't load in the old content ids
File.Delete(fn); File.Delete(fn);
ze = MyImpxZipFile["libdocs.xml"]; ze = MyImpxZipFile.GetEntry("libdocs.xml");
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\libdocs.xml"; fn = PEIPath + @"\libdocs.xml";
ze.ExtractToFile(fn, true);
xd = new XmlDocument(); xd = new XmlDocument();
xd.Load(fn); xd.Load(fn);
XmlNodeList nl = xd.SelectNodes("//libdoc"); XmlNodeList nl = xd.SelectNodes("//libdoc");
@@ -1344,9 +1353,9 @@ namespace VEPROMS
Old2NewLibDoc.Add(oldid, newid); Old2NewLibDoc.Add(oldid, newid);
} }
File.Delete(fn); File.Delete(fn);
ze = MyImpxZipFile["transitions.xml"]; ze = MyImpxZipFile.GetEntry("transitions.xml");
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\transitions.xml"; fn = PEIPath + @"\transitions.xml";
ze.ExtractToFile(fn, true);
PendingTransitions.Load(fn); PendingTransitions.Load(fn);
File.Delete(fn); File.Delete(fn);
} }
@@ -1374,25 +1383,26 @@ namespace VEPROMS
else else
dn = fi.Name.Substring(0, fi.Name.IndexOf(".")); dn = fi.Name.Substring(0, fi.Name.IndexOf("."));
txtImport.Text = ofd.FileName; txtImport.Text = ofd.FileName;
ReadOptions ro = new ReadOptions(); MyExpZipFileName = txtImport.Text;
ro.Encoding = Encoding.UTF8;
MyExpxZipFile = ZipFile.Read(txtImport.Text, ro);
string fn = string.Format(@"{0}\{1}.impx", PEIPath, dn); string fn = string.Format(@"{0}\{1}.impx", PEIPath, dn);
MyImpZipFileName = fn;
if (File.Exists(fn)) if (File.Exists(fn))
{ {
MyImpxZipFile = ZipFile.Read(fn, ro); using (ZipArchive MyImpxZipFile = ZipFile.OpenRead(fn))
ReadTransitionAndItemContentIDs(); ReadTransitionAndItemContentIDs(MyImpxZipFile);
} }
else else
{ {
MyImpxZipFile = new ZipFile(fn, Encoding.UTF8); using (FileStream zipToOpen = new FileStream(fn, FileMode.OpenOrCreate))
{
using (ZipArchive MyImpxZipFile = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{
//transitions //transitions
XmlElement xe = PendingTransitions.CreateElement("transitions"); XmlElement xe = PendingTransitions.CreateElement("transitions");
PendingTransitions.AppendChild(xe); PendingTransitions.AppendChild(xe);
fn = PEIPath + @"\transitions.xml"; fn = PEIPath + @"\transitions.xml";
PendingTransitions.Save(fn); PendingTransitions.Save(fn);
MyImpxZipFile.AddFile(fn, ""); _ = MyImpxZipFile.CreateEntryFromFile(fn, Path.GetFileName(fn));
MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
//itemids //itemids
XmlDocument xd = new XmlDocument(); XmlDocument xd = new XmlDocument();
@@ -1400,8 +1410,7 @@ namespace VEPROMS
xd.AppendChild(xe); xd.AppendChild(xe);
fn = PEIPath + @"\items.xml"; fn = PEIPath + @"\items.xml";
xd.Save(fn); xd.Save(fn);
MyImpxZipFile.AddFile(fn, ""); _ = MyImpxZipFile.CreateEntryFromFile(fn, Path.GetFileName(fn));
MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
//contentids //contentids
xd = new XmlDocument(); xd = new XmlDocument();
@@ -1409,8 +1418,7 @@ namespace VEPROMS
xd.AppendChild(xe); xd.AppendChild(xe);
fn = PEIPath + @"\contents.xml"; fn = PEIPath + @"\contents.xml";
xd.Save(fn); xd.Save(fn);
MyImpxZipFile.AddFile(fn, ""); _ = MyImpxZipFile.CreateEntryFromFile(fn, Path.GetFileName(fn));
MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
//libdocids //libdocids
xd = new XmlDocument(); xd = new XmlDocument();
@@ -1418,11 +1426,12 @@ namespace VEPROMS
xd.AppendChild(xe); xd.AppendChild(xe);
fn = PEIPath + @"\libdocs.xml"; fn = PEIPath + @"\libdocs.xml";
xd.Save(fn); xd.Save(fn);
MyImpxZipFile.AddFile(fn, ""); _ = MyImpxZipFile.CreateEntryFromFile(fn, Path.GetFileName(fn));
MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
} }
} }
}
}
if (MyDocVersion != null) if (MyDocVersion != null)
{ {
ofd.Filter = "PROMS Procedure Export Files|*.pxml"; ofd.Filter = "PROMS Procedure Export Files|*.pxml";
@@ -1595,8 +1604,11 @@ namespace VEPROMS
ExportAssociation(xe, ai, "association"); ExportAssociation(xe, ai, "association");
string fn = PEIPath + @"\folder.xml"; string fn = PEIPath + @"\folder.xml";
xn.OwnerDocument.Save(fn); xn.OwnerDocument.Save(fn);
MyExpxZipFile.AddFile(fn, "folder"); using (FileStream zipToOpen = new FileStream(MyExpZipFileName, FileMode.OpenOrCreate))
MyExpxZipFile.Save(); {
using (ZipArchive MyExpxZipFile = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{
_ = MyExpxZipFile.CreateEntryFromFile(fn, $"folder/{Path.GetFileName(fn)}");
File.Delete(fn); File.Delete(fn);
//here //here
lblExportStatus.Text = "Exporting Procedures..."; lblExportStatus.Text = "Exporting Procedures...";
@@ -1612,13 +1624,14 @@ namespace VEPROMS
ExportItem(xd, ii, "procedure"); ExportItem(xd, ii, "procedure");
fn = string.Format(@"{0}\proc{1}.xml", PEIPath, pbExportProcedure.Value.ToString().PadLeft(4, '0')); fn = string.Format(@"{0}\proc{1}.xml", PEIPath, pbExportProcedure.Value.ToString().PadLeft(4, '0'));
xd.Save(fn); xd.Save(fn);
MyExpxZipFile.AddFile(fn, "procedures"); _ = MyExpxZipFile.CreateEntryFromFile(fn, $"procedures/{Path.GetFileName(fn)}");
MyExpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
xd = null; xd = null;
} }
} }
} }
}
}
private void ExportAssociation(XmlElement xn, AssociationInfo ai, string nodename) private void ExportAssociation(XmlElement xn, AssociationInfo ai, string nodename)
{ {
/* /*
@@ -1839,12 +1852,14 @@ namespace VEPROMS
//and handled/overridden in dlgExportEP.cs //and handled/overridden in dlgExportEP.cs
} }
protected virtual void SetROLocation(ref XmlElement xindivid, ROFSTLookup.rochild roc, RODbInfo rodb, bool isMulti) protected virtual void SetEPEnhancedDocLinks(ref XmlElement xe, ItemInfo ii)
{ {
//do nothing - this will be for Electronic procedures only //do nothing - this will be for Electronic procedures only
//and handled/overridden in dlgExportEP.cs //and handled/overridden in dlgExportEP.cs
} }
protected virtual void SetEPEnhancedDocLinks(ref XmlElement xe, ItemInfo ii)
protected virtual void SetROLocation(ref XmlElement xindivid, ROFSTLookup.rochild roc, RODbInfo rodb, bool isMulti)
{ {
//do nothing - this will be for Electronic procedures only //do nothing - this will be for Electronic procedures only
//and handled/overridden in dlgExportEP.cs //and handled/overridden in dlgExportEP.cs