예제 #1
0
        public void Setup()
        {
            docsService = new DocsService(docContext,
                                          new ConfigurationBuilder()
                                          .SetBasePath(Directory.GetCurrentDirectory())
                                          .AddJsonFile("appsettings.json")
                                          .Build());

            ServiceProvider = Api1.Program.CreateHostBuilder(new string[0]).Build().Services;

            var doc = new Doc
            {
                Category = Category.APPLICATION,
                Name     = "TestFile.txt",
            };

            var ver = new Api1.Models.Version
            {
                Doc            = doc,
                Release        = 1,
                Size           = 1234,
                UploadDateTime = DateTime.Now,
                Path           = @"C:\\Files\\Tests",
            };

            docContext.Add(doc);// как обратитьс¤ к контексту, который создаетс¤ в начале, in memory?
            docContext.Versions.Add(ver);
            int res = docContext.SaveChanges();
        }
예제 #2
0
        public void GetXmlFromMember_FieldWithDoc_XmlElement()
        {
            var fieldInfo = typeof(Stub).GetField("FieldWithDoc", BindingFlags.Instance | BindingFlags.NonPublic);
            var actual    = DocsService.GetXmlFromMember(fieldInfo);

            Assert.AreEqual("Gets or sets FieldWithDoc.", actual.SelectSingleNode("summary").InnerText.Trim());
        }
예제 #3
0
        private void DatabaseMetaDataReName(ModelBuilder modelBuilder)
        {
            foreach (var entity in modelBuilder.Model.GetEntityTypes())
            {
                // Replace column names
                foreach (var property in entity.GetProperties())
                {
                    // 生成数据库字段注释的两种方式
                    // 1.给类属性加上Description标注,可以当作数据库字段说明
                    //var desAttr = property.PropertyInfo.GetCustomAttribute<DescriptionAttribute>();
                    //if (desAttr != null)
                    //{
                    //    property.Npgsql().Comment = desAttr.Description;
                    //}

                    // 2.通过反射的方式获取类属性的注解
                    // 对于没有注解的类属性,GetXmlFromMember方法的第二个参数传false,不抛出异常
                    XmlElement documentation = DocsService.GetXmlFromMember(property.PropertyInfo, false);
                    if (documentation != null && !string.IsNullOrWhiteSpace(documentation.InnerText))
                    {
                        //property.Npgsql().Comment = documentation.InnerText.Trim();
                    }
                }
            }
        }
예제 #4
0
        private static DocsService LogintoDocs()
        {
            LoadCreds();
            UserCredential credential;
            string         ApplicationName = "GuardianBot";

            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;
            }

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

            return(service);
        }
예제 #5
0
        private static void mergeText(DocsService service, string documentId)
        {
            String customerName = "Alice";
            String date         = DateTime.Now.ToString("yyyy/MM/dd");

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

            customerNameRequest.ReplaceAllText = new ReplaceAllTextRequest();
            customerNameRequest.ReplaceAllText.ContainsText = (new SubstringMatchCriteria()
            {
                Text = "{{customer-name}}",
                MatchCase = true
            });
            customerNameRequest.ReplaceAllText.ReplaceText = (customerName);
            requests.Add(customerNameRequest);
            var dateRequest = new Request();

            dateRequest.ReplaceAllText = new ReplaceAllTextRequest();
            dateRequest.ReplaceAllText.ContainsText = (new SubstringMatchCriteria()
            {
                Text = "{{date}}",
                MatchCase = true
            });
            dateRequest.ReplaceAllText.ReplaceText = (date);
            requests.Add(dateRequest);
            BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest();

            body.Requests = requests;
            service.Documents.BatchUpdate(body, documentId).Execute();
        }
예제 #6
0
        public void GetXmlFromMember_PropertyGenericOnBaseClassWithDoc_XmlElement()
        {
            var propertyInfo = typeof(Stub).GetProperty("PropertyGenericOnBaseClassWithDoc");
            var actual       = DocsService.GetXmlFromMember(propertyInfo);

            Assert.AreEqual("Gets or sets PropertyGenericOnBaseClassWithDoc.", actual.SelectSingleNode("summary").InnerText.Trim());
        }
        public void GetXmlFromMember_MethodWithCollectionOutGenericTypeParameter_XmlElement()
        {
            var method = typeof(Stub).GetMethod("MethodWithCollectionOutGenericTypeParameter");
            var actual = DocsService.GetXmlFromMember(method);

            Assert.AreEqual("MethodWithCollectionOutGenericTypeParameter method.", actual.SelectSingleNode("summary").InnerText.Trim());
        }
        private static void ProcessMethods(CheckOptions checkOptions, System.Collections.Generic.List <MethodInfo> methods, int methodsCount, TypeDto typeDto)
        {
            for (int n = 0; n < methodsCount; n++)
            {
                var mInfo = methods[n];
                var mDto  = new MethodDto {
                    Name = mInfo.ToString()
                };
                typeDto.Methods.Add(mDto);

                if (!checkOptions.LogOnlyMissing)
                {
                    Log.Write(Verbosity.Normal, LogLevel.Information, "    Processing method {0} of {1}", n + 1, methodsCount);
                }

                var methodXml = DocsService.GetXmlFromMember(mInfo, false);
                mDto.XmlDescription = GetInnerText(methodXml);

                if (string.IsNullOrEmpty(mDto.XmlDescription))
                {
                    Log.Write(Verbosity.Normal, LogLevel.Warning, "    METHOD: {0} XML: {1}", mDto.Name, MISSING_XML);
                }
                else if (!checkOptions.LogOnlyMissing)
                {
                    Log.Write(Verbosity.Normal, LogLevel.Information, "    METHOD: {0} XML: {1}", mDto.Name, mDto.XmlDescription);
                }
            }
        }
예제 #9
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);
        }
        private static void ProcessProperties(CheckOptions checkOptions, PropertyInfo[] properties, int propertiesCount, TypeDto typeDto)
        {
            for (int n = 0; n < propertiesCount; n++)
            {
                var pInfo = properties[n];
                var pDto  = new PropertyDto {
                    Name = pInfo.ToString()
                };
                typeDto.Properties.Add(pDto);

                if (!checkOptions.LogOnlyMissing)
                {
                    Log.Write(Verbosity.Normal, LogLevel.Information, "    Processing property {0} of {1}", n + 1, propertiesCount);
                }

                var propertyDocXml = DocsService.GetXmlFromMember(pInfo, false);
                pDto.XmlDescription = GetInnerText(propertyDocXml);

                if (string.IsNullOrEmpty(pDto.XmlDescription))
                {
                    Log.Write(Verbosity.Normal, LogLevel.Warning, "    PROPERTY: {0} XML: {1}", pDto.Name, MISSING_XML);
                }
                else if (!checkOptions.LogOnlyMissing)
                {
                    Log.Write(Verbosity.Normal, LogLevel.Information, "    PROPERTY: {0} XML: {1}", pDto.Name, pDto.XmlDescription);
                }
            }
        }
        private static void ProcessFields(CheckOptions checkOptions, System.Collections.Generic.List <FieldInfo> fields, int fieldsCount, TypeDto typeDto)
        {
            for (int n = 0; n < fieldsCount; n++)
            {
                var fInfo = fields[n];
                var fDto  = new FieldDto {
                    Name = fInfo.ToString()
                };
                typeDto.Fields.Add(fDto);

                if (!checkOptions.LogOnlyMissing)
                {
                    Log.Write(Verbosity.Normal, LogLevel.Information, "    Processing field {0} of {1}", n + 1, fieldsCount);
                }

                var fieldDocXml = DocsService.GetXmlFromMember(fInfo, false);
                fDto.XmlDescription = GetInnerText(fieldDocXml);

                if (string.IsNullOrEmpty(fDto.XmlDescription))
                {
                    Log.Write(Verbosity.Normal, LogLevel.Warning, "    FIELD: {0} XML: {1}", fDto.Name, MISSING_XML);
                }
                else if (!checkOptions.LogOnlyMissing)
                {
                    Log.Write(Verbosity.Normal, LogLevel.Information, "    FIELD: {0} XML: {1}", fDto.Name, fDto.XmlDescription);
                }
            }
        }
        private static void ProcessConstructors(CheckOptions checkOptions, ConstructorInfo[] constructors, int constructorsCount, TypeDto typeDto)
        {
            for (int n = 0; n < constructorsCount; n++)
            {
                var cInfo = constructors[n];

                var cDto = new ConstructorDto {
                    Name = cInfo.ToString()
                };
                typeDto.Constructors.Add(cDto);

                if (!checkOptions.LogOnlyMissing)
                {
                    Log.Write(Verbosity.Normal, LogLevel.Information, "    Processing constructor {0} of {1}", n + 1, constructorsCount);
                }

                var constructorXml = DocsService.GetXmlForConstructor(cInfo, false);
                cDto.XmlDescription = GetInnerText(constructorXml);

                if (string.IsNullOrEmpty(cDto.XmlDescription) && cInfo.GetParameters().Count() == 0)
                {
                    cDto.XmlDescription = "Default constructor is allowed to have empty summary description";
                }

                if (string.IsNullOrEmpty(cDto.XmlDescription))
                {
                    Log.Write(Verbosity.Normal, LogLevel.Warning, "    CONSTRUCTOR: {0} {1} XML: {2}", typeDto.Name, cDto.Name, MISSING_XML);
                }
                else if (!checkOptions.LogOnlyMissing)
                {
                    Log.Write(Verbosity.Normal, LogLevel.Information, "    CONSTRUCTOR: {0} {1} XML: {2}", typeDto.Name, cDto.Name, cDto.XmlDescription);
                }
            }
        }
예제 #13
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();
        }
예제 #14
0
        public void GetXmlFromMember_FieldWithoutDocNotThrow_Null()
        {
            var fieldInfo = typeof(Stub).GetField("FieldWithoutDoc", BindingFlags.Instance | BindingFlags.NonPublic);
            var actual    = DocsService.GetXmlFromMember(fieldInfo, false);

            Assert.IsNull(actual);
        }
예제 #15
0
        public void GetXmlFromMember_PropertyWithoutDocNotThrow_Null()
        {
            var propertyInfo = typeof(Stub).GetProperty("PropertyWithoutDoc");
            var actual       = DocsService.GetXmlFromMember(propertyInfo, false);

            Assert.IsNull(actual);
        }
        public void GetXmlFromMember_MethodWithCollectionOfInnerClass()
        {
            var method = typeof(Stub).GetMethod("MethodWithCollectionOfInnerClass");
            var actual = DocsService.GetXmlFromMember(method);

            Assert.AreEqual("MethodWithCollectionOfInnerClass method.", actual.SelectSingleNode("summary").InnerText.Trim());
        }
예제 #17
0
        private static DocsService CreateDocsService(string credentialFilePath)
        {
            UserCredential credential;
            //認証プロセス。credPathが作成されていないとBrowserが起動して認証ページが開くので認証を行って先に進む
            var exeDir         = GetExecutingDirectoryName();
            var secretFilePath = Path.Combine(exeDir, credentialFilePath);

            using (var stream = new FileStream(secretFilePath, FileMode.Open, FileAccess.Read))
            {
                string credPath = Path.Combine
                                      (System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
                                      ".credentials/docs.googleapis.com-satrex.json");
                //CredentialファイルがcredPathに保存される
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync
                                 (GoogleClientSecrets.Load(stream).Secrets,
                                 Scopes,
                                 "user",
                                 CancellationToken.None,
                                 new FileDataStore(credPath, true)).Result;
            }
            //API serviceを作成、Requestパラメータを設定
            var service = new DocsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            return(service);
        }
예제 #18
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);
        }
예제 #19
0
파일: GDocApi.cs 프로젝트: piotr-zysk/GAPI
        public GDocApi()
        {
            UserCredential credential;

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

                //var pscopes = new string[1];
                //pscopes[0]="https://www.googleapis.com/auth/documents";


                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "*****@*****.**",
                    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,
            });

            this.service = service;
        }
        public void GetXmlFromMember_MethodWithGenericArgumentOnBaseClass_XmlElement()
        {
            var method = typeof(Stub).GetMethod("Create");
            var actual = DocsService.GetXmlFromMember(method);

            Assert.AreEqual("Creates the specified entity.", actual.SelectSingleNode("summary").InnerText.Trim());
            Assert.AreEqual("The entity.", actual.SelectSingleNode("param").InnerText.Trim());
        }
예제 #21
0
        private static Document createDoc(DocsService service)
        {
            Document doc = new Document();

            doc.Title = "CopyTitle_" + DateTime.Now.ToLongDateString();
            doc       = service.Documents.Create(doc).Execute();
            return(doc);
        }
예제 #22
0
        public void GetXmlFromParameter_Parameter_XmlElement()
        {
            var method    = typeof(Stub).GetMethod("MethodWithGenericParameter");
            var parameter = method.GetParameters()[0];
            var actual    = DocsService.GetXmlFromParameter(parameter);

            Assert.AreEqual("Generic parameter.", actual.InnerText);
        }
예제 #23
0
 public void GetXmlFromMember_PropertyWithoutDoc_Null()
 {
     Assert.Throws <DocsByReflectionException>(() =>
     {
         var propertyInfo = typeof(Stub).GetProperty("PropertyWithoutDoc");
         DocsService.GetXmlFromMember(propertyInfo);
     });
 }
예제 #24
0
 public void GetXmlFromMember_FieldWithoutDoc_Null()
 {
     Assert.Throws <DocsByReflectionException>(() =>
     {
         var fieldInfo = typeof(Stub).GetField("FieldWithoutDoc", BindingFlags.Instance | BindingFlags.NonPublic);
         DocsService.GetXmlFromMember(fieldInfo);
     });
 }
예제 #25
0
        public void GetDocs_Get1Doc_NotNull()
        // [“естируемый метод]_[—ценарий]_[ќжидаемое поведение].
        {
            DocsService ApiService = ServiceProvider.GetService <DocsService>();
            IList <Doc> result     = ApiService.GetDocs(null);//почему не позвол¤ет обратитьс¤ к сервисам моим?

            Assert.NotNull(result);
        }
예제 #26
0
        public void GetXmlFromParameter_ParameterNoDocNotThrow_XmlElement()
        {
            var method    = typeof(Stub).GetMethod("MethodWithoutDoc");
            var parameter = method.GetParameters()[0];

            var actual = DocsService.GetXmlFromParameter(parameter, false);

            Assert.IsNull(actual);
        }
예제 #27
0
        public void GetXmlFromParameter_ParameterNoDoc_XmlElement()
        {
            var method    = typeof(Stub).GetMethod("MethodWithoutDoc");
            var parameter = method.GetParameters()[0];

            ExceptionAssert.IsThrowing(new DocsByReflectionException("Could not find documentation for specified element", null), () =>
            {
                DocsService.GetXmlFromParameter(parameter);
            });
        }
예제 #28
0
        private static string GetDescription(Type type)
        {
            var xml = DocsService.GetXmlFromType(type, false);

            if (xml != null)
            {
                return(xml.InnerText.Trim());
            }
            return(String.Empty);
        }
예제 #29
0
        private static string GetDescription(MemberInfo member)
        {
            var xml = DocsService.GetXmlFromMember(member, false);

            if (xml != null)
            {
                return(xml.InnerText.Trim());
            }
            return(String.Empty);
        }
예제 #30
0
        public DocsService GetGoogleDocsService([FromServices] IGoogleAuthProvider auth)
        {
            GoogleCredential cred    = auth.GetCredentialAsync().GetAwaiter().GetResult();
            DocsService      service = new DocsService(new BaseClientService.Initializer
            {
                HttpClientInitializer = cred,
                ApplicationName       = "WebCraft",
            });

            return(service);
        }