예제 #1
0
        //點擊卸載插件
        private async void Click_Uninstall(object sender, RoutedEventArgs e)
        {
            Button         btn         = (sender as Button);
            var            pluginType  = ((btn.Parent as StackPanel).Children[1] as Label).Content.ToString().Split(' ')[0];
            EnumPluginType content     = (EnumPluginType)Enum.Parse(typeof(EnumPluginType), pluginType);
            bool           needConfirm = false;

            foreach (var addr in Signer.Ins.addressPool.addresses)
            {
                if ((UInt16)addr.type == (UInt16)content)
                {
                    needConfirm = true;
                    break;
                }
            }
            if (needConfirm)
            {
                ND_MessageBoxResult nD_MessageBoxResult = await DialogueControl.ShowMessageBox("你有地址需要用到这个插件,是否确认卸载", ND_MessageBoxButton.OKCancel, 99999);

                if (nD_MessageBoxResult == ND_MessageBoxResult.OK)
                {
                    Result result = await ManagerControl.Ins.ToDo(EnumControl.UninstallPlugin, content);

                    GetPackageInfo();
                }
            }
        }
예제 #2
0
        //點擊安裝插件
        private async void Click_Install(object sender, RoutedEventArgs e)
        {
            Button btn        = (sender as Button);
            var    pluginType = ((btn.Parent as StackPanel).Children[1] as Label).Content.ToString().Split(' ')[0];
            var    version    = servicePackageInfo[pluginType].ToString();

            ForbidAllBtnClick();

            //安装按钮隐藏  等待按钮显示
            Image img = this.FindName(pluginType + "_gif_loading") as Image;

            img.Visibility = Visibility.Visible;
            btn.Visibility = Visibility.Hidden;

            EnumInstallType type    = EnumInstallType.Plugin;
            EnumPluginType  content = (EnumPluginType)Enum.Parse(typeof(EnumPluginType), pluginType);

            byte[] postdata;
            //从服务器获取固件或插件
            var url = HttpHelper.MakeRpcUrlPost("https://apiaggr.nel.group/api/testnet", "downloadplugin", out postdata, new MyJson.JsonNode_ValueString(pluginType + "_" + version));
            var res = await HttpHelper.HttpPost(url, postdata);

            var str_plugin = MyJson.Parse(res).AsDict()["result"].AsList()[0].AsDict()["plugin"].ToString();

            byte[] data = ThinNeo.Helper.HexString2Bytes(str_plugin);

            Result result = await ManagerControl.Ins.ToDo(EnumControl.InstallPlugin, data, type, content, version);

            GetPackageInfo();
            img.Visibility = Visibility.Hidden;
            btn.Visibility = Visibility.Visible;
            AllowAllBtnClick();
        }
예제 #3
0
        //更新固件
        public async void InstallFramework()
        {
            await Dispatcher.InvokeAsync(async() =>
            {
                ForbidAllBtnClick();

                //安装按钮隐藏  等待按钮显示
                gif_Framework_loading.Visibility = Visibility.Visible;
                Btn_Framework_update.Visibility  = Visibility.Hidden;

                var pluginType = this.label_FrameworkVersion.Content.ToString().Split(' ')[0];
                var version    = servicePackageInfo[pluginType].ToString();
                var language   = Mgr_Language.Ins.curEnumLanguage.ToString();

                byte[] postdata;
                //从服务器获取固件和插件的版本信息
                var url        = HttpHelper.MakeRpcUrlPost("https://apiaggr.nel.group/api/testnet", "downloadplugin", out postdata, new MyJson.JsonNode_ValueString(pluginType + "_" + version + "_" + language));
                var res        = await HttpHelper.HttpPost(url, postdata);
                var str_plugin = MyJson.Parse(res).AsDict()["result"].AsList()[0].AsDict()["plugin"].ToString();
                byte[] data    = ThinNeo.Helper.HexString2Bytes(str_plugin);


                EnumInstallType type   = EnumInstallType.Framework;
                EnumPluginType content = EnumPluginType.Unknow;

                Result result = await ManagerControl.Ins.ToDo(EnumControl.InstallFramework, data, type, content, version);
                gif_Framework_loading.Visibility = Visibility.Hidden;
                Btn_Framework_update.Visibility  = Visibility.Visible;

                AllowAllBtnClick();
            });
        }
예제 #4
0
        public async override Task <bool> SendMsg(params object[] _params)
        {
            try
            {
                byte[]          data         = (byte[])_params[0];
                EnumInstallType type         = (EnumInstallType)_params[1];
                EnumPluginType  content      = (EnumPluginType)_params[2];
                string          version      = ((string)_params[3]).Split('.')[0].PadLeft(2, '0') + ((string)_params[3]).Split('.')[1].PadRight(2, '0');
                byte[]          byte_version = ThinNeo.Helper.HexString2Bytes(version);

                var    hash     = NeoDun.SignTool.ComputeSHA256(data, 0, data.Length);
                string str_hash = NeoDun.SignTool.Bytes2HexString(hash, 0, hash.Length);
                int    num      = data.Length / (1024 * 50) + 1;

                List <UInt32> remoteids = new List <UInt32>();

                for (var i = 0; i < num; i++)
                {
                    byte[]           _data     = data.Skip(1024 * 50 * i).Take(1024 * 50).ToArray();
                    var              _hash     = NeoDun.SignTool.ComputeSHA256(_data, 0, _data.Length);
                    string           _str_hash = NeoDun.SignTool.Bytes2HexString(_hash, 0, _hash.Length);
                    NeoDun.DataBlock block     = signer.dataTable.newOrGet(_str_hash, (UInt32)_data.Length, NeoDun.DataBlockFrom.FromDriver);
                    block.data = _data;
                    signer.SendDataBlock(block);

                    var  __block  = signer.dataTable.getBlockBySha256(_str_hash);
                    uint remoteid = await __block.GetRemoteid();

                    if (remoteid == 0)
                    {
                        result.msgCode   = EnumMsgCode.InstallFailed;
                        result.errorCode = EnumErrorCode.IncorrectHash;
                    }
                    remoteids.Add((uint)remoteid);
                    __block.dataidRemote = 0;
                }
                NeoDun.Message signMsg = new NeoDun.Message();
                signMsg.tag1  = 0x03;
                signMsg.tag2  = 0x01;
                signMsg.msgid = NeoDun.SignTool.RandomShort();
                signMsg.writeUInt16(0, (UInt16)type);
                signMsg.writeUInt16(2, (UInt16)content);
                Array.Copy(hash, 0, signMsg.data, 4, hash.Length);
                signMsg.data[36] = byte_version[0];
                signMsg.data[37] = byte_version[1];
                for (var i = 0; i < remoteids.Count; i++)
                {
                    signMsg.writeUInt32(38, remoteids[i]);
                }

                signer.SendMessage(signMsg, true);
                return(true);
            }
            catch (Exception e)
            {
                result.msgCode   = EnumMsgCode.InstallFailed;
                result.errorCode = EnumErrorCode.IncorrectHash;
                return(false);
            }
        }
예제 #5
0
        public async override Task <bool> SendMsg(params object[] _params)
        {
            EnumPluginType enumPluginType = (EnumPluginType)_params[0];

            NeoDun.Message msg = new NeoDun.Message();
            msg.tag1  = 0x03;
            msg.tag2  = 0x03;
            msg.msgid = NeoDun.SignTool.RandomShort();
            msg.writeUInt16(0, (UInt16)enumPluginType);
            signer.SendMessage(msg, true);
            return(true);
        }