public void ExtractApiTest_PropertyNameRegex()
        {
            var options = new ExtractOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    NameOptions = new NameOptions
                    {
                        Value        = "^dc:.*",
                        MatchOptions = new MatchOptions
                        {
                            IsRegex = true
                        }
                    }
                }
            };

            var request = new ExtractRequest(options);

            var result = MetadataApi.Extract(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Properties);
            Assert.IsTrue(result.Properties.Any(x => x.Name.StartsWith("dc:", StringComparison.OrdinalIgnoreCase)));
        }
        public void ExtractApiTest_Tag()
        {
            var options = new ExtractOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    TagOptions = new TagOptions
                    {
                        ExactTag = new Tag
                        {
                            Name     = "Created",
                            Category = "Time"
                        }
                    }
                }
            };

            var request = new ExtractRequest(options);

            var result = MetadataApi.Extract(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Properties);
            Assert.IsTrue(result.Properties.Any(x => string.Equals(x.Name, "CreateTime")));
        }
        public void ExtractApiTest_PropertyNameExactPhrase()
        {
            var options = new ExtractOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    NameOptions = new NameOptions
                    {
                        Value        = "MimeType",
                        MatchOptions = new MatchOptions
                        {
                            ExactPhrase = true
                        }
                    }
                }
            };

            var request = new ExtractRequest(options);

            var result = MetadataApi.Extract(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Properties);
            Assert.IsTrue(result.Properties.Any(x => x.Name.Equals("MimeType", StringComparison.OrdinalIgnoreCase)));
        }
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new MetadataApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath    = "documents/input.docx",
                    StorageName = Common.MyStorage
                };

                var options = new ExtractOptions
                {
                    FileInfo       = fileInfo,
                    SearchCriteria = new SearchCriteria
                    {
                        TagOptions = new TagOptions
                        {
                            ExactTag = new Tag
                            {
                                Name     = "Created",
                                Category = "Time"
                            }
                        }
                    }
                };

                var request = new ExtractRequest(options);

                var response = apiInstance.Extract(request);
                foreach (var property in response.Properties)
                {
                    Console.WriteLine($"Property: {property.Name}. Value: {property.Value}");
                    if (property.Tags == null)
                    {
                        continue;
                    }

                    foreach (var tag in property.Tags)
                    {
                        Console.WriteLine($"Property tag: {tag.Category} {tag.Name} ");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling MetadataApi: " + e.Message);
            }
        }
        public void ExtractApiTest_FileNotFound()
        {
            var testFile = TestFiles.NotExist;
            var options  = new ExtractOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };

            var request = new ExtractRequest(options);

            var ex = Assert.Throws <ApiException>(() => { MetadataApi.Extract(request); });

            Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message);
        }
        public void ExtractApiTest_DocumentProtectedException()
        {
            var testFile = TestFiles.PasswordProtected;
            var options  = new ExtractOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };

            var request = new ExtractRequest(options);

            var ex = Assert.Throws <ApiException>(() => { MetadataApi.Extract(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' is protected.", ex.Message);
        }
        public void ExtractApiTest()
        {
            var options = new ExtractOptions
            {
                FileInfo = TestFiles.Docx.ToFileInfo()
            };

            var request = new ExtractRequest(options);

            var result = MetadataApi.Extract(request);

            Assert.IsNotNull(result.MetadataTree);
            Assert.IsNotEmpty(result.MetadataTree.InnerPackages);
            Assert.IsTrue(result.MetadataTree.InnerPackages.Any(x => string.Equals(x.PackageName, "FileFormat")));
        }
        public void ExtractApiTest_UnsupportedFormat()
        {
            var testFile = TestFiles.Json;
            var options  = new ExtractOptions
            {
                FileInfo       = testFile.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    TagOptions = new TagOptions
                    {
                        PossibleName = "Tag"
                    }
                }
            };

            var request = new ExtractRequest(options);

            var ex = Assert.Throws <ApiException>(() => { MetadataApi.Extract(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message);
        }
        public void ExtractApiTest_PropertyName()
        {
            var options = new ExtractOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    NameOptions = new NameOptions
                    {
                        Value = "Date"
                    }
                }
            };

            var request = new ExtractRequest(options);

            var result = MetadataApi.Extract(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Properties);
            Assert.IsTrue(result.Properties.Any(x => x.Name.Contains("Date")));
        }
        public void ExtractApiTest_PossibleTagName()
        {
            var options = new ExtractOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    TagOptions = new TagOptions
                    {
                        PossibleName = "creator"
                    }
                }
            };

            var request = new ExtractRequest(options);

            var result = MetadataApi.Extract(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Properties);
            Assert.IsTrue(result.Properties.Any(x => x.Tags.Any(t => t.Name.Contains("Creator"))));
        }
        public void ExtractApiTest_PropertyValue()
        {
            var options = new ExtractOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    ValueOptions = new ValueOptions
                    {
                        Value = "Microsoft Office Word",
                        Type  = "String"
                    }
                }
            };

            var request = new ExtractRequest(options);

            var result = MetadataApi.Extract(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Properties);
            Assert.IsTrue(result.Properties.Any(x => x.Name.StartsWith("NameOfApplication", StringComparison.OrdinalIgnoreCase)));
        }
        public void ExtractApiTest_IncorrectTag()
        {
            var options = new ExtractOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    TagOptions = new TagOptions
                    {
                        ExactTag = new Tag
                        {
                            Name     = "wrong",
                            Category = "Wrong"
                        }
                    }
                }
            };

            var request = new ExtractRequest(options);

            var ex = Assert.Throws <ApiException>(() => { MetadataApi.Extract(request); });

            Assert.AreEqual("The specified tag was not found or has incorrect format.", ex.Message);
        }