Exemple #1
0
        /// <summary>
        /// 检查是否更新
        /// </summary>
        protected async void _checkIsUpgrade()
        {
            try
            {
                //获取新版本
                HsLabelValue item = await getLastestIPAInfo();

                //取版本号
                HsVersion version = HsVersion.Parse(item.GetValueByLabel("Version"));

                string upgradeUri = item.GetValueByLabel("UpgradeURI");

                //检查版本最后一位,如果是奇数表明是一般更新,偶数表明是强制更新
                IPlatformExtension pe = DependencyService.Get <IPlatformExtension>();

                HsVersion currentVersion = HsVersion.Parse(pe.GetApplicationVersion());

                if (pe != null && version > currentVersion) //存在新版本
                {
                    if (version.Type == HsVersion.EType.Force)
                    {
                        await this.DisplayAlert($"发现新版本 {version},请立即更新", $"当前版本 {currentVersion}", "确定");

                        pe.OpenURL(upgradeUri);
                    }
                    else
                    {
                        if (await this.DisplayAlert($"发现新版本 {version},是否更新", $"当前版本 {currentVersion}", "是", "否"))
                        {
                            pe.OpenURL(upgradeUri);
                        }
                        else
                        {
                            this.onUpgradeComplete();
                        }
                    }
                }
                else
                {
                    this.onUpgradeComplete();
                }
            }
            catch (Exception e)
            {
                this.ShowError(e.Message);

                this.onUpgradeComplete();
            }
        }
Exemple #2
0
        public HsImage(Stream imageStream)
        {
            byte[] datas = new byte[imageStream.Length];

            imageStream.Seek(0, SeekOrigin.Begin);

            imageStream.Read(datas, 0, datas.Length);


            #region 获取图像大小

            IPlatformExtension platformExtension = DependencyService.Get <IPlatformExtension>(DependencyFetchTarget.GlobalInstance);



            Tuple <System.Drawing.Size, byte[]> imageData = platformExtension.ReduceImage(datas, 800);

            System.Drawing.Size size = imageData.Item1;
            datas = imageData.Item2;

            #endregion

            #region 记录元数据

            byte[] metabs = new byte[METALEN];

            using (MemoryStream ms = new MemoryStream(metabs))
            {
                //以小端方式记录元数据。
                using (BinaryWriter bw = new BinaryWriter(ms, Encoding.Unicode))
                {
                    bw.Write(ENDIAN_LITTLE); //记录第一位
                    bw.Write(JPG);           //记录2-5位
                    bw.Write(size.Width);    //记录6-9位
                    bw.Write(size.Height);   //记录10-13位
                }
            }

            #endregion

            _imageData = ImageSource.FromStream(() =>
            {
                return(new MemoryStream(datas));
            });

            _imageDataString = HsBase64.ToBase64(metabs.Concat(datas).ToArray());
        }
Exemple #3
0
        private async Task downloadAndOpen(HsFile item)
        {
            //如果文件存在与本地,则直接打开,否则先下载再打开。

            string[] cachePath = new string[] { "Cache", "Files" };

            string cachefilename = $"{item.FileHash}.{item.FileName}";

            IPlatformExtension pe = DependencyService.Get <IPlatformExtension>(DependencyFetchTarget.GlobalInstance);

            if (!pe.FileExist(cachefilename, cachePath)) //文件不存在需要下载
            {
                int index = 0;

                using (MemoryStream ms = new MemoryStream())
                {
                    while (true)
                    {
                        //下载文件...
                        HsLabelValue result = await GetWSUtil().GetSysFileSeg(GetLoginData().ProgressId, item.FileHash, index);

                        if (result == null) //文件读取完毕
                        {
                            break;
                        }

                        byte[] buffer = HsBase64.FromBase64ToBytes(result.GetValueByLabel("Data"));

                        //数据解压缩
                        buffer = HsZlib.DecompressData(buffer);

                        ms.Write(buffer, 0, buffer.Length);

                        index++;
                    }

                    byte[] fileData = ms.ToArray();

                    Debug.WriteLine(HsMD5.EncryptionMD5(fileData));

                    await pe.WriteFile(cachefilename, fileData, 2, cachePath);
                }

                await downloadAndOpen(item);
            }
            else
            {
                List <string> previewFiletypes = new List <string>()
                {
                    "DOC", "DOCX",
                    "XLS", "XLSX",
                    "PPT", "PPTX",
                    "PDF",
                    "TXT", "TEXT",
                    "JPG", "PNG"
                };

                if (previewFiletypes.Contains(item.FileType.ToUpper()))
                {
                    string url = pe.GetFileURL(cachefilename, cachePath);

                    if (!string.IsNullOrWhiteSpace(url))
                    {
                        Panel_PreviewFile panel = new Panel_PreviewFile();

                        panel.Source = new UrlWebViewSource()
                        {
                            Url = url
                        };

                        await Navigation.PushAsync(panel);
                    }
                }
                else
                {
                    pe.CallFile(cachefilename, cachePath);
                }
            }
        }
Exemple #4
0
        protected override async Task <string> update()
        {
            if (hasRretrieveAccount)
            {
                //获取账套信息
                string data = await((HsApp)Application.Current).WSUtil.Login(this.ucUserName.ControlValue, this.ucPassword.ControlValue, this.ucDb.ControlValue);

                //登录成功后将用户信息存入Application中,以便全局调用

                XElement xReturnData = XElement.Parse(data);

                ((HsApp)Application.Current).LoginData = new LoginData(
                    xReturnData.GetFirstElementValue("ProgressId"),
                    xReturnData.GetFirstElementValue("UserBh"),
                    xReturnData.GetFirstElementValue("UserName"),
                    xReturnData.GetFirstElementValue("DeptBh"),
                    xReturnData.GetFirstElementValue("DeptMc"),
                    xReturnData.GetFirstElementValue("RoleBhs"),
                    xReturnData.GetFirstElementValue("RoleMcs"));

                XElement xMenus = xReturnData.Element("Menus");

                //将登录信息存入本地
                try
                {
                    XElement xLastLogin = new XElement("Data");

                    xLastLogin.Add(new XElement("UserName", this.ucUserName.ControlValue));
                    xLastLogin.Add(new XElement("Password", this.ucIsSaved.Checked ? this.ucPassword.ControlValue : ""));
                    xLastLogin.Add(new XElement("Account", this.ucDb.ControlValue));
                    xLastLogin.Add(new XElement("IsSaved", this.ucIsSaved.Checked));

                    IPlatformExtension pe = DependencyService.Get <IPlatformExtension>(DependencyFetchTarget.GlobalInstance);

                    //await HsLocalStorageHelper.WriteAllText(LASTLOGINFILENAME, xLastLogin.ToString());
                    await pe.WriteTextFile(LASTLOGINFILENAME, xLastLogin.ToString());
                }
                catch (Exception ex)
                {
                    this.ShowError(ex.Message);
                }

                this.LoginSuccess?.Invoke(this, new HsEventArgs <XElement> {
                    Data = xMenus
                });

                return(null);
            }
            else
            {
                string data = await((HsApp)Application.Current).WSUtil.GetDbs();

                this.ucDb.Datas = data;

                this.hasRretrieveAccount = true;

                try
                {
                    IPlatformExtension pe = DependencyService.Get <IPlatformExtension>(DependencyFetchTarget.GlobalInstance);

                    //读入上次登录配置信息
                    //string lastData = await HsLocalStorageHelper.ReadAllText(LASTLOGINFILENAME, "");
                    string lastData = await pe.ReadTextFile(LASTLOGINFILENAME);

                    if (!string.IsNullOrWhiteSpace(lastData))
                    {
                        XElement xLastLogin = XElement.Parse(lastData);
                        this.ucUserName.ControlValue = xLastLogin.GetFirstElementValue("UserName");
                        this.ucPassword.ControlValue = xLastLogin.GetFirstElementValue("Password");
                        this.ucDb.ControlValue       = xLastLogin.GetFirstElementValue("Account");
                        this.ucIsSaved.Checked       = bool.Parse(xLastLogin.GetFirstElementValue("IsSaved", false.ToString()));
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }

                return(null);
            }
        }
Exemple #5
0
        public override async Task GetItems()
        {
            try
            {
                this.isRetrieveing = true;

                if (string.IsNullOrWhiteSpace(Djlx))
                {
                    throw new HsException($"属性Djlx或未定义");
                }

                if (string.IsNullOrWhiteSpace(DjId))
                {
                    return;
                }

                //
                this.Reset();

                IPlatformExtension pe = DependencyService.Get <IPlatformExtension>(DependencyFetchTarget.GlobalInstance);

                string[] cachePath = new string[] { "Cache", "Images" };

                //获取图像哈希集合
                List <HsLabelValue> items = await GetWSUtil().GetSysImageHashDatas(GetLoginData().ProgressId, Djlx, DjId);

                //逐幅获取图像,如果存在本地缓存则使用本地图片。
                foreach (HsLabelValue item in items)
                {
                    //图片的Hash值
                    string hashData = item.GetValueByLabel("HashData");

                    string imageDataString = await pe.ReadTextFile(hashData, cachePath);

                    //本地缓存中不存在文件,则从网络中获取,并写入本地。
                    if (string.IsNullOrWhiteSpace(imageDataString))
                    {
                        string result = await GetWSUtil().GetSysImageById(GetLoginData().ProgressId, item.GetValueByLabel("ImageId"));

                        XElement xData = XElement.Parse(result);

                        imageDataString = xData.GetFirstElementValue("Data");

                        await pe.WriteTextFile(hashData, imageDataString, cachePath);
                    }

                    datas.Add(new HsImage(imageDataString)
                    {
                        HashData = hashData
                    });
                }

                hasRrtrieve = true;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                this.isRetrieveing = false;
            }
        }
Exemple #6
0
        protected override async void callAction(HsActionKey actionKey, object item)
        {
            try
            {
                if (actionKey == SysActionKeys.关闭)
                {
                    await PopupNavigation.PopAsync();
                }
                else if (actionKey == SysActionKeys.修改密码)
                {
                    callAction(SysActionKeys.关闭, null);

                    this.onPopupData(actionKey, null);
                }
                else if (actionKey == SysActionKeys.UserDo1)
                {
                    //清除缓存
                    long size = await HsDependencyService <IPlatformExtension> .Instance().DirectoryDelete("Cache");

                    await this.DisplayAlert("缓存删除成功。", size != 0?$"释放空间{size.GetFileSizeString()}" : "无缓存文件", "确定");

                    callAction(SysActionKeys.关闭, null);
                }
                else if (actionKey == SysActionKeys.UserDo2)
                {
                    //获取新版本
                    HsLabelValue lvVersion = await getLastestIPAInfo();

                    //取版本号
                    HsVersion version = HsVersion.Parse(lvVersion.GetValueByLabel("Version"));

                    string upgradeUri = lvVersion.GetValueByLabel("UpgradeURI");

                    //检查版本最后一位,如果是奇数表明是一般更新,偶数表明是强制更新
                    IPlatformExtension pe = DependencyService.Get <IPlatformExtension>();

                    HsVersion currentVersion = HsVersion.Parse(pe.GetApplicationVersion());

                    if (pe != null && version > currentVersion)                     //存在新版本
                    {
                        if (version.Type == HsVersion.EType.Force)
                        {
                            await this.DisplayAlert($"发现新版本 {version},请立即更新", $"当前版本 {currentVersion}", "确定");

                            pe.OpenURL(upgradeUri);
                        }
                        else
                        {
                            if (await this.DisplayAlert($"发现新版本 {version},是否更新", $"当前版本 {currentVersion}", "是", "否"))
                            {
                                pe.OpenURL(upgradeUri);
                            }
                        }
                    }
                    else
                    {
                        await this.DisplayAlert("当前是最新版本", $"当前版本 {currentVersion}", "确定");
                    }

                    callAction(SysActionKeys.关闭, null);
                }
                else if (actionKey == SysActionKeys.注销)
                {
                    //注销
                    if (await this.DisplayAlert("是否要注销?", "", "是", "否"))
                    {
                        this.onPopupData(actionKey, null);

                        callAction(SysActionKeys.关闭, null);
                    }
                }
            }
            catch (Exception ex)
            {
                this.ShowError(ex.Message);
            }
        }