Example #1
0
        private static IAction GetAction(ActionModel action)
        {
            IAction actionInstance = null;

            switch (action.Action)
            {
            case ActionType.WriteFile:
                actionInstance = new WriteFileAction();
                break;

            case ActionType.IF:
                actionInstance = new IFAction();
                break;

            case ActionType.HttpRequest:
                actionInstance = new HttpRequestAction();
                break;

            case ActionType.Shutdown:
                actionInstance = new ShutdownAction();
                break;

            case ActionType.StartProcess:
                actionInstance = new StartProcessAction();
                break;

            case ActionType.OpenURL:
                actionInstance = new OpenURLAction();
                break;

            case ActionType.Snipping:
                actionInstance = new SnippingAction();
                break;

            case ActionType.DeleteFile:
                actionInstance = new DeleteFileAction();
                break;

            case ActionType.SoundPlay:
                actionInstance = new SoundPlayAction();
                break;

            case ActionType.GetIPAddress:
                actionInstance = new GetIPAddressAction();
                break;

            case ActionType.Keyboard:
                actionInstance = new KeyboardAction();
                break;

            case ActionType.SystemNotification:
                actionInstance = new SystemNotificationAction();
                break;

            case ActionType.DownloadFile:
                actionInstance = new DownloadFileAction();
                break;

            case ActionType.Dialog:
                actionInstance = new DialogAction();
                break;

            case ActionType.Delay:
                actionInstance = new DelayAction();
                break;

            case ActionType.Loops:
                actionInstance = new LoopsAction();
                break;

            case ActionType.KillProcess:
                actionInstance = new KillProcessAction();
                break;

            case ActionType.SetDeviceVolume:
                actionInstance = new SetDeviceVolumeAction();
                break;

            case ActionType.Regex:
                actionInstance = new RegexAction();
                break;

            case ActionType.ReadFile:
                actionInstance = new ReadFileAction();
                break;

            case ActionType.JsonDeserialize:
                actionInstance = new JsonDeserializeAction();
                break;
            }
            if (actionInstance != null)
            {
                return(actionInstance);
            }
            return(null);
        }
Example #2
0
        // Private function that handles all of the processing as much is common throughout each function

        private static object GoogleSheetsRegex(RegexAction iAction, string sSource, string sExpression, string sReplacement, int iMatchNumber, bool bIgnoreCase, bool bMultiLine, bool bRightToLeft, bool bSingleLine)
        {
            try
            {
                if (string.IsNullOrEmpty(sExpression))
                {
                    return(ExcelError.ExcelErrorNull);
                }

                // Create the reference to the output array of cells

                var oCaller = Excel(xlfCaller) as ExcelReference;
                if (oCaller == null)
                {
                    return(ExcelError.ExcelErrorRef);
                }

                // Check that the calling reference is a single cell

                if (oCaller.RowFirst != oCaller.RowLast || oCaller.ColumnFirst != oCaller.ColumnLast)
                {
                    return(ExcelError.ExcelErrorRef);
                }                                                                                                                           // Formula has been entered as an array formula

                // Assemble the Regex options

                var oRegExOptions = RegexOptions.None;

                if (bIgnoreCase)
                {
                    oRegExOptions = (oRegExOptions == RegexOptions.None ? RegexOptions.IgnoreCase : oRegExOptions | RegexOptions.IgnoreCase);
                }
                if (bMultiLine)
                {
                    oRegExOptions = (oRegExOptions == RegexOptions.None ? RegexOptions.Multiline : oRegExOptions | RegexOptions.Multiline);
                }
                if (bRightToLeft)
                {
                    oRegExOptions = (oRegExOptions == RegexOptions.None ? RegexOptions.RightToLeft : oRegExOptions | RegexOptions.RightToLeft);
                }
                if (bSingleLine)
                {
                    oRegExOptions = (oRegExOptions == RegexOptions.None ? RegexOptions.Singleline : oRegExOptions | RegexOptions.Singleline);
                }

                // Perform the Regex matching

                Regex oRegex = new Regex(sExpression, oRegExOptions);

                // Return the appropiate result

                switch (iAction)
                {
                case RegexAction.Match:
                    return(oRegex.IsMatch(sSource));

                case RegexAction.MatchCount:
                    return(oRegex.Matches(sSource).Count);

                case RegexAction.Extract:
                    MatchCollection oMatches = oRegex.Matches(sSource);
                    return(oMatches[(iMatchNumber > oMatches.Count ? oMatches.Count - 1 : iMatchNumber - 1)].Value);

                case RegexAction.Replace:
                    return(oRegex.Replace(sSource, sReplacement));
                }
            }
            catch
            {
                return(ExcelError.ExcelErrorRef);
            }

            return(null);
        }