コード例 #1
0
        public static void ExportDocList(string outFolder, string username, string password)
        {
            GDataCredentials credentials = new GDataCredentials(username, password);
            RequestSettings settings = new RequestSettings("GDocBackup", credentials);
            settings.AutoPaging = true;
            settings.PageSize = 100;
            DocumentsRequest request = new DocumentsRequest(settings);

            Feed<Document> feed = request.GetEverything();
            List<Document> docs = new List<Document>();
            foreach (Document entry in feed.Entries)
                docs.Add(entry);

            using (StreamWriter outFile = new StreamWriter(Path.Combine(outFolder, "doclist.txt"), false),
                outFile2 = new StreamWriter(Path.Combine(outFolder, "doclistdetails.txt"), false))
            {
                foreach (Document doc in docs)
                {
                    string s = doc.Title + "\t" + doc.ResourceId;
                    outFile.WriteLine(s);
                    outFile2.WriteLine(s);
                    foreach (string pf in doc.ParentFolders)
                        outFile2.WriteLine("\t\t\t" + pf);
                }
                outFile.Close();
                outFile2.Close();
            }
        }
コード例 #2
0
ファイル: TechSupport.cs プロジェクト: mindyjw/gdocbackup-1
        public static void ExportDocList(string outFolder, string username, string password)
        {
            GDataCredentials credentials = new GDataCredentials(username, password);
            RequestSettings  settings    = new RequestSettings("GDocBackup", credentials);

            settings.AutoPaging = true;
            settings.PageSize   = 100;
            DocumentsRequest request = new DocumentsRequest(settings);

            Feed <Document> feed = request.GetEverything();
            List <Document> docs = new List <Document>();

            foreach (Document entry in feed.Entries)
            {
                docs.Add(entry);
            }

            using (StreamWriter outFile = new StreamWriter(Path.Combine(outFolder, "doclist.txt"), false),
                   outFile2 = new StreamWriter(Path.Combine(outFolder, "doclistdetails.txt"), false))
            {
                foreach (Document doc in docs)
                {
                    string s = doc.Title + "\t" + doc.ResourceId;
                    outFile.WriteLine(s);
                    outFile2.WriteLine(s);
                    foreach (string pf in doc.ParentFolders)
                    {
                        outFile2.WriteLine("\t\t\t" + pf);
                    }
                }
                outFile.Close();
                outFile2.Close();
            }
        }
コード例 #3
0
ファイル: GetDocList.cs プロジェクト: superhafnium/gdocbackup
        public static void Exec(string[] args)
        {
            Console.WriteLine("*** GetDocList ***");
            Console.WriteLine("--- START ---");

            string username = args[1];
            string password = args[2];

            GDataCredentials credentials = new GDataCredentials(username, password);
            RequestSettings settings = new RequestSettings("GDocBackup", credentials);
            settings.AutoPaging = true;
            settings.PageSize = 100;
            DocumentsRequest request = new DocumentsRequest(settings);

            Feed<Document> feed = request.GetEverything();
            List<Document> docs = new List<Document>();
            foreach (Document entry in feed.Entries)
                docs.Add(entry);

            StreamWriter outFile = new StreamWriter("doclist.txt", false);
            StreamWriter outFile2 = new StreamWriter("doclistdetails.txt", false);
            foreach (Document doc in docs)
            {
                string s = doc.Title + "\t" + doc.ResourceId;
                Console.WriteLine(s);
                outFile.WriteLine(s);
                outFile2.WriteLine(s);
                foreach (string pf in doc.ParentFolders)
                    outFile2.WriteLine("\t\t\t" + pf);
            }
            outFile.Close();
            outFile2.Close();

            Console.WriteLine("--- END ---");
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: mindyjw/gdocbackup-1
        private void GetDocListExec()
        {
            WriteMessage("*** GetDocList ***");
            WriteMessage("--- START ---");

            try
            {
                string username = tbUserName.Text;;
                string password = tbPassword.Text;

                GDataCredentials credentials = new GDataCredentials(username, password);
                RequestSettings  settings    = new RequestSettings("GDocBackup", credentials);
                settings.AutoPaging = true;
                settings.PageSize   = 100;
                DocumentsRequest request = new DocumentsRequest(settings);

                Feed <Document> feed = request.GetEverything();
                List <Document> docs = new List <Document>();
                foreach (Document entry in feed.Entries)
                {
                    docs.Add(entry);
                }

                StreamWriter outFile  = new StreamWriter("doclist.txt", false);
                StreamWriter outFile2 = new StreamWriter("doclistdetails.txt", false);

                WriteMessage("Exporting document list. Please wait...");

                foreach (Document doc in docs)
                {
                    string s = doc.Title + "\t" + doc.ResourceId;
                    //WriteMessage(s);
                    outFile.WriteLine(s);
                    outFile2.WriteLine(s);
                    foreach (string pf in doc.ParentFolders)
                    {
                        outFile2.WriteLine("\t\t\t" + pf);
                    }
                }

                WriteMessage("Created file: doclist.txt");
                WriteMessage("Created file: doclistdetails.txt");


                outFile.Close();
                outFile2.Close();
            }
            catch (Exception ex)
            {
                WriteMessage("EXCEPTION: " + ex.ToString());
            }


            WriteMessage("--- END ---");
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: superhafnium/gdocbackup
        private void GetDocListExec()
        {
            WriteMessage("*** GetDocList ***");
            WriteMessage("--- START ---");

            try
            {
                string username = tbUserName.Text; ;
                string password = tbPassword.Text;

                GDataCredentials credentials = new GDataCredentials(username, password);
                RequestSettings settings = new RequestSettings("GDocBackup", credentials);
                settings.AutoPaging = true;
                settings.PageSize = 100;
                DocumentsRequest request = new DocumentsRequest(settings);

                Feed<Document> feed = request.GetEverything();
                List<Document> docs = new List<Document>();
                foreach (Document entry in feed.Entries)
                    docs.Add(entry);

                StreamWriter outFile = new StreamWriter("doclist.txt", false);
                StreamWriter outFile2 = new StreamWriter("doclistdetails.txt", false);

                WriteMessage("Exporting document list. Please wait...");

                foreach (Document doc in docs)
                {
                    string s = doc.Title + "\t" + doc.ResourceId;
                    //WriteMessage(s);
                    outFile.WriteLine(s);
                    outFile2.WriteLine(s);
                    foreach (string pf in doc.ParentFolders)
                        outFile2.WriteLine("\t\t\t" + pf);
                }

                WriteMessage("Created file: doclist.txt");
                WriteMessage("Created file: doclistdetails.txt");

                outFile.Close();
                outFile2.Close();
            }
            catch (Exception ex)
            {
                WriteMessage("EXCEPTION: " + ex.ToString());
            }

            WriteMessage("--- END ---");
        }
コード例 #6
0
        /// <summary>
        /// tests moving a document in and out of folders
        /// </summary>
        [Test] public void ModelTestArbitraryDownload()
        {
            RequestSettings settings = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
            // settings.PageSize = 15;
            DocumentsRequest r = new DocumentsRequest(settings);

            Feed <Document> feed = r.GetEverything();

            foreach (Document d in feed.Entries)
            {
                Stream res = r.Download(d, null);
                Assert.IsNotNull(res, "The download stream should not be null");
            }
            foreach (Document d in feed.Entries)
            {
                Stream res = r.Download(d, "pdf");
                Assert.IsNotNull(res, "The download stream should not be null");
            }
        }
コード例 #7
0
ファイル: GetDocList.cs プロジェクト: mindyjw/gdocbackup-1
        public static void Exec(string[] args)
        {
            Console.WriteLine("*** GetDocList ***");
            Console.WriteLine("--- START ---");

            string username = args[1];
            string password = args[2];

            GDataCredentials credentials = new GDataCredentials(username, password);
            RequestSettings  settings    = new RequestSettings("GDocBackup", credentials);

            settings.AutoPaging = true;
            settings.PageSize   = 100;
            DocumentsRequest request = new DocumentsRequest(settings);

            Feed <Document> feed = request.GetEverything();
            List <Document> docs = new List <Document>();

            foreach (Document entry in feed.Entries)
            {
                docs.Add(entry);
            }

            StreamWriter outFile  = new StreamWriter("doclist.txt", false);
            StreamWriter outFile2 = new StreamWriter("doclistdetails.txt", false);

            foreach (Document doc in docs)
            {
                string s = doc.Title + "\t" + doc.ResourceId;
                Console.WriteLine(s);
                outFile.WriteLine(s);
                outFile2.WriteLine(s);
                foreach (string pf in doc.ParentFolders)
                {
                    outFile2.WriteLine("\t\t\t" + pf);
                }
            }
            outFile.Close();
            outFile2.Close();

            Console.WriteLine("--- END ---");
        }
コード例 #8
0
ファイル: documentslive.cs プロジェクト: Zelxin/RPiKeg
     /// <summary>
     /// tests moving a document in and out of folders
     /// </summary>
     [Test] public void ModelTestArbitraryDownload()
     {
         RequestSettings settings = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
         // settings.PageSize = 15;
         DocumentsRequest r = new DocumentsRequest(settings);
 
         Feed<Document> feed = r.GetEverything();
 
         foreach (Document d in feed.Entries)
         {
             Stream res = r.Download(d, null);
             Assert.IsNotNull(res, "The download stream should not be null");
         }
         foreach (Document d in feed.Entries)
         {
             Stream res = r.Download(d, "pdf");
             Assert.IsNotNull(res, "The download stream should not be null");
         }
     }
コード例 #9
0
ファイル: Backup.cs プロジェクト: mindyjw/gdocbackup
        /// <summary>
        /// Exec backup (internal)
        /// </summary>
        private int ExecBackupSingleUser(string username)
        {
            DoFeedback(new string('-', 80));
            DoFeedback("--- ExecBackupSingleUser - username="******" ---");
            DoFeedback(new string('-', 80));

            _lastException      = null;
            _duplicatedDocNames = new List <string>();

            // Setup credentials and connection
            DoFeedback("Setup connection & get doc list");
            RequestSettings settings;

            if (_config.appsMode == false)
            {
                GDataCredentials credentials = new GDataCredentials(_config.userName, _config.password);
                settings            = new RequestSettings("GDocBackup", credentials);
                settings.AutoPaging = true;
                settings.PageSize   = 100;
            }
            else
            {
                settings            = new RequestSettings("GDocBackup", _config.appsDomain, _config.appsOAuthSecret, username, _config.appsDomain);
                settings.AutoPaging = true;
                settings.PageSize   = 100;
                //settings.Maximum = 10000;
            }

            DocumentsRequest request = new DocumentsRequest(settings);

            if (_config.iwebproxy != null)
            {
                request.Proxy = _config.iwebproxy;
            }


            // Get doc list from GDocs
            Feed <Document> feed = request.GetEverything();
            List <Document> docs = new List <Document>();

            foreach (Document entry in feed.Entries)
            {
                docs.Add(entry);
            }


            // Search for duplicated doc names in the same folder
            _duplicatedDocNames = this.FindDuplicatedNames(docs);
            DoFeedback("Duplicated Doc Names [" + _duplicatedDocNames.Count + "]");
            _duplicatedDocNames.ForEach(delegate(string s) { DoFeedback(" - " + s); });


            // Builds/updates local folder structure
            if (_config.appsMode)
            {
                this.BuildFolders(null, docs, Path.Combine(_config.outDir, username));
            }
            else
            {
                this.BuildFolders(null, docs, _config.outDir);
            }
            foreach (String k in _folderDict.Keys)
            {
                DoFeedbackDebug("FolderDict: " + k + " --> " + _folderDict[k]);
            }
            this.DumpAllDocInfo(docs);

            // Main Docs loop!
            int errorCount = 0;

            for (int i = 0; i < docs.Count; i++)
            {
                Document doc = docs[i];
                DoFeedback("ITEM: " + doc.Title + " (" + doc.Type + ") [" + (i + 1).ToString() + "/" + docs.Count + "]", ((double)i) / docs.Count);

                Document.DownloadType[] downloadTypes = null;
                switch (doc.Type)
                {
                case Document.DocumentType.Document:
                    downloadTypes = _config.docExpType;
                    break;

                case Document.DocumentType.Presentation:
                    downloadTypes = _config.presExpType;
                    break;

                case Document.DocumentType.Spreadsheet:
                    downloadTypes = _config.sprdExpType;
                    break;

                case Document.DocumentType.PDF:
                    downloadTypes = new Document.DownloadType[] { Document.DownloadType.pdf };
                    break;

                case Document.DocumentType.Drawing:
                    downloadTypes = _config.drawExpType;
                    break;

                case Document.DocumentType.Unknown:
                    downloadTypes = new Document.DownloadType[] { Document.DownloadType.zip };      // download format not used! It's only a "place-holder".
                    break;

                default:
                    break;
                }


                if (downloadTypes != null)
                {
                    int maxTentativi = 2;
                    for (int tentativi = 0; tentativi < maxTentativi; tentativi++)
                    {
                        try
                        {
                            // * WorkAround for drawing *
                            // Detect if drawing and then force downloadtype to pdf
                            //bool isDrawing = doc.ResourceId.StartsWith("drawing:");   // drawing:14TBycKwlpXJ25N......
                            //if (isDrawing)
                            //    downloadTypes = new Document.DownloadType[] { Document.DownloadType.pdf };
                            // bool isDrawing = false;

                            foreach (Document.DownloadType downloadtype in downloadTypes)
                            {
                                // Build local file path
                                string outFolderPath;
                                if (doc.ParentFolders.Count == 0)
                                {
                                    outFolderPath = _config.appsMode ? Path.Combine(_config.outDir, username) : _config.outDir;
                                }
                                else
                                {
                                    DoFeedback("Try to get folder from dict using key=[" + doc.ParentFolders[0] + "]");
                                    outFolderPath = _folderDict[doc.ParentFolders[0]];
                                }
                                string outFileFP =
                                    (doc.Type == Document.DocumentType.Unknown) ?
                                    Path.Combine(outFolderPath, this.RemoveInvalidChars(doc.Title, true)) :
                                    Path.Combine(outFolderPath, this.RemoveInvalidChars(doc.Title, false) + "." + ConvertDownloadTypeToFileExtension(downloadtype));

                                // Get current local file in infos
                                FileInfo fi = new FileInfo(outFileFP);
                                DateTime locFileDateTime  = fi.LastWriteTime;
                                DateTime gdocFileDateTime = doc.Updated;

                                // Mono and/or Ubuntu (...linux) does not support milliseconds info when saving DataTime to FileInfo.LastWriteTime. So... I remove it!   :)
                                locFileDateTime  = this.RemoveMilliseconds(locFileDateTime);
                                gdocFileDateTime = this.RemoveMilliseconds(gdocFileDateTime);

                                bool downloadDoc = (!fi.Exists || _config.downloadAll);

                                if (_config.dateDiff.HasValue)
                                {
                                    if (Math.Abs(locFileDateTime.Subtract(gdocFileDateTime).TotalSeconds) > _config.dateDiff.Value)
                                    {
                                        downloadDoc = true;
                                    }
                                }
                                else
                                {
                                    if (locFileDateTime != gdocFileDateTime)
                                    {
                                        downloadDoc = true;
                                    }
                                }


                                if (downloadDoc)
                                {
                                    DoFeedback("Start exporting " + doc.Title + "(Type=" + doc.Type + ") --> " + downloadtype.ToString());
                                    Stream gdocStream = null;
                                    try
                                    {
                                        if (doc.Type == Document.DocumentType.Unknown)
                                        {
                                            String downloadUrl = doc.DocumentEntry.Content.Src.ToString();
                                            Uri    downloadUri = new Uri(downloadUrl);
                                            if (_config.appsMode)
                                            {
                                                // add xoauth_requestor_id to the doc url if not present
                                                if (!downloadUrl.Contains("xoauth_requestor_id="))
                                                {
                                                    downloadUri = new Uri(downloadUrl + "&xoauth_requestor_id=" + this.BuildDomainUserFullName(username));
                                                }
                                            }
                                            gdocStream = request.Service.Query(downloadUri);
                                        }
                                        else if (doc.Type == Document.DocumentType.Document)
                                        {
                                            gdocStream = request.Download(doc, downloadtype.ToString());
                                        }
                                        else if (doc.Type == Document.DocumentType.Spreadsheet)
                                        {
                                            gdocStream = request.Download(doc, downloadtype.ToString());   // WAS: downloadtype.ToString());
                                        }
                                        else if (doc.Type == Document.DocumentType.Presentation)
                                        {
                                            gdocStream = request.Download(doc, downloadtype.ToString());
                                        }
                                        else if (doc.Type == Document.DocumentType.Drawing)
                                        {
                                            gdocStream = request.Download(doc, downloadtype.ToString());
                                        }
                                        else if (doc.Type != Document.DocumentType.PDF)
                                        {
                                            // *** ??? ***
                                            gdocStream = request.Download(doc, downloadtype);
                                        }
                                        else
                                        {
                                            // *** PDF ***
                                            if (_config.appsMode)
                                            {
                                                // add xoauth_requestor_id to the doc url if not present
                                                string url = doc.DocumentEntry.Content.Src.ToString();
                                                if (!url.Contains("xoauth_requestor_id="))
                                                {
                                                    doc.DocumentEntry.Content.Src = new AtomUri(url + "&xoauth_requestor_id=" + this.BuildDomainUserFullName(username));
                                                }
                                            }
                                            gdocStream = request.Download(doc, null);
                                        }

                                        using (FileStream outFile = new FileStream(outFileFP, FileMode.Create, FileAccess.Write))
                                        {
                                            byte[] buffer = new byte[8192];
                                            int    bytesRead;
                                            while ((bytesRead = gdocStream.Read(buffer, 0, buffer.Length)) > 0)
                                            {
                                                outFile.Write(buffer, 0, bytesRead);
                                            }
                                            outFile.Close();
                                        }
                                        gdocStream.Close();
                                    }
                                    finally
                                    {
                                        if (gdocStream != null)
                                        {
                                            gdocStream.Dispose();
                                        }
                                    }

                                    new FileInfo(outFileFP).LastWriteTime = doc.Updated;
                                    DoFeedback("End exporting " + doc.Title + "(Type=" + doc.Type + ") --> " + downloadtype.ToString());

                                    // ------------------------------------------------------------------------------------------------------------------------
                                    // Workaround for Issue 100 - http://code.google.com/p/gdocbackup/issues/detail?id=100
                                    if (doc.Type == Document.DocumentType.Presentation)
                                    {
                                        bool isPPTX = false;

                                        using (FileStream presentationFile = new FileStream(outFileFP, FileMode.Open, FileAccess.Read))
                                        {
                                            int byte1 = presentationFile.ReadByte();
                                            int byte2 = presentationFile.ReadByte();
                                            isPPTX = (byte1 == 80 && byte2 == 75);   // 80 75 = "PK" (pptx is a zip. Every zip starts with "PK"
                                            presentationFile.Close();
                                        }

                                        if (!isPPTX)
                                        {
                                            string newName = outFileFP.Remove(outFileFP.Length - 1);
                                            File.Delete(newName);
                                            File.Move(outFileFP, newName);
                                            DoFeedback("Presentation API bug: renaming output file [" + newName + "]");
                                        }
                                    }
                                    // ------------------------------------------------------------------------------------------------------------------------
                                }
                                else
                                {
                                    DoFeedback("Skipped doc: " + doc.Title);
                                }

                                // Send Feedback
                                DoFeedback(new FeedbackObject(
                                               (_config.appsMode ? username + "#" + doc.Title : doc.Title),
                                               doc.Type.ToString(),
                                               (doc.Type == Document.DocumentType.Unknown) ? "BIN" : downloadtype.ToString(),
                                               downloadDoc ? "BCKUP" : "SKIP",
                                               "", locFileDateTime, gdocFileDateTime));

                                tentativi = maxTentativi;
                            }
                        }
                        catch (Exception ex)
                        {
                            if (tentativi == maxTentativi - 1)
                            {
                                errorCount++;
                                DoFeedback("DOC-ERROR: " + ex.ToString());
                                DoFeedback(new FeedbackObject(
                                               (_config.appsMode ? username + "#" + doc.Title : doc.Title),
                                               doc.Type.ToString(),
                                               "", "ERROR", "", null, null));
                            }
                            else
                            {
                                DoFeedback("DOC-ERROR: (attempt " + tentativi + ") " + ex.ToString());
                            }
                        }
                    }
                }
                else
                {
                    if (doc.Type != Document.DocumentType.Folder)
                    {
                        DoFeedback(new FeedbackObject(doc.Title, doc.Type.ToString(), "", "NONE", "", null, null));
                    }
                }
            }

            return(errorCount);
        }
コード例 #10
0
ファイル: NocsService.cs プロジェクト: ipriel/nocs2
        /// <summary>
        /// Fetches/updates all DocumentEntries in a Dictionary and wraps them in a Noc class.
        /// </summary>
        /// <returns>Dictionary of ResourceId's and Noc objects.</returns>
        public static void UpdateAllEntries()
        {
            if (AllDocuments == null)
            {
                AllDocuments = new Dictionary <string, Document>();
            }

            if (AllFolders == null)
            {
                AllFolders = new Dictionary <string, Document>();
            }

            // let's first make sure the user is authenticated
            if (_settings == null)
            {
                throw new Exception("User hasn't been authenticated - internet down?");
            }

            try
            {
                var request = new DocumentsRequest(_settings)
                {
                    Service = { ProtocolMajor = 3 }
                    //BaseUri = DocumentsListQuery.documentsAclUri
                };
                var reqFactory = (GDataRequestFactory)request.Service.RequestFactory;
                reqFactory.Proxy = GetProxy();

                // we'll fetch all entries
                AllEntriesFeed = request.GetEverything();

                // if we've already retrieved items, let's clear the dictionaries before updating them
                if (AllDocuments.Count > 0)
                {
                    AllDocuments.Clear();
                }
                if (AllFolders.Count > 0)
                {
                    AllFolders.Clear();
                }

                foreach (var entry in AllEntriesFeed.Entries)
                {
                    // let's only add documents and folders
                    if (entry.Type == Document.DocumentType.Document)
                    {
                        AllDocuments.Add(entry.ResourceId, entry);
                    }
                    else if (entry.Type == Document.DocumentType.Folder)
                    {
                        AllFolders.Add(entry.ResourceId, entry);
                    }
                }
            }
            catch (GDataNotModifiedException)
            {
                // since doclist updates timestamps on feeds based on access,
                // etags are useless here and we shouldn't get here
                return;
            }
            catch (GDataRequestException exRequest)
            {
                var error = GetErrorMessage(exRequest);
                if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                {
                    throw new GDataRequestException("Couldn't fetch all entries - internet down?");
                }

                Trace.WriteLine(string.Format("\n{0} - NocsService: couldn't fetch all entries: {1}\n", DateTime.Now, error));
                throw new GDataRequestException(Tools.TrimErrorMessage(error));
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                Trace.WriteLine(string.Format("\n{0} - NocsService: couldn't fetch all entries: {1}\n", DateTime.Now, error));
                throw new Exception(error);
            }
        }