private void OnTick(object sender, EventArgs e)
        {
            _logServices.TraceEnter();
            try
            {
                _logServices.Trace("Checking if running on UI thread...");
                if (_invoker.InvokeRequired)
                {
                    _logServices.Trace("Not running on UI thread.  Delegating to UI thread...");
                    _invoker.Invoke(new OnTickDelegate(OnTick), sender, e);

                    return;
                }

                _logServices.Trace("Setting elapsed time...");
                Elapsed = DateTime.Now - _startTime;
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
            finally
            {
                _logServices.TraceExit();
            }
        }
Exemplo n.º 2
0
        public ActionResult SentimentQueryLaunch(DateInterval interval)
        {
            if (Session["Query"] != null)
            {
                return(Json(new { Error = "There is already a sentiment query in progress." }));
            }
            var mq      = new Queue <String>();
            var ev      = new AutoResetEvent(false);
            var context = new InvokerContext(
                new QuerySentiment(),
                new { interval.DateFrom, interval.DateTo, CompanyName = Session["CompanyName"] },
                message =>
            {
                mq.Enqueue(message);
                ev.Set();
            },
                track => { });

            Session["Query"] = new QueryContext(context, mq, ev);
            Task.Run(() =>
            {
                invoker.Invoke(context);
                ev.Set();
            }).ContinueWith(t =>
            {
                mq.Enqueue("Error: " + t.Exception.GetBaseException().ToString());
                ev.Set();
            }, TaskContinuationOptions.OnlyOnFaulted);
            return(SentimentQueryProgress());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invokes the applicable listeners for this node.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="evt"></param>
        void InvokeListeners(XNode node, Event evt)
        {
            Contract.Requires <ArgumentNullException>(node != null);
            Contract.Requires <ArgumentNullException>(evt != null);

            // Initialize event's currentTarget attribute to the object for which these steps are run.
            evt.currentTarget = node;

            // invoke registered listeners
            foreach (var registration in node.Interface <EventTarget>().state.registrations)
            {
                // If event's stop immediate propagation flag is set, terminate the invoke algorithm.
                if (evt.stopImmediatePropagation)
                {
                    return;
                }

                // If event's type attribute value is not listener's type, terminate these substeps (and run them for
                // the next event listener).
                if (evt.type != registration.EventType)
                {
                    continue;
                }

                // If event's eventPhase attribute value is CAPTURING_PHASE and listener's capture is false, terminate
                // these substeps (and run them for the next event listener).
                if (evt.eventPhase == EventPhase.Capturing && registration.Capture == false)
                {
                    continue;
                }

                // If event's eventPhase attribute value is BUBBLING_PHASE and listener's capture is true, terminate
                // these substeps (and run them for the next event listener).
                if (evt.eventPhase == EventPhase.Bubbling && registration.Capture == true)
                {
                    continue;
                }

                // Call listener's callback's handleEvent, with the event passed to this algorithm as the first
                // argument and event's currentTarget attribute value as callback this value.
                invoker.Invoke(() =>
                               registration.Listener.HandleEvent(evt));
            }

            // invoke listeners available directly as interfaces
            foreach (var listener in node.Interfaces <IEventListener>())
            {
                // If event's stop immediate propagation flag is set, terminate the invoke algorithm.
                if (evt.stopImmediatePropagation)
                {
                    return;
                }

                invoker.Invoke(() =>
                               listener.HandleEvent(evt));
            }
        }
Exemplo n.º 4
0
 public void Go(IContext context)
 {
     _context = context;
     _initializer.Initialize(_context);
     _invoker.Invoke(_context);
     _finalizer.Finalize(_context);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Parses and handles commands from input.
        /// </summary>
        public void AcceptCommands()
        {
            string s;

            while (true)
            {
                try
                {
                    s = Read().Trim();
                    if (s != "")
                    {
                        Parser.Invoke(this, s);
                    }
                }
                catch (ExitCommandException)
                {
                    CloseAllConnections(ExitMessage);
                    HandleAfterExit();
                    break;
                }
                catch (ParseException pe)
                {
                    Write(pe.Message);
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Handles incoming packets.
 /// </summary>
 void Handle()
 {
     try
     {
         while (true)
         {
             Parser.Invoke(this, Stream.Read());
         }
     }
     catch (EndException e)
     {
         HandleNormalConnectionClose(e.Reason);
         RemoveConnection();
     }
     catch
     {
         bool sc;
         lock (this)
         {
             sc = should_close;
         }
         if (!sc)
         {
             HandleAbruptConnectionClose();
             RemoveConnection();
         }
     }
 }
Exemplo n.º 7
0
        public void InvokeHandleEvent(Event evt)
        {
            Contract.Requires <ArgumentNullException>(evt != null);

            invoker.Invoke(() =>
                           handler.Value.HandleEvent(evt));
        }
Exemplo n.º 8
0
        //private readonly ResultHandler _resultHandler;

        //public InvokerWrapper(IInvoker invoker, IInvokeFilter[]  filters, ResultHandler resultHandler = null)
        //{
        //    _invoker = invoker;
        //    _filters = filters;
        //    _resultHandler = resultHandler ?? SeifApplication.AppEnv.GlobalConfiguration.ConsumerConfiguration.GetResultHandler();
        //}

        //public string Url
        //{
        //    get { return _invoker == null ? string.Empty : _invoker.Url; }
        //}

        //public ISerializer Serializer
        //{
        //    get
        //    {
        //        if (_invoker != null)
        //            return _invoker.Serializer;
        //        return null;
        //    }
        //}

        //public ResultHandler ResultHandler
        //{
        //    get { return _resultHandler; }
        //}

        public InvokeResult Invoke(IInvocation invocation)
        {
            var context = new InvokeContext {
                Invocation = invocation
            };

            foreach (var invokeFilter in _filters.Where(p => p is IPreInvokeFilter))
            {
                var preFilter = invokeFilter as IPreInvokeFilter;
                if (preFilter != null)
                {
                    preFilter.Execute(context);
                }
            }

            try
            {
                var result = _invoker.Invoke(invocation);
                result.Status        = ResultStatus.Success;
                context.InvokeResult = result;

                // Reverse
                var postFilters = _filters.Where(p => p is IPostInvokeFilter).Cast <IPostInvokeFilter>();
                foreach (var invokeFilter in postFilters.Reverse())
                {
                    invokeFilter.Execute(context);
                }

                return(context.InvokeResult);
            }
            catch (Exception ex)
            {
                context.InvokeException = ex;

                // Reverse
                var errorFilters = _filters.Where(p => p is IExceptionFilter).Cast <IExceptionFilter>();
                foreach (var invokeFilter in errorFilters.Reverse())
                {
                    invokeFilter.Execute(context);
                    if (context.IsExceptionHandled)
                    {
                        return(context.InvokeResult);
                    }
                }

                throw context.InvokeException;
            }
            //result.Result = ResultHandler.ProcessResult(result, invocation.ReturnType, _invoker.Serializer);

            //// Reverse
            //foreach (var invokeFilter in _filters.Reverse())
            //{
            //    result = invokeFilter.PostInvoke(result);
            //}

            //return result;
        }
Exemplo n.º 9
0
 public bool Invoke(object localInstance, ref object returnValue, object[] parameters, Type[] genericArguments,
                    MethodInfo methodInfo)
 {
     // ReSharper disable once ConvertIfStatementToReturnStatement
     if (methodMatcher.IsMatch(methodInfo.GetParameterTypeAndNames(), genericArguments, methodInfo.ReturnType))
     {
         return(masterInvoker.Invoke(localInstance, ref returnValue, parameters, genericArguments, methodInfo));
     }
     return(true);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Implements the setter for Value.
 /// </summary>
 /// <param name="value"></param>
 void SetValue(string value)
 {
     invoker.Invoke(() =>
     {
         if (modelItem != null)
         {
             modelItem.Value = value ?? "";
         }
     });
 }
Exemplo n.º 11
0
        public JsonResult Login(Credentials credentials)
        {
            if (!ModelState.IsValid)
            {
                return(ControllerExtensions.CreateModelValidationResult(this));
            }

            var context = invoker.Invoke(new InvokerContext(new UserLogin(), credentials));

            if (!context.Results.LoggedIn)
            {
                return(ControllerExtensions.CreateModelErrors(this, context.Messages.ToArray()));
            }

            TempData["Messages"] = context.Messages;

            FormsAuthentication.SetAuthCookie(credentials.CompanyName, false);
            Session["CompanyName"] = credentials.CompanyName;
            return(Json(new { Success = true, RedirectURL = Url.Action("Index", "Home") }));
        }
        public object Invoke(params object[] args)
        {
            if (_target == null)
            {
                throw new NotImplementedException();
            }

            if (_invoker == null)
            {
                throw new NotImplementedException();
            }

            return(_invoker.Invoke(_target.Target, _target.Method, _suppliedArguments, args));
        }
Exemplo n.º 13
0
    void DoQueueMethod()
    {
        lock (_queueMethodLock)
        {
            if (_queuedMethod.Count > 0)
            {
                _tmpQueueMethod.AddRange(_queuedMethod);
                _queuedMethod.Clear();
            }
        }

        if (_tmpQueueMethod.Count > 0)
        {
            for (int i = 0; i < _tmpQueueMethod.Count; i++)
            {
                IInvoker invoker = _tmpQueueMethod[i];
                invoker.Invoke();
            }
            _tmpQueueMethod.Clear();
        }
    }
        protected T Invoke <T>(string name, params Tuple <string, object>[] args)
        {
            JToken arg = null;

            if (args.Length == 1 && args[0].Item2 != null)
            {
                arg = JToken.FromObject(args[0].Item2);
            }
            else if (args.Length > 1)
            {
                JObject argo = new JObject();
                arg = argo;
                for (int i = 0; i < args.Length; i++)
                {
                    argo[args[i].Item1] = JToken.FromObject(args[i].Item2);
                }
            }

            JToken result = invoker.Invoke(name, arg);

            return(result.Value <T>());
        }
        public TResult Invoke()
        {
            var x = _inner.Invoke();

            return(_behaviour(x));
        }
Exemplo n.º 16
0
 public void Invoke(System.Windows.Forms.MethodInvoker globalSystemWindowsFormsMethodInvoker)
 {
     invoker.Invoke(globalSystemWindowsFormsMethodInvoker);
 }