Esempio n. 1
0
        private async void myDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            // Ignore clicks that are not on button cells.
            if (e.RowIndex < 0 || e.ColumnIndex !=
                myDataGridView1.Columns["updateDataGridViewTextBoxColumn"].Index &&
                e.ColumnIndex != myDataGridView1.Columns["Parameter"].Index)
            {
                return;
            }

            byte nodeID = (byte)myDataGridView1[iDDataGridViewTextBoxColumn.Index, e.RowIndex].Value;

            if (e.ColumnIndex == myDataGridView1.Columns["Parameter"].Index)
            {
                IProgressReporterDialogue prd = new ProgressReporterDialogue();
                List <uavcan.uavcan_protocol_param_GetSet_res> paramlist =
                    new List <uavcan.uavcan_protocol_param_GetSet_res>();
                prd.DoWork += dialogue =>
                {
                    paramlist = can.GetParameters(nodeID);
                };
                prd.UpdateProgressAndStatus(-1, Strings.GettingParams);
                prd.RunBackgroundOperationAsync();

                new UAVCANParams(can, nodeID, paramlist).ShowUserControl();
            }
            else if (e.ColumnIndex == myDataGridView1.Columns["updateDataGridViewTextBoxColumn"].Index)
            {
                ProgressReporterDialogue    prd      = new ProgressReporterDialogue();
                uavcan.FileSendProgressArgs filesend = (id, file, percent) =>
                {
                    prd.UpdateProgressAndStatus((int)percent, id + " " + file);
                };
                can.FileSendProgress += filesend;
                if (CustomMessageBox.Show("Do you want to search the internet for an update?", "Update", CustomMessageBox.MessageBoxButtons.YesNo) == CustomMessageBox.DialogResult.Yes)
                {
                    var devicename = myDataGridView1[nameDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString();
                    var hwversion  = double.Parse(myDataGridView1[hardwareVersionDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(), CultureInfo.InvariantCulture);

                    var url = can.LookForUpdate(devicename, hwversion);

                    if (url != string.Empty)
                    {
                        try
                        {
                            prd.DoWork += dialogue =>
                            {
                                var tempfile = Path.GetTempFileName();
                                Download.getFilefromNet(url, tempfile);

                                try
                                {
                                    can.Update(nodeID, devicename, hwversion, tempfile);
                                }
                                catch (Exception ex)
                                {
                                    throw;
                                }

                                return;
                            };

                            prd.RunBackgroundOperationAsync();
                        }
                        catch (Exception ex)
                        {
                            CustomMessageBox.Show(ex.Message, Strings.ERROR);
                        }
                    }
                    else
                    {
                        CustomMessageBox.Show(Strings.UpdateNotFound, Strings.UpdateNotFound);
                    }
                }
                else
                {
                    FileDialog fd = new OpenFileDialog();
                    fd.RestoreDirectory = true;
                    fd.Filter           = "*.bin|*.bin";
                    var dia = fd.ShowDialog();

                    if (fd.CheckFileExists && dia == DialogResult.OK)
                    {
                        try
                        {
                            prd.DoWork += dialogue =>
                            {
                                can.Update(nodeID, myDataGridView1[nameDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(), 0,
                                           fd.FileName);

                                return;
                            };

                            prd.RunBackgroundOperationAsync();
                        }
                        catch (Exception ex)
                        {
                            CustomMessageBox.Show(ex.Message, Strings.ERROR);
                        }
                    }
                }
                can.FileSendProgress -= filesend;
                prd.Dispose();
            }
        }
Esempio n. 2
0
        private async void myDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            // Ignore clicks that are not on button cells.
            if (e.RowIndex < 0 || e.ColumnIndex !=
                myDataGridView1.Columns["updateDataGridViewTextBoxColumn"].Index &&
                e.ColumnIndex != myDataGridView1.Columns["Parameter"].Index)
            {
                return;
            }

            byte nodeID = (byte)myDataGridView1[iDDataGridViewTextBoxColumn.Index, e.RowIndex].Value;

            if (e.ColumnIndex == myDataGridView1.Columns["Parameter"].Index)
            {
                var paramlist = can.GetParameters(nodeID);

                new UAVCANParams(can, nodeID, paramlist).ShowUserControl();
            }
            else if (e.ColumnIndex == myDataGridView1.Columns["updateDataGridViewTextBoxColumn"].Index)
            {
                if (CustomMessageBox.Show("Do you want to search the internet for an update?", "Update", CustomMessageBox.MessageBoxButtons.YesNo) == CustomMessageBox.DialogResult.Yes)
                {
                    var devicename = myDataGridView1[nameDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString();
                    var hwversion  = double.Parse(myDataGridView1[hardwareVersionDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(), CultureInfo.InvariantCulture);

                    var url = can.LookForUpdate(devicename, hwversion);

                    if (url != string.Empty)
                    {
                        try
                        {
                            await Task.Run(() =>
                            {
                                var tempfile = Path.GetTempFileName();
                                Download.getFilefromNet(url, tempfile);

                                can.Update(devicename, hwversion, tempfile);
                            });
                        }
                        catch (Exception ex)
                        {
                            CustomMessageBox.Show(ex.Message, Strings.ERROR);
                        }
                    }
                    else
                    {
                        CustomMessageBox.Show(Strings.UpdateNotFound, Strings.UpdateNotFound);
                    }
                }
                else
                {
                    FileDialog fd = new OpenFileDialog();
                    fd.RestoreDirectory = true;
                    fd.Filter           = "*-crc.bin|*-crc.bin";
                    var dia = fd.ShowDialog();

                    if (fd.CheckFileExists && dia == DialogResult.OK)
                    {
                        try
                        {
                            await Task.Run(() =>
                            {
                                can.Update(myDataGridView1[nameDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(), 0,
                                           fd.FileName);
                            });
                        }
                        catch (Exception ex)
                        {
                            CustomMessageBox.Show(ex.Message, Strings.ERROR);
                        }
                    }
                }
            }
        }