public override bool Equals(object obj)
            {
                ActionWrapper wrapper = obj as ActionWrapper;

                if (wrapper == null)
                {
                    return(false);
                }
                if (this.ParameterType != wrapper.ParameterType)
                {
                    return(false);
                }
                if (this._object == null && wrapper._object == null)
                {
                    return(true);
                }
                else
                if (this._object != null && wrapper._object != null)
                {
                    if (this._object.Target != wrapper._object.Target)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                if (this._method != wrapper._method)
                {
                    return(false);
                }
                return(true);
            }
 private static ParameterContext[] GetContextParms(ActionWrapper action, NakedObject target)
 {
     NakedObjectActionParameter[] parms = action.GetParameters(target);
     return(parms.Select(p => new ParameterContext {
         Action = action, Parameter = p
     }).ToArray());
 }
        protected void InitializeServiceApi(Type interfaceType)
        {
            ConcurrentDictionary <string, ActionWrapper> wrapper;

            if (cache.TryGetValue(interfaceType, out wrapper))
            {
                return;
            }
            var newWrapper = new ConcurrentDictionary <string, ActionWrapper>();

            foreach (var methodInfo in interfaceType.GetMethods())
            {
                var template   = ExtensionsFactory.GetServiceTemplate(methodInfo);
                var actionName = GetActionName(methodInfo);
                var action     = new ActionWrapper {
                    Name = actionName, ReturnType = methodInfo.ReturnType, RouteTemplate = template, Parameters = new List <ParameterWrapper>()
                };
                var actions  = methodInfo.GetCustomAttributes(true).OfType <IActionHttpMethodProvider>();
                var methods  = ExtensionsFactory.GetHttpMethods(actions.ToList(), methodInfo);
                var handlers = ExtensionsFactory.GetHeaderInspectors(methodInfo);
                action.CustomHandlers = handlers;
                action.Actions        = methods;
                BuildParameterInfo(methodInfo, action);
                newWrapper.TryAdd(action.Name, action);
            }
            if (cache.TryGetValue(interfaceType, out wrapper))
            {
                return;
            }
            cache.TryAdd(interfaceType, newWrapper);
        }
        public static NakedObjectActionParameter[] GetParameters(this ActionWrapper action)
        {
            NakedObjectSpecification[] parameterTypes = action.getParameterTypes();
            int index = 0;

            return(parameterTypes.Select(nakedObjectSpecification => new NakedObjectActionParameter(GetShortName(nakedObjectSpecification), index++, nakedObjectSpecification, action, null, null)).ToArray());
        }
        private static Tuple <ActionContext, NakedObjectSpecification> GetActionTypeInternal(string typeName, string actionName)
        {
            if (string.IsNullOrEmpty(typeName.Trim()) || string.IsNullOrWhiteSpace(actionName.Trim()))
            {
                throw new BadRequestNOSException();
            }

            NakedObjectSpecification spec = [email protected]().loadSpecification(typeName);

            if (spec is NoMemberSpecification)
            {
                throw new TypeResourceNotFoundNOSException(typeName);
            }

            ActionWrapper action = spec.GetActionLeafNodes().SingleOrDefault(p => p.getId() == actionName);

            if (action == null)
            {
                throw new ActionResourceNotFoundNOSException(actionName);
            }

            var actionContext = new ActionContext {
                Action = action
            };

            return(new Tuple <ActionContext, NakedObjectSpecification>(actionContext, spec));
        }
示例#6
0
        private void Process(List <ActionWrapper> myWrappedActions)
        {
            try
            {
                acutPrintf("Process Started!!\n");
                acutPrintf(myWrappedActions[0].Parameter + "\n");

                for (int i = 0; i < myWrappedActions.Count; i++)
                {
                    ActionWrapper myActions = myWrappedActions[i];
                    if (myActions == null)
                    {
                        throw new ArgumentNullException();
                    }

                    acutPrintf(myActions.Type.ToString() + "\n");
                    myWrappedActions[i]        = _BricsCadEntityInjector.Dispatcher(myActions);
                    myWrappedActions[i].Status = ActionWrapper.StatusEnum.Ok;
                }
            }
            catch (System.Exception ex)
            {
                string Error = string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace);
                acutPrintf(Error);
            }
        }
示例#7
0
    public void Act(EventAction action, List <Dependency> deps = null)
    {
        //Debug.Log("Act " + action.GetType().Name, gameObject);
        //Debug.Log(action.State);
        ActionWrapper wrapper = new ActionWrapper();

        wrapper.Action = action;
        bool canDo = true;

        if (deps == null)
        {
            wrapper.Deps = action.GetDependencies(); //Here it should ask the action to get its dependencies
            canDo        = Traverse(wrapper.Deps);   //Here it should traverse those and answer whether it's possible to achieve this action at all,
                                                     //while also marking external dependencies
        }
        else
        {
            wrapper.Deps = deps;
        }
        if (!canDo)
        {
            action.State = EventAction.ActionState.Failed;
        }
        else
        {
            //Debug.Log("Put as current action");
            PutAsCurrentAction(wrapper);
        }
    }
        private Tuple <ActionWrapper, NakedObjectSpecification, NakedObjectActionParameter> GetActionParameterTypeInternal(string typeName, string actionName, string parmName)
        {
            if (string.IsNullOrEmpty(typeName.Trim()) || string.IsNullOrWhiteSpace(actionName.Trim()) || string.IsNullOrWhiteSpace(parmName.Trim()))
            {
                throw new BadRequestNOSException();
            }

            NakedObjectSpecification spec = [email protected]().loadSpecification(typeName);

            if (spec is NoMemberSpecification)
            {
                throw new TypeResourceNotFoundNOSException(typeName);
            }

            ActionWrapper action = spec.GetActionLeafNodes().SingleOrDefault(p => p.getId() == actionName);

            if (action == null)
            {
                throw new ActionResourceNotFoundNOSException(actionName);
            }

            NakedObjectActionParameter parm = action.GetParameters().SingleOrDefault(p => p.getId() == parmName);

            if (parm == null)
            {
                throw new ActionResourceNotFoundNOSException(parmName);
            }

            return(new Tuple <ActionWrapper, NakedObjectSpecification, NakedObjectActionParameter>(action, spec, parm));
        }
示例#9
0
        private async Task <ResultWrapper> CreateResult(
            ActionWrapper action,
            HttpResponseMessage response)
        {
            Type type = typeof(Task).IsAssignableFrom(action.ReturnType) ? ((IEnumerable <Type>)action.ReturnType.GetGenericArguments()).FirstOrDefault <Type>() : action.ReturnType;

            if (type == typeof(void) || type == (Type)null)
            {
                return new ResultWrapper()
                       {
                           Type          = typeof(void),
                           IsVoid        = true,
                           Value         = (object)null,
                           Status        = response.StatusCode,
                           StatusMessage = response.ReasonPhrase,
                           ActionId      = response.ActionId()
                       }
            }
            ;
            object resultFromResponse = await this.GetResultFromResponse(action, response, type);

            return(new ResultWrapper()
            {
                Type = type,
                IsVoid = false,
                Value = resultFromResponse,
                Status = response.StatusCode,
                StatusMessage = response.ReasonPhrase,
                ActionId = response.ActionId()
            });
        }
示例#10
0
 private static void BuildParameterInfo(MethodInfo methodInfo, ActionWrapper action)
 {
     foreach (var parameterInfo in methodInfo.GetParameters())
     {
         var @in = parameterInfo.GetCustomAttribute <InAttribute>(true);
         if (@in == null)
         {
             var fromBody = parameterInfo.GetCustomAttribute <FromBodyAttribute>(true);
             if (fromBody != null)
             {
                 @in = new InAttribute(InclutionTypes.Body);
             }
             if (@in == null)
             {
                 var fromUri = parameterInfo.GetCustomAttribute <FromUriAttribute>(true);
                 if (fromUri != null)
                 {
                     @in = new InAttribute(InclutionTypes.Path);
                 }
             }
         }
         action.Parameters.Add(new ParameterWrapper {
             Name = parameterInfo.Name, Type = parameterInfo.ParameterType, In = @in?.InclutionType ?? InclutionTypes.Body
         });
     }
 }
 public void Unsubscribe <T>(Action <T> action, string key = null)
 {
     lock (this._locker)
     {
         ActionWrapper wrapper = new ActionWrapper(action);
         this.Remove(key, wrapper);
     }
 }
示例#12
0
        private void Resync()
        {
            FileSyncData sync = this.Project.GetSyncData() as FileSyncData;

            this.Text        = sync.Text;
            this.ImageKey    = sync.ImageKey;
            this.ContextMenu = ActionWrapper.GetContextMenu(this.Project.ContextActions);
        }
示例#13
0
 private ResultWrapper InvokeAction(
     string name,
     ParameterWrapper[] parameters,
     ActionWrapper action,
     string path)
 {
     return(Task.Run <ResultWrapper>((Func <Task <ResultWrapper> >)(async() => await this.InvokeActionAsync(parameters, action, path))).Result);
 }
 public NakedObjectActionParameter(string id, int number, NakedObjectSpecification spec, ActionWrapper action, object[] choices, object dflt) {
     this.id = id;
     this.number = number;
     this.spec = spec;
     this.action = action;
     this.choices = choices;
     this.dflt = dflt;
 }
示例#15
0
 public NakedObjectActionParameter(string id, int number, NakedObjectSpecification spec, ActionWrapper action, object[] choices, object dflt)
 {
     this.id      = id;
     this.number  = number;
     this.spec    = spec;
     this.action  = action;
     this.choices = choices;
     this.dflt    = dflt;
 }
示例#16
0
        private void Resync()
        {
            FileSyncData sync = this.File.GetSyncData() as FileSyncData;

            this.Text             = sync.Text;
            this.ImageKey         = sync.ImageKey;
            this.SelectedImageKey = sync.ImageKey;
            this.ContextMenuStrip = ActionWrapper.GetContextMenu(this.File.ContextActions);
        }
示例#17
0
        public static IAsyncResult BeginInvoke(Func <object> proc, AsyncCallback callback)
        {
            ActionWrapper wrap = new ActionWrapper
            {
                RunFunc  = proc,
                Callback = callback,
            };

            System.Threading.ThreadPool.QueueUserWorkItem(wrap.DoRun);
            return(wrap);
        }
        private ActionWrapper Find(string key, ActionWrapper wrapper)
        {
            ActionWrapper found = null;

            if (this._actions.ContainsKey(key))
            {
                found = this._actions[key].SingleOrDefault(x => x.Equals(wrapper));
            }

            return(found);
        }
		static HttpExtensions()
		{
			// 使用这个内部方法写HTTP头会比较方便,
			// 因为有些头不允许直接添加,需要通过属性来设置,那样就需要一大堆的判断,写起来很麻烦。
			MethodInfo method = typeof(WebHeaderCollection).GetMethod(
				"AddWithoutValidate",
				BindingFlags.Instance | BindingFlags.NonPublic, null,
				new Type[] { typeof(string), typeof(string) }, null);

			s_AddWithoutValidateInvoker = new ActionWrapper<WebHeaderCollection, string, string>();
			s_AddWithoutValidateInvoker.BindMethod(method);
		}
示例#20
0
        static HttpExtensions()
        {
            // 使用这个内部方法写HTTP头会比较方便,
            // 因为有些头不允许直接添加,需要通过属性来设置,那样就需要一大堆的判断,写起来很麻烦。
            MethodInfo method = typeof(WebHeaderCollection).GetMethod(
                "AddWithoutValidate",
                BindingFlags.Instance | BindingFlags.NonPublic, null,
                new Type[] { typeof(string), typeof(string) }, null);

            s_AddWithoutValidateInvoker = new ActionWrapper <WebHeaderCollection, string, string>();
            s_AddWithoutValidateInvoker.BindMethod(method);
        }
示例#21
0
    public List <ActionWrapper> GetAllAsWrapper(List <Model.Action> myActionList, string filename)
    {
        List <ActionWrapper> returnList = new List <ActionWrapper>();

        returnList.Add(new ActionWrapper()
        {
            Name = nameof(ActionWrapper.TypeEnum.ReadDwgFile), Type = ActionWrapper.TypeEnum.ReadDwgFile, FileName = filename
        });

        foreach (Model.Action item in myActionList)
        {
            ActionWrapper myActionWrapper = new ActionWrapper()
            {
                FileName = filename
            };
            switch (Enum.Parse(typeof(ActionWrapper.TypeEnum), item.Name))
            {
            case ActionWrapper.TypeEnum.AddCircle:
                myActionWrapper.Type = ActionWrapper.TypeEnum.AddCircle;
                break;

            case ActionWrapper.TypeEnum.AddLayer:
                myActionWrapper.Type = ActionWrapper.TypeEnum.AddLayer;
                break;

            case ActionWrapper.TypeEnum.AddLine:
                myActionWrapper.Type = ActionWrapper.TypeEnum.AddLine;
                break;

            case ActionWrapper.TypeEnum.AddPolyLine:
                myActionWrapper.Type = ActionWrapper.TypeEnum.AddPolyLine;
                break;

            case ActionWrapper.TypeEnum.CreateTable:
                myActionWrapper.Type = ActionWrapper.TypeEnum.CreateTable;
                break;

            case ActionWrapper.TypeEnum.PerfomranceTest:
                myActionWrapper.Type = ActionWrapper.TypeEnum.PerfomranceTest;
                break;

            default:
                throw new ArgumentException("Unrecognized action type!!");
            }
            returnList.Add(myActionWrapper);
        }

        returnList.Add(new ActionWrapper()
        {
            Name = nameof(ActionWrapper.TypeEnum.SaveDwgFile), Type = ActionWrapper.TypeEnum.SaveDwgFile, FileName = filename
        });
        return(returnList);
    }
示例#22
0
 public static ActionWrapper <T> WithSubscriptionDetails <T>(this ActionWrapper <T> baseAction, ActionSubscriptionDetails details)
 {
     return(new ActionWrapper <T>
     {
         RuleId = baseAction.RuleId,
         FlightName = baseAction.FlightName,
         ActionPath = baseAction.ActionPath,
         Precedence = baseAction.Precedence,
         Action = baseAction.Action,
         Subscription = details
     });
 }
示例#23
0
        /// <summary>When overridden in a derived class, returns a <see cref="T:System.Windows.DataTemplate"/> based on custom logic.</summary>
        /// <returns>Returns a <see cref="T:System.Windows.DataTemplate"/> or null. The default value is null.</returns>
        /// <param name="item">The data object for which to select the template.</param>
        /// <param name="container">The data-bound object.</param>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            ActionWrapper    wrapper = (ActionWrapper)item;
            FrameworkElement element = (FrameworkElement)container;

            // when the action is a Call use a different data template which will pase the call amount on the button
            if (wrapper.Action == GuiActions.Call)
            {
                return((DataTemplate)element.TryFindResource("CallButtonTemplate"));
            }
            // in all other cases use the default template
            return((DataTemplate)element.TryFindResource("ActionButtonTemplate"));
        }
示例#24
0
 private static async Task <string> TryGetErrorBody(
     ActionWrapper action,
     HttpResponseMessage resp)
 {
     try
     {
         return(await resp.Content.ReadAsStringAsync());
     }
     catch
     {
     }
     return((string)null);
 }
        private void Remove(string key, ActionWrapper wrapper)
        {
            if (key == null)
            {
                key = string.Empty;
            }
            ActionWrapper found = this.Find(key, wrapper);

            if (found != null)
            {
                this._actions[key].Remove(wrapper);
            }
        }
示例#26
0
        public ResultWrapper Execute(string name, ParameterWrapper[] parameters)
        {
            ActionWrapper action   = this.GetAction(name);
            string        path     = RestWrapper.BuildActionUrl(parameters, action);
            int           num      = 0;
            int           interval = action.Interval;

            while (num <= action.NumberOfRetries)
            {
                ++num;
                try
                {
                    ResultWrapper result = CircuitBreakerContainer.GetCircuitBreaker(this.interfaceType).Execute(this.baseUri + path, (Func <ResultWrapper>)(() => this.InvokeAction(name, parameters, action, path)), this._serviceLocator);
                    if (result.Error != null)
                    {
                        if (result.Error is SuspendedDependencyException || !action.Retry || num > action.NumberOfRetries || !this.IsTransient(action, result.Error))
                        {
                            return(result);
                        }
                        this._serviceLocator.GetService <ILogger>()?.Error(result.Error);
                        this._serviceLocator.GetService <ILogger>()?.Message(string.Format("Retrying action {0}, retry count {1}", (object)action.Name, (object)num));
                        interval *= action.IncrementalRetry ? num : 1;
                        result.EndState();
                        Thread.Sleep(interval);
                    }
                    else
                    {
                        if (num > 1)
                        {
                            result.GetState().Extras.Add("retryCount", (object)num);
                        }
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    this._logger?.Error(ex);
                    if (!action.Retry || num > action.NumberOfRetries || !this.IsTransient(action, ex))
                    {
                        throw;
                    }
                    else
                    {
                        Thread.Sleep(action.IncrementalRetry ? num : action.Interval);
                    }
                }
            }
            throw new Exception("Should not get here!?!");
        }
示例#27
0
        public IAction this[T key]
        {
            get
            {
                if (this._actionContainer.TryGetValue(key, out IAction actionwrapper))
                {
                    return(actionwrapper);
                }

                ActionWrapper <T> wrapper = new ActionWrapper <T>(key, this.Action, this.ActionCanExecute);

                this._actionContainer.Add(key, wrapper);

                return(wrapper);
            }
        }
        public void InvokeAction(string actorName, string operationType)
        {
            ActionWrapper action;
            ActorBase     actor;

            try
            {
                actor = _actors[actorName];
            }
            catch
            {
                Console.WriteLine("Invalid Actor Name");
                return;
            }

            switch ((OperationType)int.Parse(operationType))
            {
            case OperationType.Increment:
                action = new ActionWrapper(this, actorName, actor.Increment);
                break;

            case OperationType.Decrement:
                action = new ActionWrapper(this, actorName, actor.Decrement);
                break;

            default:
                throw new InvalidOperationException();
            }

            var actorState = false;

            actorState = _actorRunningState[actorName];

            if (actorState) //running
            {
                _actorsActions[actorName].Enqueue(action.DoPendingAction);
            }
            else
            {
                _actorRunningState[actorName] = true;
                var thread = new Thread(() => action.DoAction());
                thread.Start();
                _threads.Add(thread);
            }

            Console.WriteLine($"Added {(OperationType)int.Parse(operationType)} to actor {actorName}");
        }
示例#29
0
        private void GetHeaderValues(ActionWrapper action, HttpResponseMessage response)
        {
            if (response == null)
            {
                return;
            }
            List <IHeaderHandler> source = new List <IHeaderHandler>();

            foreach (IHeaderInspector customHandler in action.CustomHandlers)
            {
                source.AddRange((IEnumerable <IHeaderHandler>)customHandler.GetHandlers(this._serviceLocator));
            }
            foreach (IHeaderHandler headerHandler in (IEnumerable <IHeaderHandler>)source.OrderBy <IHeaderHandler, int>((Func <IHeaderHandler, int>)(f => f.ProcessingOrder)))
            {
                headerHandler.GetHeader(response);
            }
        }
        private void Add(string key, ActionWrapper wrapper)
        {
            if (key == null)
            {
                key = string.Empty;
            }
            ActionWrapper found = this.Find(key, wrapper);

            if (found == null)
            {
                if (!this._actions.ContainsKey(key))
                {
                    this._actions.Add(key, new List <ActionWrapper>());
                }
                this._actions[key].Add(wrapper);
            }
        }
示例#31
0
        public ActionWrapper Dispatcher(ActionWrapper myActionWrapper)
        {
            currentActionWrapper = myActionWrapper;

            switch (myActionWrapper.Type)
            {
            case ActionWrapper.TypeEnum.AddCircle:
                addCircle();
                break;

            case ActionWrapper.TypeEnum.AddLayer:
                addLayer();
                break;

            case ActionWrapper.TypeEnum.AddLine:
                addLine();
                break;

            case ActionWrapper.TypeEnum.AddPolyLine:
                addPolyLine();
                break;

            case ActionWrapper.TypeEnum.CreateTable:
                createTable();
                break;

            case ActionWrapper.TypeEnum.PerfomranceTest:
                performanceTest();
                break;

            case ActionWrapper.TypeEnum.ReadDwgFile:
                readDwgFile(_FileService.GetPath(myActionWrapper.FileName));
                break;

            case ActionWrapper.TypeEnum.SaveDwgFile:
                saveDwgFile(_FileService.GetPath(myActionWrapper.FileName));
                break;

            default:
                myActionWrapper.Status = ActionWrapper.StatusEnum.DataError;
                break;
            }

            return(currentActionWrapper);
        }
示例#32
0
        protected override async Task DoLogAsync(string message, Exception exception, LogType logType, bool sync)
        {
            Tuple <string, Exception, Task> result;

            result = ActionWrapper.Execute(() => logRepository.Add(GetLogModel(message, logType, exception)));

            if (WebUtils.WithoutErrors(result.Item1))
            {
                result = sync ? ActionWrapper.Execute(() => logRepository.Commit()) : await ActionWrapper.ExecuteAsync(logRepository.CommitAsync);
            }

            if (!WebUtils.WithoutErrors(result.Item1))
            {
                message = $"{message}; {result}";

                fileLogger.Value.Log(message, exception, logType);
            }
        }
 public ActionFacade(ActionWrapper action, Naked target, IFrameworkFacade frameworkFacade) {
     this.action = action;
     this.target = target;
     FrameworkFacade = frameworkFacade;
 }
示例#34
0
 private async void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
 {
     var backArgs = e;
     var wrapper = new ActionWrapper
     {
         WrappedAction = () => { backArgs.Handled = true; }
     };
     await GoToPreviousState(wrapper);
 }
        /// <summary>
        /// Invoke all the given actions in parallel in their own thread. 
        /// <para>
        /// A memory barrier is used to line up all actions in an attempt to ensure they are all invoked at the same time. The idea is 
        /// to cause maximum contention. However this is very much up to the OS, number or cores, whether true threading is used etc.
        /// </para>
        /// <para>
        /// If you are performing multiple operations inside your action, it is suggested to to add a Thread.Yield() in suitable
        /// places to increase the chance you will get out of order execution between threads (rather than one thread executing all the
        /// way through without being switched out partway through operation)
        /// </para>
        /// </summary>
        /// <param name="parallelActions">actions to complete in parallel</param>
        /// <param name="timeout">timeout period after which to abort</param>
        /// <param name="priority">priority with which to run threads</param>
        public static void InvokeAllWaitingForCompletion(IEnumerable<Action> parallelActions, TimeSpan timeout, ThreadPriority priority = ThreadPriority.Normal)
        {
            var actionList = new List<Action>(parallelActions); // allow multiple iteration      
            var barrierToCauseContention = new Barrier(actionList.Count());
            var wrappedActions = new List<ActionWrapper>(actionList.Count());
            var threads = new List<Thread>(actionList.Count);

            // wrap passed in actions so we can monitor the state of their execution and collect any exceptions thrown
            // the wrapped actions will wait on the barrier
            foreach (var action in actionList)
            {
                var wrapper = new ActionWrapper(barrierToCauseContention, action);
                var thread = new Thread(wrapper.Invoke) { Priority = priority };

                threads.Add(thread);                
                wrappedActions.Add(wrapper);

                thread.Start();
            }

            // wait till all actions complete
            var timeoutInMs = timeout.TotalMilliseconds;
            var stopWatch = Stopwatch.StartNew();
            var allComplete = false;
            while (!allComplete)
            {
                // if we timed out
                if (stopWatch.ElapsedMilliseconds > timeoutInMs)
                {
                    // kill all the threads still running
                    foreach (var t in threads)
                    {
                        TerminateThreadQuietly(t);
                    }
                    TestFirstAssert.Fail(string.Format("Timed out waiting for all actions to complete. Waitied for {0} milliseonds (TimeSpan {1}). Aborted remaining threads", timeoutInMs, timeout));
                }

                // determine if all actions complete
                var complete = true;
                foreach (var wrapper in wrappedActions)
                {
                    if (!wrapper.IsComplete)
                    {
                        complete = false;
                        break;
                    }
                }
                allComplete = complete;
                if (!allComplete)
                {
                    Thread.Sleep(100); // give actions a bit of time to complete
                }
            }

            // fail if any of the actions threw an exception
            var exceptions = new List<string>();
            foreach (var wrapper in wrappedActions)
            {
                if (wrapper.HasFailed)
                {
                    exceptions.Add("thread[" + wrapper.ThreadId + "] : " + wrapper.Exception);
                }
            }
            if (exceptions.Count > 0)
            {               
                var msg = "===============Action Error===========\r\n" + string.Join("\r\n===============Action Error===========", exceptions);
                TestFirstAssert.Fail(msg);
            }
        }
示例#36
0
 protected async void BackRequested(object sender, BackRequestedEventArgs e)
 {
     var backArgs = e;
     var wrapper = new ActionWrapper
     {
         WrappedAction = () => { backArgs.Handled = true; }
     };
     await GoToPreviousState(wrapper);
 }
示例#37
0
        private async Task GoToPreviousState(ActionWrapper onsuccess)
        { 

        Debug.WriteLine("Going back");

            var reg = RegionForCurrentWindow as IHasStates;
            //var win = Window.Current.CoreWindow;
            //var regId = (from r in RegionWindows
            //    where r.Value == win
            //    select r.Key).FirstOrDefault();
            //if (regId != null)
            //{
            //    var reg = RegionManager.RegionById(regId) as IHasStates;
            if (reg?.StateManager.PreviousStateExists ?? false)
            {
                onsuccess.InvokeAction();
                if (!(reg?.StateManager.GoToPreviousStateIsBlocked ?? false))
                {
                    await reg.StateManager.GoBackToPreviousState();
                }
                return;
            }
            //}

            //var gb = GoBackViewModel;
            //if (gb != null)
            //{

            //    var cancel = new CancelEventArgs();
            //    await GoBackViewModel.GoingBack(cancel);
            //    if (cancel.Cancel)
            //    {
            //        e.Handled = true;
            //        return;
            //    }
            //}
            //e.Handled = true;
            //if (Frame.CanGoBack)
            //{
            //    Frame.GoBack();
            //}
        }