Пример #1
0
        private async void But_dlartifact_Click(object sender, EventArgs e)
        {
            var perm = (JToken)cmb_applications.SelectedValue;

            var id = perm["id"].Value <string>();

            var xmlfile = await digitalSky.GetPermissionArtifact(id).ConfigureAwait(false);

            var artifactdir = Settings.GetDataDirectory() + Path.DirectorySeparatorChar + "DigitalSkyArtifact";

            if (!Directory.Exists(artifactdir))
            {
                Directory.CreateDirectory(artifactdir);
            }

            var destlocalfile = artifactdir + Path.DirectorySeparatorChar + id + ".xml";

            File.WriteAllText(destlocalfile, xmlfile);

            MAVFtp ftp = new MAVFtp(MainV2.comPort, (byte)MainV2.comPort.sysidcurrent,
                                    (byte)MainV2.comPort.compidcurrent);

            ftp.UploadFile(id + ".xml", destlocalfile, null);

            ftp = null;
        }
Пример #2
0
        private async void DownloadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem listView1SelectedItem in listView1.SelectedItems)
            {
                toolStripStatusLabel1.Text = "Download " + listView1SelectedItem.Text;
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.FileName         = listView1SelectedItem.Text;
                sfd.RestoreDirectory = true;
                sfd.OverwritePrompt  = true;
                var dr = sfd.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    var path = treeView1.SelectedNode.FullPath + "/" + listView1SelectedItem.Text;
                    ProgressReporterDialogue prd    = new ProgressReporterDialogue();
                    CancellationTokenSource  cancel = new CancellationTokenSource();
                    prd.doWorkArgs.CancelRequestChanged += (o, args) =>
                    {
                        prd.doWorkArgs.ErrorMessage = "User Cancel";
                        cancel.Cancel();
                        _mavftp.kCmdResetSessions();
                    };
                    prd.doWorkArgs.ForceExit = false;
                    Action <string, int> progress = delegate(string message, int i)
                    {
                        prd.UpdateProgressAndStatus(i, toolStripStatusLabel1.Text);
                    };
                    _mavftp.Progress += progress;

                    prd.DoWork += (iprd) =>
                    {
                        var ms = _mavftp.GetFile(path, cancel, false);
                        if (cancel.IsCancellationRequested)
                        {
                            iprd.doWorkArgs.CancelAcknowledged = true;
                            iprd.doWorkArgs.CancelRequested    = true;
                            return;
                        }

                        File.WriteAllBytes(sfd.FileName, ms.ToArray());

                        prd.UpdateProgressAndStatus(-1, "Calc CRC");
                        uint crc = 0;
                        _mavftp.kCmdCalcFileCRC32(path, ref crc, cancel);
                        var crc32a = MAVFtp.crc_crc32(0, File.ReadAllBytes(sfd.FileName));
                        if (crc32a != crc)
                        {
                            throw new BadCrcException();
                        }
                    };
                    prd.RunBackgroundOperationAsync();
                    _mavftp.Progress -= progress;
                }
                else if (dr == DialogResult.Cancel)
                {
                    return;
                }
            }

            toolStripStatusLabel1.Text = "Ready";
        }
Пример #3
0
        //handle_command_int_packet
        //MAV_CMD_SCRIPTING
        //SCRIPTING_CMD_REPL_START

        public AP_REPL(MAVLinkInterface mavint)
        {
            _mavint = mavint;
            _sysid  = _mavint.MAV.sysid;
            _compid = _mavint.MAV.compid;
            _mavftp = new MAVFtp(_mavint, _sysid, _compid);
        }
Пример #4
0
        public MavFTPUI(MAVLinkInterface mav)
        {
            _mav              = mav;
            _mavftp           = new MAVFtp(_mav, (byte)_mav.sysidcurrent, (byte)mav.compidcurrent);
            _mavftp.Progress += (message, percent) =>
            {
                if (toolStripProgressBar1.Value == percent)
                {
                    return;
                }

                if (this.IsDisposed)
                {
                    _mavftp = null;
                    return;
                }

                this.BeginInvokeIfRequired(() =>
                {
                    toolStripProgressBar1.Value = percent;
                    toolStripStatusLabel1.Text  = message;
                    statusStrip1.Refresh();
                });
            };
            InitializeComponent();

            ThemeManager.ApplyThemeTo(this);

            treeView1.PathSeparator = "/";
        }
Пример #5
0
        public MavFTPUI(MAVLinkInterface mav)
        {
            _mav              = mav;
            _mavftp           = new MAVFtp(_mav, (byte)_mav.sysidcurrent, (byte)mav.compidcurrent);
            _mavftp.Progress += (percent) =>
            {
                this.BeginInvokeIfRequired(() => { toolStripProgressBar1.Value = percent; statusStrip1.Refresh(); });
            };
            InitializeComponent();

            ThemeManager.ApplyThemeTo(this);

            treeView1.PathSeparator = "/";
        }
Пример #6
0
        private void but_td_Click(object sender, EventArgs e)
        {
            string path = "@SYS/threads.txt";

            if (InputBox.Show("path", "path", ref path) == DialogResult.OK)
            {
                if (MainV2.comPort.BaseStream.IsOpen)
                {
                    var mavftp = new MAVFtp(MainV2.comPort, (byte)MainV2.comPort.sysidcurrent,
                                            (byte)MainV2.comPort.compidcurrent);
                    var st     = mavftp.GetFile(path, new CancellationTokenSource(5000), true);
                    var output = Path.Combine(Settings.GetUserDataDirectory(), Path.GetFileName(path));
                    File.WriteAllBytes(output, st.GetBuffer());
                }
            }
        }
Пример #7
0
        private async Task UploadFile(string ofdFileName)
        {
            toolStripStatusLabel1.Text = "Upload " + Path.GetFileName(ofdFileName);
            var fn = treeView1.SelectedNode.FullPath + "/" + Path.GetFileName(ofdFileName);
            ProgressReporterDialogue prd    = new ProgressReporterDialogue();
            CancellationTokenSource  cancel = new CancellationTokenSource();

            prd.doWorkArgs.CancelRequestChanged += (o, args) =>
            {
                prd.doWorkArgs.ErrorMessage = "User Cancel";
                cancel.Cancel();
                _mavftp.kCmdResetSessions();
            };
            prd.doWorkArgs.ForceExit = false;

            Action <string, int> progress = delegate(string message, int i)
            {
                prd.UpdateProgressAndStatus(i, toolStripStatusLabel1.Text);
            };

            _mavftp.Progress += progress;

            prd.DoWork += (iprd) =>
            {
                _mavftp.UploadFile(fn, ofdFileName, cancel);
                if (cancel.IsCancellationRequested)
                {
                    iprd.doWorkArgs.CancelAcknowledged = true;
                    iprd.doWorkArgs.CancelRequested    = true;
                    return;
                }

                prd.UpdateProgressAndStatus(-1, "Calc CRC");
                uint crc = 0;
                _mavftp.kCmdCalcFileCRC32(fn, ref crc, cancel);
                var crc32a = MAVFtp.crc_crc32(0, File.ReadAllBytes(ofdFileName));
                if (crc32a != crc)
                {
                    throw new BadCrcException();
                }
            };
            prd.RunBackgroundOperationAsync();
            _mavftp.Progress          -= progress;
            toolStripStatusLabel1.Text = "Ready";
        }
Пример #8
0
 public DirectoryInfo(string dir, MAVFtp mavftp)
 {
     _mavftp  = mavftp;
     FullPath = dir;
 }