public static void SetOutputDirectory(string dirName, string configFile) { try { UtilityMethods.CreateDirectory(dirName); } catch (ConverterException exception) { // unable to create directory string errMsg = UtilityMethods.Format(CurConResource.OutputDirCreationFailed, exception.Message, configFile); throw new ConverterException(errMsg); } OutputDirectory = dirName; }
public static void SetOutputDirectory(string dirName, string configFile) { try { UtilityMethods.CreateDirectory(dirName); } catch (ConverterException exception) { // unable to create directory string errMsg = UtilityMethods.Format(CQResource.CQ_OUTDIR_CREATION_FAILED, dirName, configFile, exception.Message); throw new ConverterException(errMsg); } OutputDirectory = dirName; }
public override bool DoWork() { Error = string.Empty; Started = true; if (CancelToken.IsCancellationRequested) { return(false); } var targetDirectory = Path.Combine(Path.GetDirectoryName(SourceFile), "done"); UtilityMethods.CreateDirectory(targetDirectory); if (!_initialized && !Initialize(targetDirectory)) { if (string.IsNullOrEmpty(Error)) { Error = $"Could not fully process video file: {SourceFile}"; } return(false); } using (var encoder = new FfmpegEncoder(this)) { encoder.StartEncoding(CancelToken.Token); encoder.AwaitCompletion(); if (CancelToken.IsCancellationRequested) { Task.Delay(300).Wait(); FileUtils.SafeDeleteFile(TargetFile); } if (!string.IsNullOrEmpty(encoder.Error)) { Error = $"ffmpeg Error: {encoder.Error}"; } } return(string.IsNullOrEmpty(Error) && !CancelToken.IsCancellationRequested); }
public override bool DoWork() { Started = true; UtilityMethods.CreateDirectory(_assemblyLineWorkingDirectory); foreach (var task in _steps) { if (!DoTask(task)) { return(false); } FileProvider = task; } var finalFile = GetFilePath(); _ = FileUtils.MoveFileToFolder(finalFile, _assemblyLineRootDirectory, out finalFile); _ = FileUtils.RenameFile(finalFile, _assemblyLineId, out finalFile); UtilityMethods.SafeDeleteDirectory(_assemblyLineWorkingDirectory); FileProvider = new FilePathProvider(finalFile); return(true); }
} // end of ProcessHistory() /// <summary> /// Processes the attachments for current record /// </summary> private void ProcessAttachments() { int noOfAttachments = 0; try { OAdAttachmentFields allAttachments = CQWrapper.GetAttachmentFields(m_CQEntity); StringCollection filesAttached = new StringCollection(); int attachmentsIndex = 0; for (attachmentsIndex = 0; attachmentsIndex < CQWrapper.AttachmentsFieldsCount(allAttachments); attachmentsIndex++) { object ob = (object)attachmentsIndex; OAdAttachmentField attachmentFld = CQWrapper.AttachmentsFieldsItem(allAttachments, ref ob); // process all attachments OAdAttachments attachments = CQWrapper.GetAttachments(attachmentFld); int attachmentIndex; for (attachmentIndex = 0; attachmentIndex < CQWrapper.AttachmentsCount(attachments); attachmentIndex++) { // there are some attachments // create the dir for this bug dbid only if string dirName = Path.Combine(CQConstants.AttachmentsDir, m_dbid.ToString()); if (attachmentIndex == 0) // for the first time { // check if dir with curr dbid exist if (Directory.Exists(dirName)) { // if the dir exists, clean the contents // as it is the system created dir Logger.Write(LogSource.CQ, TraceLevel.Warning, "Removing folder {0} recursively for attachments of entity {1}", m_dbid, m_entityName); try { Directory.Delete(dirName, true); } catch (IOException ioe) { Logger.Write(LogSource.CQ, TraceLevel.Warning, "Failed to delete folder {0} containing attachments for work item {1}", dirName, SourceId); Logger.WriteException(LogSource.CQ, ioe); } catch (UnauthorizedAccessException uae) { Logger.Write(LogSource.CQ, TraceLevel.Warning, "Permission denied for deleting folder {0} containing attachments for work item {1}", dirName, SourceId); Logger.WriteException(LogSource.CQ, uae); } } Logger.Write(LogSource.CQ, TraceLevel.Info, "Creating folder {0} for attachments of entity {1}", m_dbid, m_entityName); UtilityMethods.CreateDirectory(dirName); } // for every attachments attachment create a separate // sub dir as (attchmentsIndex+attchmentIndex) string currAttachmentDir = Path.Combine(dirName, attachmentsIndex.ToString(CultureInfo.InvariantCulture)); currAttachmentDir = Path.Combine(currAttachmentDir, attachmentIndex.ToString(CultureInfo.InvariantCulture)); // there cannot be any dir existing as we already cleaned up Logger.Write(LogSource.CQ, TraceLevel.Info, "Creating folder {0} for attachment {1} of entity {2}", currAttachmentDir, attachmentIndex + 1, m_entityName); UtilityMethods.CreateDirectory(currAttachmentDir); object obIndex = (object)attachmentIndex; OAdAttachment aAttachment = CQWrapper.AttachmentsItem(attachments, ref obIndex); noOfAttachments++; string attachFileName; string attachDescription; CQWrapper.GetAttachmentFileNameAndDescription(aAttachment, out attachFileName, out attachDescription); Logger.Write(LogSource.CQ, TraceLevel.Verbose, "Adding attachment"); Logger.Write(LogSource.CQ, TraceLevel.Verbose, "\tFile Name : {0}", attachFileName); Logger.Write(LogSource.CQ, TraceLevel.Verbose, "\tDescription : {0}", attachDescription); // save the attachment as file on disk string tempfile = Path.Combine(currAttachmentDir, attachFileName); CQWrapper.LoadAttachment(aAttachment, tempfile); m_imWorkItem.Attachments.Add(new InMemoryAttachment(tempfile, attachDescription, false)); filesAttached.Add(attachFileName); #if DEBUG CommonConstants.NoOfAttachments++; CommonConstants.TotalAttachmentSize += CQWrapper.AttachmentFileSize(aAttachment); #endif } // end of processing attachment } // end of processing attachments } finally { } } // end of GetAttachments
/// <summary> /// This method takes the stylesheet filename as input /// </summary> /// <param name="styleSheetFileName"></param> public void EndReporting(bool generateSupportFiles) { Logger.EnteredMethod(LogSource.Common); if (m_writer == null) { Logger.Write(LogSource.Common, TraceLevel.Error, "The method EndReporting called without calling StartReporting"); return; } // Check if the file is already generated before. if (!triedOnce) { if (summaryField.Status == null) { summaryField.Status = CommonResource.ProcessIncomplete; } DateTime endDateTime = DateTime.Now; summaryField.EndTime = endDateTime.ToString(CultureInfo.CurrentCulture); TimeSpan totalTime = endDateTime.Subtract(m_startDateTime); //Do not report milliseconds int days = totalTime.Days; int hours = totalTime.Hours; int mins = totalTime.Minutes; int seconds = totalTime.Seconds; totalTime = new TimeSpan(days, hours, mins, seconds); summaryField.TotalTime = totalTime.ToString(); // I dont know if this will be an issue for glob/loc. I dont think so. this.RunBy = Environment.UserDomainName + Path.DirectorySeparatorChar + Environment.UserName; try { GenerateXml(m_writer, generateSupportFiles); triedOnce = true; } finally { m_writer.Close(); if (generateSupportFiles) { //Create the directory first; FileInfo info = new FileInfo(m_fileName); string parentPath = info.Directory.FullName; string outputDirName = Path.Combine(parentPath, Report.SupportFileDirectory); UtilityMethods.CreateDirectory(outputDirName); //Then copy the files foreach (string str in Report.SupportFiles) { UtilityMethods.CopyFromAssemblyToDestination(str, Path.Combine(outputDirName, str)); } } // If the previous attempt to write failed // Write the report into the new backup file // Any exceptions here would be propagated to the caller!! if (!triedOnce) { triedOnce = true; m_backupFileName = Path.GetTempPath() + "MigrationReport.xml"; // The name of the file is not yet finalized in spec. m_fileName = m_backupFileName; // Set the file name to the new name GenerateXml(new StreamWriter(m_backupFileName), generateSupportFiles); } } } #if DEBUG //only in debug mode validate the generated xml file against the reportschema xsd file. try { UtilityMethods.ValidateXmlFile(m_fileName, m_xsdFileName); } catch (ConverterException e) { Logger.WriteException(LogSource.Common, e); UtilityMethods.DisplayError("The generated Report file does not comply with the xsd file"); } #endif Logger.ExitingMethod(LogSource.Common); }