Пример #1
0
        private static void RegisterApplicationEvent()
        {
            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
            err = Interop.ApplicationManager.AppManagerEventCreate(out _eventHandle);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to create the application event handle");
            }

            err = Interop.ApplicationManager.AppManagerEventSetStatus(_eventHandle, Interop.ApplicationManager.AppManagerEventStatusType.All);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle);
                _eventHandle = IntPtr.Zero;
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to set the application event");
            }

            s_eventCallback = (string appType, string appId, Interop.ApplicationManager.AppManagerEventType eventType, Interop.ApplicationManager.AppManagerEventState eventState, IntPtr eventHandle, IntPtr UserData) =>
            {
                if (eventType == Interop.ApplicationManager.AppManagerEventType.Enable)
                {
                    s_enabledHandler?.Invoke(null, new ApplicationEnabledEventArgs(appId, (ApplicationEventState)eventState));
                }
                else if (eventType == Interop.ApplicationManager.AppManagerEventType.Disable)
                {
                    s_disabledHandler?.Invoke(null, new ApplicationDisabledEventArgs(appId, (ApplicationEventState)eventState));
                }
            };
            err = Interop.ApplicationManager.AppManagerSetEventCallback(_eventHandle, s_eventCallback, IntPtr.Zero);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle);
                _eventHandle = IntPtr.Zero;
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to set the application event callback");
            }
        }
Пример #2
0
        public static IEnumerable <RecentApplicationInfo> GetRecentApplications()
        {
            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;

            List <RecentApplicationInfo> result = new List <RecentApplicationInfo>();
            IntPtr table;
            int    nrows, ncols;

            err = Interop.ApplicationManager.RuaHistoryLoadDb(out table, out nrows, out ncols);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to load a table for the recent application list.");
            }

            for (int row = 0; row < nrows; ++row)
            {
                Interop.ApplicationManager.RuaRec record;

                err = Interop.ApplicationManager.RuaHistoryGetRecord(out record, table, nrows, ncols, row);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to get record.");
                }

                RecentApplicationInfo info = new RecentApplicationInfo(record);
                result.Add(info);
            }

            err = Interop.ApplicationManager.RuaHistoryUnLoadDb(ref table);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to unload a table for the recent application list.");
            }

            return(result);
        }