示例#1
0
        /// <summary>
        /// Handles Duplicate Action
        /// </summary>
        /// <param name="sender">The Sender</param>
        /// <param name="args">The Event Arguments</param>
        private void HandleDuplicateAction(object sender, Controls.ActionEditorControlEventArgs args)
        {
            try
            {
                var sendingControl = sender as Control;
                var existingAction = args.Action;
                var newAction      = new Model.Macro.Action();

                newAction.ActionType  = existingAction.ActionType;
                newAction.ActionDelay = existingAction.ActionDelay;

                newAction.ScreenResolution.X = existingAction.ScreenResolution.X;
                newAction.ScreenResolution.Y = existingAction.ScreenResolution.Y;

                newAction.ScreenPosition.X = existingAction.ScreenPosition.X;
                newAction.ScreenPosition.Y = existingAction.ScreenPosition.Y;

                SourceMacro.Assembly.Add(newAction);
                AddMacroActonEditorControl(newAction);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Handling Duplicate Action", caught);
                throw;
            }
        }
示例#2
0
 /// <summary>
 /// Handle Add Action Click
 /// </summary>
 /// <param name="sender">The Sender</param>
 /// <param name="e">The Event Arguments</param>
 private void HandleAddActionClick(object sender, EventArgs e)
 {
     try
     {
         //var newAction = IoC.GetComponent<IMacroAction>();
         var newAction = new Model.Macro.Action();
         SourceMacro.Assembly.Add(newAction);
         AddMacroActonEditorControl(newAction);
     }
     catch (Exception caught)
     {
         logger.Error("Unexpected Error Handling Add Action Click", caught);
         throw;
     }
 }
示例#3
0
        /// <summary>
        /// Get Action Source
        /// </summary>
        /// <param name="action">The Action</param>
        /// <returns>The Action Source</returns>
        private string GetActionSource(DataContract.Macro.Action action)
        {
            try
            {
                var sbAction = new StringBuilder();

                var actionTypeValue = action.ActionType == DataContract.Macro.ActionType.Screen ? 0 : 1;
                sbAction.Append($"{actionTypeValue}{SEPARATOR_SEQUENCE}{action.ScreenResolution.Y}|{action.ScreenResolution.X}|{COMMAND_MULTI}:1:0:{action.ScreenPosition.Y}:{action.ScreenPosition.X}{SEPARATOR_SEQUENCE}{action.ActionDelay}\r\n");
                sbAction.Append($"{actionTypeValue}{SEPARATOR_SEQUENCE}{action.ScreenResolution.Y}|{action.ScreenResolution.X}|{COMMAND_MULTI}:0:6{SEPARATOR_SEQUENCE}{action.ActionDelay + 1}\r\n");
                sbAction.Append($"{actionTypeValue}{SEPARATOR_SEQUENCE}{action.ScreenResolution.Y}|{action.ScreenResolution.X}|{COMMAND_MULTI}:0:6{SEPARATOR_SEQUENCE}{action.ActionDelay + 1}\r\n");
                sbAction.Append($"{actionTypeValue}{SEPARATOR_SEQUENCE}{action.ScreenResolution.Y}|{action.ScreenResolution.X}|{COMMAND_MULTI}:0:1{SEPARATOR_SEQUENCE}{action.ActionDelay + 1}\r\n");

                return(sbAction.ToString());
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Getting Action Source", caught);
                throw;
            }
        }
示例#4
0
        // <summary>
        /// Add Macro Action Editor Control
        /// </summary>
        /// <param name="macroAction">The Macro Action</param>
        private void AddMacroActonEditorControl(Model.Macro.Action macroAction)
        {
            try
            {
                if (macroAction == null)
                {
                    throw new ArgumentNullException("macroAction");
                }

                var actionEditorControl = new Controls.MacroActionEditorControl(macroAction);
                MacroActionsFlowPanel.Controls.Add(actionEditorControl);
                actionEditorControl.RemoveAction    += new Action <object, Controls.ActionEditorControlEventArgs>(HandleRemoveAction);
                actionEditorControl.DuplicateAction += new Action <object, Controls.ActionEditorControlEventArgs>(HandleDuplicateAction);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Adding Macro Action Editor Control to Designer", caught);
                throw;
            }
        }
示例#5
0
        /// <summary>
        /// Build Macro Action
        /// </summary>
        /// <param name="actionSource">The Action Source</param>
        /// <returns>The Macro Action Data Contract</returns>
        /// <remarks>
        /// Not really sure what to say about this.
        /// This is a result of haste, and discovery.  What I would really like to do
        /// is build a lexical parser of some sort, and draw meaning behind the language
        /// of the source, which might allow for interesting capabilities...
        ///
        /// Whatever... will get there
        /// </remarks>
        private DataContract.Macro.Action BuildMacroAction(string actionSource)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(actionSource))
                {
                    throw new ArgumentNullException("actionSource");
                }

                var macroAction = new DataContract.Macro.Action();

                var sourceTok = actionSource.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                if (sourceTok.Count() != 4)
                {
                    //But really we are only concerned about the first line, it has the information we need...
                    throw new ApplicationException("Expectng 4 source lines to represent this action");
                }

                var firstLine    = sourceTok[0];
                var firstLineTok = firstLine.Split(new[] { SEPARATOR_SEQUENCE }, StringSplitOptions.RemoveEmptyEntries);
                if (firstLineTok.Count() != 3)
                {
                    throw new ApplicationException("Expectng 3 action segments");
                }

                int parseOut = -1;
                if (int.TryParse(firstLineTok[0], out parseOut))
                {
                    macroAction.ActionType = parseOut == 0 ? DataContract.Macro.ActionType.Screen : DataContract.Macro.ActionType.Keyboard;
                }

                //Extract Screen dimensions and tap position from second segment
                var secondSegmentTok = firstLineTok[1].Split(new[] { "|", ":", COMMAND_MULTI }, StringSplitOptions.RemoveEmptyEntries);
                if (secondSegmentTok.Count() != 6)
                {
                    throw new ApplicationException("Expecting 6 Arguments in second segment");
                }
                if (int.TryParse(secondSegmentTok[0], out parseOut))
                {
                    macroAction.ScreenResolution.Y = parseOut;
                }
                if (int.TryParse(secondSegmentTok[1], out parseOut))
                {
                    macroAction.ScreenResolution.X = parseOut;
                }
                if (int.TryParse(secondSegmentTok[4], out parseOut))
                {
                    macroAction.ScreenPosition.Y = parseOut;
                }
                if (int.TryParse(secondSegmentTok[5], out parseOut))
                {
                    macroAction.ScreenPosition.X = parseOut;
                }

                //Extract Action Delay from last segment
                if (int.TryParse(firstLineTok[2], out parseOut))
                {
                    macroAction.ActionDelay = parseOut;
                }

                return(macroAction);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Building Macro Action", caught);
                throw;
            }
        }