コード例 #1
0
        private bool IsPanelDataValid(Panel panel, bool isErrorClear)
        {
            bool isValid = true;

            if (isErrorClear)
            {
                errorProvider.Clear();
            }
            foreach (Control control in panel.Controls)
            {
                string rules = (string)control.Tag;
                if (!String.IsNullOrWhiteSpace(rules))
                {
                    ValidationResult response = validator.Validate(control.Text, rules);
                    if (response.success == false)
                    {
                        isValid = false;

                        errorProvider.SetIconPadding(control, -20);
                        errorProvider.SetError(control, ECRDictionary.GetTranslation(response.message));
                    }
                }
            }
            return(isValid);
        }
コード例 #2
0
        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            Stream         inputStream = null;
            OpenFileDialog fileDialog  = new OpenFileDialog();

            fileDialog.InitialDirectory = "c:\\";
            fileDialog.Filter           = "Hex files (*.hex)|*.hex";
            fileDialog.RestoreDirectory = true;
            DialogResult userReaction = fileDialog.ShowDialog();

            if (userReaction == DialogResult.OK)
            {
                try
                {
                    if ((inputStream = fileDialog.OpenFile()) != null)
                    {
                        labelFileName.Text = fileDialog.SafeFileName;
                        using (inputStream)
                        {
                            this.intelHex.Load(inputStream);
                            this.intelHex.ParseHeaders();
                            this.RefreshHexInfo();
                        }
                    }
                }
                catch (Exception)
                {
                    ShowErrorMessage(ECRDictionary.GetTranslation("Cannot open the file"));
                }
            }
            if (userReaction == DialogResult.Cancel || userReaction == DialogResult.Abort)
            {
                Clear();
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: artemkramov/hex-uploader
 public MainForm()
 {
     InitializeComponent();
     validator = new Validator();
     device    = new ECRDevice();
     device.HttpClient.HttpErrorEvent += OnHttpError;
     ECRDictionary.InitTranslations();
 }
コード例 #4
0
        public MainForm()
        {
            int screenWidth = Screen.PrimaryScreen.Bounds.Width;

            //this.MaximumSize = new System.Drawing.Size(screenWidth, this.Height);
            InitializeComponent();
            validator = new Validator();
            device    = new ECRDevice();
            device.HttpClient.HttpErrorEvent += OnHttpError;
            device.HttpErrorEvent            += OnHttpError;
            ECRDictionary.InitTranslations();
        }
コード例 #5
0
        private async void btnUploadHex_Click(object sender, EventArgs e)
        {
            LoadingButton(btnUploadHex);
            try
            {
                byte[]       buffer       = this.intelHex.ToBinary();
                FirmwareInfo firmwareInfo = new FirmwareInfo();
                firmwareInfo.Set("Version", intelHex.Headers.Version);
                firmwareInfo.Set("Description", intelHex.Headers.Description);
                firmwareInfo.Set("FirmwareGUID", intelHex.Headers.FirmwareGUID);
                Task <dynamic> task = Task.Factory.StartNew(() => device.SendFirmwareInfo(firmwareInfo));
                dynamic        responseFirmwareInfo = await task;

                ResponseFirmware response = device.ParseFirmwareInfoResponse(responseFirmwareInfo);
                if (response.IsSuccess)
                {
                    panelUploadProgress.Visible = true;
                    Task <dynamic> taskSend = Task.Factory.StartNew(() => device.SendHexFile(buffer));
                    dynamic        responseFirmwareUpload = await taskSend;
                    ResetButton(btnUploadHex);
                    panelUploadProgress.Visible = false;
                    response = device.ParseFirmwareUploadResponse(responseFirmwareUpload);
                    if (response.IsSuccess)
                    {
                        ShowInfoMessage(ECRDictionary.GetTranslation("Hex file was uploaded successfully"));
                    }
                    else
                    {
                        if (response.Error.Length > 0)
                        {
                            ShowErrorMessage(response.Error);
                        }
                    }
                }
                else
                {
                    ResetButton(btnUploadHex);
                    if (response.Error.Length > 0)
                    {
                        ShowErrorMessage(response.Error);
                    }
                }
            }
            catch (IntelHexParserException)
            {
                panelUploadProgress.Visible = false;
                ResetButton(btnUploadHex);
                ShowErrorMessage(ECRDictionary.GetTranslation("Invalid HEX format"));
            }
        }
コード例 #6
0
        private async void btnConnect_Click(object sender, EventArgs e)
        {
            if (IsPanelDataValid(panelLogin, true))
            {
                ChangePanelsState(false);

                LoadingButton(btnConnect);
                var panelData = this.FetchPanelData(panelLogin);
                try
                {
                    device.Connect(panelData["textboxIP"], panelData["textboxUsername"], panelData["textboxPassword"]);
                    Task <dynamic> task  = Task.Factory.StartNew(() => device.GetState());
                    dynamic        state = await task;
                    task.Dispose();
                    if (state != null)
                    {
                        Task  taskLoadData = Task.Factory.StartNew(() => device.LoadDeviceData());
                        await taskLoadData;
                        taskLoadData.Dispose();

                        Task  taskLoadDescriptions = Task.Factory.StartNew(() => device.LoadTranslations());
                        await taskLoadDescriptions;

                        Task <dynamic> taskLoadInformation = Task.Factory.StartNew(() => device.GetInformation());
                        dynamic        information         = await taskLoadInformation;
                        FillInformation(information);
                        panelInformation.Visible = true;

                        ResetButton(btnConnect);
                        ShowInfoMessage(ECRDictionary.GetTranslation("Connected successfully"));
                        ChangePanelsState(true);
                    }
                    else
                    {
                        ResetButton(btnConnect);
                    }
                }
                catch (Exception ex)
                {
                    ResetButton(btnConnect);
                    ShowErrorMessage(ECRDictionary.GetTranslation(ex.Message));
                }
            }
        }
コード例 #7
0
        private async void btnFlash_Click(object sender, EventArgs e)
        {
            LoadingButton(btnFlash);
            Task <dynamic>   task = Task.Factory.StartNew(() => device.Flash());
            dynamic          responseFirmwareInfo = await task;
            ResponseFirmware response             = device.ParseFirmwareResponseBurn(responseFirmwareInfo);

            ResetButton(btnFlash);
            if (response.IsSuccess)
            {
                ShowInfoMessage(ECRDictionary.GetTranslation("Flash is starting..."));
                Clear();
                ChangePanelsState(false);
            }
            else
            {
                ResetButton(btnFlash);
                if (response.Error.Length > 0)
                {
                    ShowErrorMessage(response.Error);
                }
            }
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: artemkramov/hex-uploader
 private void ShowInfoMessage(string message)
 {
     MessageBox.Show(message, ECRDictionary.GetTranslation("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
コード例 #9
0
ファイル: Form1.cs プロジェクト: artemkramov/hex-uploader
 private void ShowErrorMessage(string message)
 {
     MessageBox.Show(message, ECRDictionary.GetTranslation("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
コード例 #10
0
ファイル: Form1.cs プロジェクト: artemkramov/hex-uploader
 private void OnHttpError(object sender, HttpErrorEventArgs e)
 {
     ShowErrorMessage(ECRDictionary.GetTranslation(e.Message));
 }
コード例 #11
0
ファイル: Form1.cs プロジェクト: artemkramov/hex-uploader
 private void LoadingButton(Button button)
 {
     buttonStates.Add(button.Name, button.Text);
     button.Text    = ECRDictionary.GetTranslation("In work...");
     button.Enabled = false;
 }