예제 #1
0
        public Response UpdateService(ServiceUpdate service)
        {
            var result = RunInsertJson(service.images);

            if (result.valid)
            {
                var procedure = "sp_service_update";
                using (var conn = new MySqlConnection(_connectionString))
                {
                    try
                    {
                        conn.Open();
                        var param = new DynamicParameters();
                        param.Add("INid", service.id);
                        param.Add("INname", service.name);
                        param.Add("INdescription", service.description);
                        param.Add("INcontent", service.content);
                        param.Add("INurl", service.url);
                        param.Add("INserviceTypeId", service.serviceTypeId);
                        var data = conn.QueryFirstOrDefault <Response>(procedure, param, commandType: System.Data.CommandType.StoredProcedure);
                        return(data);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        public async void EditService()
        {
            Value = true;
            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Warning,
                    Languages.CheckConnection,
                    Languages.Ok);

                return;
            }
            if (string.IsNullOrEmpty(Ambulatory.code) || string.IsNullOrEmpty(Ambulatory.description))
            {
                Value = true;
                return;
            }
            var _ambulatory = new Ambulatory
            {
                id          = Service.ambulatory.id,
                code        = Service.ambulatory.code,
                description = Service.ambulatory.description,
                zipCode     = Service.ambulatory.zipCode,
                domicile    = Service.ambulatory.domicile,
                residence   = Service.ambulatory.residence,
                phone       = Service.ambulatory.phone,
                tvaCode     = Service.ambulatory.tvaCode
            };
            var _service = new ServiceUpdate
            {
                ambulatory   = _ambulatory,
                usresWrapper = Service.usresWrapper
            };
            var cookie = Settings.Cookie;  //.Split(11, 33)
            var res    = cookie.Substring(11, 32);

            var response = await apiService.Put <ServiceUpdate>(
                "https://portalesp.smart-path.it",
                "/Portalesp",
                "/ambulatory/update",
                res,
                _service);

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok");

                return;
            }
            Value = false;
            ServiceViewModel.GetInstance().Update(_ambulatory);
            MessagingCenter.Send((App)Application.Current, "OnSaved");
            DependencyService.Get <INotification>().CreateNotification("PortalSP", "Service Updated");
            await App.Current.MainPage.Navigation.PopPopupAsync(true);
        }
        public IActionResult UpdateService([FromBody] ServiceUpdate service)
        {
            if (!Request.Headers.ContainsKey("Authorization"))
            {
                return(Unauthorized());
            }
            var data = _alphahomeService.UpdateService(service);

            if (data.valid)
            {
                return(new JsonResult(data));
            }
            return(BadRequest(data));
        }
예제 #4
0
        public CheckUpdateModel()
        {
            ZipHelper.ExtractProgress += ZipHelper_ExtractProgress;
            FileHelper.CopyProgress   += FileHelper_CopyProgress;

            if (!System.IO.File.Exists(CommonPath.ClientUpdate.CombineCurrentDirectory()))
            {
                LogManager.Logger.Warn($"没有找到 {CommonPath.ClientUpdate.CombineCurrentDirectory()}");
                return;
            }

            // 获取本地版本
            CacheManager.Instance.Version = CommonPath.ClientUpdate.LoadFromXml <ClientUpdate>();

            // 获取服务端版本
            var path = CacheManager.Instance.Version.URL + CacheManager.Instance.Version.Path;

            try
            {
                WebClientPro client      = new WebClientPro();
                string       serviceInfo = Encoding.UTF8.GetString(client.DownloadData(path));
                _serviceUpdate = serviceInfo.XmlDeserailize <ServiceUpdate>();

                var localVersion   = $"{CacheManager.Instance.Version.Version}_{CacheManager.Instance.Version.VersionType}";
                var serviceVersoin = $"{_serviceUpdate.Version}_{_serviceUpdate.VersionType}";

                this.Message = $"发现最新版本:{serviceVersoin},升级?";

                StringBuilder strb = new StringBuilder();
                strb.AppendLine($"{serviceVersoin} 升级:");
                strb.Append(_serviceUpdate.Conent);

                this.Content = strb.ToString();
            }
            catch (Exception ex)
            {
                LogManager.Logger.Warn($"下载版本信息失败:{ex.Message}");
            }
        }
        public MainWindowModel()
        {
            // 注册日志
            var logCfg = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config");

            XmlConfigurator.ConfigureAndWatch(logCfg);
            _logger = LogManager.GetLogger("ClientLog");

            ZipHelper.ExtractProgress += ZipHelper_ExtractProgress;

            try
            {
                Task.Run(() =>
                {
                    // 次数
                    int time = 0;
                    bool run = true;
                    do
                    {
                        KillMainProcess("Client");
                        Thread.Sleep(1000);

                        Process[] runApplications = Process.GetProcessesByName("Client");
                        if (runApplications.Length == 0)
                        {
                            run = false;
                        }

                        time += 1;
                        if (time == 5)
                        {
                            // 尝试5次以后就不继续尝试了。
                            run = false;
                        }
                    }while (run);

                    // 获取原始路径
                    if (File.Exists("source.info"))
                    {
                        try
                        {
                            _sourcePath = "source.info".FileDeSerialize() as string;
                            _logger.Info($"反序列化原始路径:{_sourcePath}");
                        }
                        catch (Exception ex)
                        {
                            _logger.Warn(ex.Message);
                            MessageBox.Show($"序列化失败:{ex.Message}");
                            return;
                        }

                        // 清除原始文件
                        var hasPath = Directory.Exists(_sourcePath);
                        if (hasPath)
                        {
                            _logger.Info($"清除原始文件");

                            var allFiles = Directory.GetFiles(_sourcePath);
                            var files    = allFiles?.Where(f => f.LastIndexOf("user.info") == -1);
                            if (files != null)
                            {
                                foreach (var f in files)
                                {
                                    File.Delete(f);
                                    _logger.Info($"正在删除文件:{f}");
                                }
                            }
                        }
                    }
                    else
                    {
                        _logger.Info("没有找到source.info");
                        MessageBox.Show("升级失败!由于网络等因素,关闭后从新升级!");
                        System.Environment.Exit(-5);
                        return;
                    }

                    _logger.Info($"获取服务端客户端配置文件");

                    // 获取服务端客户端配置文件
                    if (File.Exists(CommonPath.ServiceUpdate.CombineCurrentDirectory()))
                    {
                        _serviceInfo = CommonPath.ServiceUpdate.CombineCurrentDirectory().LoadFromXml <ServiceUpdate>();
                    }
                    // 获取本地客户端配置文件
                    if (File.Exists(CommonPath.ClientUpdate.CombineCurrentDirectory()))
                    {
                        _clientInfo = (CommonPath.ClientUpdate.CombineCurrentDirectory().LoadFromXml <ClientUpdate>());
                    }

                    _logger.Info($"解压文件到原始路径");

                    var erroMessage = string.Empty;
                    // 解压文件到原始路径
                    var success = ZipHelper.Decompress(_sourcePath, Path.Combine(Environment.CurrentDirectory, _serviceInfo.Path), out erroMessage);
                    if (!success)
                    {
                        _logger.Warn(erroMessage);
                        MessageBox.Show($"序列化失败:{erroMessage}");
                        System.Environment.Exit(-5);
                        return;
                    }

                    _logger.Info($"1.正在解压文件{_sourcePath} To {Path.Combine(Environment.CurrentDirectory, _serviceInfo.Path)}");

                    // 删除原始路径的ZIP文件
                    System.IO.File.Delete(Path.Combine(_sourcePath, _serviceInfo.Path));
                    _logger.Info($"删除下载的Zip文件;{Path.Combine(_sourcePath, _serviceInfo.Path)}");

                    _clientInfo.UpdateTime  = DateTime.Now;
                    _clientInfo.Version     = _serviceInfo.Version;
                    _clientInfo.VersionType = _serviceInfo.VersionType;
                    _clientInfo.Conent      = _serviceInfo.Conent;

                    try
                    {
                        // 更新客户端文件
                        Path.Combine(_sourcePath, "ClientUpdate.xml").SaveToXml <ClientUpdate>(_clientInfo);

                        // 设置更新路径
                        Path.Combine(_sourcePath, "target.info").FileSerialize(Environment.CurrentDirectory);
                    }
                    catch (Exception ex)
                    {
                        _logger.Info($"{ex.Message}");
                        MessageBox.Show("升级失败!由于网络等因素,关闭后从新升级!");
                        System.Environment.Exit(-5);
                    }

                    _logger.Info($"启动任务;{Path.Combine(_sourcePath, "Client.exe")}");

                    // 启动原始程序 Client
                    try
                    {
                        Process process                    = new Process();
                        process.StartInfo.FileName         = Path.Combine(_sourcePath, "Client.exe");
                        process.StartInfo.WorkingDirectory = _sourcePath;
                        process.Start();
                    }
                    catch (Exception ex)
                    {
                        _logger.Info($"启动任务失败:{ex.Message}");
                        MessageBox.Show("升级失败!由于网络等因素,关闭后从新升级!");
                        System.Environment.Exit(-5);
                    }

                    _logger.Info($"已经启动;{Path.Combine(_sourcePath, "Client.exe")}");

                    // 关闭当前程序
                    GalaSoft.MvvmLight.Threading.DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        System.Environment.Exit(-5);
                        _logger.Info($"关闭当前升级程序,升级成功.");
                    });
                });
            }
            catch (Exception ex)
            {
                _logger.Info(ex.Message);

                MessageBox.Show("升级失败!由于网络等因素,关闭后从新升级!");
                System.Environment.Exit(-5);
            }
        }
예제 #6
0
 public Response UpdateService(ServiceUpdate service)
 {
     return _alphahomeRepo.UpdateService(service);
 }