Example #1
0
        private static List <TogglTimeEntryView> ConvertToTimeEntryList(IntPtr first)
        {
            using (var token = Performance.Measure("marshalling time entry list"))
            {
                List <TogglTimeEntryView> list = new List <TogglTimeEntryView>();
                if (IntPtr.Zero == first)
                {
                    token.WithInfo("count: 0");
                    return(list);
                }
                TogglTimeEntryView n = (TogglTimeEntryView)Marshal.PtrToStructure(
                    first, typeof(TogglTimeEntryView));

                while (true)
                {
                    list.Add(n);
                    if (n.Next == IntPtr.Zero)
                    {
                        break;
                    }
                    n = (TogglTimeEntryView)Marshal.PtrToStructure(
                        n.Next, typeof(TogglTimeEntryView));
                }
                token.WithInfo("count: " + list.Count);
                return(list);
            }
        }
Example #2
0
        private static void listenToLibEvents()
        {
            toggl_on_show_app(ctx, delegate(bool open)
            {
                using (Performance.Measure("Calling OnApp"))
                {
                    OnApp(open);
                }
            });

            toggl_on_error(ctx, delegate(string errmsg, bool user_error)
            {
                using (Performance.Measure("Calling OnError, user_error: {1}, message: {0}", errmsg, user_error))
                {
                    OnError(errmsg, user_error);
                }
            });

            toggl_on_online_state(ctx, delegate(Int64 state)
            {
                using (Performance.Measure("Calling OnOnlineState, state: {0}", state))
                {
                    OnOnlineState(state);
                }
            });

            toggl_on_login(ctx, delegate(bool open, UInt64 user_id)
            {
                using (Performance.Measure("Calling OnLogin"))
                {
                    OnLogin(open, user_id);
                }
            });

            toggl_on_reminder(ctx, delegate(string title, string informative_text)
            {
                using (Performance.Measure("Calling OnReminder, title: {0}", title))
                {
                    OnReminder(title, informative_text);
                }
            });

            toggl_on_time_entry_list(ctx, delegate(bool open, IntPtr first)
            {
                using (Performance.Measure("Calling OnTimeEntryList"))
                {
                    var list = ConvertToTimeEntryList(first);
                    OnTimeEntryList(open, list);
                }
            });

            toggl_on_time_entry_autocomplete(ctx, delegate(IntPtr first)
            {
                using (Performance.Measure("Calling OnTimeEntryAutocomplete"))
                {
                    var list = ConvertToAutocompleteList(first);
                    OnTimeEntryAutocomplete(list);
                }
            });

            toggl_on_mini_timer_autocomplete(ctx, delegate(IntPtr first)
            {
                using (Performance.Measure("Calling OnMinitimerAutocomplete"))
                {
                    var list = ConvertToAutocompleteList(first);
                    OnMinitimerAutocomplete(list);
                }
            });

            toggl_on_project_autocomplete(ctx, delegate(IntPtr first)
            {
                using (Performance.Measure("Calling OnProjectAutocomplete"))
                {
                    var list = ConvertToAutocompleteList(first);
                    OnProjectAutocomplete(list);
                }
            });

            toggl_on_time_entry_editor(ctx, delegate(
                                           bool open,
                                           IntPtr te,
                                           string focused_field_name)
            {
                using (Performance.Measure("Calling OnTimeEntryEditor, focused field: {0}", focused_field_name))
                {
                    TogglTimeEntryView model = (TogglTimeEntryView)Marshal.PtrToStructure(
                        te, typeof(TogglTimeEntryView));
                    OnTimeEntryEditor(open, model, focused_field_name);
                }
            });

            toggl_on_workspace_select(ctx, delegate(IntPtr first)
            {
                using (Performance.Measure("Calling OnWorkspaceSelect"))
                {
                    var list = ConvertToViewItemList(first);
                    OnWorkspaceSelect(list);
                }
            });

            toggl_on_client_select(ctx, delegate(IntPtr first)
            {
                using (Performance.Measure("Calling OnClientSelect"))
                {
                    var list = ConvertToViewItemList(first);
                    OnClientSelect(list);
                }
            });

            toggl_on_tags(ctx, delegate(IntPtr first)
            {
                using (Performance.Measure("Calling OnTags"))
                {
                    var list = ConvertToViewItemList(first);
                    OnTags(list);
                }
            });

            toggl_on_settings(ctx, delegate(bool open, IntPtr settings)
            {
                using (Performance.Measure("Calling OnSettings"))
                {
                    TogglSettingsView model = (TogglSettingsView)Marshal.PtrToStructure(
                        settings, typeof(TogglSettingsView));
                    OnSettings(open, model);
                }
            });

            toggl_on_timer_state(ctx, delegate(IntPtr te)
            {
                if (te == IntPtr.Zero)
                {
                    using (Performance.Measure("Calling OnStoppedTimerState"))
                    {
                        OnStoppedTimerState();
                        return;
                    }
                }
                using (Performance.Measure("Calling OnRunningTimerState"))
                {
                    TogglTimeEntryView view =
                        (TogglTimeEntryView)Marshal.PtrToStructure(
                            te, typeof(TogglTimeEntryView));
                    OnRunningTimerState(view);
                }
            });

            toggl_on_url(ctx, delegate(string url)
            {
                using (Performance.Measure("Calling OnURL"))
                {
                    OnURL(url);
                }
            });

            toggl_on_idle_notification(ctx, delegate(
                                           string guid,
                                           string since,
                                           string duration,
                                           UInt64 started,
                                           string description)
            {
                using (Performance.Measure("Calling OnIdleNotification"))
                {
                    OnIdleNotification(guid, since, duration, started, description);
                }
            });
        }