Beispiel #1
0
 private void RemoveTabsNotFoundInAllDocuments()
 {
     for (var i = 0; i < tabs.TabCount; i++)
     {
         var tab = tabs.TabPages[i] as Noc;
         if (tab != null && !tab.Document.IsDraft && !NocsService.AllDocuments.ContainsKey(tab.Document.ResourceId))
         {
             // tab document isn't a draft (untitled)
             // AND we couldn't find the documentId in AllDocuments after a background-"GetAllItems"
             // -> we have to remove the document from tabs completely (in a thread-safe way)
             Debug.WriteLine(DateTime.Now + " - Main: removing an open tab of a document that was removed in Google Docs: " + tab.Document.Title);
             MainFormThreadSafeDelegate removeTab = RemoveTabThreadSafe;
             Invoke(removeTab, i);
         }
     }
 }
Beispiel #2
0
        private void BgWorkerLoadDocumentContent_Completed(object sender, RunWorkerCompletedEventArgs e)
        {
            var updatedDocument = e.Result as Document;

            // let's first check for an error
            if (e.Error != null)
            {
                if (updatedDocument == null)
                {
                    Trace.WriteLine(DateTime.Now + " - Main: error while loading document content");
                }
                else
                {
                    Trace.WriteLine(DateTime.Now + " - Main: error while loading document content: " + updatedDocument.Title);
                }

                Status(StatusType.ContentUpdateError, e.Error.Message);
                return;
            }

            if (updatedDocument != null)
            {
                // if for some reason the document wasn't found or file was corrupt, we'll remove that tab

                /*
                 * TODO: later these errors should create a small box inside the gray, inactive Tab,
                 *        where we will inform the user to either reload the document or save it inside docs.google.com
                 */
                if (updatedDocument.Summary != null &&
                    (updatedDocument.Summary.ToLowerInvariant().Contains("document not found") ||
                     updatedDocument.Summary.ToLowerInvariant().Contains("file is corrupt, or an unknown format")))
                {
                    for (var i = 0; i < tabs.TabCount; i++)
                    {
                        var tab = tabs.TabPages[i] as Noc;
                        if (tab != null && !tab.Document.IsDraft && tab.Document.ResourceId == updatedDocument.ResourceId)
                        {
                            // tab document isn't a draft (untitled)
                            // AND we couldn't find the documentId in AllDocuments after a background-"GetAllItems"
                            // -> we have to remove the document from tabs completely (in a thread-safe way)
                            Debug.WriteLine(DateTime.Now + " - Main: removing an open tab of a document that wasn't found while loading document content: " + tab.Document.Title);
                            MainFormThreadSafeDelegate removeTab = RemoveTabThreadSafe;
                            Invoke(removeTab, i);
                        }
                    }
                    updatedDocument.Summary = null;
                }
                else
                {
                    // let's activate the document and update the content
                    foreach (var tab in tabs.TabPages.Cast <Noc>().Where(
                                 tab => !tab.Document.IsDraft &&
                                 tab.Document.ResourceId == updatedDocument.ResourceId))
                    {
                        tab.Document = updatedDocument;
                        tab.Activate();
                    }
                }
            }

            // let's handle the loader icon with a thread lock
            lock (_threadLock)
            {
                // let's first decrement the current number of workers
                // (should always be over 0 at this point
                if (_contentUpdaterWorkers > 0)
                {
                    _contentUpdaterWorkers--;
                }

                if (_contentUpdaterWorkers == 0)
                {
                    // there are no more updaters active, we can disable loader/clear status
                    Status(StatusType.Reset, null);
                }
            }
        }