private void DgLabels_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dgLabels.Columns[e.ColumnIndex].CellType == typeof(DataGridViewLinkCell))
     {
         var lbl = (Models.ElementLabel)dgLabels.Rows[e.RowIndex].DataBoundItem;
         if (e.ColumnIndex == clmEdit.Index)
         {
             var editor = new FrmLabelEditor(lbl);
             if (editor.ShowDialog() != DialogResult.Cancel)
             {
                 BindLabels();
             }
         }
         else if (e.ColumnIndex == clmRun.Index)
         {
             var objLabel = new Objects.LabelObject(lbl, _act._ReturnDataCollection);
             try
             {
                 objLabel.ExecuteBehavior();
             }
             catch (Exception ex)
             {
                 txtResult.AppendText(ex.ToString());
             }
         }
         else
         {
             throw new NotImplementedException();
         }
     }
 }
Esempio n. 2
0
        private void DgLabels_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var idx = e.RowIndex;

            if (idx == dgLabels.NewRowIndex)
            {
                FrmLabelEditor editor = new PriceChecker.FrmLabelEditor(_action);
                if (editor.ShowDialog() != DialogResult.Cancel)
                {
                    BindLabels();
                }
            }
            else
            {
                var lbl = (Models.ElementLabel)dgLabels.Rows[e.RowIndex].DataBoundItem;
                if (e.ColumnIndex == clmEdit.Index)
                {
                    var editor = new FrmLabelEditor(lbl);
                    if (editor.ShowDialog() != DialogResult.Cancel)
                    {
                        BindLabels();
                    }
                }
                else if (e.ColumnIndex == clmMoveDown.Index)
                {
                    lbo.MoveDown(lbl);
                    BindLabels();
                }
                else if (e.ColumnIndex == clmMoveUp.Index)
                {
                    lbo.MoveUp(lbl);
                    BindLabels();
                }
                else if (e.ColumnIndex == clmExecute.Index)
                {
                    var objLabel = new Objects.LabelObject(lbl, null);
                    try
                    {
                        objLabel.ExecuteBehavior();
                    }
                    catch (Exception ex)
                    {
                        txtProgress.AppendText(ex.ToString());
                    }
                }
            }
        }
        /* A routine can execute flawless but not get what we want, e.g node selected but not have value, or select nodes
         * return count = 0 so we
         * need to return a boolean to tell the action to stop, not throw error everywhere */
        /// <summary>
        /// Make this public so we can call directly to test on a routine.
        /// </summary>
        /// <param name="routine"></param>
        /// <returns></returns>
        protected virtual void InnerExecuteAction(bool reportLabel)
        {
            BO.ElementLabelBO elbo   = new BO.ElementLabelBO();
            List <int>        lblIds = elbo.GetQueryable(_ActionData.ActionId).OrderBy(l => l.LabelOrder).Select(l => l.LabelId).ToList();

            Objects.LabelObject objLabel;
            for (int i = 0; i < lblIds.Count; i++)
            {
                if (_wk != null && _wk.CancellationPending)
                {
                    break;
                }
                //well this should be enough to refresh data
                elbo = new BO.ElementLabelBO();
                var label = elbo.GetLabel(lblIds[i]);
                //In this case we use special wait not just sleep
                if (label.ExpectedBehavior != (int)WebElementBehavior.WaitForSomethingHappen)
                {
                    var sleep = label.WaitSeconds == 0 ? DefaultLabelWaitMiliseconds : label.WaitSeconds * 1000;
                    System.Threading.Thread.Sleep(sleep);
                }
                if (_wk != null && _wk.CancellationPending)
                {
                    break;
                }
                if (_wk != null && reportLabel)
                {
                    _wk.ReportProgress(0, "execute label \"" + label.LabelName + "\"");
                }
                objLabel             = new LabelObject(label, this._inputDatas);
                objLabel._NodeParent = _CurrentHtmlAgilityNodeParent;
                objLabel._wk         = _wk;
                try
                {
                    objLabel.ExecuteBehavior();
                    //do not wait by label.seconds because it is for behavior like waitforvisible etc
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
                    if (objLabel._ReturnData != null)
                    {
                        if (_ReturnDataCollection == null)
                        {
                            _ReturnDataCollection = new Dictionary <string, object>();
                        }
                        _ReturnDataCollection[objLabel._LabelData.ReturnDataKey] = objLabel._ReturnData;
                    }
                }
                catch (MyExceptions.BreakRoutineIfFoundException)
                {
                    if (_wk != null)
                    {
                        _wk.ReportProgress(0, "Found label " + label.LabelName + ", break routine" + Environment.NewLine);
                    }
                    break;
                }
                catch (MyExceptions.BreakRoutineIfNOTFoundException)
                {
                    if (_wk != null)
                    {
                        _wk.ReportProgress(0, "Not found label " + label.LabelName + ", break routine" + Environment.NewLine);
                    }
                    break;
                }
                catch (Exception ex)
                {
                    //we should make the error short for easy reading
                    string message = "Error on action: " + _ActionData.ActionName + Environment.NewLine;
                    message += "Label: " + label.LabelName + Environment.NewLine;
                    message += "Label Error Type: " + ex.GetType() + Environment.NewLine;
                    message += "Detail message: " + ex.Message;
                    //if the error is handle we don't need to add it to error collection
                    objLastError            = new ErrorObject();
                    objLastError.Label      = label;
                    objLastError.ActionName = _ActionData.ActionName;
                    //we throw to handle the error upper so we can cover all overload method
                    throw;
                }
            }
        }