Beispiel #1
0
        private void ImportTranslations()
        {
            SetState(false);

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "",
                AsyncArgument = txtFilePath.Text,
                Work          = (bw, e) =>
                {
                    var engine = new Engine();
                    engine.Import(e.Argument.ToString(), Service, bw);
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                        MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    SetState(false);
                },
                ProgressChanged = e => { SetWorkingMessage(e.UserState.ToString()); }
            });
        }
Beispiel #2
0
        private void ImportTranslations()
        {
            SetState(false);

            WorkAsync("",
                      (bw, e) =>
            {
                var engine = new Engine();
                engine.Import(e.Argument.ToString(), Service, bw);
            },
                      e =>
            {
                if (e.Error != null)
                {
                    string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                    MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                SetState(false);
            },
                      e => SetWorkingMessage(e.UserState.ToString()),
                      txtFilePath.Text);
        }
Beispiel #3
0
        private void ImportTranslations()
        {
            var lm = new LogManager(GetType());

            if (File.Exists(lm.FilePath))
            {
                if (MessageBox.Show(this, @"A log file already exists. Would you like to create a new log file?", @"Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    File.Copy(lm.FilePath, $"{lm.FilePath.Substring(0, lm.FilePath.Length - 4)}-{DateTime.Now:yyyyMMdd_HHmmss}.txt", true);
                    File.Delete(lm.FilePath);
                }
            }

            numberOferrors      = 0;
            pbOverall.ForeColor = SystemColors.Highlight;
            SetState(true);

            BaseTranslation.BulkCount = (int)nudBatchCount.Value;

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "",
                AsyncArgument = txtFilePath.Text,
                Work          = (bw, e) =>
                {
                    var engine    = new Engine();
                    engine.OnLog += (sender, evt) =>
                    {
                        if (evt.Type == LogType.Error)
                        {
                            LogError(evt.Message);
                        }
                        else if (evt.Type == LogType.Warning)
                        {
                            LogWarning(evt.Message);
                        }
                        else
                        {
                            LogInfo(evt.Message);
                        }
                    };
                    engine.OnProgress += (sender, evt) =>
                    {
                        Invoke(new Action(() =>
                        {
                            if (string.IsNullOrEmpty(evt.SheetName))
                            {
                                currentControl?.End(currentControl.Error == 0);
                                return;
                            }

                            if (currentControl == null || currentControl.SheetName != evt.SheetName)
                            {
                                currentControl?.End(currentControl.Error == 0);
                                currentControl      = new ProgressControl(evt.SheetName);
                                currentControl.Dock = DockStyle.Top;

                                pnlNewProgress.Controls.Add(currentControl);
                                pnlNewProgress.Controls.SetChildIndex(currentControl, 0);
                                pnlNewProgress.ScrollControlIntoView(currentControl);
                            }

                            currentControl.Count   = evt.TotalItems;
                            currentControl.Error   = evt.FailureCount;
                            currentControl.Success = evt.SuccessCount;
                        }));
                    };

                    engine.Import(e.Argument.ToString(), Service, bw);
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                        MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    SetState(false);

                    lblProgress.Text = "";

                    if (File.Exists(lm.FilePath))
                    {
                        llOpenLog.Visible = true;
                    }
                },
                ProgressChanged = e =>
                {
                    if (e.UserState is ProgressInfo pInfo)
                    {
                        lblProgress.Text = pInfo.Message;
                        if (numberOferrors > 0)
                        {
                            pbOverall.ForeColor = Color.Red;
                            pbOverall.Invalidate();

                            llOpenLog.Visible = true;
                        }

                        if (pInfo.Overall != 0)
                        {
                            pbOverall.Value = pInfo.Overall > pbOverall.Maximum ? pbOverall.Maximum : pInfo.Overall;
                        }
                    }
                    else
                    {
                        SetWorkingMessage(e.UserState.ToString());
                    }
                }
            });
Beispiel #4
0
        private void ImportTranslations()
        {
            SetState(false);

            WorkAsync("",
                (bw, e) =>
                {
                    var engine = new Engine();
                    engine.Import(e.Argument.ToString(), Service, bw);
                },
                e =>
                {
                    if (e.Error != null)
                    {
                        string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                        MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    SetState(false);
                },
                e=>SetWorkingMessage(e.UserState.ToString()),
                txtFilePath.Text);
        }
Beispiel #5
0
        private void ImportTranslations()
        {
            SetState(false);

            WorkAsync(new WorkAsyncInfo
            {
                Message = "",
                AsyncArgument = txtFilePath.Text,
                Work = (bw, e) =>
                {
                    var engine = new Engine();
                    engine.Import(e.Argument.ToString(), Service, bw);
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                        MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    SetState(false);
                },
                ProgressChanged = e => { SetWorkingMessage(e.UserState.ToString()); }
            });
        }
Beispiel #6
0
        private void ImportTranslations()
        {
            numberOferrors      = 0;
            pbOverall.ForeColor = SystemColors.Highlight;
            pbItem.ForeColor    = SystemColors.Highlight;
            SetState(true);

            gbProgress.Visible = true;

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "",
                AsyncArgument = txtFilePath.Text,
                Work          = (bw, e) =>
                {
                    var engine    = new Engine();
                    engine.OnLog += (sender, evt) =>
                    {
                        if (!evt.Success)
                        {
                            numberOferrors++;
                            LogError("{0}\t{1}", evt.SheetName, evt.Message);
                        }
                    };
                    engine.Import(e.Argument.ToString(), Service, bw);
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        string errorMessage = CrmExceptionHelper.GetErrorMessage(e.Error, true);
                        MessageBox.Show(this, errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    SetState(false);
                    //gbProgress.Visible = false;
                },
                ProgressChanged = e =>
                {
                    var pInfo = e.UserState as ProgressInfo;
                    //MessageBox.Show($"{pInfo?.Overall}/{pInfo?.Item}/{pInfo?.Message}");
                    if (pInfo != null)
                    {
                        if (pInfo.Item == 1)
                        {
                            pbItem.ForeColor = SystemColors.Highlight;
                        }

                        if (numberOferrors > 0)
                        {
                            pbOverall.ForeColor = Color.Red;
                            pbItem.ForeColor    = Color.Red;
                            pbOverall.Invalidate();
                            pbItem.Invalidate();

                            llOpenLog.Visible = true;
                            lblErrors.Text    = string.Format(lblErrors.Tag.ToString(), numberOferrors);
                        }

                        if (pInfo.Overall != 0)
                        {
                            pbOverall.Value = pInfo.Overall > pbOverall.Maximum ? pbOverall.Maximum : pInfo.Overall;
                        }

                        if (pInfo.Item != 0)
                        {
                            pbItem.Value = pInfo.Item > pbItem.Maximum ? pbItem.Maximum : pInfo.Item;
                        }

                        if (pInfo.Message != null)
                        {
                            lblProgress.Text = pInfo.Message;
                        }
                    }
                    else
                    {
                        SetWorkingMessage(e.UserState.ToString());
                    }
                }
            });
        }