private void ValidateRemoteAddress(ClientParameter clientParameter)
        {
            if (clientParameter == null)
            {
                throw new NullReferenceException("Client parameter not set.");
            }

            if (string.IsNullOrEmpty(clientParameter.ClientVersion))
            {
                throw new NullReferenceException("Client version not set.");
            }

            if (string.IsNullOrEmpty(clientParameter.LastVersion))
            {
                throw new NullReferenceException("Last version not set.");
            }

            if (string.IsNullOrEmpty(clientParameter.InstallPath))
            {
                throw new NullReferenceException("Install path not set.");
            }

            if (string.IsNullOrEmpty(clientParameter.AppName))
            {
                throw new NullReferenceException("Main app name not set.");
            }

            if (clientParameter.UpdateVersions == null || clientParameter.UpdateVersions.Count == 0)
            {
                throw new NullReferenceException("Update versions not set.");
            }
        }
Exemplo n.º 2
0
 private void ResolveQuestionFromRouting(ref IExecutionResult executionResult, ref IExecuteRequest executeRequest)
 {
     try
     {
         var missingParameters = executionResult.Questions?.Parameters;
         var type = executionResult.Questions?.Parameters.Select(p => p.Type);
         foreach (var missingParameter in missingParameters)
         {
             var missingParameterName = missingParameter.Name;
             var missingParameterType = missingParameter.Type;
             if (MissingParameterHasRouting(missingParameterName))
             {
                 var value = Task.Run(async() => await _routingController.GetParameterValue(missingParameterName)).Result;
                 if (value == null)
                 {
                     continue;
                 }
                 var parameter = new ClientParameter(missingParameterName, value, missingParameterType, missingParameterName);
                 executeRequest.Parameters.Add(parameter);
                 executionResult = Execute(executeRequest);
             }
         }
     }
     catch
     {
         return;
     }
 }
 /// <summary>
 /// Set parameter.
 /// </summary>
 /// <param name="clientParameter">ClientParameter object to base64 string.</param>
 /// <returns></returns>
 public GeneralUpdateBootstrap RemoteAddressBase64(string clientParameter)
 {
     try
     {
         ClientParameter = SerializeUtil.Deserialize <ClientParameter>(clientParameter);
         ValidateRemoteAddress(ClientParameter);
         InitPacket();
     }
     catch (Exception ex)
     {
         throw new Exception($"Client parameter json conversion failed, please check whether the parameter content is legal : { ex.Message },{ ex.StackTrace }.");
     }
     return(this);
 }
Exemplo n.º 4
0
 public GeneralClientBootstrap Config(ClientParameter clientParameter)
 {
     ValidateConfig(clientParameter);
     Packet.ClientVersion   = clientParameter.ClientVersion;
     Packet.AppType         = clientParameter.AppType;
     Packet.ValidateUrl     = clientParameter.ValidateUrl;
     Packet.UpdateUrl       = clientParameter.UpdateUrl;
     Packet.MainValidateUrl = clientParameter.MainValidateUrl;
     Packet.MainUpdateUrl   = clientParameter.MainUpdateUrl;
     Packet.AppName         = clientParameter.AppName;
     Packet.MainAppName     = clientParameter.MainAppName;
     Packet.InstallPath     = clientParameter.InstallPath;
     Packet.UpdateLogUrl    = clientParameter.UpdateLogUrl;
     Packet.IsUpdate        = clientParameter.IsUpdate;
     return(this);
 }
Exemplo n.º 5
0
        private void ResolveQuestionFromRouting(ref IExecutionResult executionResult, ref IExecuteRequest executeRequest)
        {
            var missingParameterName = executionResult.QuestionFirstParameter?.Name;

            if (MissingParameterHasRouting(missingParameterName))
            {
                var value = _routingController.GetParameterValue(missingParameterName);
                if (value == null)
                {
                    return;
                }
                //var parameter = new RoutingParameter(missingParameterName, value);
                var parameter = new ClientParameter(missingParameterName, value, TypeInference.InferenceResult.TypeEnum.Unknown, missingParameterName);
                executeRequest.Parameters.Add(parameter);
                executionResult = Execute(executeRequest);
            }
        }
Exemplo n.º 6
0
        private void ValidateConfig(ClientParameter clientParameter)
        {
            if (clientParameter == null)
            {
                throw new NullReferenceException("Client parameter not set.");
            }

            if (string.IsNullOrEmpty(clientParameter.ClientVersion))
            {
                throw new NullReferenceException("Client version not set.");
            }

            if (string.IsNullOrEmpty(clientParameter.InstallPath))
            {
                throw new NullReferenceException("Install path not set.");
            }

            if (string.IsNullOrEmpty(clientParameter.UpdateUrl))
            {
                throw new NullReferenceException("Update url not set.");
            }
            else if (!DataValidateUtil.IsURL(clientParameter.UpdateUrl))
            {
                throw new Exception("Illegal url address.");
            }

            if (string.IsNullOrEmpty(clientParameter.ValidateUrl))
            {
                throw new NullReferenceException("Update url not set.");
            }
            else if (!DataValidateUtil.IsURL(clientParameter.ValidateUrl))
            {
                throw new Exception("Illegal url address.");
            }

            if (string.IsNullOrEmpty(clientParameter.AppName))
            {
                throw new NullReferenceException("Main app name not set.");
            }
        }
Exemplo n.º 7
0
 protected override bool StartApp(string appName)
 {
     try
     {
         Task.Run(async() =>
         {
             var respDTO = await HttpUtil.GetTaskAsync <UpdateValidateRespDTO>(Packet.MainValidateUrl);
             if (respDTO.Code == 200)
             {
                 var body = respDTO.Body;
                 try
                 {
                     //Request updated information for the main application.
                     var clientParameter              = new ClientParameter();
                     clientParameter.ClientVersion    = Packet.ClientVersion;
                     clientParameter.LastVersion      = Packet.LastVersion;
                     clientParameter.InstallPath      = Packet.InstallPath;
                     clientParameter.UpdateLogUrl     = Packet.UpdateLogUrl;
                     clientParameter.MainValidateUrl  = Packet.MainValidateUrl;
                     clientParameter.MainUpdateUrl    = Packet.MainUpdateUrl;
                     clientParameter.AppName          = Packet.MainAppName;
                     clientParameter.AppType          = 1;
                     clientParameter.CompressEncoding = ConvertUtil.ToEncodingType(Packet.Encoding);
                     clientParameter.CompressFormat   = Packet.Format;
                     clientParameter.DownloadTimeOut  = Packet.DownloadTimeOut;
                     clientParameter.UpdateVersions   = ConvertUtil.ToUpdateVersions(body.UpdateVersions);
                     var clientParameterBase64        = SerializeUtil.Serialize(clientParameter);
                     if (!string.IsNullOrEmpty(Packet.UpdateLogUrl))
                     {
                         Process.Start("explorer.exe", Packet.UpdateLogUrl);
                     }
                     Process.Start($"{Packet.InstallPath}\\{appName}.exe", clientParameterBase64);
                     Process.GetCurrentProcess().Kill();
                 }
                 catch (Exception ex)
                 {
                     if (ExceptionEventAction != null)
                     {
                         ExceptionEventAction(this, new ExceptionEventArgs(ex));
                     }
                 }
             }
             else
             {
                 if (ExceptionEventAction != null)
                 {
                     ExceptionEventAction(this,
                                          new ExceptionEventArgs(new System.Exception($"{ respDTO.Code }{ respDTO.Message }")));
                 }
             }
         });
         return(true);
     }
     catch (Exception ex)
     {
         if (ExceptionEventAction != null)
         {
             ExceptionEventAction(this, new ExceptionEventArgs(ex));
         }
         return(false);
     }
 }
Exemplo n.º 8
0
        private void BtnClientTest_Click(object sender, RoutedEventArgs e)
        {
            Task.Run(async() =>
            {
                //主程序信息
                var mainVersion = "1.1.1.1";

                //该对象用于主程序客户端与更新组件进程之间交互用的对象
                clientParameter = new ClientParameter();

                //本机的客户端程序应用地址
                clientParameter.InstallPath = @"D:\Updatetest_hub\Run_app";
                //更新公告网页
                //clientParameter.UpdateLogUrl = "https://www.baidu.com/";

                #region update app.

                clientParameter.ClientVersion = "1.1.1.1";

                //客户端类型:1.主程序客户端 2.更新组件
                clientParameter.AppType = (int)AppType.UpdateApp;
                //更新组件请求验证更新的服务端地址
                clientParameter.ValidateUrl = $"{baseUrl}/validate/{ clientParameter.AppType }/{ clientParameter.ClientVersion }";
                //更新组件更新包下载地址
                clientParameter.UpdateUrl = $"{baseUrl}/versions/{ clientParameter.AppType }/{ clientParameter.ClientVersion }";
                //更新程序exe名称
                clientParameter.AppName = "AutoUpdate.Core";

                #endregion update app.

                #region main app.

                //更新组件的版本号
                clientParameter.ClientVersion = "1.1.1";
                //主程序客户端exe名称
                clientParameter.MainAppName = "AutoUpdate.ClientCore";
                //主程序客户端请求验证更新的服务端地址
                clientParameter.MainValidateUrl = $"{baseUrl}/validate/{ (int)AppType.ClientApp }/{ mainVersion }";
                //主程序客户端更新包下载地址
                clientParameter.MainUpdateUrl = $"{baseUrl}/versions/{ (int)AppType.ClientApp }/{ mainVersion }";

                #endregion main app.

                var generalClientBootstrap = new GeneralClientBootstrap();
                //单个或多个更新包下载通知事件
                generalClientBootstrap.MutiDownloadProgressChanged += OnMutiDownloadProgressChanged;
                //单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
                generalClientBootstrap.MutiDownloadStatistics += OnMutiDownloadStatistics;
                //单个或多个更新包下载完成
                generalClientBootstrap.MutiDownloadCompleted += OnMutiDownloadCompleted;
                //完成所有的下载任务通知
                generalClientBootstrap.MutiAllDownloadCompleted += OnMutiAllDownloadCompleted;
                //下载过程出现的异常通知
                generalClientBootstrap.MutiDownloadError += OnMutiDownloadError;
                //整个更新过程出现的任何问题都会通过这个事件通知
                generalClientBootstrap.Exception += OnException;
                //ClientStrategy该更新策略将完成1.自动升级组件自更新 2.启动更新组件 3.配置好ClientParameter无需再像之前的版本写args数组进程通讯了。
                //generalClientBootstrap.Config(clientParameter).
                generalClientBootstrap.Config(baseUrl).
                Option(UpdateOption.DownloadTimeOut, 60).
                Option(UpdateOption.Encoding, Encoding.Default).
                Option(UpdateOption.Format, "zip").
                //注入一个func让用户决定是否跳过本次更新,如果是强制更新则不生效
                SetCustomOption(ShowCustomOption).
                Strategy <ClientStrategy>();
                await generalClientBootstrap.LaunchTaskAsync();
            });
        }