Exemplo n.º 1
0
        public async Task <DocstoreApiResponse> GetDocument(string documentName, string path)
        {
            DocstoreApiResponse apiResponse = new DocstoreApiResponse();

            apiResponse = JsonConvert.DeserializeObject <DocstoreApiResponse>("{\"Status\":0,\"Message\":null,\"Response\":{\"create_version_action\":null,\"id\":\"2a04776f-b499-4bfd-b1c0-50149ef3d4f8\",\"name\":\"agreement878999294.xlsx\",\"fully_qualified_name\":null,\"comment\":null,\"created\":\"2018-10-28T13:03:04.974700+08:00\",\"updated\":\"2018-10-28T13:03:04.974717+08:00\",\"parent\":\"https://docs.dev.darkdonny.pw/docstore/documents/61a03476-0afb-41d8-a313-e0549b3573e6/\",\"created_by\":\"40ebceda-d7d0-4d68-9a51-f9c37a8ff274\",\"last_modified_by\":null,\"latest_version\":null,\"children\":null,\"url\":\"https://docs.dev.darkdonny.pw/docstore/documentversions/2a04776f-b499-4bfd-b1c0-50149ef3d4f8/\",\"metadata\":{\"test\":\"test1\",\"test1\":\"test2\"},\"sha512\":\"ea9e56461b19fb85ac77e348eec359abb854276b293e60738c3e9a1063fe91fcc5932c60181890bc647c20b82711fe6648511e43740e1111295556a2ecce168f\",\"file\":\"https://terra-dev-docstore.s3.amazonaws.com/media/jigartest/agreement878999294.xlsx/2a04776f-b499-4bfd-b1c0-50149ef3d4f8/agreement878999294.xlsx?AWSAccessKeyId=AKIAJJNGHSP5QARXW6CQ&Signature=D0H6EcfxrVPemIc2f7imRNFyvyw%3D&Expires=1540703100\"}}");
            return(apiResponse);
        }
Exemplo n.º 2
0
        public async Task <DocstoreApiResponse> UpsertDocument(string documentName, string path, byte[] filecontent, Dictionary <string, string> metadata)
        {
            DocstoreApiResponse apiResponse = new DocstoreApiResponse();

            apiResponse = JsonConvert.DeserializeObject <DocstoreApiResponse>("{\"Status\":0,\"Message\":null,\"Response\":{\"create_version_action\":\"https://docs.dev.darkdonny.pw/docstore/documentversions/61a03476-0afb-41d8-a313-e0549b3573e6/create/\",\"id\":\"61a03476-0afb-41d8-a313-e0549b3573e6\",\"name\":\"agreement878999294.xlsx\",\"fully_qualified_name\":\"jigartest/agreement878999294.xlsx\",\"comment\":null,\"created\":\"2018-10-28T13:03:04.966346+08:00\",\"updated\":\"2018-10-28T13:03:04.966365+08:00\",\"parent\":\"https://docs.dev.darkdonny.pw/docstore/folder/5e7eeaa1-f12d-44db-8da0-d05f1b9e61b5\",\"created_by\":\"40ebceda-d7d0-4d68-9a51-f9c37a8ff274\",\"last_modified_by\":\"40ebceda-d7d0-4d68-9a51-f9c37a8ff274\",\"latest_version\":\"https://docs.dev.darkdonny.pw/docstore/documentversions/2a04776f-b499-4bfd-b1c0-50149ef3d4f8/\",\"children\":[\"https://docs.dev.darkdonny.pw/docstore/documentversions/2a04776f-b499-4bfd-b1c0-50149ef3d4f8/\"],\"url\":\"https://docs.dev.darkdonny.pw/docstore/documents/61a03476-0afb-41d8-a313-e0549b3573e6/\",\"metadata\":{\"test\":\"test1\",\"test1\":\"test2\"},\"sha512\":null,\"file\":null}}");
            return(apiResponse);
        }
Exemplo n.º 3
0
        public async Task <DocstoreApiResponse> CreateTempDocumeent(string documentName, string path, byte[] filecontent, Dictionary <string, string> metadata, int timetoLive = 5)
        {
            DocstoreApiResponse apiResponse = new DocstoreApiResponse();

            try {
                this.restClient.requestUrl = string.Format("{0}/{1}/", this.docstoreServiceendPoint, "documents-create-temp");

                //this.logger.LogTrace(this.GetLogRecord("Request->Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.CreateTempDocumeent", path));
                var content = new MultipartFormDataContent();
                content.Add(new StringContent(documentName, Encoding.UTF8), "name");
                content.Add(new StringContent(path, Encoding.UTF8), "path");
                content.Add(new StringContent(timetoLive.ToString(), Encoding.UTF8), "ttl");
                content.Add(new ByteArrayContent(filecontent), "file", documentName);
                content.Add(new StringContent(JsonConvert.SerializeObject(metadata), Encoding.UTF8, "application/json"), "metadata");


                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                HttpResponseMessage responseMessage = await this.restClient.Post(content);

                if (responseMessage.IsSuccessStatusCode)
                {
                    apiResponse.Status = ApiStatus.Success;
                    var responseString = await responseMessage.Content.ReadAsStringAsync();

                    apiResponse.Response = GetDocstoreResponse(responseString);
                    stopwatch.Stop();
                    this.logger.LogTrace(this.GetLogRecord("Request Success -> Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.CreateTempDocumeent", path, stopwatch.ElapsedMilliseconds));
                }
                else
                {
                    apiResponse.Status  = ApiStatus.Error;
                    apiResponse.Message = await responseMessage.Content.ReadAsStringAsync();

                    stopwatch.Stop();
                    this.logger.LogError(this.GetLogRecord("Request Error -> Url:" + this.restClient.requestUrl + " documentName:" + documentName + " ErrorMessage:" + apiResponse.Message, "DocstoreClient.CreateTempDocumeent", path, stopwatch.ElapsedMilliseconds));
                }
            } catch (Exception ex) {
                apiResponse.Status  = ApiStatus.Error;
                apiResponse.Message = ex.Message;

                this.logger.LogError(this.GetLogRecord("Request Error -> Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.CreateTempDocumeent", path), ex);
            }

            return(apiResponse);
        }
Exemplo n.º 4
0
        public async Task <DocstoreApiResponse> DeleteDocument(string documentName, string path)
        {
            DocstoreApiResponse apiResponse = new DocstoreApiResponse();

            try {
                this.restClient.requestUrl = string.Format("{0}/{1}/", this.docstoreServiceendPoint, "documents-delete-by-path");
                //this.logger.LogTrace(this.GetLogRecord("Request->Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.DeleteDocument", path));
                var formContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("name", documentName),
                    new KeyValuePair <string, string>("path", path)
                });

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                HttpResponseMessage responseMessage = await this.restClient.Post(formContent);

                if (responseMessage.IsSuccessStatusCode)
                {
                    apiResponse.Status = ApiStatus.Success;
                    var responseString = await responseMessage.Content.ReadAsStringAsync();

                    apiResponse.Response = GetDocstoreResponse(responseString);

                    stopwatch.Stop();
                    this.logger.LogTrace(this.GetLogRecord("Request Success -> Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.DeleteDocument", path, stopwatch.ElapsedMilliseconds));
                }
                else
                {
                    apiResponse.Status  = ApiStatus.Error;
                    apiResponse.Message = await responseMessage.Content.ReadAsStringAsync();

                    stopwatch.Stop();
                    this.logger.LogError(this.GetLogRecord("Request Error -> Url:" + this.restClient.requestUrl + " documentName:" + documentName + " ErrorMessage:" + apiResponse.Message, "DocstoreClient.DeleteDocument", path, stopwatch.ElapsedMilliseconds));
                }
            } catch (Exception ex) {
                apiResponse.Status  = ApiStatus.Error;
                apiResponse.Message = ex.Message;

                this.logger.LogError(this.GetLogRecord("Request Error -> Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.DeleteDocument", path), ex);
            }

            return(apiResponse);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            ILoggerFactory loggerFactory  = new LoggerFactory();
            string         userToken      = "eyJraWQiOiJhWW0ya2xQOHFWMzFiSndkd1JSVDVVTkRCZjlUVEpnTE5hQUViVGo3QVFJPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI0MGViY2VkYS1kN2QwLTRkNjgtOWE1MS1mOWMzN2E4ZmYyNzQiLCJhdWQiOiJxcG5kaGNyZDd1ZzRqZnFkaWRidmtuNTVnIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImV2ZW50X2lkIjoiZWUyMWRkZmEtZGE2Yy0xMWU4LWI3YWMtMmJkMTc3YTYwY2U1IiwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE1NDA3MDIyMDIsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy13ZXN0LTIuYW1hem9uYXdzLmNvbVwvdXMtd2VzdC0yX01Ocm5TRmxNYSIsImNvZ25pdG86dXNlcm5hbWUiOiJleGNlbGFkbWluIiwiZXhwIjoxNTQwNzA1ODAyLCJpYXQiOjE1NDA3MDIyMDIsImVtYWlsIjoidmlqYXlkYmFnYWRhaUBnbWFpbC5jb20ifQ.MFjDHWhPGFYuPTZkPp_EMASIvgB6h9CmTMvmqW-DN2L85WIaVbq3fquk0VAiXCp1VeyLVeh0RhpOc86FQgtstDSMMPTxPMfOT0QDa73rHsrqA86RBRJImJ7L9bOxdqawe3_d1OpdQpOOluNPj-FOy-Sg0birDXdduH8Bmvq_a9-YxXiEhUKOStKS6OuYFW1PQRIGeGNObBbi5sX4aNH92Bpi4iqh9vE2A1CbSz9MrePBUtPZqB5WIyuFfbRTP7nD-8uZbrLpixii_MQ51pZ8pWfhPX0HzWMZZWp3hNHmmh5tf5yv3OGyNoVHKQygbL6D1zq7uXcxcu2WRiWBmuNU9g";
            DocstoreClient docstoreClient = new DocstoreClient(userToken, "https://docs.dev.darkdonny.pw/docstore", loggerFactory);

            byte[] bytecontet = System.IO.File.ReadAllBytes("documents/0e7d10a8-b41b-41ff-8945-f91b027d0393.xlsx");

            byte[] gb = Guid.NewGuid().ToByteArray();
            int    i  = BitConverter.ToInt32(gb, 0);

            Dictionary <string, string> metadata = new Dictionary <string, string>();

            metadata.Add("test", "test1");
            metadata.Add("test1", "test2");

            string documentName          = string.Format("agreement{0}", Math.Abs(i)) + ".xlsx";
            DocstoreApiResponse response = docstoreClient.CreateDocument(documentName, "jigartest", bytecontet, metadata).Result;

            Console.WriteLine("Create Document: {0}", response.Response.Name);

            documentName = string.Format("agreement{0}", Math.Abs(i)) + ".xlsx";
            response     = docstoreClient.UpsertDocument(documentName, "jigartest", bytecontet, metadata).Result;
            Console.WriteLine("Upsert Document: {0}", response.Response.Name);

            response = docstoreClient.GetDocument(documentName, "ExcelEngine/Services").Result;
            Console.WriteLine("Get Latest Version Document: {0}", response.Response.File);

            DocumentDownloadManager downloadManager = new DocumentDownloadManager();
            // byte[] content = downloadManager.DownloadFileContent(response.Response.File);

            //System.IO.File.WriteAllBytes("documents/test.xlsx", content);
//            response = docstoreClient.DeleteDocument(documentName, "jigartest").Result;
//          Console.WriteLine("Document Deleted sucessfully");

            DocstoreListApiResponse result = docstoreClient.ListDocuments("ExcelEngine/Services").Result;

            Console.WriteLine("Total Count:" + result.Response.Count);

            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
Exemplo n.º 6
0
        public async Task <DocstoreApiResponse> GetDocument(string documentName, string path)
        {
            DocstoreApiResponse apiResponse = new DocstoreApiResponse();

            try {
                this.restClient.requestUrl = string.Format("{0}/{1}/?name={2}&path={3}", this.docstoreServiceendPoint, "documents-get-latest", documentName, path);
                //this.logger.LogTrace(this.GetLogRecord("Request->Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.GetDocument", path));

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                HttpResponseMessage responseMessage = await this.restClient.Get();

                if (responseMessage.IsSuccessStatusCode)
                {
                    apiResponse.Status = ApiStatus.Success;
                    var responseString = await responseMessage.Content.ReadAsStringAsync();

                    apiResponse.Response = GetDocstoreResponse(responseString);
                    stopwatch.Stop();
                    this.logger.LogTrace(this.GetLogRecord("Request Success -> Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.GetDocument", path, stopwatch.ElapsedMilliseconds));
                }
                else
                {
                    apiResponse.Status  = ApiStatus.Error;
                    apiResponse.Message = await responseMessage.Content.ReadAsStringAsync();

                    stopwatch.Stop();
                    this.logger.LogError(this.GetLogRecord("Request Error -> Url:" + this.restClient.requestUrl + " documentName:" + documentName + " ErrorMessage:" + apiResponse.Message, "DocstoreClient.GetDocument", path, stopwatch.ElapsedMilliseconds));
                }
            } catch (Exception ex) {
                apiResponse.Status  = ApiStatus.Error;
                apiResponse.Message = ex.Message;

                this.logger.LogError(this.GetLogRecord("Request Error -> Url:" + this.restClient.requestUrl + " documentName:" + documentName, "DocstoreClient.GetDocument", path), ex);
            }

            return(apiResponse);
        }
Exemplo n.º 7
0
        public async Task <DocstoreApiResponse> DeleteDocument(string documentName, string path)
        {
            DocstoreApiResponse apiResponse = new DocstoreApiResponse();

            return(apiResponse);
        }