private void UpdateImageInDAM( string path, NexdoxResourceManager.ImageList updatedImages, string fileNameWithoutExtension, NexdoxResourceManager.ImageResource image) { NexdoxResourceManager.ImageResource imageResource = Statics.CentralResources.Images[image.Name]; imageResource.CheckOut(); imageResource.UploadImageFile(path + fileNameWithoutExtension + ".eps", false, false); imageResource.Save("", false); imageResource.CheckIn(); if (string.Compare(_appInfo["Region"], "Live", true) == 0) { imageResource.SetCurrentRegionVersion("Live", imageResource.VersionNo); imageResource.SetCurrentRegionVersion("Test", imageResource.VersionNo); } else if (string.Compare(_appInfo["Region"], "Test", true) == 0) { imageResource.SetCurrentRegionVersion("Test", imageResource.VersionNo); } //Always into Dev imageResource.SetCurrentRegionVersion("Dev", imageResource.VersionNo); updatedImages.Add(image); }
private void AddNewImageToDAM( string path, NexdoxResourceManager.ImageList updatedImages, string fileNameWithoutExtension) { Statics.CentralResources.DisconnectFromDam(); NexdoxResourceManager.ImageResource newResource = new NexdoxResourceManager.ImageResource(); newResource.ParentResourceManager = Statics.CentralResources; newResource.Name = fileNameWithoutExtension; newResource.UploadImageFile(path + fileNameWithoutExtension + ".eps", true, false); Statics.CentralResources.ConnectToDam(); newResource.Save("", true); newResource.CheckIn(); Statics.CentralResources.ResourceManagerAsset.CheckOut(); Statics.CentralResources.Images.Add(newResource); Statics.CentralResources.ResourceManagerAsset.Save("", false); Statics.CentralResources.ResourceManagerAsset.CheckIn(); if (string.Compare(_appInfo["Region"], "Live", true) == 0) { newResource.SetCurrentRegionVersion("Live", 0); newResource.SetCurrentRegionVersion("Test", 0); Statics.CentralResources.ResourceManagerAsset.SetCurrentRegionVersion( "Live", Statics.CentralResources.ResourceManagerAsset.VersionNo); Statics.CentralResources.ResourceManagerAsset.SetCurrentRegionVersion( "Test", Statics.CentralResources.ResourceManagerAsset.VersionNo); } else if (string.Compare(_appInfo["Region"], "Test", true) == 0) { newResource.SetCurrentRegionVersion("Test", 0); Statics.CentralResources.ResourceManagerAsset.SetCurrentRegionVersion( "Test", Statics.CentralResources.ResourceManagerAsset.VersionNo); } //Always into Dev newResource.SetCurrentRegionVersion("Dev", 0); Statics.CentralResources.ResourceManagerAsset.SetCurrentRegionVersion( "Dev", Statics.CentralResources.ResourceManagerAsset.VersionNo); updatedImages.Add(newResource); }
/////// <summary> /////// Checks to see if any of the XML files are over the size threshold and attempts to splirt them into smaller files /////// </summary> ////private void SplitHugeDataFiles() ////{ //// int hugeFileSplitThreshold = Int32.Parse(_appInfo["HugeFileSplitThreshold"]) * 1000; //// foreach (string inputFile in Directory.GetFiles(_appInfo.OutputPath, _appInfo["XmlFileMask"])) //// { //// FileInfo fi = new FileInfo(inputFile); //// if (fi.Length < hugeFileSplitThreshold) //// continue; //// var documents = XElement.Load(inputFile).Elements("Document_Data"); //// string docSubType = documents.First().Element("Doc").Element("Doc_Sub_Type").Value; //// if (!(new[] { "PER", "AGT" }).Contains(docSubType)) //// continue; //// int splitCount = (int)(fi.Length / hugeFileSplitThreshold) + 1; //// var consolidatedDocuments = documents.GroupBy(d => d.Element("Addressee").Element("Id").Value).OrderBy(g => g.Count()).Reverse(); //// int documentsPerChunk = (int)(documents.Count() / splitCount); //// int counter = 0; //// string mainPartOfInitialFileNames = Path.ChangeExtension(inputFile, null); //// XElement initialJobFile = XElement.Load(mainPartOfInitialFileNames + ".job"); //// List<XElement> tempDocuments = new List<XElement>(); //// foreach (var documentsForOneAddressee in consolidatedDocuments) //// { //// if (tempDocuments.Count + documentsForOneAddressee.Count() < documentsPerChunk) //// { //// tempDocuments.AddRange(documentsForOneAddressee); //// } //// else //// { //// if (tempDocuments.Count() == 0) // Is still too large, but we had no possibility to change this //// { //// tempDocuments = documentsForOneAddressee.ToList(); //// // Process tempDocuments and clear tempDocuments //// SaveSmallerXMLChunks(tempDocuments, initialJobFile, mainPartOfInitialFileNames, counter); //// tempDocuments.Clear(); //// } //// else //// { //// // Process tempDocuments, and tail should be saved //// SaveSmallerXMLChunks(tempDocuments, initialJobFile, mainPartOfInitialFileNames, counter); //// tempDocuments = documentsForOneAddressee.ToList(); //// } //// counter++; //// } //// } //// SaveSmallerXMLChunks(tempDocuments, initialJobFile, mainPartOfInitialFileNames, counter); //// File.Move(mainPartOfInitialFileNames + ".xml", mainPartOfInitialFileNames + ".xml.huge"); //// File.Move(mainPartOfInitialFileNames + ".job", mainPartOfInitialFileNames + ".job.huge"); //// } ////} /////// <summary> /////// saves chunks of xml as smaller input files /////// </summary> /////// <param name="documents">List of documents that makeup our new file</param> /////// <param name="initialJobFile">The initial XML file</param> /////// <param name="mainPartOfInitialFileNames">Filename</param> /////// <param name="counter">Current File Chunk Number</param> ////private void SaveSmallerXMLChunks(List<XElement> documents, XElement initialJobFile, string mainPartOfInitialFileNames, int counter) ////{ //// string newMainpartOfName = string.Format("{0}.{1:d3}", mainPartOfInitialFileNames, counter); //// XElement newDocumentSet = new XElement("Document_Pack", documents); //// initialJobFile.Element("Rec_Total").Element("count").Value = documents.Count().ToString(); //// newDocumentSet.Save(newMainpartOfName + ".xml"); //// initialJobFile.Save(newMainpartOfName + ".job"); ////} /// <summary> /// Updates any new PDFs supplied into the shared resources folder /// </summary> private void ProcessInserts(string pdfFile) { //Get filename of the insert string pdfFileName = Path.GetFileName(pdfFile); string path = pdfFile.Replace(pdfFileName, ""); NexdoxMessaging.SendMessage(" Processing pdf file " + pdfFileName + "...", true, this); try { string pdfInsert = pdfFile; string epsInsert = pdfInsert.Substring(0, pdfInsert.LastIndexOf(".")); System.Diagnostics.Process process; ProcessStartInfo processInfo = new ProcessStartInfo( _appInfo["PDFConversionAppPath"] + @"\pdf2vec.exe", "\"" + pdfInsert + "\" \"" + epsInsert + ".eps\""); processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; processInfo.RedirectStandardOutput = true; process = System.Diagnostics.Process.Start(processInfo); process.WaitForExit(10000); //10 seconds? using (StreamWriter writer = new StreamWriter(_appInfo.OutputPath + "test.txt")) { string line; while ((line = process.StandardOutput.ReadLine()) != null) { writer.WriteLine(line); } } int exitCode = process.ExitCode; process.Close(); } catch (Exception e) { NexdoxMessaging.SendMessage("ERROR - When converting eps file - " + e.Message, false, null); } //Ok, now we need to make sure that there is no showpage. Otherwise our output will create //an additional page. blast! NexdoxResourceManager.ImageList allImages = Statics.CentralResources.Images.FindAllMatchingNames(Path.GetFileNameWithoutExtension(pdfFile)); NexdoxResourceManager.ImageList updatedImages = new NexdoxResourceManager.ImageList(); foreach (string file in Directory.GetFiles(path, Path.GetFileNameWithoutExtension(pdfFile) + "*.eps")) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); string newFileNameWithoutExtension = fileNameWithoutExtension.Replace("-", "_").Replace(" ", "_"); File.Move(path + fileNameWithoutExtension + ".eps", path + newFileNameWithoutExtension + ".temp"); using (StreamWriter writer = new StreamWriter(path + newFileNameWithoutExtension + ".eps", false)) { using (StreamReader reader = new StreamReader(path + newFileNameWithoutExtension + ".temp")) { string line; while ((line = reader.ReadLine()) != null) { if (line.Contains("showpage") || line.Contains("verydoc")) { continue; } writer.WriteLine(line); } } } NexdoxResourceManager.ImageList images = Statics.CentralResources.Images.FindAllMatchingNames(newFileNameWithoutExtension); if (images.Count > 1) { bool imageUploaded = false; foreach (NexdoxResourceManager.ImageResource image in images) { if (string.Compare(image.BaseName, newFileNameWithoutExtension, true) == 0) { UpdateImageInDAM(path, updatedImages, newFileNameWithoutExtension, image); imageUploaded = true; } } if (!imageUploaded) { AddNewImageToDAM(path, updatedImages, newFileNameWithoutExtension); } } else if (images.Count == 0) { AddNewImageToDAM(path, updatedImages, newFileNameWithoutExtension); } else { UpdateImageInDAM(path, updatedImages, newFileNameWithoutExtension, images[0]); } File.Delete(newFileNameWithoutExtension + ".temp"); } string errMsg = String.Empty; // DV - I'm not sure why this bit is here, it looks to duplicate what happens above, seemingly just // here to catch any issues //chekout RMC foreach (NexdoxResourceManager.ImageResource image in allImages) { if (!updatedImages.Contains(image)) { NexdoxResourceManager.CheckOutResult result = image.ParentResourceManager.ResourceManagerAsset.CheckOut(); if (result != NexdoxResourceManager.CheckOutResult.Success) { throw NexdoxMessaging.Exception( "Error checking out parent resource: " + image.ParentResourceManager.ResourceManagerAsset.Name + ". " + result.ToString(), this); } result = image.CheckOut(); if (result != NexdoxResourceManager.CheckOutResult.Success) { throw NexdoxMessaging.Exception( "Error checking out image resource: " + image.Name + ". " + result.ToString(), this); } image.Deleted = true; image.Save("", false); image.CheckIn(); image.ParentResourceManager.ResourceManagerAsset.Save("", false); image.ParentResourceManager.ResourceManagerAsset.CheckIn(); if (string.Compare(_appInfo["Region"], "Live", true) == 0) { image.SetCurrentRegionVersion("Live", image.VersionNo); image.SetCurrentRegionVersion("Test", image.VersionNo); image.ParentResourceManager.ResourceManagerAsset.SetCurrentRegionVersion( "Live", image.ParentResourceManager.ResourceManagerAsset.VersionNo); image.ParentResourceManager.ResourceManagerAsset.SetCurrentRegionVersion( "Test", image.ParentResourceManager.ResourceManagerAsset.VersionNo); } else if (string.Compare(_appInfo["Region"], "Test", true) == 0) { image.SetCurrentRegionVersion("Test", image.VersionNo); image.ParentResourceManager.ResourceManagerAsset.SetCurrentRegionVersion( "Test", image.ParentResourceManager.ResourceManagerAsset.VersionNo); } //Always into Dev image.SetCurrentRegionVersion("Dev", image.VersionNo); image.ParentResourceManager.ResourceManagerAsset.SetCurrentRegionVersion( "Dev", image.ParentResourceManager.ResourceManagerAsset.VersionNo); } } }