Example #1
0
		/// <summary>
		/// Makes A new instance of Parameters from arguments.
		/// </summary>
		/// <returns>New instance of Parameters.</returns>
		/// <param name="args">Arguments.</param>
		/// <param name="settings">Settings.</param>
		public Parameters MakeParameters(string[] args, NameValueCollection settings) {
			if (args.Length < 5) {
				throw makeArgumentException ("Number of argument must be 5.");
			}

			string basePath = settings["basePath"];
			string pathPrefix = (basePath == null ? string.Empty : basePath + Path.DirectorySeparatorChar);

			Parameters p = new Parameters();
			p.JobId = args[0];
			p.ProgramId = args[1];
			p.TargetFilePath = EmbedDateTime (pathPrefix + args [2]);
			p.IntervalSeconds = int.Parse(args[3]);
			p.Times = int.Parse(args[4]);
			p.BasePath = basePath;

			if (p.IntervalSeconds < 1) {
				throw makeArgumentException ("Interval seconds must be greater than 0.");
			}
			if (p.Times < 1) {
				throw makeArgumentException ("Times must be greater than 0.");
			}

			return p;
		}
Example #2
0
		/// <summary>
		/// Makes A new instance of Parameters from arguments.
		/// </summary>
		/// <returns>New instance of Parameters.</returns>
		/// <param name="args">Arguments.</param>
		/// <param name="settings">Settings.</param>
		public Parameters MakeParameters(string[] args, NameValueCollection settings) {
			if (args.Length < 4) {
				throw makeArgumentException ("Number of argument must be 4.");
			}

			string basePath = settings["basePath"];
			string pathPrefix = (basePath == null ? string.Empty : basePath + Path.DirectorySeparatorChar);

			Parameters p = new Parameters();
			p.JobId = args[0];
			p.ProgramId = args[1];
			p.TargetFilePath = EmbedDateTime (pathPrefix + args [2]);
			p.ZipFilePath = EmbedDateTime (pathPrefix + args [3]);
			p.BasePath = basePath;

			if (File.Exists (p.ZipFilePath)) {
				throw makeArgumentException ("Zip file \"{0}\" already exists.", p.ZipFilePath);
			}

			if (GetFileNames(p.TargetFilePath).Length == 0) {
				throw makeArgumentException ("Target file(s) \"{0}\" is not found.", p.TargetFilePath);
			}

			return p;
		}
Example #3
0
		public void ChangeEolString(Parameters p) {
			using(StreamReader sr = new StreamReader(p.SourceFilePath, p.Charset)) {
				using (StreamWriter sw = new StreamWriter (p.DestinationFilePath, false, p.Charset)) {
					string line = null;
					while ((line = sr.ReadLine()) != null) {
						sw.Write (line);
						sw.Write (p.Eol);
					}

				}
			}
		}
Example #4
0
		/// <summary>
		/// Makes A new instance of Parameters from arguments.
		/// </summary>
		/// <returns>New instance of Parameters.</returns>
		/// <param name="args">Arguments.</param>
		/// <param name="settings">Settings.</param>
		public Parameters MakeParameters(string[] args, NameValueCollection settings) {
			if (args.Length < 5) {
				throw makeArgumentException ("Number of argument must be greater than or equal 5.");
			}

			string basePath = settings["basePath"];
			string pathPrefix = (basePath == null ? string.Empty : basePath + Path.DirectorySeparatorChar);

			Parameters p = new Parameters();
			p.JobId = args[0];
			p.ProgramId = args[1];
			p.SourceFilePath = EmbedDateTime (pathPrefix + args [2]);
			p.DestinationFilePath = EmbedDateTime (pathPrefix + args [3]);
			p.BasePath = basePath;
			if (args.Length == 6) {
				p.Charset = Encoding.GetEncoding (args [5]);
			} else {
				p.Charset = Encoding.Default;
			}

			string eol = args [4].ToUpper ();
			if (eol.Equals ("CRLF")) {
				p.Eol = "\r\n";
			} else if (eol.Equals ("LF")) {
				p.Eol = "\n";
			} else if (eol.Equals ("CR")) {
				p.Eol = "\r";
			} else {
				throw makeArgumentException ("Invalid eol option \"{0}\".", args [4]);
			}

			if (File.Exists (p.DestinationFilePath)) {
				throw makeArgumentException ("Dest file \"{0}\" already exists.", p.DestinationFilePath);
			}

			if (!File.Exists (p.SourceFilePath)) {
				throw makeArgumentException ("Source file \"{0}\" is not found.", p.SourceFilePath);
			}

			return p;
		}
Example #5
0
		public bool CheckIfFileExists(Parameters p) {
			return File.Exists (p.TargetFilePath);
		}
Example #6
0
		/// <summary>
		/// Makes the name of the zip entry.
		/// </summary>
		/// <returns>The zip entry name.</returns>
		/// <param name="p">Parameters object.</param>
		/// <param name="fullpath">Fullpath of targrt file.</param>
		public string MakeZipEntryName(Parameters p, string fullpath) {
			if (p.BasePath == null) {
				string root = Path.GetPathRoot (fullpath);
				return fullpath.Substring (root.Length + 1);
			}
			string baseFullPath = Path.GetFullPath (p.BasePath);

			if (fullpath.StartsWith (baseFullPath)) {
				return fullpath.Substring (baseFullPath.Length + 1);
			} else {
				throw makeArgumentException ("Target file path \"{1}\" must start with base path \"{0}\".",
						p.BasePath, fullpath);
			}
		}
Example #7
0
		/// <summary>
		/// Makes the zip file.
		/// </summary>
		/// <param name="p">Parameters object.</param>
		public void MakeZipFile (Parameters p) {
			using (var zf = ZipFile.Open (p.ZipFilePath, ZipArchiveMode.Create)) {
				foreach (string file in GetFileNames(p.TargetFilePath)) {
					string zipEntryName = MakeZipEntryName (p, file);
					Console.WriteLine ("Add target file \"{0}\" into zip file \"{1}\" as zip entry \"{2}\"",
						file, p.ZipFilePath, zipEntryName);
					zf.CreateEntryFromFile (file, MakeZipEntryName(p, file));
				}
			}
		}