Exemplo n.º 1
0
        DisplayInfoAsync(OneNote.Window owner, string text)
        {
            const MessageBoxIcon Icon = MessageBoxIcon.Information;
            var parent = new Win32Window(owner);

            await DisplayAsync(parent, text, Icon).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  用于显示窗体的方法
        /// </summary>
        /// <param name="control"> 表示传递给每个功能区用户界面 (UI) 控件的
        /// 回调过程的对象. </param>
        public void ShowForm(IRibbonControl control)
        {
            OneNote.Window      context = control.Context as OneNote.Window;
            CWin32WindowWrapper owner   =
                new CWin32WindowWrapper((IntPtr)context.WindowHandle);
            TestForm form = new TestForm(applicationObject as OneNote.Application);

            form.ShowDialog(owner);

            form.Dispose();
            form    = null;
            context = null;
            owner   = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
        }
Exemplo n.º 3
0
        public async void CreateNewPage(object sender, EventArgs e)
        {
            var settings = sender as IPageSettingsModel;

            if (settings == null)
            {
                return;
            }

            int retryCount = 0, retryLimit = 4;
            Func <OneNote.Window, string[], Task> modalDisplay = null;

            OneNote.Window modalOwner = null;
            string[]       modalText  = null;
            var            delay      = TimeSpan.FromMilliseconds(250);

            for (; ;)  // BEGIN Retry pattern
            {
                try
                {
                    await CreateNewPageAsync(settings).ConfigureAwait(false);

                    break;
                }
                catch (Exception ex)
                {
                    modalOwner = Application.Windows.CurrentWindow;
                    if (Utils.ExceptionHandler.IsTransientError(ex))
                    {
                        if (++retryCount > retryLimit)
                        {
                            Utils.ExceptionHandler.HandleException(ex);
                            modalDisplay =
                                Utils.WinHelper.DisplayWarningAsync;
                            modalText = new[] {
                                "OneNote is busy.",
                                "Please try again in a moment."
                            };
                            break;
                        }
                    }
                    else
                    {
                        Utils.ExceptionHandler.HandleException(ex);
                        modalDisplay = Utils.WinHelper.DisplayErrorAsync;
                        modalText    = new[] {
                            "OneNote API Error",
                            Utils.ExceptionHandler.FormatHResult(ex.HResult)
                        };
                        break;
                    }
                }/* end catch */

                Tracer.WriteWarnLine("Transient error, sleeping {0} ms . . .",
                                     delay.Milliseconds);

                await Task.Delay(delay).ConfigureAwait(false);
            }// *END* Retry pattern

            if (modalDisplay != null)
            {
                await modalDisplay(modalOwner, modalText).ConfigureAwait(false);
            }
        }
Exemplo n.º 4
0
        DisplayInfoAsync(OneNote.Window owner, string[] text)
        {
            var multiLineText = string.Join(Environment.NewLine, text);

            await DisplayInfoAsync(owner, multiLineText).ConfigureAwait(false);
        }
Exemplo n.º 5
0
 internal Win32Window(OneNote.Window context)
     : this((IntPtr)context.WindowHandle)
 {
 }
Exemplo n.º 6
0
        /// <summary>
        /// Find the OneNote main window from the given window context.
        /// </summary>
        /// <param name="context">Window context; typically an IRibbonControl reference.</param>
        /// <returns>The window wrapper.</returns>
        /// <remarks>
        /// Call with
        /// <![CDATA[
        /// var owner = UIHelper.GetOwner((IRibbonControl)control.Context as Window);
        /// ]]>
        /// </remarks>

        public static Win32WindowHandle GetOwner(One.Window context)
        {
            return(new Win32WindowHandle(Native.GetParent(Native.GetParent((IntPtr)context.WindowHandle))));
        }
Exemplo n.º 7
0
        public async void CreateNewPage(object sender, EventArgs e)
        {
            var settings = sender as IPageSettingsModel;

            if (settings == null)
            {
                return;
            }

            int retryCount = 0, retryLimit = 5;
            Func <OneNote.Window, string[], Task> modalDisplay = null;

            OneNote.Window modalOwner = null;
            string[]       modalText  = null;

            var latencyFactor = (StorageAccount.IsDefault) ? 1 : 10;
            var delay         = TimeSpan.FromMilliseconds(500 * latencyFactor);
            var stopwatch     = Stopwatch.StartNew();

            for (; ;)  // BEGIN Retry pattern
            {
                try
                {
                    await CreateNewPageTask(settings).ConfigureAwait(false);

                    break;
                }
                catch (Exception ex)
                {
                    modalOwner = Application.Windows.CurrentWindow;
                    if (Utils.ExceptionHandler.IsTransientError(ex))
                    {
                        if (++retryCount > retryLimit)
                        {
                            Utils.ExceptionHandler.HandleException(ex);
                            modalDisplay =
                                Utils.WinHelper.DisplayWarningAsync;
                            modalText = new[] {
                                "OneNote is busy.",
                                "Please try again in a moment."
                            };
                            break;
                        }
                    }
                    else
                    {
                        Utils.ExceptionHandler.HandleException(ex);
                        var errorMessage = new List <string>
                        {
                            "OneNote API Error",
                            Utils.ExceptionHandler.FormatHResult(ex.HResult)
                        };
                        if (App.IsErrorCode(ex.HResult))
                        {
                            errorMessage.Add(App.ErrorCodeTable[ex.HResult]);
                        }
                        modalDisplay = Utils.WinHelper.DisplayErrorAsync;
                        modalText    = errorMessage.ToArray();
                        break;
                    }
                }/* end catch */

                Tracer.WriteWarnLine("Transient error, sleeping {0} ms . . .",
                                     delay.TotalMilliseconds);

                await Task.Delay(delay).ConfigureAwait(false);
            }// *END* Retry pattern

            stopwatch.Stop();

            if (modalDisplay != null)
            {
                await modalDisplay(modalOwner, modalText).ConfigureAwait(false);
            }
            else
            {
                Tracer.WriteInfoLine("CreateNewPage elapsed time: {0} ms",
                                     stopwatch.ElapsedMilliseconds.ToString("N0"));
            }
        }