示例#1
0
        private async void Btn_download_Click(object sender, RoutedEventArgs e)
        {//download
            try
            {
                HelpClass.StartAwait(grid_main);

                HelpClass.validateWindow(requiredControlList, this);
                if (cb_type.SelectedIndex != -1)
                {
                    //string activeState = "rn";//rn OR up  from buton
                    string activeState = cb_type.SelectedValue.ToString();

                    PackageUser pumodel = new PackageUser();
                    ReportCls   rc      = new ReportCls();
                    SendDetail  sd      = new SendDetail();
                    sd = await pumodel.ActivateServerOffline(packageUser.packageUserId, activeState);

                    packagesSend packtemp = new packagesSend();
                    if (sd.packageSend.result > 0)
                    {
                        //encode
                        string myContent = JsonConvert.SerializeObject(sd);

                        saveFileDialog.Filter = "File|*.ac;";
                        if (saveFileDialog.ShowDialog() == true)
                        {
                            string DestPath = saveFileDialog.FileName;

                            bool res = false;

                            res = rc.encodestring(myContent, DestPath);
                            // rc.DelFile(pdfpath);
                            //  rc.decodefile(DestPath,@"D:\stringlist.txt");
                            if (res)
                            {
                                //done
                                Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopSave"), animation: ToasterAnimation.FadeIn);
                            }
                            else
                            {
                                Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn);
                            }
                        }
                    }
                    else
                    {
                        //error
                        Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn);
                    }

                    HelpClass.EndAwait(grid_main);
                }
            }
            catch (Exception ex)
            {
                HelpClass.EndAwait(grid_main);
                HelpClass.ExceptionMessage(ex, this);
            }
        }
        private async void Btn_upgrade_Click(object sender, RoutedEventArgs e)
        {                                                       //upgrade
            int    chk           = 0;
            string activationkey = progDetails.packageSaleCode; //get from info

            if (progDetails.isOnlineServer.Value)               //online
            {
                try
                {
                    if (activationkey.Trim() != "".Trim())
                    {
                        AvtivateServer ac = new AvtivateServer();

                        chk = await ac.checkconn();

                        chk = await ac.StatSendserverkey(activationkey, "up");

                        // //change      chk = 3;
                        //nochange     chk = 2;

                        if (chk <= 0)
                        {
                            string message = "inc(" + chk + ")";

                            string messagecode = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(message));

                            string msg = MainWindow.resourcemanager.GetString("trUpgradeNotCompleted") + "(" +
                                         MainWindow.resourcemanager.GetString("trErrorCode") + ":" + messagecode + ")";

                            Toaster.ShowWarning(Window.GetWindow(this), message: msg, animation: ToasterAnimation.FadeIn);
                        }

                        else
                        {
                            if (chk == 3)
                            {
                                Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trUpgradeCompleted"), animation: ToasterAnimation.FadeIn);
                                progDetails = await progDetailsModel.getCurrentInfo();

                                this.DataContext = progDetails;
                            }
                            else if (chk == 2)
                            {
                                Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trNoChanges"), animation: ToasterAnimation.FadeIn);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trServerNotFount"), animation: ToasterAnimation.FadeIn);
                }
            }
            else//offline
            {
                // start activate

                chk = 0;
                string message = "";
                try
                {
                    bool           isServerActivated = true;
                    AvtivateServer ac          = new AvtivateServer();
                    string         activeState = "up";
                    int            activematch = 0;

                    string filepath = "";
                    openFileDialog.Filter = "INC|*.ac; ";
                    SendDetail customerdata = new SendDetail();
                    SendDetail dc           = new SendDetail();
                    if (openFileDialog.ShowDialog() == true)
                    {
                        filepath = openFileDialog.FileName;

                        //   bool resr = ReportCls.decodefile(filepath, @"D:\stringlist.txt");//comment

                        string objectstr = "";

                        objectstr = ReportCls.decodetoString(filepath);

                        dc = JsonConvert.DeserializeObject <SendDetail>(objectstr, new JsonSerializerSettings {
                            DateParseHandling = DateParseHandling.None
                        });
                        packagesSend pss = new packagesSend();

                        pss = dc.packageSend;
                        isServerActivated = dc.packageSend.isServerActivated;
                        pss.activeApp     = "-";

                        dc.packageSend = pss;

                        // string activeState = "";
                        if (dc.packageSend.activeState == activeState)
                        {
                            activematch  = 1;
                            customerdata = await ac.OfflineActivate(dc, activeState);
                        }
                        else
                        {
                            Toaster.ShowWarning(Window.GetWindow(this), message: "The file isn't upgrade file", animation: ToasterAnimation.FadeIn);
                        }
                    }

                    // upload

                    if (activematch == 1)
                    {
                        if (customerdata.packageSend.result > 0)
                        {
                            // if first activate OR upgrade  show save dialoge to save customer data in file
                            saveFileDialog.Filter = "File|*.ac;";
                            if (saveFileDialog.ShowDialog() == true)
                            {
                                string DestPath = saveFileDialog.FileName;

                                string myContent = JsonConvert.SerializeObject(customerdata);

                                bool res = false;

                                res = ReportCls.encodestring(myContent, DestPath);

                                if (res)
                                {
                                    //     //done
                                    //   MessageBox.Show("Success");
                                    Toaster.ShowSuccess(Window.GetWindow(this), message: "Success", animation: ToasterAnimation.FadeIn);
                                }
                                else
                                {
                                    Toaster.ShowWarning(Window.GetWindow(this), message: "Error", animation: ToasterAnimation.FadeIn);
                                    //   MessageBox.Show("Error");
                                }
                            }
                        }
                        else
                        {
                            //   MessageBox.Show(customerdata.packageSend.result.ToString());
                            string msg = "NOT complete - " + customerdata.packageSend.result.ToString();
                            Toaster.ShowWarning(Window.GetWindow(this), msg, animation: ToasterAnimation.FadeIn);
                        }
                    }
                    else
                    {
                        //close
                    }

                    //end uploaa
                }
                catch (Exception ex)
                {
                    Toaster.ShowWarning(Window.GetWindow(this), message: "The server Not Found", animation: ToasterAnimation.FadeIn);
                }


                //end activate
            }
        }
        private async void Btn_upload_Click(object sender, RoutedEventArgs e)
        {
            //upload
            bool ress = AvtivateServer.validateUrl(tb_serverUri.Text);

            if (ress)
            {
                //int chk = await ac.checkconn();
                try
                {
                    validateEmptyTextBox(tb_serverUri, p_errorServerUri, tt_errorServerUri, "trEmptyError");
                    if (!tb_serverUri.Text.Equals(""))
                    {
                        // start activate
                        string t = Global.APIUri;//temp delete


                        string message = "";
                        try
                        {
                            if (tb_serverUri.Text.Trim() != "".Trim())
                            {
                                bool           isServerActivated = true;
                                AvtivateServer ac = new AvtivateServer();
                                Global.APIUri = tb_serverUri.Text + @"/api/";

                                string filepath = "";
                                openFileDialog.Filter = "INC|*.ac; ";
                                SendDetail customerdata = new SendDetail();
                                SendDetail dc           = new SendDetail();
                                if (openFileDialog.ShowDialog() == true)
                                {
                                    filepath = openFileDialog.FileName;

                                    //   bool resr = ReportCls.decodefile(filepath, @"D:\stringlist.txt");//comment

                                    string objectstr = "";

                                    objectstr = ReportCls.decodetoString(filepath);

                                    dc = JsonConvert.DeserializeObject <SendDetail>(objectstr, new JsonSerializerSettings {
                                        DateParseHandling = DateParseHandling.None
                                    });
                                    packagesSend pss = new packagesSend();

                                    pss = dc.packageSend;
                                    isServerActivated = dc.packageSend.isServerActivated;
                                    pss.activeApp     = "all";//no comment

                                    dc.packageSend = pss;

                                    // string activeState = "";
                                    customerdata = await ac.OfflineActivate(dc, "up");
                                }
                                // upload

                                if (customerdata.packageSend.result > 0)
                                {
                                    if (isServerActivated == false || (isServerActivated == true && dc.packageSend.activeState == "up"))
                                    {
                                        // if first activate OR upgrade  show save dialoge to save customer data in file
                                        saveFileDialog.Filter = "File|*.ac;";
                                        if (saveFileDialog.ShowDialog() == true)
                                        {
                                            string DestPath = saveFileDialog.FileName;

                                            string myContent = JsonConvert.SerializeObject(customerdata);

                                            bool res = false;

                                            res = ReportCls.encodestring(myContent, DestPath);

                                            if (res)
                                            {
                                                //     //done
                                                //   MessageBox.Show("Success");
                                                Toaster.ShowSuccess(Window.GetWindow(this), message: "Success", animation: ToasterAnimation.FadeIn);
                                            }
                                            else
                                            {
                                                Toaster.ShowWarning(Window.GetWindow(this), message: "Error", animation: ToasterAnimation.FadeIn);
                                                //   MessageBox.Show("Error");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // if extend show extend result
                                        //renew no save

                                        Toaster.ShowSuccess(Window.GetWindow(this), message: "Success Extend", animation: ToasterAnimation.FadeIn);
                                    }
                                }
                                else
                                {
                                    //MessageBox.Show(customerdata.packageSend.result.ToString());
                                    Toaster.ShowWarning(Window.GetWindow(this), message: "Error-" + customerdata.packageSend.result.ToString(), animation: ToasterAnimation.FadeIn);
                                }
                                //end uploaa
                            }
                        }
                        catch (Exception ex)
                        {
                            Global.APIUri = t;//temp delete
                            Toaster.ShowWarning(Window.GetWindow(this), message: "The server Not Found", animation: ToasterAnimation.FadeIn);
                        }


                        //end activate

                        await Task.Delay(2000);

                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    Toaster.ShowWarning(Window.GetWindow(this), message: "The server Not Found", animation: ToasterAnimation.FadeIn);
                }
            }
            else
            {
                Toaster.ShowWarning(Window.GetWindow(this), message: "The server Not Found", animation: ToasterAnimation.FadeIn);
            }
        }