// 出力ファイル名を取得 public string GetOutputPath(int jk, string defaultName = "") { string outputPath = string.IsNullOrEmpty(OutputFileName) ? "" : OutputFileName.EndsWith(@"\") ? OutputFileName : Path.GetDirectoryName(OutputFileName); string outputName = Path.GetFileName(OutputFileName); if (Directory.Exists(OutputFileName)) { outputPath = OutputFileName; outputName = ""; } if (string.IsNullOrEmpty(outputName)) { outputName = defaultName; } if (string.IsNullOrEmpty(outputPath)) { outputPath = ""; } else if (!outputPath.EndsWith(@"\")) { outputPath += @"\"; } if (CreateDirectory) { outputPath += $"jk{jk}" + @"\"; } return(outputPath + outputName); }
private void ValidateExtractTrackingDataParameters() { if (string.IsNullOrWhiteSpace(OutputFileName)) { throw new ApplicationException("Output file name is empty or null. Please fill output file name."); } if (!OutputFileName.ToLower().EndsWith(".csv") && !OutputFileName.ToLower().EndsWith(".zip")) { throw new ApplicationException("Invalid file extension. Only csv or zip allowed."); } }
/// <summary> /// Application entry point /// </summary> /// <param name="args">Command line arguments</param> private static void Main(string[] args) { // Parse the provided arguments if (args.Length > 0) { ParseArguments(args); } WriteOutput(); var appVersion = Assembly.GetExecutingAssembly().GetName().Version; WriteOutput("pfSense Backup Tool v{0}.{1}.{2} by Koen Zomers", new object[] { appVersion.Major, appVersion.Minor, appVersion.Build }); WriteOutput(); // Check if parameters have been provided if (args.Length == 0) { // No arguments have been provided WriteOutput("ERROR: No arguments provided"); WriteOutput(); DisplayHelp(); Environment.Exit(1); } // Make sure the provided arguments have been provided if (string.IsNullOrEmpty(PfSenseServerDetails.Username) || string.IsNullOrEmpty(PfSenseServerDetails.Password) || string.IsNullOrEmpty(PfSenseServerDetails.ServerAddress)) { WriteOutput("ERROR: Not all required options have been provided"); DisplayHelp(); Environment.Exit(1); } // Check if the output filename parsed resulted in an error if (!string.IsNullOrEmpty(OutputFileName) && OutputFileName.Equals("ERROR", StringComparison.InvariantCultureIgnoreCase)) { WriteOutput("ERROR: Provided output filename contains illegal characters"); Environment.Exit(1); } // Retrieve the backup file from pfSense RetrieveBackupFile(); Environment.Exit(0); }
public override int GetHashCode() { unchecked { int hashCode = (Header.GetHashCode()); hashCode = (hashCode * 397) ^ (DicomFilePath != null ? DicomFilePath.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OutputFileName != null ? OutputFileName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (WasAnonymised.GetHashCode()); hashCode = (hashCode * 397) ^ (IsIdentifiable.GetHashCode()); hashCode = (hashCode * 397) ^ (ExtractedFileStatus.GetHashCode()); hashCode = (hashCode * 397) ^ (StatusMessage.GetHashCode()); return(hashCode); } }
private void ValidateExtractDataExtensionParameters() { if (string.IsNullOrWhiteSpace(DECustomerKey)) { throw new ApplicationException("Data extension customer key is empty or null. Please fill data extension customer key."); } if (string.IsNullOrWhiteSpace(OutputFileName)) { throw new ApplicationException("Output file name is empty or null. Please fill output file name."); } if (!OutputFileName.ToLower().EndsWith(".zip")) { throw new ApplicationException("Invalid file extension. Only zip extension allowed, as the return data will be in individual files."); } }
void metroBackWorker_DoWork(object sender, DoWorkEventArgs e) { DateTime earliestDatetime = DateTime.Now; List <MetroDataPoint> listOfData = new List <MetroDataPoint>(); List <DateTime> listofDates = new List <DateTime>(); List <string> listofMetros = new List <string>(); using (Stream stream = File.Open(InputFileName, FileMode.Open)) { using (StreamReader reader = new StreamReader(stream)) { do { string raw = reader.ReadLine(); string[] values = raw.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); metroBackWorker.ReportProgress(10, "Reading..."); if (values.Length == 10 && values[0].StartsWith("MT")) { MetroDataPoint thisDataPoint = new MetroDataPoint(values[0].Trim(), values[1].Trim(), values[2].Trim(), values[3].Trim(), values[4].Trim(), values[5].Trim(), values[6].Trim(), values[7].Trim(), values[8].Trim(), values[9].Trim()); listOfData.Add(thisDataPoint); if (!listofDates.Contains(thisDataPoint.DateOfData)) { listofDates.Add(thisDataPoint.DateOfData); } if (!listofMetros.Contains(thisDataPoint.Area)) { listofMetros.Add(thisDataPoint.Area); } } } while (reader.Peek() != -1); System.IO.StreamWriter outputFileLF = new System.IO.StreamWriter(OutputFileName.Insert(OutputFileName.Length - 4, "_LaborForce"), true); System.IO.StreamWriter outputFileE = new System.IO.StreamWriter(OutputFileName.Insert(OutputFileName.Length - 4, "_Employment"), true); System.IO.StreamWriter outputFileUE = new System.IO.StreamWriter(OutputFileName.Insert(OutputFileName.Length - 4, "_Unemployment"), true); System.IO.StreamWriter outputFileUER = new System.IO.StreamWriter(OutputFileName.Insert(OutputFileName.Length - 4, "_UnempoymentRate"), true); // Write headers string header = "Date"; foreach (string metro in listofMetros) { header = header + "," + metro; } outputFileLF.WriteLine(header); outputFileE.WriteLine(header); outputFileUE.WriteLine(header); outputFileUER.WriteLine(header); foreach (DateTime dt in listofDates) { string laborLine = "" + dt.Month.ToString() + "/" + dt.Day.ToString() + "/" + dt.Year.ToString(); string employLine = laborLine; string unemployLine = laborLine; string unemployRateLine = laborLine; metroBackWorker.ReportProgress(80, "Date: " + dt.Year.ToString() + "/" + dt.Month.ToString()); foreach (string metro in listofMetros) { bool hasValue = false; foreach (MetroDataPoint mdp in listOfData) { if (mdp.DateOfData == dt && mdp.Area == metro) { laborLine = laborLine + "," + mdp.CivilianLaborForce.ToString("N0").Replace(",", ""); unemployLine = unemployLine + "," + mdp.Unemployment.ToString("N0").Replace(",", ""); unemployRateLine = unemployRateLine + "," + mdp.UnempoymentRate.ToString("N1").Replace(",", ""); employLine = employLine + "," + mdp.Employment.ToString("N0").Replace(",", ""); hasValue = true; break; } } if (!hasValue) { laborLine = laborLine + ","; unemployLine = unemployLine + ","; unemployRateLine = unemployRateLine + ","; employLine = employLine + ","; } } outputFileLF.WriteLine(laborLine); outputFileE.WriteLine(employLine); outputFileUE.WriteLine(unemployLine); outputFileUER.WriteLine(unemployRateLine); } outputFileLF.Close(); outputFileE.Close(); outputFileUE.Close(); outputFileUER.Close(); } } }
void blsStateBackWorker_DoWork(object sender, DoWorkEventArgs e) { System.IO.StreamWriter outputFile = new System.IO.StreamWriter(OutputFileName, true); Dictionary <string, Dictionary <DateTime, BLSValue> > bulkDataHolder = new Dictionary <string, Dictionary <DateTime, BLSValue> >(); List <DateTime> possibleDates = new List <DateTime>(); Dictionary <string, StreamWriter> outputFiles = new Dictionary <string, StreamWriter>(); Dictionary <string, string> industryOutputs = new Dictionary <string, string>(); int countFromAdjust = 0; using (Stream stream = File.Open(InputFileName, FileMode.Open)) { using (StreamReader reader = new StreamReader(stream)) { bool nextIsTitle = false; int titleCount = 0; string currentSeries = ""; do { string raw = reader.ReadLine(); string[] values = raw.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //Find out what metric we're looking at // This will need to be tweaked on a case by case basis if (nextIsTitle) { #region for state industry data if (titleCount == 3) { string[] titleValues = raw.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (titleValues.Length == 2) { string industry = titleValues[1].Trim().Replace(',', '_'); if (!outputFiles.ContainsKey(industry)) { string newFilePath = OutputFileName.Insert(OutputFileName.Length - 4, industry); outputFiles.Add(industry, new StreamWriter(newFilePath, true)); } currentSeries = currentSeries + " - " + industry; if (!bulkDataHolder.ContainsKey(currentSeries)) { bulkDataHolder.Add(currentSeries, new Dictionary <DateTime, BLSValue>()); } } nextIsTitle = false; } else if (titleCount == 0) { string[] titleValues = raw.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (titleValues.Length == 2) { currentSeries = titleValues[1].Replace(',', '/'); } titleCount++; } else { titleCount++; } #endregion } //Whatever is under "Seasonally Adjusted" if (raw.StartsWith("Seasonally Adjusted")) { nextIsTitle = true; titleCount = 0; } // Now we can look at the data if (values.Length == 4 && values[0] != "Series id" && values[0] != "Series Id") { BLSValue blsVal = new BLSValue(currentSeries, values[0], values[1], values[2], values[3]); bulkDataHolder[currentSeries].Add(blsVal.ValueDate, blsVal); if (!possibleDates.Contains(blsVal.ValueDate)) { possibleDates.Add(blsVal.ValueDate); } } } while (reader.Peek() != -1); //Now we should have all the data, so let's start writing it out // First we need headers for the big file string headerData = "Date"; foreach (KeyValuePair <string, Dictionary <DateTime, BLSValue> > kv in bulkDataHolder) { headerData = headerData + "," + kv.Key.Replace(',', ' '); string[] indParse = kv.Key.Split(new string[] { " - " }, StringSplitOptions.RemoveEmptyEntries); if (!industryOutputs.ContainsKey(indParse[1])) { industryOutputs.Add(indParse[1], "Year," + indParse[0].Replace(',', ' ')); } else { industryOutputs[indParse[1]] = industryOutputs[indParse[1]] + "," + indParse[0]; } } outputFile.WriteLine(headerData); foreach (KeyValuePair <string, string> kv in industryOutputs) { if (outputFiles.ContainsKey(kv.Key)) { outputFiles[kv.Key].WriteLine(kv.Value); } } // Then we need to sort our dates (just in case) var sortedDates = from date in possibleDates orderby date ascending select date; // foreach (DateTime d in sortedDates) { string writeDateLine = "" + d.Month + "/" + d.Day + "/" + d.Year; string yearStart = "" + d.Month + "/" + d.Day + "/" + d.Year; industryOutputs = new Dictionary <string, string>(); foreach (KeyValuePair <string, Dictionary <DateTime, BLSValue> > kv in bulkDataHolder) { writeDateLine = writeDateLine + ","; if (kv.Value.ContainsKey(d)) { writeDateLine = writeDateLine + kv.Value[d].Value; } string[] indParse = kv.Key.Split(new string[] { " - " }, StringSplitOptions.RemoveEmptyEntries); string industryLine = ""; if (kv.Value.ContainsKey(d)) { industryLine = "," + kv.Value[d].Value; } else { industryLine = ","; } if (industryOutputs.ContainsKey(indParse[1])) { industryOutputs[indParse[1]] = industryOutputs[indParse[1]] + industryLine; } else { industryOutputs.Add(indParse[1], yearStart + industryLine); } } foreach (KeyValuePair <string, string> kvp in industryOutputs) { if (outputFiles.ContainsKey(kvp.Key)) { outputFiles[kvp.Key].WriteLine(kvp.Value); } } outputFile.WriteLine(writeDateLine); } foreach (KeyValuePair <string, StreamWriter> kvp in outputFiles) { kvp.Value.Close(); } outputFile.Close(); } } }
/// <summary> /// Converts the relative output file to an absolute file path. /// </summary> public string GetAbsoluteOutputFile() { string folder = new FileInfo(FileName).DirectoryName; return(Path.Combine(folder, OutputFileName.Replace("/", "\\"))); }
public override int GetHashCode() { return(OutputFileName.GetHashCode()); }
/// <summary> /// Converts the relative output file to an absolute file path. /// </summary> public string GetAbsoluteOutputFile() { string folder = new FileInfo(FileName).DirectoryName; return(Path.Combine(folder, OutputFileName.NormalizePath())); }
public override void StepRun(bool serialize, int i, string variety = null, string parameterName = null, double parameterValue = 0) { if (i == 0) { ///<Behnam> string miName, piName, riName, roiName, siiName, soiName, viName; miName = RunItem.Normal.ManagementItem; piName = RunItem.Normal.ParameterItem; riName = RunItem.Name; roiName = RunItem.Normal.RunOptionItem; siiName = RunItem.Normal.SiteItem; soiName = RunItem.Normal.SoilItem; viName = RunItem.Normal.VarietyItem; ManagementItem mi = null; CropParameterItem pi = null; RunOptionItem roi = null; SiteItem sii = null; SoilItem soi = null; CropParameterItem vi = null; RunCore.GetItems(riName, miName, piName, roiName, siiName, soiName, viName, ref mi, ref pi, ref roi, ref sii, ref soi, ref vi); switch (roi.OutputPattern) { case "V13": ProjectFile.OutputVersion = OutputVersion.V13; break; case "V15": ProjectFile.OutputVersion = OutputVersion.V15; break; case "Cus": ProjectFile.OutputVersion = OutputVersion.Cus; break; case "Maize": ProjectFile.OutputVersion = OutputVersion.Maize; break; } ///</Behnam> ///<Behnam (2016.01.19)> ///<Comment>Adding the Summary file to the outputs of a Normal run</Comment> var SumOutputFileName = OutputFile.ExtractMultiRunHeader(); SumOutputFileName.Title = OutputFileName.Replace(OutputExtention, SumOutputExtention); Book.Add(SumOutputFileName); Run.isFirstYear = true; var excelPage = RunCore.Run(RunItem.Name, true, true, ManagementItem, ParameterItem, RunOptionItem, SiteItem, SoilItem, VarietyItem); excelPage.Title = OutputFileName; Book.Add(excelPage); var WarningOutputFileName = OutputFile.ExtractWarningsNormalRun(RunCore.RunInstance); WarningOutputFileName.Title = "Warnings"; Book.Add(WarningOutputFileName); if (serialize) { RunCore.Save(excelPage, AbsoluteOutputPath, true); } if (ProjectFile.OutputVersion == OutputVersion.Cus) { Run.SecondLine = false; Book[0].Add(OutputFile.ExtractMultiRunLine(RunCore.RunInstance)); } Book[0].Add(OutputFile.ExtractMultiRunLine(RunCore.RunInstance)); ///</Behnam> } else { throw new RunException(RunItem.Name, "Normal run index != 0"); } }
public Reporter() : base() { Contract.Requires(!ClassifierResultsFileName.IsEmpty()); Contract.Requires(!OutputFileName.IsEmpty()); }
public Extractor() { Contract.Requires(!OutputFileName.IsEmpty()); }
public Transformer() : base() { Contract.Requires(!InputFileName.IsEmpty()); Contract.Requires(!OutputFileName.IsEmpty()); }
internal void Build(ProcessArgumentBuilder builder) { if (InputFile == null) { throw new ArgumentNullException(nameof(InputFile)); } if (Generator != CodeGenerator.None || GeneratorSettings != null) { if (GeneratorSettings == null) { builder.AppendSwitch(ArgumentNames.Generator, Generator.ToGeneratorName()); } else { builder.AppendSwitch(ArgumentNames.Generator, Generator == CodeGenerator.None ? GeneratorSettings.Generator.ToGeneratorName() : Generator.ToGeneratorName()); builder.Append(string.Join(" ", GeneratorSettings.GetArguments() .Select( p => $"{(p.Key.StartsWith(ArgumentNames.Separator) ? string.Empty : ArgumentNames.Separator)}{p.Key} {p.Value}"))); } } if (Namespace.IsNotEmpty()) { builder.AppendSwitch(ArgumentNames.Namespace, Namespace.Quote()); } if (OutputDirectory != null) { builder.AppendSwitch(ArgumentNames.OutputDir, OutputDirectory.FullPath.Quote()); } if (Modeler.IsNotEmpty()) { builder.AppendSwitch(ArgumentNames.Modeler, Modeler); } if (ClientName.IsNotEmpty()) { builder.AppendSwitch(ArgumentNames.ClientName, ClientName); } if (PayloadFlattenThreshold.HasValue) { builder.AppendSwitch(ArgumentNames.Threshold, PayloadFlattenThreshold.Value.ToString()); } if (HeaderComment.IsNotEmpty()) { builder.AppendSwitch(ArgumentNames.Header, HeaderComment.Quote()); } if (AddCredentials) { builder.AppendSwitch(ArgumentNames.Credentials, "true"); } if (OutputFileName.IsNotEmpty()) { builder.AppendSwitch(ArgumentNames.OutputFile, OutputFileName.Quote()); } if (Verbose) { builder.AppendSwitch(ArgumentNames.Verbose, "true"); } builder.AppendSwitch(ArgumentNames.InputFile, InputFile.FullPath.Quote()); }
static void Main(string[] args) { object oMissing = Type.Missing; //System.Reflection.Missing.Value; Word.Application WordApp = null; Word.Document Document = null; Word.Table Table = null; string CurrentDirectory = System.IO.Directory.GetCurrentDirectory(), tmpString; CurrentDirectory = CurrentDirectory.Substring(0, CurrentDirectory.LastIndexOf("bin", CurrentDirectory.Length - 1)); object InputFileName, OutputFileName, tmpObject; try { try { try { WordApp = (Word.Application)Marshal.GetActiveObject("Word.Application"); } catch (COMException eException) { if (eException.ErrorCode == -2147221021) { WordApp = new Word.Application(); } } WordApp.Visible = true; #if TEST_BOOKMARK InputFileName = CurrentDirectory + "Word_tst.doc"; Document = WordApp.Documents.Open(ref InputFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); if (Document.Bookmarks.Count > 0) { tmpString = "MyBookmark"; if (Document.Bookmarks.Exists(tmpString)) { tmpObject = tmpString; #if TEST_BOOKMARK_BY_BOOKMARKS_COLLECTION Document.Bookmarks.Item(ref tmpObject).Select(); #else object What = Word.WdGoToItem.wdGoToBookmark; WordApp.Selection.GoTo(/*What*/ ref What, /*Which*/ ref oMissing, /*Count*/ ref oMissing, /*Name*/ ref tmpObject); #endif WordApp.Selection.Text = "1234567890"; } } OutputFileName = CurrentDirectory + "Word_tst_out.doc"; if (File.Exists(OutputFileName.ToString())) { File.Delete(OutputFileName.ToString()); } Document.SaveAs(ref OutputFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); Document.Close(ref oMissing, ref oMissing, ref oMissing); #endif Document = WordApp.Documents.Add(ref oMissing, ref oMissing); int index = 0, rows = 3, columns = 2; Table = Document.Tables.Add(WordApp.Selection.Range, rows + 1, columns); Table.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; Table.Range.Bold = 1; for (int i = 0; i < columns; i++) { Table.Cell(0, i + 1).Range.InsertAfter(i.ToString()); } for (int j = 1; j <= rows; j++) { Table.Rows.Item(j + 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; Table.Rows.Item(j + 1).Range.Bold = 0; for (int i = 0; i < columns; i++) { Table.Cell(j + 1, i + 1).Range.InsertAfter(index.ToString()); index++; } } OutputFileName = CurrentDirectory + "test_out.doc"; if (File.Exists(OutputFileName.ToString())) { File.Delete(OutputFileName.ToString()); } Document.SaveAs(ref OutputFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); Document.Close(ref oMissing, ref oMissing, ref oMissing); } catch (COMException eException) { string tmp = eException.GetType().FullName + Environment.NewLine + "ErrorCode: " + eException.ErrorCode + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace; Console.WriteLine(tmp); } catch (ArgumentException eException) { string tmp = eException.GetType().FullName + Environment.NewLine + "ParamName: " + eException.ParamName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace; Console.WriteLine(tmp); } catch (Exception eException) { string tmp = eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace; Console.WriteLine(tmp); } } finally { if (Table != null) { Marshal.ReleaseComObject(Table); Table = null; } if (Document != null) { Marshal.ReleaseComObject(Document); Document = null; } if (WordApp != null) { WordApp.Quit(ref oMissing, ref oMissing, ref oMissing); Marshal.ReleaseComObject(WordApp); WordApp = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.GetTotalMemory(true); //GC.SuppressFinalize(this); } }