コード例 #1
0
		static void Main(string[] args)
		{
			Assembly a = Assembly.GetExecutingAssembly();
			if (args.Length == 0)
			{
				About frmAbout = new About(a);
				frmAbout.ShowDialog();
			}
			else
			{
				ProcessCommandLine(args, a);
			}
		}
コード例 #2
0
		/// <summary>
		/// Processes the command line arguments.
		/// </summary>
		/// <param name="args">The command line arguments.</param>
		/// <param name="a">Assembly.</param>
		private static void ProcessCommandLine(string [] args, Assembly a)
		{
			string vLogFileName = null;
			string vserver = null;
			string vSaveFileName = null;
			string vLoadFileName = null;
			string vPackageGUID = null;
			string vVersionGUID = null;
			string vEncryptPassword = null;
			bool PkgFlag = false;
			bool Sqlflag = false;
			bool removeflag = false;
			bool saveflag = false;
			bool loadflag = false;
			bool DTSflag1 = false;
			bool DTSflag2 = false;
			bool TestFlag = false;
			bool verflag = false;

			string vpkgname = "Replace This Name";

			for (int ii = 0; ii < args.Length; ii++)
			{
				switch (args[ii].ToLower())
				{
					case "help":
					case "/help":
					case "/?":
					{
						About frmAbout = new About(a);
						frmAbout.ShowDialog();
						return;
					}
					case "/h":
					{
						ErrorFlag = true;
						break;
					}
					case "/d":
					{
						debugflag = true;
						break;
					}
					case "/r":
					{
						removeflag = true;
						break;
					}
					case "/f":
					{
						if (ii + 1 < args.Length)
						{
							vLogFileName = args[ii + 1];
							if (!vLogFileName.ToLower().EndsWith("\\"))
							{
								vLogFileName = vLogFileName + "DTSPackage.log";
							}
							ii ++;
						}
						break;
					}
					case "/x":
					{
						saveflag = true;
						removeflag = false;
						if (ii + 1 < args.Length)
						{
							vSaveFileName = args[ii + 1];
							if (!vSaveFileName.ToLower().EndsWith(".xml"))
							{
								if (!vSaveFileName.ToLower().EndsWith(".dts"))
								{
									vSaveFileName += ".xml";
								}
								else
								{
									DTSflag2 = true;
								}
							}
							ii ++;
						}
						break;
					}
					case "/l":
					{
						loadflag = true;
						removeflag = false;
						if (ii + 1 < args.Length)
						{
							vLoadFileName = args[ii + 1];
							if (!vLoadFileName.ToLower().EndsWith(".xml"))
							{
								if (!vLoadFileName.ToLower().EndsWith(".dts"))
								{
									vLoadFileName += ".xml";
								}
								else
								{
									DTSflag1 = true;
								}
							}
							ii ++;
						}
						break;
					}
					case "/i": //package ID guid
					{
						if (ii + 1 < args.Length)
						{
							vPackageGUID = args[ii + 1];
							if (!vPackageGUID.EndsWith("}"))
							{
								vPackageGUID = vPackageGUID + "}";
							}
							if (!vPackageGUID.StartsWith("{"))
							{
								vPackageGUID = "{" + vPackageGUID;
							}
							ii ++;
						}
						break;
					}
					case "/v": //package version guid
					{
						if (ii + 1 < args.Length)
						{
							vVersionGUID = args[ii + 1];
							if (!vVersionGUID.EndsWith("}"))
							{
								vVersionGUID = vVersionGUID + "}";
							}
							if (!vVersionGUID.StartsWith("{"))
							{
								vVersionGUID = "{" + vVersionGUID;
							}
							ii ++;
						}
						break;
					}
					case "/w":
					{
						AuthType = DTSPackage2.authTypeFlags.Trusted;
						break;
					}
					case "/t":
					{
						TestFlag = true;
						break;
					}
					case "/u":
					{
						if (ii + 1 < args.Length)
						{
							vuser = args[ii + 1];
							ii ++;
						}
						break;
					}
					case "/p":
					{
						if (ii + 1 < args.Length)
						{
							vpass = args[ii + 1];
							ii ++;
						}
						break;
					}
					case "/s":
					{
						Sqlflag = true;
						if (ii + 1 < args.Length)
						{
							vserver = args[ii + 1];
							ii ++;
						}
						break;
					}
					case "/n":
					{
						PkgFlag = true;
						if (ii + 1 < args.Length)
						{
							vpkgname = args[ii + 1];
							ii ++;
						}
						break;
					}
					case "/e":
					{
						if (ii + 1 < args.Length)
						{
							vEncryptPassword = args[ii + 1];
							ii ++;
						}
						break;
					}
					case "/pi":
					{
						verflag = true;
						break;
					}
				}
			} // end of for loop that parses the passed in args array
			if (TestFlag)
			{
				ErrorFlag = false;
				debugflag = true;
			}
			if (vuser == null)
			{
				vuser = "******"; //set default user
			}

			if (Sqlflag && vserver != null)
			{
				if (!ErrorFlag && vserver.IndexOf("/") >= 0 )
				{
                    logger.Error("SQL Server Name [" + vserver + "] contains a forward slash!\n\nThe DTS installation program can not connect.\n\nTo connect to a SQL instance, the SQL Server Instance string\nmust have a back slash.");
                    return;
					//MessageBox.Show("SQL Server Name [" + vserver + "] contains a forward slash!\n\nThe DTS installation program can not connect.\n\nTo connect to a SQL instance, the SQL Server Instance string\nmust have a back slash.", "SQL CONNECTION ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
				else
				{
					gsComputername = vserver;
					if (!ErrorFlag && debugflag)
					{
						string msgStr = null;
						if (AuthType == DTSPackage2.authTypeFlags.Default)
						{
							msgStr = "SQL Server Name: " + gsComputername + "\nUser ID: " + vuser + "\nPassword: not shown";
						}
						else
						{
							msgStr = "SQL Server Name: " + gsComputername + "\nSQL Login is using Windows Authentication.";
						}
                        logger.Debug(msgStr);
						//MessageBox.Show(msgStr, "DEBUG HELP", MessageBoxButtons.OK, MessageBoxIcon.Information);
					}
				}
			}
			else
			{
				gsComputername = GetLocalMachineName();
				if (!ErrorFlag && debugflag)
				{
					string msgStr = null;
					if (AuthType == DTSPackage2.authTypeFlags.Default)
					{
						msgStr = "SQL Server Name: " + gsComputername + "\nUser ID: " + vuser + "\nPassword: not shown";
					}
					else
					{
						msgStr = "SQL Server Name: " + gsComputername + "\nSQL Login is using Windows Authentication.";
					}
                    logger.Debug(msgStr);
					//MessageBox.Show(msgStr, "DEBUG HELP", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
			}
			if (PkgFlag && vpkgname != null)
			{
				if (!ErrorFlag && debugflag)
				{
                    logger.Debug("CommandLine DTS Package Name: " + vpkgname);
					//MessageBox.Show("CommandLine DTS Package Name: " + vpkgname, "DEBUG HELP", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
			}
			else
			{
				if (!ErrorFlag)
				{
                    logger.Info("CommandLine DTS Package Name: " + vpkgname);
					//MessageBox.Show("CommandLine DTS Package Name: " + vpkgname, "DEBUG HELP", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
				return;
			}

			if (TestFlag)
			{
				string testresult = null;
				if (TestConnection(gsComputername, vuser, vpass))
				{
					testresult = "Successful";
				}
				else
				{
					testresult = "Failed";
				}
				if (!ErrorFlag)
				{
                    logger.Info(testresult + " Connection Test.");
					//MessageBox.Show(testresult + " Connection Test.", "DEBUG HELP", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
				return;
			}

			DTSPackage2 oPackage = InitializeDTSPackage(
				vpkgname,
				(vLogFileName != null ? vLogFileName : a.Location + vpkgname + ".log"),
				System.Diagnostics.FileVersionInfo.GetVersionInfo(a.Location).FileDescription);

			oPackage.Authentication = AuthType;

			if (!removeflag && !saveflag && !loadflag && !DTSflag1 && !DTSflag2 && !verflag)
			{
				if (!ErrorFlag)
				{
                    logger.Info("No valid command line options were entered for loading or saving the package.");
					//MessageBox.Show("No valid command line options were entered for loading or saving the package.", "PACKAGE OPTIONS ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
				return;
			}
			if (!removeflag && !saveflag && verflag && !DTSflag1)
			{
				string packageInfo = oPackage.GetPackageVersionInfo(gsComputername, vpkgname, vuser, vpass, AuthType, false);
				if (!ErrorFlag)
				{
					About frmAbout = new About();
					frmAbout.ShowText(packageInfo);
					frmAbout.Dispose();
				}
				return;
			}
			if (!removeflag && !saveflag && verflag && DTSflag1)
			{
				string packageInfo = oPackage.GetPackageVersionInfo(vLoadFileName);
				if (!ErrorFlag)
				{
					About frmAbout = new About();
					frmAbout.ShowText(packageInfo);
					frmAbout.Dispose();
				}
				return;
			}
			if (!removeflag && !saveflag && loadflag && !DTSflag1)
			{
				// call Create DTS on SQL Server from XML file
				LoadPackageFromXMLDoc(oPackage, vLoadFileName, vEncryptPassword);
				return;
			}
			if (!removeflag && !saveflag && loadflag && DTSflag1)
			{
				// call Create DTS on SQL Server from DTS file
				LoadPackageFromDTSFile(oPackage, vLoadFileName, vEncryptPassword, vPackageGUID, vVersionGUID);
				return;
			}
			if (!removeflag && saveflag && loadflag && !DTSflag1 && DTSflag2)
			{
				// call convert XML file to DTS File
				LoadPackageFromXMLDoc(oPackage, vSaveFileName, vEncryptPassword);
				return;
			}
			if (!removeflag && saveflag && loadflag && DTSflag1 && !DTSflag2)
			{
				// call convert DTS file to XML file
				LoadPackageFromDTSFile(oPackage, vLoadFileName, vSaveFileName, vEncryptPassword, vPackageGUID, vVersionGUID);
				return;
			}
			if (!removeflag && saveflag && !loadflag)
			{
				// call load Package from SQL Server
				LoadPackageFromSQLServer(oPackage, vEncryptPassword ,vPackageGUID, vVersionGUID);

				// call Serialize as XML file
				SerializePackageAsXMLFile(oPackage, vSaveFileName);
				return;
			}
			if(removeflag)
			{
				// call Remove DTS
				RemovePackageFromSQLServer(oPackage, vPackageGUID, vVersionGUID);
				return;
			}
		}