Example #1
0
        private void Write()
        {
            string[] Scopes = { DocsService.Scope.Documents, DocsService.Scope.DriveFile, DocsService.Scope.Drive };

            UserCredential credential;

            using (var stream = new FileStream($"/Users/mathiasgammelgaard/credentials/credentials.json", FileMode.Open, FileAccess.Read)) {
                string credPath = "/Users/mathiasgammelgaard/credentials/token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            DocsService service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential
            });

            // Define request parameters.
            String documentId = "1tldY_DpX5IM9wPqIKN9FVgwfBT2Ueq__F8pwOI8dLVI";

            DocumentsResource.GetRequest documentRequest = service.Documents.Get(documentId);
            Document doc = documentRequest.Execute();

            List <Request> requests = new List <Request>();

            DeleteAllContent(requests, doc, service, documentId);

            foreach (Course course in courses)
            {
                //AddHeaderLine(course.title, requests, 1);
                foreach (Section section in course.sections)
                {
                    if (section.description != null)
                    {
                        AddHeaderLine(section.name, requests, 3);
                        AddParagraph(section.description.levels[0].description, requests);
                    }
                    else
                    {
                        AddHeaderLine(section.name, requests, 3, false);
                        AddQuizQuestions(section.quiz.levels[0], requests);
                    }
                }
            }



            BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest();

            body.Requests = requests;
            DocumentsResource.BatchUpdateRequest updateRequest = service.Documents.BatchUpdate(body, documentId);

            updateRequest.Execute();
        }
Example #2
0
        public static void Retrieve()
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            String documentId = "1qAnB3vcKDsSuwFmRB0gtDyepFx60t1CdI9hbKAvCXQc";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE
            Document doc = request.Execute();

            fileUtil.createFile(doc);
        }
Example #3
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            String documentId = "195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Title);
        }
Example #4
0
        public Document GetDoc(string fileId)
        {
            DocumentsResource.GetRequest request = this.service.Documents.Get(fileId);
            Document doc = request.Execute();

            return(doc);
        }
Example #5
0
        public static string GetTitle(string documentId)
        {
            DocumentsResource.GetRequest request = Service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Title);
            return(doc.Title);
        }
        private static async Task GrabGoogleDocsAnswers()
        {
            string[] scopes          = { DocsService.Scope.DocumentsReadonly };
            string   ApplicationName = "Google Docs API .NET Quickstart";

            var            secretsFile = "client_secret.apps.googleusercontent.com.json";
            string         credPath    = "token.json";
            UserCredential credential  = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                (await GoogleClientSecrets.FromFileAsync(secretsFile)).Secrets,
                scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)
                );

            Console.WriteLine("Credential file saved to: " + credPath);
            /* Create Google Docs API service. */
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            const string documentId = "1bfifCfwhLuhP-_dXvtQdgByGpcvvWIgDrRQbeQrExtg";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);
            Document doc = await request.ExecuteAsync();

            int counter = 0;

            while (counter < doc.Body.Content.Count)
            {
                if (doc.Body.Content[counter]?.Paragraph?.Bullet != null)
                {
                    string a = string.Join("", doc.Body.Content[counter + 1].Paragraph.Elements.Select(e => e.TextRun.Content));
                    a = a.Replace("Answer: ", "");

                    QaDict.Add(new List <string>
                    {
                        ProcessString(doc.Body.Content[counter].Paragraph.Elements[0].TextRun.Content),
                        ProcessString(a)
                    });
                    counter++;
                }

                counter++;
            }
        }
Example #7
0
        private void btn_start_Click(object sender, EventArgs e)
        {
            string[]       Scopes          = { DocsService.Scope.DocumentsReadonly };
            string         ApplicationName = "SmartSV";
            UserCredential credential;

/*            using (var stream =
 *              new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
 *          {
 *              string credPath = "token.json";
 *
 *              credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
 *                  GoogleClientSecrets.Load(stream).Secrets,
 *                  Scopes,
 *                  "user",
 *                  CancellationToken.None,
 *                  new FileDataStore(credPath, true)).Result;
 *              Console.WriteLine("Credential file saved to: " + credPath);
 *          }*/

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = null,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            String documentId = "1PT8NkFir3y74tbbPK1qNIjmw3xtzh39Cet8eaKpqyXU";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Title);


            // Note: for the application hook, use the Hook.AppEvents() instead
            m_GlobalHook = Hook.GlobalEvents();

            m_GlobalHook.KeyPress += GlobalHookKeyPress;
        }
Example #8
0
 public static Document GetDocument(string documentId)
 {
     // Console.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + " start");
     // Console.WriteLine($"documentId:{documentId}");
     try
     {
         DocumentsResource.GetRequest request = Service.Documents.Get(documentId);
         // Console.WriteLine(request.PrettyPrint);
         Document doc = request.Execute();
         // Console.WriteLine("Found {0}", doc.Title);
         return(doc);
     }
     catch (Google.GoogleApiException ex)
     {
         Console.Error.WriteLine("Googleドキュメントが取得できませんでした。MymeTypeを確認してください。");
         Console.Error.WriteLine($"{ex.GetType().Name} {ex.Message} ");
         throw ex;
     }
 }
        static void Main(string[] args)
        {
            try
            {
                UserCredential credential;
                // Load client secrets.
                using (var stream =
                           new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
                {
                    /* The file token.json stores the user's access and refresh tokens, and is created
                     * automatically when the authorization flow completes for the first time. */
                    string credPath = "token.json";

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.FromStream(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }

                // Create Google Docs API service.
                var service = new DocsService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName
                });

                // Define request parameters.
                String documentId = "195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE";
                DocumentsResource.GetRequest request = service.Documents.Get(documentId);

                // Prints the title of the requested doc:
                // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
                Document doc = request.Execute();
                Console.WriteLine("The title of the doc is: {0}", doc.Title);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #10
0
        public static string GetAllText(string documentId)
        {
            Console.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name + " start");
            DocumentsResource.GetRequest request = Service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Title);

            var bodyText = string.Empty;

            foreach (var element in doc.Body.Content)
            {
                bodyText += GetContent(element);
            }

            return(bodyText);
        }
Example #11
0
        public static List <string> ReadRules()
        {
            DocsService service = LogintoDocs();

            DocumentsResource.GetRequest request = service.Documents.Get(docsId);
            Document      doc     = request.Execute();
            List <string> message = new List <string>();

            foreach (var text in doc.Body.Content)
            {
                try
                {
                    foreach (var par in text.Paragraph.Elements)
                    {
                        message.Add(par.TextRun.Content);
                    }
                }
                catch { }
            }

            return(message);
        }
Example #12
0
        public static string Invoke()
        {
            UserCredential credential;

            using (var stream = new FileStream(CRED_FILE, FileMode.Open, FileAccess.Read))
            {
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(TOKEN_FILE, true)).Result;
                Console.WriteLine("Credential file saved to: " + TOKEN_FILE);
            }

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = APPLICATION_NAME
            });

            // Define request parameters.
            // ReSharper disable once StringLiteralTypo
            const string documentId = "1-SUfBAAJutCcb-bZHEfqGmiOO7Lh4uoSwpnBuDa-v6A";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // Prints the title of the requested doc:
            // https://docs.google.com/document/d/1-SUfBAAJutCcb-bZHEfqGmiOO7Lh4uoSwpnBuDa-v6A/edit?usp=sharing
            Document doc = request.Execute();

            Console.WriteLine("The title of the doc is: {0}", doc.Body.Content);

            return(ReadStructuralElements(doc.Body.Content));
        }
Example #13
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Docs API service.
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define request parameters.
            String documentId = "10iaemvyMan4ZfjUj1VqI1ubPCsh-krpPI92Pm3z5zjs";

            DocumentsResource.GetRequest request = service.Documents.Get(documentId);

            // Parse the document's body
            Document doc = request.Execute();

            Console.WriteLine($"Title: {doc.Title}");
            var paragraphs = 0;
            var days       = 0;
            var wfh        = 0;
            var tagDict    = new Dictionary <string, int>();

            foreach (var element in doc.Body.Content)
            {
                if (element.Paragraph != null)
                {
                    paragraphs += 1;
                    var sb = new StringBuilder();
                    foreach (var parel in element.Paragraph.Elements)
                    {
                        sb.Append(parel.TextRun?.Content);
                    }
                    var text = sb.ToString();

                    // Date "title" parsing
                    if (IsADateHeading(text))
                    {
                        Console.WriteLine($"Date: {GetDateFromTitle(text.Trim()).ToString("dd/MMM/yyyy")}");
                        days += 1;
                        if (text.ToLower().Contains("[wfh]"))
                        {
                            wfh += 1;
                        }
                        SearchForPossibleDayTags(text, tagDict);
                    }

                    // Pluralsight example
                    if ((text != null) && (text.Contains("Pluralsight:")))
                    {
                        Console.WriteLine(text);
                    }
                }
            }
            Console.WriteLine($"\nParagraph count: {paragraphs}");
            Console.WriteLine($"Work days: {days}");
            Console.WriteLine($"Remoting days: {wfh} ({decimal.Parse(wfh.ToString())/decimal.Parse(days.ToString()):P})");
            Console.WriteLine("\nDay Tags:");
            foreach (var item in tagDict.OrderBy(i => i.Key))
            {
                Console.WriteLine($"[{item.Key}]: {item.Value}");
            }
            Console.ReadLine();
        }