コード例 #1
0
ファイル: Indexus.cs プロジェクト: windygu/mysoftsolution
        /// <summary>
        /// The main entry point for the process
        /// options:
        ///  - Install
        /// 1. /install
        /// 2. /i
        ///  - Uninstall
        /// 1. /uninstall
        /// 2. /u
        /// </summary>
        /// <param name="args">The args. A <see cref="T:System.String[]"/> Object.</param>
        public static void Main(string[] args)
        {
            #region Access Log
#if TRACE
            {
                COM.Handler.LogHandler.Tracking("Access Method: " + typeof(Indexus).FullName + "->" + ((object)MethodBase.GetCurrentMethod()).ToString() + " ;");
            }
#endif
            #endregion Access Log

            string optionalArgs = string.Empty;
            if (args.Length > 0)
            {
                optionalArgs = args[0];
            }
            #region args Handling
            if (!string.IsNullOrEmpty(optionalArgs))
            {
                if ("/?".Equals(optionalArgs.ToLower()))
                {
                    Console.WriteLine("Help Menu");
                    Console.ReadLine();
                    return;
                }
                else if ("/local".Equals(optionalArgs.ToLower()))
                {
                    Console.Title           = "Shared Cache - Server";
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.ForegroundColor = ConsoleColor.White;
                    // running as cmd appliacation
                    Indexus SrvIndexus = new Indexus();
                    SrvIndexus.StartService();
                    Console.ReadLine();
                    SrvIndexus.StopService();
                    return;
                }
                else if (@"/verbose".Equals(optionalArgs.ToLower()))
                {
                    // Console.SetOut(this);
                    // Console.SetIn(Console.Out);
                    // Console.ReadLine();
                    return;
                }

                TransactedInstaller ti = new TransactedInstaller();
                IndexusInstaller    ii = new IndexusInstaller();
                ti.Installers.Add(ii);
                string         path    = string.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location);
                string[]       cmd     = { path };
                InstallContext context = new InstallContext(string.Empty, cmd);
                ti.Context = context;

                if ("/install".Equals(optionalArgs.ToLower()) || "/i".Equals(optionalArgs.ToLower()))
                {
                    ti.Install(new Hashtable());
                }
                else if ("/uninstall".Equals(optionalArgs.ToLower()) || "/u".Equals(optionalArgs.ToLower()))
                {
                    ti.Uninstall(null);
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(@"Your provided Argument is not available." + Environment.NewLine);
                    sb.Append(@"Use one of the following once:" + Environment.NewLine);
                    sb.AppendFormat(@"To Install the service '{0}': '/install' or '/i'" + Environment.NewLine, @"IndeXus.Net");
                    sb.AppendFormat(@"To Un-Install the service'{0}': '/uninstall' or '/u'" + Environment.NewLine, @"IndeXus.Net");
                    Console.WriteLine(sb.ToString());
                }
            }
            else
            {
                // nothing received as input argument
                ServiceBase[] servicesToRun;
                servicesToRun = new ServiceBase[] { new Indexus() };
                ServiceBase.Run(servicesToRun);
            }
            #endregion args Handling
        }
コード例 #2
0
		/// <summary>
		/// The main entry point for the process
		/// options: 
		///  - Install
		/// 1. /install 
		/// 2. /i
		///  - Uninstall
		/// 1. /uninstall
		/// 2. /u
		/// </summary>
		/// <param name="args">The args. A <see cref="T:System.String[]"/> Object.</param>
		public static void Main(string[] args)
		{
			#region Access Log
#if TRACE			
			{
				COM.Handler.LogHandler.Tracking("Access Method: " + typeof(Indexus).FullName + "->" + ((object)MethodBase.GetCurrentMethod()).ToString() + " ;");
			}
#endif
			#endregion Access Log

			string optionalArgs = string.Empty;
			if (args.Length > 0)
			{
				optionalArgs = args[0];
			}
			#region args Handling
			if (!string.IsNullOrEmpty(optionalArgs))
			{
				if("/?".Equals(optionalArgs.ToLower()))
				{
					Console.WriteLine("Help Menu");
					Console.ReadLine();
					return;
				}
				else if("/local".Equals(optionalArgs.ToLower()))
				{
					Console.Title = "Shared Cache - Server";
					Console.BackgroundColor = ConsoleColor.DarkBlue;
					Console.ForegroundColor = ConsoleColor.White;
					// running as cmd appliacation
					Indexus SrvIndexus = new Indexus();
					SrvIndexus.StartService();
					Console.ReadLine();
					SrvIndexus.StopService();
					return;
				}
				else if(@"/verbose".Equals(optionalArgs.ToLower()))
				{
					// Console.SetOut(this);
					// Console.SetIn(Console.Out);
					// Console.ReadLine();
					return;
				}
				
				TransactedInstaller ti = new TransactedInstaller();
				IndexusInstaller ii = new IndexusInstaller();
				ti.Installers.Add(ii);
				string path = string.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location);
				string[] cmd = { path };
				InstallContext context = new InstallContext(string.Empty, cmd);
				ti.Context = context;

				if ("/install".Equals(optionalArgs.ToLower()) || "/i".Equals(optionalArgs.ToLower()))
				{
					ti.Install(new Hashtable());
				}
				else if ("/uninstall".Equals(optionalArgs.ToLower()) || "/u".Equals(optionalArgs.ToLower()))
				{
					ti.Uninstall(null);
				}
				else
				{
					StringBuilder sb = new StringBuilder();
					sb.Append(@"Your provided Argument is not available." + Environment.NewLine);
					sb.Append(@"Use one of the following once:" + Environment.NewLine);
					sb.AppendFormat(@"To Install the service '{0}': '/install' or '/i'" + Environment.NewLine, @"IndeXus.Net");
					sb.AppendFormat(@"To Un-Install the service'{0}': '/uninstall' or '/u'" + Environment.NewLine, @"IndeXus.Net");
					Console.WriteLine(sb.ToString());
				}
			}
			else
			{
				// nothing received as input argument
				ServiceBase[] servicesToRun;
				servicesToRun = new ServiceBase[] { new Indexus() };
				ServiceBase.Run(servicesToRun);
			}
			#endregion args Handling
		}