Beispiel #1
0
        /// <summary>
        /// Handles app event sent from Razer SDK.
        /// </summary>
        /// <param name="type">App event type.</param>
        /// <param name="firstParam">The first DWORD parameter.</param>
        /// <param name="secondParam">The second DWORD parameter.</param>
        /// <returns><see cref="HRESULT" /> object indicating success or failure.</returns>
        private HRESULT HandleAppEvent(AppEventType type, uint firstParam, uint secondParam)
        {
            const int Result = HRESULT.RZSB_OK;

            if (type == AppEventType.Invalid || type == AppEventType.None)
            {
                _log.DebugFormat("Unsupported AppEventType: {0}", type);
                return(Result);
            }

            OnAppEvent(type, firstParam, secondParam);

            switch (type)
            {
            case AppEventType.Activated:
                OnActivated(firstParam, secondParam);
                break;

            case AppEventType.Close:
                OnClose(firstParam, secondParam);
                break;

            case AppEventType.Deactivated:
                OnDeactivated(firstParam, secondParam);
                break;

            case AppEventType.Exit:
                OnExit(firstParam, secondParam);
                break;
            }

            return(Result);
        }
Beispiel #2
0
 public static void Dispatch(AppEventType type, params object[] data)
 {
     if (Events.ContainsKey(type))
     {
         Events[type].Dispatch(new AppEvent(type, data));
     }
 }
Beispiel #3
0
 public static void ExecuteHandler(AppEventType eventType)
 {
     foreach (var handler in GetHandler(eventType))
     {
         handler.Execute_AppHandler();
     }
 }
Beispiel #4
0
        /// <summary>
        /// Represents low-level networking call that can be used to transmit an event to the browser.
        /// </summary>
        /// <param name="client">The client to transmit the event to.</param>
        /// <param name="propertyName">The name of the event to transmit.</param>
        /// <param name="type">The type of the event to transmit.</param>
        /// <param name="eventValue">The value of the event to transmit.</param>
        internal static void SendEvent(ClientObject client, AppEventType type, BoxedValue target, string eventName, BoxedValue eventValue)
        {
            try
            {
                // Check if the target is an object and retrieve the id.
                var oid = 0;
                if (target.IsObject && target.Object is BaseObject)
                    oid = ((BaseObject)target.Object).Oid;

                // Get the client
                var channel = client.Target;

                // Convert to a string
                var stringValue = TypeConverter.ToNullableString(
                    Native.Serialize(client.Env, eventValue, true)
                    );

                // Dispatch the inform
                channel.TransmitEvent(type, oid, eventName, stringValue);
            }
            catch (Exception ex)
            {
                // Log the exception
                Service.Logger.Log(ex);
            }
        }
 public void Subscribe(AppEventType type, Listener listener)
 {
     if (!listenersMap.ContainsKey(type))
         listenersMap.Add(type, new Listener(listener));
     else
         listenersMap[type] += listener;
 }
Beispiel #6
0
 /// <summary>
 /// 获取指定事件按照 ID 和优先级排序后的结果
 /// </summary>
 /// <param name="events">要获取的事件源的应用</param>
 /// <param name="type">事件类型</param>
 /// <returns>事件列表</returns>
 private static IEnumerable <AppEvent> GetEvents(CQPSimulatorApp app, AppEventType type)
 {
     return(from temp in app.Library.AppInfo.Events
            where temp.Type == type
            orderby temp.Id
            orderby temp.Priority
            select temp);
 }
Beispiel #7
0
        public static void On(AppEventType type, ExEventDelegate <AppEvent> d)
        {
            if (!Events.ContainsKey(type))
            {
                Events.Add(type, new ExEvent <AppEvent>());
            }

            Events[type] += d;
        }
Beispiel #8
0
        /// <summary>
        /// Raises app event to subscribers.
        /// </summary>
        /// <param name="type">App event type.</param>
        /// <param name="firstParam">The first DWORD parameter.</param>
        /// <param name="secondParam">The second DWORD parameter.</param>
        private void OnAppEvent(AppEventType type, uint firstParam, uint secondParam)
        {
            var func = AppEvent;

            if (func != null)
            {
                func(this, new AppEventEventArgs(type, firstParam, secondParam));
            }
        }
Beispiel #9
0
        public AppEventArgs(Guid id, DateTime event_ts, AppEventType appEventType, T beforeChange, T afterChange)
        {
            this.id           = id;
            this.event_ts     = event_ts;
            this.appEventType = appEventType;

            this.beforeChange = beforeChange;
            this.afterChange  = afterChange;
        }
    public void Unsubscribe(AppEventType type, Listener listener)
    {
        if(!listenersMap.ContainsKey(type))
        {
            Debug.LogError(type.ToString() + " doesn't exist");
            return;
        }

        listenersMap[type] -= listener;
    }
        // This function is used to subscribe to an event using an asynchrnous handler
        public virtual Guid Subscribe(AppEventType appEventType, Func <AppEventArgs <T>, Task> handler)
        {
            var newhandler = new EventHandlerEntry <T>();

            newhandler.EventHandlerID = Guid.NewGuid();
            newhandler.AppEventType   = appEventType;
            newhandler.EventHandler   = handler;

            allEventHandlers.Add(newhandler);

            return(newhandler.EventHandlerID);
        }
Beispiel #12
0
 public EventLogItem(DateTime timestamp, Exception ex, string description)
 {
     Timestamp  = timestamp;
     EventType  = AppEventType.Error;
     ObjectType = ex.Source;
     if (ex.Data.Contains("ObjectName"))
     {
         ObjectName = ex.Data["ObjectName"].ToString();
     }
     Description = description + ", exception: " + ex.Message;
     ErrorCode   = "0x" + Convert.ToString(ex.HResult, 16);
     StackTrace  = ex.StackTrace;
 }
Beispiel #13
0
        private static IEnumerable <IAppEvent> GetHandler(AppEventType eventType)
        {
            Type             interfaceType = typeof(IAppEvent);
            List <IAppEvent> result        = new List <IAppEvent>();

            foreach (var item in Assembly.GetExecutingAssembly().GetTypes().Where(t => interfaceType.IsAssignableFrom(t) && !t.IsInterface))
            {
                IAppEvent handler = (IAppEvent)Activator.CreateInstance(item);
                result.Add(handler);
            }

            return(result.Where(i => i.EvenType == eventType));
        }
Beispiel #14
0
 public EventLogItem(DateTime timestamp, string objectType, string objectName, string description, bool ConfigError = false)
 {
     Timestamp   = timestamp;
     ObjectType  = objectType;
     ObjectName  = objectName;
     Description = description;
     if (ConfigError)
     {
         EventType = AppEventType.ConfigErr;
     }
     else
     {
         EventType = AppEventType.Debug;
     }
 }
Beispiel #15
0
        public EmailEventArgs(Guid id, DateTime event_ts, AppEventType appEventType,
                              string subject, string textMsg, string htmlMsg,
                              List <string> notifyTo, List <string> notifyCC, List <string> notifyBCC
                              )
        {
            this.id           = id;
            this.event_ts     = event_ts;
            this.appEventType = appEventType;

            this.subject   = subject;
            this.textMsg   = textMsg;
            this.htmlMsg   = htmlMsg;
            this.notifyTo  = notifyTo;
            this.notifyCC  = notifyCC;
            this.notifyBCC = notifyBCC;
        }
Beispiel #16
0
        /// <summary>
        /// Represents low-level networking call that can be used to transmit an event to the browser.
        /// </summary>
        /// <param name="client">The client to transmit the event to.</param>
        /// <param name="propertyName">The name of the event to transmit.</param>
        /// <param name="type">The type of the event to transmit.</param>
        /// <param name="eventValue">The value of the event to transmit.</param>
        internal static void SendEvent(BoxedValue client, AppEventType type, BoxedValue target, string eventName, BoxedValue eventValue)
        {
            try
            {
                // Check if it's an object
                if (!client.IsObject)
                    return;

                // Unbox & check if alive
                var unboxedClient = client.Object as ClientObject;
                if (unboxedClient == null && unboxedClient.IsAlive)
                    return;

                // Unboxed call
                Native.SendEvent(unboxedClient, type, target, eventName, eventValue);
            }
            catch (Exception ex)
            {
                // Log the exception
                Service.Logger.Log(ex);
            }
        }
Beispiel #17
0
 void handle_app_events(AppEventType event_type, params object[] param_array)
 {
     if (event_type == AppEventType.LOG)
     {
         Console.WriteLine(param_array[0]);
     }
     else
     {
         // A default handler that relies on the .ToString()
         Console.Write(event_type + ": ");
         if (param_array != null && param_array.Length > 0)
         {
             foreach (var obj in param_array)
             {
                 Console.WriteLine(obj);
             }
         }
         else
         {
             Console.WriteLine();
         }
     }
 }
 public GameObjectEvent(AppEventType type, GameObject g)
 {
     Type = type;
     gameObject = g;
 }
Beispiel #19
0
        /// <summary>
        /// Run app event
        /// </summary>
        /// <remarks>DEPRECATED METHOD, USE EVENT SPECIFIC METHOD INSTEAD</remarks>
        /// <param name="appEvent">The app event type</param>
        /// <param name="model">The service model</param>
        /// <param name="modelState">The model state</param>
        /// <returns>True if the event was handled</returns>
        public override async Task <bool> RunAppEvent(AppEventType appEvent, object model, ModelStateDictionary modelState = null)
        {
            _logger.LogInformation($"RunAppEvent {appEvent}");

            return(await Task.FromResult(true));
        }
Beispiel #20
0
 internal static extern ErrorCode AddEventHandler(out IntPtr handle, AppEventType eventType, AppEventCallback callback, IntPtr data);
 public SendNumberEvent(int value)
 {
     Type = AppEventType.SEND_NUMBER;
     number = value;
 }
 public virtual void OnEvent(AppEventType appEventType, AppEventArgs <T> e)
 {
     this.__executeEventHandlers(
         this.allEventHandlers.Where(ed => ed.AppEventType == appEventType), e);
 }
        /// <summary>
        /// Executes the event.
        /// </summary>
        /// <param name="eventActionType">Type of the event action.</param>
        /// <param name="type">The type.</param>
        /// <param name="state">The state.</param>
        /// <param name="eventItem">The event item.</param>
        protected void ExecuteEventImpl(Type eventActionType, AppEventType type, string state, object eventItem)
        {
            List<Delegate> delegateList;

            if (_events.TryGetValue(eventActionType, out delegateList))
            {
                foreach (Delegate delgate in delegateList)
                {
                    try
                    {
                        delgate.DynamicInvoke(eventItem, new AppEventArgs(type, state));
                    }
                    catch (Exception ex)
                    {
                        if (ExceptionHandler != null)
                        {
                            ExceptionHandler(ex);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Executes the event.
        /// </summary>
        /// <param name="appType">Type of the application.</param>
        /// <param name="state">The state.</param>
        /// <param name="eventItem">The event item.</param>
        public void ExecuteEvent(AppEventType appType, string state, object eventItem)
        {
            Type[] tArray = eventItem.GetType().FindInterfaces(Module.FilterTypeName, "*");

            foreach(Type type in tArray)
            {
                ExecuteEventImpl(type, appType, state, eventItem);
            }

            ExecuteEventImpl(eventItem.GetType(), appType, state, eventItem);
        }
Beispiel #25
0
 public AppEvent(AppEventType type, params object[] data)
 {
     this.EventType = type;
     this.Data      = data;
 }
 public SortNumberEvent(Controller controller)
 {
     Type = AppEventType.SORT_NUMBER;
     ctrl = controller;
 }
Beispiel #27
0
 /// <inheritdoc />
 public abstract Task <bool> RunAppEvent(AppEventType appEvent, object model, ModelStateDictionary modelState = null);
        /// <summary>
        /// Event handler for events issued by the backup manager thread.
        /// This function runs on the backup manager thread, so it cannot
        /// access the GUI elements directly.
        /// </summary>
        void handle_event(AppEventType event_type, params object[] param_array)
        {
            if (event_type == AppEventType.LOG)
            {
                string text = (string)param_array[0];
                add_line_of_text(text);
            }
            else if (event_type == AppEventType.ERROR)
            {
                app_mode = AppMode.ERROR;
                Output_tb.Dispatcher.BeginInvoke(new Func_Icon(change_notify_icon), error_icon);

                var error_message = (string)param_array[0];
                Output_tb.Dispatcher.BeginInvoke(
                    new Func_string(show_error_message_box), error_message);

                add_line_of_text(error_message);
            }
            else if (event_type == AppEventType.CHECK_BACKUPS_DONE)
            {
                // This is the backup manager thread, so better to not call:
                // backup_manager.start_live_backup();
                // directly. Better call it via GUI thread, for consistency.
                Output_tb.Dispatcher.BeginInvoke(new Func_void(start_live_backup), null);
                add_line_of_text("All backups are up to date.");
            }
            else if (event_type == AppEventType.GET_RESTORE_INFO_DONE)
            {
                if (app_mode == AppMode.RESTORE_GET_INFO)
                {
                    RestoreInfo info = (RestoreInfo)param_array[0];
                    RestoreInfo_text.Dispatcher.BeginInvoke(
                        new Func_RestoreInfo(restore_window.get_restore_info_done), info);

                    app_mode = AppMode.RESTORE_UNDER_WAY;
                    restore_mode_files_processed = 0;
                }
            }
            else if (event_type == AppEventType.FILES_PROCESSED)
            {
                int files_processed = (int)param_array[0];

                restore_mode_files_processed += files_processed;
                string progress = "Files processed: " + restore_mode_files_processed.ToString();

                if (app_mode == AppMode.RESTORE_GET_INFO)
                {
                    RestoreInfo_text.Dispatcher.BeginInvoke(
                        new Func_TextBlock_string(set_text_block_text), RestoreInfo_text, progress);
                }
                else if (app_mode == AppMode.RESTORE_UNDER_WAY)
                {
                    RestoreInfo_text.Dispatcher.BeginInvoke(
                        new Func_TextBlock_string(set_text_block_text), RestoreStatus_text, progress);
                }
            }
            else if (event_type == AppEventType.RESTORE_DONE)
            {
                if (app_mode == AppMode.RESTORE_UNDER_WAY)
                {
                    string message = "Files processed: " + restore_mode_files_processed.ToString()
                                     + "\nRestore completed.";
                    RestoreInfo_text.Dispatcher.BeginInvoke(
                        new Func_TextBlock_string(set_text_block_text), RestoreStatus_text, message);
                    app_mode = AppMode.RESTORE_DONE;
                }
            }
            else if (event_type == AppEventType.BM_THREAD_IDLE)
            {
                if (app_mode != AppMode.ERROR)
                {
                    Output_tb.Dispatcher.BeginInvoke(
                        new Func_Icon(change_notify_icon), ready_icon);
                }
            }
            else if (event_type == AppEventType.BM_THREAD_RUNNING)
            {
                if (app_mode != AppMode.ERROR)
                {
                    Output_tb.Dispatcher.BeginInvoke(
                        new Func_Icon(change_notify_icon), busy_icon);
                }
            }
        }
Beispiel #29
0
 public override Task <bool> RunAppEvent(AppEventType appEvent, object model, ModelStateDictionary modelState = null)
 {
     return(Task.FromResult(true));
 }
Beispiel #30
0
        /// <summary>
        /// Run app event
        /// </summary>
        /// <remarks>DEPRECATED METHOD, USE EVENT SPECIFIC METHOD INSTEAD</remarks>
        /// <param name="appEvent">The app event type</param>
        /// <param name="model">The service model</param>
        /// <param name="modelState">The model state</param>
        /// <returns></returns>
        public override async Task <bool> RunAppEvent(AppEventType appEvent, object model, ModelStateDictionary modelState)
        {
            _logger.LogInformation($"RunAppEvent {appEvent}");

            return(true);
        }
 public ModifyButtonEvent(AppEventType type)
 {
     Type = type;
 }
Beispiel #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AppEventEventArgs" /> class.
 /// </summary>
 /// <param name="eventType">App event type.</param>
 /// <param name="firstParam">App event mode associated with this event.</param>
 /// <param name="secondParam">Process ID associated with event.</param>
 internal AppEventEventArgs(AppEventType eventType, uint firstParam, uint secondParam)
 {
     _eventType   = eventType;
     _firstParam  = firstParam;
     _secondParam = secondParam;
 }