示例#1
0
        private void ExecTask()
        {
            while (true)
            {
                try
                {
                    if (_isRunFirstTime)
                    {
                        Thread.Sleep(ExecutePeriod());
                    }

                    ExecuteJob?.Invoke();
                    if (_isStopTaskWithBusiness)
                    {
                        LogInfoWriter.GetInstance().Info("the schedule task has been stopped!");
                        break;
                    }

                    Thread.Sleep(ExecutePeriod());
                }
                catch (Exception e)
                {
                    LogInfoWriter.GetInstance().Warn("run schedule task warning!", e);
                }
            }
        }
示例#2
0
        /// <summary>
        /// 操作应用程序池 (回收、停止、重启)
        /// </summary>
        /// <param name="operateAppPoolType">操作类型</param>
        /// <param name="appPoolName">应用程序池名称</param>
        /// <param name="logInsance">日志实例</param>
        /// <returns></returns>
        private static bool OperateAppPool(OperateAppPoolType operateAppPoolType, string appPoolName, string logInsance)
        {
            LogInfoWriter.GetInstance(logInsance).Info($"{operateAppPoolType}AppPool info appName:{appPoolName}");
            var appPool  = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
            var findPool = appPool.Children.Find(appPoolName, "IIsApplicationPool");

            findPool.Invoke(operateAppPoolType.ToString(), null);
            appPool.CommitChanges();
            appPool.Close();
            return(true);
        }
示例#3
0
        public static void Stop()
        {
            new Thread(() =>
            {
                int waitTime;
                int.TryParse(ConfigurationManager.AppSettings["WaitTime"].ToLower(), out waitTime);
                LogInfoWriter.GetInstance("DemoService").InfoFormat("服务:{0}\t{1}", DateTime.Now, waitTime);
                Thread.Sleep(waitTime * 1000);
            }).Start();

            //Thread.Sleep(waitTime * 1000);
        }
示例#4
0
 public static void Start()
 {
     new Thread(() =>
     {
         Benlai.Common.HttpClientUtils.Get("http://111.com", Encoding.UTF8, int.MaxValue);
         //while (true)
         //{
         //    Thread.Sleep(int.MaxValue);
         LogInfoWriter.GetInstance("DemoService").InfoFormat("服务:{0}", DateTime.Now);
         //}
     }).Start();
 }
示例#5
0
        public void Start()
        {
            CatConfig.Init(AppConfig.CatDomain, AppConfig.CatEnable, AppConfig.CatServer);

            MapArea.RegisterMapArea();

            if (AppConfig.HttpPort > 0)
            {
                Task.Factory.StartNew(() =>
                {
                    _webApp = new WebApp();
                    _webApp.Start(AppConfig.HttpPort);
                }, TaskCreationOptions.LongRunning)
                .ContinueWith(t =>
                {
                    if (!t.IsFaulted)
                    {
                        return;
                    }
                    LogInfoWriter.GetInstance().Error("TcpApp start error", t.Exception);
                    if (t.Exception != null)
                    {
                        throw t.Exception;
                    }
                });
            }

            if (AppConfig.TcpPort > 0)
            {
                Task.Factory.StartNew(() =>
                {
                    _tcpApp = new TcpApp();
                    _tcpApp.Start(AppConfig.TcpPort);
                }, TaskCreationOptions.LongRunning)
                .ContinueWith(t =>
                {
                    if (!t.IsFaulted)
                    {
                        return;
                    }
                    LogInfoWriter.GetInstance().Error("TcpApp start error", t.Exception);
                    if (t.Exception != null)
                    {
                        throw t.Exception;
                    }
                });
            }
        }
示例#6
0
        static void TaskPoolServiceRun()
        {
            var rnd      = new Random();
            var lst      = new List <TaskModel>();
            var taskPool = new TaskPool(5, 4);

            taskPool.OnCancelled += () =>
            {
                LogInfoWriter.GetInstance().Info($"Thread -- {Thread.CurrentThread.ManagedThreadId} -- On Cancelled");
            };
            for (var i = 0; i < 100; i++)
            {
                var s = rnd.Next(4, 10);

                var j             = i;
                var isException   = false;//s % 4 == 0;
                var isCancel      = i == 10;
                var testTaskModel = new TaskModel(new Action(() =>
                {
                    if (isCancel)
                    {
                        taskPool.Cancel();
                    }
                    LogInfoWriter.GetInstance().Info($"Thread -- {Thread.CurrentThread.ManagedThreadId} -- 第{j}个任务(用时{s}秒){(isException ? "有异常" : "")}  已经开始 ");
                    Thread.Sleep(s * 1000);
                    LogInfoWriter.GetInstance().Info($"Thread -- {Thread.CurrentThread.ManagedThreadId} -- 第{j}个任务(用时{s}秒){(isException ? "有异常" : "")}  已经结束");
                    if (isException)
                    {
                        throw new Exception("this task is failed");
                    }
                }))
                {
                    TaskName = $"第{j}个任务(用时{s}秒){(isException ? "有异常" : "")}",
                };
                lst.Add(testTaskModel);
            }

            taskPool.SetTaskInfoList(lst);
            taskPool.Start();

            Console.WriteLine();
            Console.ReadLine();
        }
示例#7
0
        public void Cancel()
        {
            var    currentTaskId = Thread.CurrentThread.ManagedThreadId;
            string debugStr      = $"Thread -- {currentTaskId}";

            LogInfoWriter.GetInstance().Info($"{debugStr} --Check Cancel");

            if (_cts.IsCancellationRequested)
            {
                return;
            }
            LogInfoWriter.GetInstance().Info($"{debugStr} --Start Cancel");

            _cts.Cancel(); //设置为取消
            _cts.Token.Register(() =>
            {
                OnCancelled?.Invoke();
                Clear();
                LogInfoWriter.GetInstance().Info($"{debugStr} --End Cancel");
            });
        }
示例#8
0
        /// <summary>
        /// 重启应用池
        /// </summary>
        /// <param name="appPoolName">应用程序池名称</param>
        /// <param name="waitTime">等待时间</param>
        /// <param name="logInsance">日志输出名</param>
        /// <returns></returns>
        public static bool RestartAppPool(string appPoolName, int waitTime, string logInsance)
        {
            try
            {
                return(RecycleAppPool(appPoolName, logInsance) && StopAppPool(appPoolName, logInsance) &&
                       StartAppPool(appPoolName, logInsance));
            }
            catch (Exception e)
            {
                LogInfoWriter.GetInstance(logInsance).Error($"RestartAppPool error and ReTry appName:{appPoolName}\r\n{e}");

                ThreadWait(waitTime * 1000);
                try
                {
                    StopAppPool(appPoolName, logInsance);
                    return(StartAppPool(appPoolName, logInsance));
                }
                catch (Exception ex)
                {
                    LogInfoWriter.GetInstance(logInsance).Error($"StopAppPool error and TryStart appName:{appPoolName}\r\n{ex}");
                    throw;
                }
            }
        }
示例#9
0
 protected override void OnStop()
 {
     LogInfoWriter.GetInstance("TestWinService").Info($"Stop TestWinService {DateTime.Now}");
 }
示例#10
0
 protected override void OnStart(string[] args)
 {
     LogInfoWriter.GetInstance("TestWinService").Info($"Start TestWinService {DateTime.Now}");
 }
示例#11
0
        /// <summary>
        /// 等待JenkinsBuildTask并返回任务结果
        /// </summary>
        /// <param name="appName">应用名称</param>
        /// <param name="environment">所属环境</param>
        /// <param name="logDirName">日志输出文件夹名</param>
        /// <returns>Tuple bool--是否编译成功, string--成功则为任务id 则是异常信息或空, string--编译的SVN的版本 </returns>
        private static Tuple <bool, string, string> WaitJkbtAndGetResult(string appName, string environment,
                                                                         string logDirName)
        {
            var jkbtId = "";

            try
            {
                //第一步:检查Jenkins的任务队列是否有等待执行的任务,没人排队任务则继续第二步
                var jenkinsQueueUrl = GetJenkinsConfig("JenkinsQueueApiUrl", "");
                LogInfoWriter.GetInstance(logDirName).Info($"start check jenkins build task queue is empty, JenkinsQueueApiUrl:{jenkinsQueueUrl}");
                var isJkQueueEmpty = ExecExtensions.RetryUntilTrueWithTimeout(() =>
                {
                    var queueInfo     = HttpClientUtils.GetJson(jenkinsQueueUrl);
                    var queueInfoJObj = JObject.Parse(queueInfo);
                    Console.WriteLine("jenkins build task queue is not empty");
                    return(!queueInfoJObj["items"].Values <JObject>().Any());
                }, ConfigManager.GetConfigObject("JenkinsQueueCheckTimeout", 5) * OneMinute);
                if (!isJkQueueEmpty)
                {
                    throw new Exception("wait jenkins build task finish error; ErrorMsg:check wether jenkins build task queue is empty timout");
                }
                LogInfoWriter.GetInstance(logDirName).Info("check jenkins build task queue is empty end");

                //第二步:获取Jenkins的编译任务Id
                var getJkbtNumberUrl = GetJenkinsConfig("JenkinsGetBuildTaskIdApiUrl", "");
                getJkbtNumberUrl = String.Format(getJkbtNumberUrl, appName, environment);
                LogInfoWriter.GetInstance(logDirName).Info($"start get jenkins build task id, JenkinsGetBuildTaskIdApiUrl:{getJkbtNumberUrl}");
                var jkbtNumberInfo = HttpClientUtils.Get(getJkbtNumberUrl);
                jkbtId = GetJenkinsXmlValue(jkbtNumberInfo);
                if (String.IsNullOrWhiteSpace(jkbtId))
                {
                    throw new Exception("get jenkins build task id error,the jenkins build task id is null or empty!");
                }
                LogInfoWriter.GetInstance(logDirName).Info($"get jenkins build task id:{jkbtId} end");

                //第三步:根据Jenkins的编译任务Id获取其执行结果
                var getJkbtResultUrl = GetJenkinsConfig("JenkinsGetBuildTaskResultApiUrl", "");
                getJkbtResultUrl = String.Format(getJkbtResultUrl, appName, environment, jkbtId);
                LogInfoWriter.GetInstance(logDirName).Info($"start get jenkins build task:{jkbtId} result, JenkinsGetBuildTaskResultApiUrl:{getJkbtResultUrl}");
                var isJkbtFinish = ExecExtensions.RetryUntilTrueWithTimeout(() =>
                {
                    if (String.Equals(JkbtResultSuccess, HttpClientUtils.Get(getJkbtResultUrl),
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        return(ExecExtensions.ResultType.Success);
                    }
                    if (String.Equals(JkbtResultFailure, HttpClientUtils.Get(getJkbtResultUrl),
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        return(ExecExtensions.ResultType.Failure);
                    }
                    return(ExecExtensions.ResultType.Continue);
                }, ConfigManager.GetConfigObject("JenkinsGetBuildTaskResultTimeout", 10) * OneMinute);
                LogInfoWriter.GetInstance(logDirName).Info($"get jenkins build task:{jkbtId} result end");

                //第四步:根据Jenkins编译任务结果返回最终结果
                switch (isJkbtFinish)
                {
                case ExecExtensions.ResultType.Success:
                    var getJkbtSvnNumberUrl = GetJenkinsConfig("JenkinsGetBuildTaskSvnNumberUrl", "");
                    getJkbtSvnNumberUrl = String.Format(getJkbtSvnNumberUrl, appName, environment, jkbtId);
                    LogInfoWriter.GetInstance(logDirName).Info($"start get jenkins build task:{jkbtId} svn number,JenkinsGetBuildTaskSvnNumberUrl:{getJkbtSvnNumberUrl}");
                    var jkbtSvnNumberInfo = HttpClientUtils.Get(getJkbtSvnNumberUrl);
                    var jkbtSvnNumber     = GetJenkinsXmlValue(jkbtSvnNumberInfo);
                    if (String.IsNullOrWhiteSpace(jkbtSvnNumber))
                    {
                        throw new Exception("$the jenkins build task:{jkbtId} svn number is null or empty!");
                    }
                    return(Tuple.Create(true, jkbtId, jkbtSvnNumber));

                case ExecExtensions.ResultType.Failure:
                    return(Tuple.Create(false, jkbtId, "jenkins build task failure"));

                case ExecExtensions.ResultType.Timeout:
                    return(Tuple.Create(false, jkbtId, "jenkins build task timeout"));
                }
            }
            catch (Exception ex)
            {
                return(Tuple.Create(false, jkbtId, ex.ToString()));
            }
            return(Tuple.Create(false, jkbtId, "unknow error"));
        }
示例#12
0
        private void ExecuteTask()
        {
            var    currentTaskId = Thread.CurrentThread.ManagedThreadId;
            string debugStr      = $"Thread -- {currentTaskId}";

            while (!_isFinished && !_cts.IsCancellationRequested)
            {
                LogInfoWriter.GetInstance().Info($"{debugStr} --Check Start [taskInfoList:{_taskInfoList.Count()}, hasCompleteTaskInfoList:{_hasCompleteTaskInfoList.Count()}, runningTaskInfoDic:{_runningTaskInfoDic.Count()}]");
                Thread.Sleep(1000);
                lock (_lockObj)
                {
                    //所有任务已完成
                    if (_taskInfoList.Count() <= 0)
                    {
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Check taskInfoList.Count() <= 100 \r\n");
                        _isFinished = true;
                        return;
                    }

                    //任务失败数超过任务要求的最大可失败数
                    LogInfoWriter.GetInstance().Info($"{debugStr} --Check hasCompleteTaskInfoList.Count(s => s.IsFailed):{_hasCompleteTaskInfoList.Count(s => s.IsFailed)}");
                    if (_hasCompleteTaskInfoList.Count(s => s.IsFailed) >= _taskFailedMaxCount)
                    {
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Check hasCompleteTaskInfoList.Count(s => s.IsFailed) >= {_taskFailedMaxCount} \r\n");
                        _isFinished = true;
                        return;
                    }

                    //正在进行的任务数 = 最大可并发任务 则跳过获取新任务  继续等待当前运行的任务完成
                    LogInfoWriter.GetInstance().Info($"{debugStr} --Check runningTaskInfoDic.Count():{_runningTaskInfoDic.Count()}");
                    if (_runningTaskInfoDic.Count() == _concurrencyRunTaskMaxcount)
                    {
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Check runningTaskInfoDic.Count() == {_concurrencyRunTaskMaxcount} \r\n");
                        continue;
                    }

                    //正在运行的任务中存在失败的任务且还有其他任务未结束 则不去获取新任务
                    LogInfoWriter.GetInstance().Info($"{debugStr} --Check runningTaskInfoDic.Values.Any(s => s.IsFailed):{_runningTaskInfoDic.Values.Any(s => s.IsFailed)}");
                    LogInfoWriter.GetInstance().Info($"{debugStr} --Check runningTaskInfoDic.Values.Any(s => !s.IsCompleted):{_runningTaskInfoDic.Values.Any(s => !s.IsCompleted)}");
                    if (_runningTaskInfoDic.Values.Any(s => s.IsFailed) &&
                        _runningTaskInfoDic.Values.Any(s => !s.IsCompleted))
                    {
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Check runningTaskInfoDic.Values.Any(s => s.IsFailed) == _runningTaskInfoDic.Values.Any(s => !s.IsCompleted) == true \r\n");
                        continue;
                    }
                    //如果当前正在运行任务小于最大 并发任务数 且当前线程没有正在运行的任务  则去拉取新任务执行
                    if (_runningTaskInfoDic.Count < _concurrencyRunTaskMaxcount &&
                        !_runningTaskInfoDic.ContainsKey(currentTaskId))
                    {
                        var t = _taskInfoList.First(s => !s.IsCompleted);
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Get GetTask Success :{t.TaskName}");
                        _runningTaskInfoDic.Add(currentTaskId, t);
                        _taskInfoList.Remove(t);
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Get taskInfoList.Count():{_taskInfoList.Count()}");
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Get runningTaskInfoDic.Count():{_runningTaskInfoDic.Count()}\r\n");
                    }
                }
                if (_runningTaskInfoDic.ContainsKey(currentTaskId))
                {
                    var task = _runningTaskInfoDic[currentTaskId];

                    try
                    {
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Execute Start");
                        OnBeforeStart?.Invoke(task);
                        task.TaskAction?.Invoke();
                        Interlocked.Increment(ref _successTaskCount);
                        OnAfterStart?.Invoke(task);
                    }
                    catch (Exception e)
                    {
                        task.ExecuteFailed(e);
                        Interlocked.Increment(ref _failedTaskCount);
                        OnExceptionOccurred?.Invoke(e);
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Execute Failed");
                    }
                    finally
                    {
                        task.HasCompleted();
                        Interlocked.Increment(ref _completedTaskCount);
                        OnCompleted?.Invoke(task);
                        LogInfoWriter.GetInstance().Info($"{debugStr} -- Execute runningTaskInfoDic.Values.Any(s => s.IsFailed):{_runningTaskInfoDic.Values.Any(s => s.IsFailed)}!");
                        LogInfoWriter.GetInstance().Info($"{debugStr} -- Execute hasCompleteTaskInfoList.Any(s => s.IsFailed)):{_hasCompleteTaskInfoList.Any(s => s.IsFailed)}!");
                        LogInfoWriter.GetInstance().Info($"{debugStr} -- Execute runningTaskInfoDic.Values.Any(s=>!s.IsCompleted):{_runningTaskInfoDic.Values.Any(s => !s.IsCompleted)}!");

                        while ((_runningTaskInfoDic.Values.Any(s => s.IsFailed) || _hasCompleteTaskInfoList.Any(s => s.IsFailed)) && _runningTaskInfoDic.Values.Any(s => !s.IsCompleted))
                        {
                            LogInfoWriter.GetInstance().Info($"{debugStr} -- Execute Wait [taskInfoList:{_taskInfoList.Count()}, hasCompleteTaskInfoList:{_hasCompleteTaskInfoList.Count()}, runningTaskInfoDic:{_runningTaskInfoDic.Count()}]");
                            LogInfoWriter.GetInstance().Info($"{debugStr} -- Execute Wait there has some task failed ,so wait all current running task has finished!");
                            LogInfoWriter.GetInstance().Info($"{debugStr} -- Execute Wait [runningTaskInfoDic:{_runningTaskInfoDic.Values.Select(s=>s.TaskName + ":[" +s.IsFailed+","+s.IsCompleted+"]").Aggregate((s,r)=>s+" - "+r)}]");
                            Thread.Sleep(1000);
                        }
                        if (_runningTaskInfoDic.ContainsKey(currentTaskId))
                        {
                            LogInfoWriter.GetInstance().Info($"{debugStr} -- Execute Add [runningTaskInfoDic:{_runningTaskInfoDic.Values.Select(s => s.TaskName + ":[" + s.IsFailed + "," + s.IsCompleted + "]").Aggregate((s, r) => s + " - " + r)}]");
                            LogInfoWriter.GetInstance().Info($"{debugStr} --Execute Add {task.TaskName} HasComplete and Remove running");
                            _runningTaskInfoDic.Remove(currentTaskId);
                            _hasCompleteTaskInfoList.Add(task);
                        }
                        LogInfoWriter.GetInstance().Info($"{debugStr} --Execute End");
                    }
                }

                LogInfoWriter.GetInstance().Info($"{debugStr} --Check End [taskInfoList:{_taskInfoList.Count()}, hasCompleteTaskInfoList:{_hasCompleteTaskInfoList.Count()}, runningTaskInfoDic:{_runningTaskInfoDic.Count()}]");
            }
        }
示例#13
0
        static void Main(string[] args)
        {
            try
            {
                #region IIS

//                using (ServerManager mgr = new ServerManager(@"C:\Windows\System32\inetsrv\config\applicationHost.config"))
//                {
//                    Site site = mgr.Sites["test.plf.benlai.com"];
//
//                }
                var poolName = "test.plf.benlai.com";

                IisUtility.RecycleAppPool(poolName, "");
                Console.WriteLine($"RecycleAppPool");
                IisUtility.StopAppPool(poolName, "");
                Console.WriteLine("StopAppPool");
                IisUtility.RecycleAppPool(poolName, "");
                Console.WriteLine($"RecycleAppPool");
                IisUtility.StopAppPool(poolName, "");
                Console.WriteLine("StopAppPool");
                IisUtility.StopAppPool(poolName, "");
                Console.WriteLine("StopAppPool");
                IisUtility.StartAppPool(poolName, "");
                Console.WriteLine("StartAppPool");
                IisUtility.StopAppPool(poolName, "");
                Console.WriteLine("StopAppPool");
                IisUtility.StartAppPool(poolName, "");
                Console.WriteLine("StartAppPool");
                IisUtility.StartAppPool(poolName, "");
                Console.WriteLine("StartAppPool");
                Console.ReadKey();


                //Console.WriteLine("Please wait...");

                //Process pro = new Process();

                //ProcessStartInfo psi = new ProcessStartInfo()
                //{
                //    UseShellExecute = true,
                //    RedirectStandardOutput = false,
                //    RedirectStandardError = false
                //};
                //psi.Arguments = @"/Online /Enable-Feature /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-ASP " +
                //    "/FeatureName:IIS-ASPNET /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-CGI " +
                //    "/FeatureName:IIS-ClientCertificateMappingAuthentication /FeatureName:IIS-CommonHttpFeatures " +
                //    "/FeatureName:IIS-CustomLogging /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DigestAuthentication " +
                //    "/FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-FTPExtensibility /FeatureName:IIS-FTPServer " +
                //    "/FeatureName:IIS-FTPSvc /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-HostableWebCore " +
                //    "/FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-HttpErrors " +
                //    "/FeatureName:IIS-HttpLogging /FeatureName:IIS-HttpRedirect /FeatureName:IIS-HttpTracing " +
                //    "/FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-IISCertificateMappingAuthentication " +
                //    "/FeatureName:IIS-IPSecurity /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter " +
                //    "/FeatureName:IIS-LegacyScripts /FeatureName:IIS-LegacySnapIn /FeatureName:IIS-LoggingLibraries /" +
                //    "FeatureName:IIS-ManagementConsole  /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-ManagementService " +
                //    "/FeatureName:IIS-Metabase /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-ODBCLogging " +
                //    "/FeatureName:IIS-Performance /FeatureName:IIS-RequestFiltering /FeatureName:IIS-RequestMonitor /FeatureName:IIS-Security " +
                //    "/FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-StaticContent /FeatureName:IIS-URLAuthorization " +
                //    "/FeatureName:IIS-WebDAV /FeatureName:IIS-WebServer /FeatureName:IIS-WebServerManagementTools " +
                //    "/FeatureName:IIS-WebServerRole /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-WMICompatibility " +
                //    "/FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment /FeatureName:WAS-ProcessModel " +
                //    "/FeatureName:WAS-WindowsActivationService\" > out.txt ";
                //psi.WindowStyle = ProcessWindowStyle.Normal;
                //psi.ErrorDialog = true;

                //psi.FileName = "cmd.exe";

                //if (!File.Exists(@"C:\Windows\SysWOW64\dism.exe"))
                //{
                //    psi.Arguments = @"/C ""C:\Windows\SysWOW64\dism.exe " + psi.Arguments;
                //    psi.WorkingDirectory = @"C:\Windows\SysWOW64\";
                //}
                //else if (File.Exists(@"C:\Windows\System32\dism.exe"))
                //{
                //    psi.Arguments = @"/C ""C:\Windows\System32\dism.exe " + psi.Arguments;
                //    psi.WorkingDirectory = @"C:\Windows\System32\";
                //}

                //pro.StartInfo = psi;
                //pro.Start();
                //pro.WaitForExit();

                //Console.WriteLine("IIS is installed");
                //Console.WriteLine("PLEASE restart the computer once");
                //Thread.Sleep(5000);

                //try
                //{
                //    AutoDeploy.Program.SetupIIS();
                //    Console.WriteLine("Done. Press any key to close.");
                //}
                //catch (Exception ex)
                //{
                //    Console.WriteLine("Exception occurred:" + ex.Message);
                //}
                //Console.ReadLine();

                //                IisUtility.ApplicationHostConfigurationPath = @"C:\Windows\System32\inetsrv\config\applicationHost.config";
                //                Console.WriteLine(IisUtility.ApplicationHostConfigurationPath);
                //                if (IisUtility.VerifyWebSiteIsExist("TestWeb"))
                //                {
                //                    IisUtility.DeleteSite("TestWeb");
                //                Console.WriteLine("delete web site success");
                //                }
                //                if (!IisUtility.VerifyWebSiteIsExist("TestWeb"))
                //                {
                //                    IisUtility.CreateSite("TestWeb", "*:8001:localhost", @ConfigurationManager.AppSettings["WebPhysicalPath"], 650, 20, NetVersion.V4, 25, @"D:\Temp", LogFormat.W3c, LogExtFileFlags.BytesRecv | LogExtFileFlags.ClientIP | LogExtFileFlags.Cookie, LoggingRolloverPeriod.MaxSize, 50,);
                //                }
                //                Console.WriteLine("create web site success");

                #endregion

                //#region Window Service

                //                var serviceName = "TestWinService";
                //
                //                WindowServiceInstallUtility.InstallWinService(serviceName, @ConfigurationManager.AppSettings["WindowServiceProgramFullPath"],2);
                //
                //                WindowsServiceUtility.StartWinService(serviceName, 2);
                //
                //                WindowsServiceUtility.StopWinService(serviceName, 2);
                //
                //                WindowServiceUtility.ChangeServiceStartType(WindowServiceStartType.Automatic, serviceName);
                //
                //                WindowServiceUtility.StartService(serviceName, 2);

                //                WindowServiceUtility.UninstallService(serviceName, @ConfigurationManager.AppSettings["WindowServiceProgramFullPath"]);

                //#endregion

                //    var test = new List<ModelTest>
                //{
                //        new ModelTest {A = 1, B = "1"},
                //        new ModelTest {A = 2, B = "2"},
                //        new ModelTest {A = 3, B = "3"},
                //        new ModelTest {A = 4, B = "4"}
                //    };
                //    Console.WriteLine(new Version(1,0));
                //    test.Select(s => s.A = s.A + 1).ToList().ForEach(Console.WriteLine);
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                LogInfoWriter.GetInstance("DeploymentTest").Error(ex);
            }
            Console.WriteLine("end");
            Console.ReadKey();
        }