Пример #1
0
        private static string Webapicall_ReadMetaData(string baseAddressUrl, string requestUri, MetadataParamBatch param)
        {
            string strresult = String.Empty;

            try
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.BaseAddress = new Uri(baseAddressUrl);

                    // Create POST data and convert it to a byte array.
                    string postData  = JsonConvert.SerializeObject(param);// IRDownloadFinalData
                    byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);

                    // Set the ContentType property of the WebRequest.
                    var content = new StringContent(postData, Encoding.UTF8, "application/json");


                    httpClient.Timeout = new TimeSpan(0, 15, 0);
                    HttpResponseMessage httpResponseMessage = httpClient.PostAsync(requestUri, content).Result;
                    httpResponseMessage.Content.ReadAsStringAsync().Wait();


                    Task <string> response = httpResponseMessage.Content.ReadAsStringAsync();


                    MetadataResult bsObj = JsonConvert.DeserializeObject <MetadataResult>(response.Result.ToString());
                    strresult = JsonConvert.SerializeObject(bsObj);
                }
            }
            catch { }
            return(strresult);
        }
Пример #2
0
        static void Main(string[] args)
        {
            string filepath = string.Empty; //@"D:\Metadata\Test\testfile\universe10e_ch03.ppt";
            List <DocumentData> metadata = GetMetaDataList();
            string   loop          = "n";
            FileInfo fi            = null;
            string   GlobalAPITken = "3DbjvtceazqibXkOYX2lpbKCkeXdGXyweIBdtIgc15k715v56cNOdgA3bQhNdUp4DRl9MCPJHAsL4yMYXYTzyF3OQoKp17Ifi0c-3zgWb9QuUHAF73EYhAyU3Cps3sax5EEf9OHB95O9_9XhEWki1XLJjKaaN1N-NBOxRDG2XbpxlYIHq1YarZCXeVv69jx8ChB-Ltm-WCPRiP2LKJPYPLQuRI_qUGa3wIu7u2f-fouJRANRt1aa2y8oh5oaw_dNI4tVAnOpbhY9ly2wJFuYJfXs7cFAPZYqSlb254n7qow";

            do
            {
                filepath = string.Empty;
                Console.Clear();
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("1 - files metadata on file");
                Console.WriteLine("2 - Read file metadata");
                Console.WriteLine("3 - Read file metadata after url download");
                Console.WriteLine("4 - Fetch the SFDC 18 Dig Id(SalesForceID) using the OnyxCustomerId value");
                Console.WriteLine("5 - DocumentSecurity Metadata/Apply API");
                Console.WriteLine("6 - DocumentSecurity Metadata/Read API");
                Console.WriteLine("7 - Microsoft.Office.Interop dll Convert doc,xls and ppt file to docx, xlsx, and pptx");
                Console.WriteLine("8 - opensource Convert doc,xls and ppt file to docx, xlsx, and pptx");
                Console.WriteLine("9 - DocumentSecurity Token API");
                Console.WriteLine("10 - Call DocumentSecurity api/Account/CurrentUser API");
                Console.WriteLine("11 - Image file Apply Metadata");
                Console.WriteLine("12 - Image file Read Metadata");
                Console.WriteLine("0 - Exist");
                Console.WriteLine("-----------------------------------");
                Console.Write("Enter your choice: ");
                string input = Console.ReadLine();
                Console.WriteLine("");
                string filesfolder = @"C:\DocumentSecurity\Logs\test\Instructor_Resource_PDFs";
                string zipfilepath = string.Empty;
                switch (input.ToString())
                {
                case "1":
                {
                    Console.Write("\nEnter file path to apply metadata: ");
                    filepath = Console.ReadLine();
                    Console.Write("\nFile Path:{0} ", filepath);
                    fi = new FileInfo(filepath);
                    if (!string.IsNullOrEmpty(filepath) && fi.Exists)
                    {
                        string outputfilename = Path.Combine(fi.DirectoryName, "Output_" + fi.Name);
                        metadata = GetMetaDataList();
                        Console.WriteLine(string.Format("\n File Applymetadata  Start time:{0}, files folder", DateTime.Now.ToString("o"), fi.FullName));
                        switch (fi.Extension.ToUpper())
                        {
                        case ".DOC":
                        case ".XLS":
                        case ".PPT":
                            //ApplyMetaDataInComments(fi.FullName, metadata);
                            ApplyMetaData(fi.FullName, metadata);
                            break;

                        case ".PDF":
                            ApplyMetaDataInPDF(fi.FullName, outputfilename, metadata);
                            Console.WriteLine("Please check output file: {0} ", outputfilename);
                            break;
                        }
                        Console.WriteLine(string.Format("File Applymetadata End time:{0} , file path:{1}", DateTime.Now.ToString("o"), fi.FullName));
                        Console.WriteLine("-----------------output------------------------");
                        Console.WriteLine("Please check file: {0} ", fi.FullName);
                    }
                    else
                    {
                        Console.WriteLine("File path you have given not exists...");
                    }
                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "2":
                {
                    Console.Write("\nEnter file path to read metadata: ");
                    filepath = Console.ReadLine();
                    Console.Write("\nFile Path:{0} ", filepath);
                    fi = new FileInfo(filepath);
                    if (!string.IsNullOrEmpty(filepath) && fi.Exists)
                    {
                        Console.WriteLine(string.Format("\nRead File Metadata Start time:{0}, files folder", DateTime.Now.ToString("o"), fi.FullName));
                        switch (fi.Extension.ToUpper())
                        {
                        case ".DOC":
                        case ".XLS":
                        case ".PPT":
                            // metadata = ReadMetaDataInComments(fi.FullName);
                            metadata = ReadMetaData(fi.FullName);
                            break;

                        case ".PDF":
                            metadata = ReadMetaDataFromPDF(fi.FullName, metadata);
                            break;
                        }
                        Console.WriteLine(string.Format("\nRead File Metadata End time:{0}, files folder", DateTime.Now.ToString("o"), fi.FullName));
                        Console.WriteLine("-----------------output------------------------");
                        Console.WriteLine("---Key----\t|\t------Value---- ");
                        foreach (DocumentData md in metadata)
                        {
                            Console.WriteLine("  {0}\t|\t{1} ", md.Key, md.Text);
                        }
                    }
                    else
                    {
                        Console.WriteLine("File path you have given not exists...");
                    }

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "3":
                {
                    Console.Write("\nEnter file url to read metadata: ");
                    string url = Console.ReadLine();
                    //  url = "http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/w1.doc";//Answers_workbook.pdf
                    filepath = DownloadFileFromServer(url, "ttt");
                    Console.Write("\nFile Path:{0} ", filepath);
                    fi = new FileInfo(filepath);
                    if (!string.IsNullOrEmpty(filepath) && fi.Exists)
                    {
                        Console.WriteLine(string.Format("\nRead File Metadata Start time:{0}, files folder", DateTime.Now.ToString("o"), fi.FullName));
                        switch (fi.Extension.ToUpper())
                        {
                        case ".DOC":
                        case ".XLS":
                        case ".PPT":
                            //  metadata = ReadMetaDataInComments(fi.FullName);
                            metadata = ReadMetaData(fi.FullName);
                            break;

                        case ".PDF":
                            metadata = ReadMetaDataFromPDF(fi.FullName, metadata);
                            break;
                        }

                        Console.WriteLine(string.Format("\nRead File Metadata End time:{0}, files folder", DateTime.Now.ToString("o"), fi.FullName));
                        Console.WriteLine("-----------------output------------------------");
                        Console.WriteLine("---Key----\t|\t------Value---- ");
                        foreach (DocumentData md in metadata)
                        {
                            Console.WriteLine("  {0}\t|\t{1} ", md.Key, md.Text);
                        }
                    }
                    else
                    {
                        Console.WriteLine("File path you have given not exists...");
                    }

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "4":
                {
                    Console.Write("\nEnter OnyxCustomerId: ");
                    string OnyxCustomerId = Console.ReadLine();        //24073460
                    Console.WriteLine(string.Format("\nCall service to fetch SalesForceID Start time:{0}", DateTime.Now.ToString("o")));

                    string SalesForceID = GetUserSalesforceIdByOnyxCustomerID(OnyxCustomerId);
                    Console.WriteLine(string.Format("Call service to fetch SalesForceID End time:{0} ", DateTime.Now.ToString("o")));

                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine(SalesForceID);

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "5":
                {            //"http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/Answers_workbook.pdf";
                    // "http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181013/a7648575-62bc-4ed2-8151-1d69ffd69a4a.zip";
                    //"http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/221dc991-ae8c-4a10-8108-1c95a0723fdf.zip";
                    string sourceFileUrl = /*Console.ReadLine();//*/ "http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/w.docx";
                    sourceFileUrl = "http://local.macmillanlearning.com/catalog//Workarea/images/testfile/Table_1-1.zip";
                    string             api_baseAddressUrl  = "http://local.macmillanlearning.com/DocumentSecurityService/";
                    string             api_requestUri      = "Metadata/Apply";
                    MetadataParamBatch oMetadataParamBatch = new MetadataParamBatch();
                    oMetadataParamBatch.UserId = "1212";
                    List <MetadataParam> lstMetaDataParam = new List <MetadataParam>();
                    lstMetaDataParam.Add(new MetadataParam {
                            documentType = DocumentType.ZIP, InputFileName = sourceFileUrl, ResourceType = "IR", ResourceName = "test"
                        });
                    oMetadataParamBatch.MetadataParams = lstMetaDataParam;
                    List <DocumentData> metadataCollection = new List <DocumentData>()
                    {
                        new DocumentData {
                            Key = "CopyRight", Text = "2018"
                        },
                        new DocumentData {
                            Key = "CompanyName", Text = "Macmillan Learning"
                        },
                        new DocumentData {
                            Key = "CreatedOn", Text = "16-Nov-2018"
                        },
                        new DocumentData {
                            Key = "RequestId", Text = "11111"
                        },
                        new DocumentData {
                            Key = "RequestDate", Text = "16-Nov-2018"
                        }
                    };

                    oMetadataParamBatch.MetadataCollection = metadataCollection;

                    Console.WriteLine(sourceFileUrl);
                    Console.WriteLine("");
                    string strresult = Webapicall_ApplyMetaData(api_baseAddressUrl, api_requestUri, oMetadataParamBatch);
                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine(strresult);

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "6":
                {            //"http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/Answers_workbook.pdf";
                    // "http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181013/a7648575-62bc-4ed2-8151-1d69ffd69a4a.zip";
                    //"http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/221dc991-ae8c-4a10-8108-1c95a0723fdf.zip";
                    string             sourceFileUrl      = Console.ReadLine(); //"http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/w.docx";
                    string             api_baseAddressUrl = "http://local.macmillanlearning.com/DocumentSecurityService/";
                    string             api_requestUri     = "Metadata/Read";
                    MetadataParamBatch parameters         = new MetadataParamBatch();

                    List <DocumentData> metadataCollection = new List <DocumentData>()
                    {
                        new DocumentData {
                            Key = "CopyRight"
                        },
                        new DocumentData {
                            Key = "CompanyName"
                        },
                        new DocumentData {
                            Key = "CreatedOn"
                        },
                        new DocumentData {
                            Key = "RequestId"
                        },
                        new DocumentData {
                            Key = "RequestDate"
                        }
                    };

                    parameters.MetadataCollection = metadataCollection;

                    Console.WriteLine(sourceFileUrl);
                    Console.WriteLine("");
                    List <MetadataParam> metadataParams = new List <MetadataParam>();
                    metadataParams.Add(new MetadataParam()
                        {
                            documentType   = DocumentType.JPEG,
                            InputFileName  = sourceFileUrl,
                            OutputFileName = sourceFileUrl,
                            ResourceName   = "test"
                        });
                    parameters.MetadataParams = metadataParams;


                    string strresult = Webapicall_ReadMetaData(api_baseAddressUrl, api_requestUri, parameters);
                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine(strresult);

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "7":
                {
                    Console.Write("\nEnter file path of doc,xls or ppt: ");
                    filepath = Console.ReadLine();
                    fi       = new FileInfo(filepath);
                    switch (fi.Extension.ToUpper())
                    {
                    case ".DOC":
                    { filepath = TransformNewOfficeDocument.DOCToDOCX(fi.FullName); }
                    break;

                    case ".XLS":
                    { filepath = TransformNewOfficeDocument.XLSToXLSX(fi.FullName); }
                    break;

                    case ".PPT":
                    { filepath = TransformNewOfficeDocument.PPTToPPTX(fi.FullName); }
                    break;
                    }
                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine(filepath);

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "8":
                {
                    Console.Write("\nEnter file path of doc,xls or ppt: ");
                    filepath = Console.ReadLine();
                    fi       = new FileInfo(filepath);
                    switch (fi.Extension.ToUpper())
                    {
                    case ".DOC":
                    { filepath = TransformNewOfficeDocument_OpenSource.DOCToDOCX(fi.FullName); }
                    break;

                    case ".XLS":
                    { filepath = TransformNewOfficeDocument.XLSToXLSX(fi.FullName); }
                    break;

                    case ".PPT":
                    { filepath = TransformNewOfficeDocument.PPTToPPTX(fi.FullName); }
                    break;
                    }
                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine(filepath);

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "9":
                {
                    Console.Write("\n call  DocumentSecurity.WebService/token API : ");
                    string userName   = "******";
                    string password   = "******";
                    string apiBaseUri = "http://localhost";
                    string webAPIUrl  = "DocumentSecurity.WebService/token";
                    string token      = GetAPIToken(userName, password, apiBaseUri, webAPIUrl).Result;
                    GlobalAPITken = token;

                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine("Token: {0}", token);

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "10":
                {
                    Console.Write("\n DocumentSecurity.WebService/api/Account/CurrentUser: "******"http://localhost";
                    string webAPIUrl  = "DocumentSecurity.WebService/api/Account/CurrentUser";
                    Console.Write("\n Enter Token: ");
                    string token = Console.ReadLine();
                    if (string.IsNullOrEmpty(token))
                    {
                        token = GlobalAPITken;
                    }
                    string result = GetCurrentUserDetail(apiBaseUri, webAPIUrl, token).Result;
                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine(result);

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "11":
                {
                    string sourceFileUrl = /*Console.ReadLine();//*/ "http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/w.docx";
                    sourceFileUrl = "http://local.macmillanlearning.com/catalog//Workarea/images/testfile/Table_1-1.zip";
                    MetadataParamBatch oMetadataParamBatch = new MetadataParamBatch();
                    oMetadataParamBatch.UserId = "1212";
                    List <MetadataParam> lstMetaDataParam = new List <MetadataParam>();
                    lstMetaDataParam.Add(new MetadataParam {
                            documentType = DocumentType.ZIP, InputFileName = sourceFileUrl, ResourceType = "IR", ResourceName = "test"
                        });
                    oMetadataParamBatch.MetadataParams = lstMetaDataParam;
                    List <DocumentData> metadataCollection = new List <DocumentData>()
                    {
                        new DocumentData {
                            Key = "CopyRight", Text = "2018"
                        },
                        new DocumentData {
                            Key = "CompanyName", Text = "Macmillan Learning"
                        },
                        new DocumentData {
                            Key = "CreatedOn", Text = "16-Nov-2018"
                        },
                        new DocumentData {
                            Key = "RequestId", Text = "11111"
                        },
                        new DocumentData {
                            Key = "RequestDate", Text = "16-Nov-2018"
                        }
                    };

                    oMetadataParamBatch.MetadataCollection = metadataCollection;

                    //fi= new FileInfo(@"C:\Users\sk00538811\Pictures\[30-nov-2018] error-catalog.png");
                    fi = new FileInfo(@"C:\Users\sk00538811\Pictures\14THCARTOON.gif");
                    Console.WriteLine(fi.FullName);
                    Console.WriteLine("");
                    MetadataResult objresult = null;
                    switch (fi.Extension.ToUpper())
                    {
                    case ".JPG":
                    { objresult = new Security.Metadata.DocumentTypes.JPEGImageDocument().ApplyMetaData(fi.FullName, fi.FullName.ToUpper().Replace(".JPG", "_Copy.JPG"), oMetadataParamBatch.MetadataCollection); }
                    break;

                    case ".JPEG":
                    { objresult = new Security.Metadata.DocumentTypes.JPEGImageDocument().ApplyMetaData(fi.FullName, fi.FullName.ToUpper().Replace(".JPEG", "_Copy.JPEG"), oMetadataParamBatch.MetadataCollection); }
                    break;

                    case ".BMP":
                    { objresult = new Security.Metadata.DocumentTypes.JPEGImageDocument().ApplyMetaData(fi.FullName, fi.FullName.ToUpper().Replace(".BMP", "_Copy.BMP"), oMetadataParamBatch.MetadataCollection); }
                    break;

                    case ".GIF":
                    { objresult = new Security.Metadata.DocumentTypes.JPEGImageDocument().ApplyMetaData(fi.FullName, fi.FullName.ToUpper().Replace(".GIF", "_Copy.GIF"), oMetadataParamBatch.MetadataCollection); }
                    break;

                    case ".PNG":
                    { objresult = new Security.Metadata.DocumentTypes.PNGImageDocument().ApplyMetaData(fi.FullName, fi.FullName.ToUpper().Replace(".PNG", "_Copy.PNG"), oMetadataParamBatch.MetadataCollection); }
                    break;
                    }
                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine(JsonConvert.SerializeObject(objresult));

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "12":
                {
                    string sourceFileUrl = /*Console.ReadLine();//*/ "http://dev-s3c-webpub.s3.amazonaws.com/dev/bcs-test/Catalog-IR/20181011/w.docx";
                    sourceFileUrl = "http://local.macmillanlearning.com/catalog//Workarea/images/testfile/Table_1-1.zip";
                    MetadataParamBatch oMetadataParamBatch = new MetadataParamBatch();
                    oMetadataParamBatch.UserId = "1212";
                    List <MetadataParam> lstMetaDataParam = new List <MetadataParam>();
                    lstMetaDataParam.Add(new MetadataParam {
                            documentType = DocumentType.ZIP, InputFileName = sourceFileUrl, ResourceType = "IR", ResourceName = "test"
                        });
                    oMetadataParamBatch.MetadataParams = lstMetaDataParam;
                    List <DocumentData> metadataCollection = new List <DocumentData>()
                    {
                        new DocumentData {
                            Key = "CopyRight", Text = "2018"
                        },
                        new DocumentData {
                            Key = "CompanyName", Text = "Macmillan Learning"
                        },
                        new DocumentData {
                            Key = "CreatedOn", Text = "16-Nov-2018"
                        },
                        new DocumentData {
                            Key = "RequestId", Text = "11111"
                        },
                        new DocumentData {
                            Key = "RequestDate", Text = "16-Nov-2018"
                        }
                    };

                    oMetadataParamBatch.MetadataCollection = metadataCollection;

                    List <string> reqMetadataCollection = new List <string>()
                    {
                        "CopyRight",
                        "CompanyName",
                        "CreatedOn",
                        "RequestId",
                        "RequestDate"
                    };

                    //  fi= new FileInfo(@"C:\Users\sk00538811\Pictures\[30-nov-2018] error-catalog_copy.png");
                    fi = new FileInfo(@"C:\Users\sk00538811\Pictures\14THCARTOON_copy.gif");
                    Console.WriteLine(fi.FullName);
                    Console.WriteLine("");
                    MetadataResult objresult = null;
                    switch (fi.Extension.ToUpper())
                    {
                    case ".JPG":
                    case ".JPEG":
                    case ".BMP":
                    case ".GIF":
                    { objresult = new Security.Metadata.DocumentTypes.JPEGImageDocument().ReadMetaData(fi.FullName, reqMetadataCollection); }
                    break;

                    case ".PNG":
                    { objresult = new Security.Metadata.DocumentTypes.PNGImageDocument().ReadMetaData(fi.FullName, reqMetadataCollection); }
                    break;
                    }
                    Console.WriteLine("-----------------output------------------------");
                    Console.WriteLine(JsonConvert.SerializeObject(objresult));

                    Console.WriteLine("Press Enter key to return main menu...");
                    Console.ReadLine();
                }
                break;

                case "0":
                    Console.Write("\nAre you sure you want to exit.(y/n)?");
                    input = Console.ReadLine();
                    loop  = input;
                    break;

                default:
                    return;
                }
            } while (loop != "y");
            //
        }