コード例 #1
0
ファイル: Workflow.cs プロジェクト: MarySam/WaitTime
        public void Validate()
        {
            ValidActions.Validate(this.Actions);
            if (this.Links != null)
            {
                Utils.AssertArgument(this.Links.Callback != null, "Callback link cannot be specified as null");
                Utils.AssertArgument(this.Links.Callback.IsAbsoluteUri, "Callback link must be an absolute uri");
            }
            ApplicationState.Validate(this.AppState);

            if (this.NotificationSubscriptions != null)
            {
                if (!this.NotificationSubscriptions.Contains <NotificationType>(NotificationType.CallStateChange))
                {
                    List <NotificationType> newNotificationSubscriptionList = new List <NotificationType>();
                    newNotificationSubscriptionList.Add(NotificationType.CallStateChange);
                    newNotificationSubscriptionList.AddRange(this.NotificationSubscriptions);
                    this.NotificationSubscriptions = newNotificationSubscriptionList;
                }
            }
            else
            {
                List <NotificationType> callStateNotificationList = new List <NotificationType>();
                callStateNotificationList.Add(NotificationType.CallStateChange);
                this.NotificationSubscriptions = callStateNotificationList;
            }
        }
コード例 #2
0
        public static void Validate(IEnumerable <ActionBase> actions)
        {
            Utils.AssertArgument(actions != null, "Null Actions List not allowed");
            ActionBase[] actionsToBeValidated = actions.ToArray();
            Utils.AssertArgument(actionsToBeValidated.Length > 0, "Empty Actions List not allowed");

            if (actionsToBeValidated.Length > 1 && actionsToBeValidated.Any((a) => { return(a.IsStandaloneAction); }))
            {
                Utils.AssertArgument(
                    false,
                    "The stand-alone action '{0}' cannot be specified with any other actions",
                    (actionsToBeValidated.FirstOrDefault((a) => { return(a.IsStandaloneAction); })).Action);
            }

            // Validate each action is correct.
            for (int i = 0; i < actionsToBeValidated.Length; ++i)
            {
                Utils.AssertArgument(actionsToBeValidated[i] != null, "action {0} cannot be null", i);
                ValidActions.Validate(actionsToBeValidated[i].Action);
                actionsToBeValidated[i].Validate();
            }

            // Validate the actions are correctly ordered.
            for (int i = 1; i < actionsToBeValidated.Length; ++i)
            {
                if (ValidActions.CompareOrder(actionsToBeValidated[i - 1].Action, actionsToBeValidated[i].Action) > 0)
                {
                    Utils.AssertArgument(false, "Action {0} can not precede action {1}.", actionsToBeValidated[i - 1].Action, actionsToBeValidated[i].Action);
                }
            }

            // Ensure that actions are not duplicated
            for (int i = 0; i < actionsToBeValidated.Length; ++i)
            {
                if (ValidActions.IsMultiAction(actionsToBeValidated[i].Action))
                {
                    continue;
                }
                int actionCount = actionsToBeValidated.Where(a => a.Action == actionsToBeValidated[i].Action).Count();
                Utils.AssertArgument(actionCount <= 1, "Action {0} can not be specified multiple times in same workflow.", actionsToBeValidated[i].Action);
            }

            // Some actions (Answer and PlaceCall) cannot be combined in one workflow.
            var exclusiveActions = actionsToBeValidated.Where(a => ValidActions.IsExclusiveAction(a.Action)).ToArray();

            if (exclusiveActions.Count() > 1)
            {
                Utils.AssertArgument(false, "Action {0} can not be specified with action {1}.", exclusiveActions[0].Action, exclusiveActions[1].Action);
            }
        }
コード例 #3
0
ファイル: Workflow.cs プロジェクト: Hellpop/AuthorizedBot
        /// <summary>
        /// Validate the WorkFlow
        /// </summary>
        /// <param name="expectEmptyActions">Allow Actions to be empty</param>
        public virtual void Validate(bool expectEmptyActions)
        {
            if (expectEmptyActions)
            {
                Utils.AssertArgument(this.Actions == null || this.Actions.Count() == 0, "Actions must either be null or empty collection");
            }
            else
            {
                ValidActions.Validate(this.Actions);
            }

            if (this.Links != null)
            {
                Utils.AssertArgument(this.Links.Callback != null, "Callback link cannot be specified as null");
                Utils.AssertArgument(this.Links.Callback.IsAbsoluteUri, "Callback link must be an absolute uri");
                Utils.AssertArgument(this.Links.Callback.Scheme == "https", "Callback link must be an secure HTTPS uri");
            }

            ApplicationState.Validate(this.AppState);
        }
コード例 #4
0
 public static void Validate(string action)
 {
     Utils.AssertArgument(!String.IsNullOrWhiteSpace(action), "Action Name cannot be null or empty");
     Utils.AssertArgument(ValidActions.IsValidAction(action), "{0} is not a valid action", action);
 }
コード例 #5
0
 public virtual void Validate()
 {
     Utils.AssertArgument(!String.IsNullOrWhiteSpace(this.OperationId), "A valid OperationId must be specified");
     ValidActions.Validate(this.Action);
 }