Exemple #1
0
        public void RemoveApiTest_Tag()
        {
            var options = new RemoveOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    TagOptions = new TagOptions
                    {
                        ExactTag = new Tag
                        {
                            Name     = "Created",
                            Category = "Time"
                        }
                    }
                }
            };

            var request = new RemoveRequest(options);

            var result = MetadataApi.Remove(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Path);
            Assert.IsNotEmpty(result.Url);
            Assert.Greater(result.RemovedCount, 0);
        }
Exemple #2
0
        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.doc",
                    StorageName = Common.MyStorage
                };

                var options = new RemoveOptions
                {
                    FileInfo       = fileInfo,
                    SearchCriteria = new SearchCriteria
                    {
                        NameOptions = new NameOptions
                        {
                            Value = "Application"
                        }
                    }
                };

                var request = new RemoveRequest(options);

                var response = apiInstance.Remove(request);
                Console.WriteLine("Resultant file path: " + response.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling MetadataApi: " + e.Message);
            }
        }
        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")));
        }
Exemple #4
0
        public void SetApiTest_PossibleTagName()
        {
            var testFile = TestFiles.Xlsx;

            var options = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "New Creator",
                        Type           = "String",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                PossibleName = "creator"
                            }
                        },
                    }
                }
            };

            var request = new SetRequest(options);

            var result = MetadataApi.Set(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Path);
            Assert.IsNotEmpty(result.Url);
            Assert.Greater(result.SetCount, 0);
        }
        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)));
        }
Exemple #6
0
        public void RemoveApiTest_PropertyNameRegex()
        {
            var options = new RemoveOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    NameOptions = new NameOptions
                    {
                        Value        = "^[N]ame[A-Z].*",
                        MatchOptions = new MatchOptions
                        {
                            IsRegex = true
                        }
                    }
                }
            };

            var request = new RemoveRequest(options);

            var result = MetadataApi.Remove(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Path);
            Assert.IsNotEmpty(result.Url);
            Assert.Greater(result.RemovedCount, 0);
        }
        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)));
        }
Exemple #8
0
        public void RemoveApiTest_PropertyNameExactPhrase()
        {
            var options = new RemoveOptions
            {
                FileInfo       = TestFiles.Docx.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    NameOptions = new NameOptions
                    {
                        Value        = "NameOfApplication",
                        MatchOptions = new MatchOptions
                        {
                            ExactPhrase = true
                        }
                    }
                }
            };

            var request = new RemoveRequest(options);

            var result = MetadataApi.Remove(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Path);
            Assert.IsNotEmpty(result.Url);
            Assert.Greater(result.RemovedCount, 0);
        }
Exemple #9
0
        public void RemoveApiTest()
        {
            var testFile = TestFiles.Docx;
            var options  = new RemoveOptions
            {
                FileInfo       = testFile.ToFileInfo(),
                SearchCriteria = new SearchCriteria
                {
                    TagOptions = new TagOptions
                    {
                        ExactTag = new Tag
                        {
                            Name     = "Title",
                            Category = "Content"
                        }
                    }
                }
            };

            var request = new RemoveRequest(options);

            var result = MetadataApi.Remove(request);

            Assert.IsNotNull(result);
            Assert.Greater(result.RemovedCount, 0);
        }
        public void AddApiTest_FileNotFound()
        {
            var testFile = TestFiles.NotExist;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Creator",
                                    Category = "Person"
                                }
                            }
                        },
                        Value = "New Value",
                        Type  = "String"
                    }
                }
            };

            var request = new AddRequest(options);

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

            Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message);
        }
        public void AddApiTest_PossibleTagName()
        {
            var testFile = TestFiles.Xlsx;
            var now      = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss");

            var options = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        Value          = now,
                        Type           = "DateTime",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                PossibleName = "timeprinted"
                            }
                        },
                    }
                }
            };

            var request = new AddRequest(options);

            var result = MetadataApi.Add(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Path);
            Assert.IsNotEmpty(result.Url);
            Assert.Greater(result.AddedCount, 0);
        }
        public void AddApiTest_ValueFormatException()
        {
            var testFile = TestFiles.Jpg;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Printed",
                                    Category = "Time"
                                }
                            }
                        },
                        Value = "New Value",
                        Type  = "DateTime"
                    }
                }
            };

            var request = new AddRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { MetadataApi.Add(request); });

            Assert.AreEqual(ex.Message, "Request parameters missing or have incorrect format");
        }
        public void AddApiTestWrongValueTypeForTag()
        {
            var testFile = TestFiles.Docx;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Printed",
                                    Category = "Time"
                                }
                            }
                        },
                        Value = "New Value",
                        Type  = "String"
                    }
                }
            };

            var request = new AddRequest(options);

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

            Assert.AreEqual($"There are no changes in metadata.", ex.Message);
        }
        public void AddApiTest()
        {
            var now      = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss");
            var testFile = TestFiles.Docx;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Printed",
                                    Category = "Time"
                                }
                            }
                        },
                        Value = now,
                        Type  = "DateTime"
                    }
                }
            };

            var request = new AddRequest(options);

            var result = MetadataApi.Add(request);

            Assert.IsNotNull(result);
            Assert.Greater(result.AddedCount, 0);
        }
Exemple #15
0
        public void SetApiTest_DateTime()
        {
            var testFile = TestFiles.Xlsx;
            var now      = DateTime.Now;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = now.ToString("MM-dd-yyyy hh:mm:ss"),
                        Type           = "DateTime",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Created",
                                    Category = "Time"
                                }
                            }
                        },
                    }
                }
            };

            var request = new SetRequest(options);

            var result = MetadataApi.Set(request);

            Assert.IsNotNull(result);
            Assert.Greater(result.SetCount, 0);
        }
        /// <summary>
        /// Checks to make sure tha the specified code produces the expected API.
        /// </summary>
        /// <param name="filePrefix">The prefix to the code..</param>
        public static void CheckApi([CallerMemberName] string filePrefix = null)
        {
            string assemblyFilePath = null;

            try
            {
                var codeFilePath = Path.Combine(_rootDirectory, filePrefix + ".cs");
                var apiFilePath  = Path.Combine(_rootDirectory, filePrefix + ".txt");

                if (!File.Exists(apiFilePath))
                {
                    File.Create(apiFilePath).Close();
                }

                var code = File.ReadAllText(codeFilePath);
                assemblyFilePath = CreateAssembly(code);

                var publicApi   = MetadataApi.GeneratePublicApi(assemblyFilePath);
                var expectedApi = File.ReadAllText(apiFilePath);

                var receivedFileName = filePrefix + ".received.txt";
                File.WriteAllText(receivedFileName, publicApi);

                TestHelpers.CheckEquals(publicApi, expectedApi, receivedFileName, apiFilePath);
            }
            finally
            {
                if (assemblyFilePath != null)
                {
                    File.Delete(assemblyFilePath);
                }
            }
        }
Exemple #17
0
        public void SetApiTest_Integer()
        {
            var testFile = TestFiles.Docx;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "14",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "SoftwareVersion",
                                    Category = "Tool"
                                }
                            }
                        },
                        Type = "integer"
                    }
                }
            };

            var request = new SetRequest(options);

            var result = MetadataApi.Set(request);

            Assert.IsNotNull(result);
            Assert.Greater(result.SetCount, 0);
        }
Exemple #18
0
        public void SetApiTest()
        {
            var testFile = TestFiles.Docx;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "NewAuthor",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Creator",
                                    Category = "Person"
                                }
                            }
                        },
                        Type = "String"
                    }
                }
            };

            var request = new SetRequest(options);

            var result = MetadataApi.Set(request);

            Assert.IsNotNull(result);
            Assert.Greater(result.SetCount, 0);
        }
Exemple #19
0
        public void SetApiTest_FileNotFound()
        {
            var testFile = TestFiles.NotExist;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "NewAuthor",
                        Type           = "Boolean",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Creator",
                                    Category = "Person"
                                }
                            }
                        },
                    }
                }
            };

            var request = new SetRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); });

            Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message);
        }
Exemple #20
0
        public void SetApiTest_NoChanges()
        {
            var testFile = TestFiles.Psd;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "NewAuthor",
                        Type           = "String",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Owner",
                                    Category = "Legal"
                                }
                            }
                        },
                    }
                }
            };

            var request = new SetRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); });

            Assert.AreEqual($"There are no changes in metadata.", ex.Message);
        }
Exemple #21
0
        public void SetApiTest_DocumentProtectedException()
        {
            var testFile = TestFiles.PasswordProtected;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "NewAuthor",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Creator",
                                    Category = "Person"
                                }
                            }
                        },
                        Type = "String"
                    }
                }
            };

            var request = new SetRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' is protected.", ex.Message);
        }
Exemple #22
0
        public void SetApiTest_UnsupportedFormat()
        {
            var testFile = TestFiles.Json;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "NewAuthor",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Creator",
                                    Category = "Person"
                                }
                            }
                        },
                        Type = "String"
                    }
                }
            };

            var request = new SetRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message);
        }
Exemple #23
0
        public void SetApiTest_ValueFormatException()
        {
            var testFile = TestFiles.Jpg;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "NewAuthor",
                        Type           = "Boolean",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Printed",
                                    Category = "Time"
                                }
                            }
                        },
                    }
                }
            };

            var request = new SetRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); });

            Assert.AreEqual(ex.Message, "Request parameters missing or have incorrect format");
        }
Exemple #24
0
        public void SetApiTest_WrongTypeForTag()
        {
            var testFile = TestFiles.Pptx;
            var options  = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "true",
                        Type           = "Boolean",
                        SearchCriteria = new SearchCriteria
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Creator",
                                    Category = "Person"
                                }
                            }
                        },
                    }
                }
            };

            var request = new SetRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); });

            Assert.AreEqual($"There are no changes in metadata.", ex.Message);
        }
Exemple #25
0
        public void SetApiTest_PropertyValue()
        {
            var testFile = TestFiles.Docx;

            var options = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = "Microsoft Office Word Application",
                        Type           = "String",
                        SearchCriteria = new SearchCriteria
                        {
                            ValueOptions = new ValueOptions
                            {
                                Value = "Microsoft Office Word",
                                Type  = "String"
                            }
                        },
                    }
                }
            };

            var request = new SetRequest(options);

            var result = MetadataApi.Set(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Path);
            Assert.IsNotEmpty(result.Url);
            Assert.Greater(result.SetCount, 0);
        }
Exemple #26
0
        public void SetApiTest_PropertyName()
        {
            var testFile = TestFiles.Docx;
            var now      = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss");

            var options = new SetOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <SetProperty>
                {
                    new SetProperty
                    {
                        NewValue       = now,
                        Type           = "DateTime",
                        SearchCriteria = new SearchCriteria
                        {
                            NameOptions = new NameOptions
                            {
                                Value = "Date"
                            }
                        },
                    }
                }
            };

            var request = new SetRequest(options);

            var result = MetadataApi.Set(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Path);
            Assert.IsNotEmpty(result.Url);
            Assert.Greater(result.SetCount, 0);
        }
Exemple #27
0
        public void TestEquals()
        {
            var assembly = Assembly.GetAssembly(typeof(RxApp));
            var oldApi   = ApiGenerator.GeneratePublicApi(assembly, new ApiGeneratorOptions());

            var newApi = MetadataApi.GeneratePublicApi(assembly);

            File.WriteAllText("old.txt", oldApi);
            File.WriteAllText("new.txt", newApi);

            TestHelpers.CheckEquals(newApi, oldApi, "new.txt", "old.txt");
        }
        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_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_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);
        }