Example #1
0
        /*
         * 加载word 文件
         *
         * @param DocumentViewer 显示容器
         *
         * @param DControl ctl 控件信息
         */
        private void loadWord()
        {
            try
            {
                XpsDocument           xpsDoc = new XpsDocument(wordFullPath, FileAccess.Read, CompressionOption.SuperFast);
                FixedDocumentSequence fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
                DocumentPaginator     documentPaginator     = fixedDocumentSequence.DocumentPaginator;
                size = fixedDocumentSequence.DocumentPaginator.PageSize;
                for (int i = 0; i < documentPaginator.PageCount; i++)
                {
                    DispatcherContainer dispatcherContainer = new DispatcherContainer();
                    dispatcherContainer.Width  = size.Width;
                    dispatcherContainer.Height = size.Height;
                    dispatcherContainer.Tag    = i;
                    contentStackPanel.Children.Add(dispatcherContainer);

                    CWordPageQueue cwordPageQueue = new CWordPageQueue();
                    pageQueueList.Add(cwordPageQueue);
                }
                xpsDoc.Close();
            }
            catch (Exception)
            {
            }
        }
Example #2
0
        private async void RemovePageTask(int pageId, TaskInfo taskInfo)
        {
            DispatcherContainer target = (DispatcherContainer)contentStackPanel.Children[pageId];

            Console.WriteLine("移除页面:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);
            UIElement uiElement = target.Child;

            uiElement = null;
            target.SetValue(ContentPresenter.ContentProperty, null);

            await target.SetChildAsync <Border>(() =>
            {
                Console.WriteLine("移除页面await:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);
                return(new Border());
            }
                                                , () =>
            {
                Border bd = new Border();
                pageQueueList[pageId].list.Remove(taskInfo);
                if (pageQueueList[pageId].list.Count > 0)
                {
                    RemovePageTask(pageId, pageQueueList[pageId].list[0]);
                }
                return(bd);
            });
        }
Example #3
0
        private async void LoadPageTask(int pageId, TaskInfo taskInfo)
        {
            DispatcherContainer target = (DispatcherContainer)contentStackPanel.Children[pageId];

            // if (target.Child != null && target.Child is FixedPage) return;
            //  if (target.GetIsUpdatingChild()) return;
            // Console.WriteLine("获取页面:" + pageId);
            Console.WriteLine("获取页面:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);

            //await 回调,执行下一个
            await target.SetChildAsync <FixedPage>(() =>
            {
                FixedPage fp = new FixedPage();
                try
                {
                    XpsDocument xpsDoc = new XpsDocument(wordFullPath, FileAccess.Read);
                    FixedDocumentSequence fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
                    foreach (DocumentReference DocRef in fixedDocumentSequence.References)
                    {
                        Console.WriteLine("获取页面await:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);
                        Console.WriteLine();
                        bool bForceReload       = false;
                        FixedDocument DocFd     = DocRef.GetDocument(bForceReload);
                        PageContent pageContent = DocFd.Pages[pageId];
                        fp = pageContent.GetPageRoot(false);

                        // pageContent.SetValue(ContentPresenter.ContentProperty, null);

                        //for (int i = 0; i < fixedPage.Children.Count; i++)
                        //{
                        //    UIElement uiElement = fp.Children[i];
                        //    fixedPage.Children.Remove(uiElement);
                        //    fp.Children.Add(uiElement);
                        //}
                    }
                    // xpsDoc.Close();//这个地方需要注意关闭,否则的话会出现莫名其妙的错误
                    return(fp);
                }
                catch (Exception)
                {
                    return(fp);
                }
            }
                                                   , () =>
            {
                FixedPage fp = new FixedPage();
                pageQueueList[pageId].list.Remove(taskInfo);
                if (pageQueueList[pageId].list.Count > 0)
                {
                    LoadPageTask(pageId, pageQueueList[pageId].list[0]);
                }
                return(fp);
            });


            //  Console.WriteLine("任务是否完成:"+task.IsCompleted);
        }
        /// <summary>
        /// Creates a NativeQueue which can be used to enqueue Event Data to be created when the DispatcherSystem runs.
        /// </summary>
        /// <typeparam name="T">struct, IComponentData</typeparam>
        /// <returns>NativeQueue</returns>
        public NativeQueue <T> CreateDispatcherQueue <T>() where T : struct, IComponentData
        {
            if (!_dictionary.TryGetValue(typeof(T), out var dispatcherContainer))
            {
                _dictionary.Add(typeof(T), dispatcherContainer = new DispatcherContainer <T>(this));
            }

            return(((DispatcherContainer <T>)dispatcherContainer).CreateDispatcherQueue());
        }
Example #5
0
        public void AddListener <MessageType>(MonoBehaviour that, string name, MessageDispatcher.Handler <MessageType> handler)
        {
            Debug.Assert(null != that, "That is not null");
            int id = that.GetInstanceID();
            DispatcherContainer container;

            if (!objects.TryGetValue(id, out container))
            {
                container            = new DispatcherContainer();
                container.instance   = that;
                container.dispatcher = new MessageDispatcher();
                objects[id]          = container;
            }
            container.dispatcher.AddListener(name, handler);
        }
Example #6
0
        private async void CWord_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            double topOffset = cWordScrollViewer.VerticalOffset;
            int    page      = (int)Math.Floor(topOffset / size.Height);

            if (page == currPage)
            {
                return;
            }
            if (page >= contentStackPanel.Children.Count)
            {
                return;
            }
            //if (page < currPage) return;
            currPage = page;


            //DispatcherContainer target = (DispatcherContainer)contentStackPanel.Children[this.currPage];

            //await target.SetChildAsync(() =>
            //{
            //    XpsDocument xpsDoc = new XpsDocument(wordFullPath, FileAccess.Read, CompressionOption.SuperFast);
            //    FixedDocumentSequence fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
            //    foreach (DocumentReference DocRef in fixedDocumentSequence.References)
            //    {
            //        bool bForceReload = false;
            //        FixedDocument DocFd = DocRef.GetDocument(bForceReload);

            //        return DocFd.Pages[currPage].GetPageRoot(false);
            //    }
            //    xpsDoc.Close();//这个地方需要注意关闭,否则的话会出现莫名其妙的错误
            //    return null;
            //});

            // lock (this) {

            for (int b = 0; b < contentStackPanel.Children.Count; b++)
            {
                DispatcherContainer ele = (DispatcherContainer)contentStackPanel.Children[b];

                if (b >= currPage - 2 && b <= currPage + 1)
                {
                    //显示前面3页,后面5页
                    if (ele.Child == null || ele.Child is Border)
                    {
                        //1.向队列中添加任务
                        int count = pageQueueList[b].list.Count;
                        if (count == 0)
                        {
                            TaskInfo taskInfo = new TaskInfo();
                            taskInfo.taskStatus = 0;
                            taskInfo.isLoadPage = true;
                            pageQueueList[b].list.Add(taskInfo);
                            LoadPageTask(b, taskInfo);
                        }
                        else if (count == 1)
                        {
                            TaskInfo taskInfo = new TaskInfo();
                            taskInfo.taskStatus = 0;
                            taskInfo.isLoadPage = true;
                            pageQueueList[b].list.Add(taskInfo);
                        }
                        else
                        {
                            TaskInfo taskInfo = new TaskInfo();
                            taskInfo.taskStatus      = 0;
                            taskInfo.isLoadPage      = true;
                            pageQueueList[b].list[1] = taskInfo;
                        }
                    }
                }
                else
                {
                    if (ele.Child != null && (ele.Child is FixedPage))
                    {
                        //1.向队列中添加任务
                        int count2 = pageQueueList[b].list.Count;
                        if (count2 == 0)
                        {
                            TaskInfo taskInfo = new TaskInfo();
                            taskInfo.taskStatus = 0;
                            taskInfo.isLoadPage = false;
                            pageQueueList[b].list.Add(taskInfo);
                            RemovePageTask(b, taskInfo);
                        }
                        else if (count2 == 1)
                        {
                            TaskInfo taskInfo = new TaskInfo();
                            taskInfo.taskStatus = 0;
                            taskInfo.isLoadPage = false;
                            pageQueueList[b].list.Add(taskInfo);
                        }
                        else
                        {
                            TaskInfo taskInfo = new TaskInfo();
                            taskInfo.taskStatus      = 0;
                            taskInfo.isLoadPage      = false;
                            pageQueueList[b].list[1] = taskInfo;
                        }

                        //UIElement uiElement = ele.Child;
                        //uiElement = null;
                        //ele.SetValue(ContentPresenter.ContentProperty, null);
                        ////没有断开父元素与子元素链接
                        //ele.SetChildAsync(() =>
                        //{
                        //    return new Border();
                        //});
                    }
                }
            }


            //}
        }