コード例 #1
0
        // Get OnlyOffice editing status for a given item
        // curl -X POST http://daniel.erasme.lan/onlyoffice/coauthoring/CommandService.ashx
        // -H "Content-Type: application/json" -d
        // '{"key": "3180REV3", "c": "info"}'
        public static async Task <JsonValue> GetInfoAsync(string publicUrl, string key)
        {
            JsonValue res = null;
            var       uri = new Uri(new Uri(publicUrl), "/onlyoffice/coauthoring/CommandService.ashx");

            using (HttpClient client = await HttpClient.CreateAsync(uri))
            {
                HttpClientRequest request = new HttpClientRequest();
                request.Method            = "POST";
                request.Path              = uri.PathAndQuery;
                request.Headers["accept"] = "application/json";
                request.Content           = new JsonObject
                {
                    ["key"] = key,
                    ["c"]   = "info"
                };
                await client.SendRequestAsync(request);

                HttpClientResponse response = await client.GetResponseAsync();

                if (response.StatusCode == 200)
                {
                    res = await response.ReadAsJsonAsync();
                }
            }
            return(res);
        }
コード例 #2
0
 public BonAppService(BonAppSetup setup)
 {
     this.setup = setup;
     // allow data caching to 20 min
     cache = new Utils.Cache <JsonValue>(200, TimeSpan.FromMinutes(20), async(string key) =>
     {
         JsonValue res = null;
         var url       = new Uri(setup.url);
         using (HttpClient client = await HttpClient.CreateAsync(url))
         {
             HttpClientRequest request = new HttpClientRequest();
             request.Method            = "GET";
             request.Path = key;
             request.Headers["menuapi-key"] = setup.apiKey;
             await client.SendRequestAsync(request);
             HttpClientResponse response = await client.GetResponseAsync();
             if (response.StatusCode == 200)
             {
                 res = await response.ReadAsJsonAsync();
             }
             else
             {
                 Console.WriteLine(await response.ReadAsStringAsync());
             }
         }
         return(res);
     });
 }
コード例 #3
0
        //# Thumbnail avec OnlyOffice
        //        curl -X POST http://hostname/onlyoffice/ConvertService.ashx
        // -H "Content-Type: application/json" -d
        // '{"async": false, "outputtype":"jpg","thumbnail":{"aspect": 0, "width": 64, "height": 64 },"filetype":"docx","url": "http://hostname/api/docs/3180/content"}'
        public static async Task <string> ConvertAsync(Logger logger, HttpContext c, string fileUrl, OnlyOfficeFileType fileType, OnlyOfficeFileType destFileType)
        {
            string resFileUrl = null;
            var    uri        = new Uri(new Uri(c.SelfURL()), "/onlyoffice/ConvertService.ashx");

            logger.Log(LogLevel.Info, $"OnlyOffice ConvertService URL: {uri}");
            using (HttpClient client = await HttpClient.CreateAsync(uri))
            {
                HttpClientRequest request = new HttpClientRequest();
                request.Method            = "POST";
                request.Path              = uri.PathAndQuery;
                request.Headers["accept"] = "application/json";
                var jsonContent = new JsonObject
                {
                    ["key"]        = Guid.NewGuid().ToString(),
                    ["async"]      = false,
                    ["codePage"]   = 65001,
                    ["filetype"]   = fileType.ToString(),
                    ["outputtype"] = destFileType.ToString(),
                    ["url"]        = fileUrl
                };
                request.Content = jsonContent;
                logger.Log(LogLevel.Debug, $"OnlyOffice ConvertService send message for file convert (url: {uri.ToString()}). Response: {jsonContent.ToString()}");
                await client.SendRequestAsync(request);

                HttpClientResponse response = await client.GetResponseAsync();

                if (response.StatusCode == 200)
                {
                    var json = await response.ReadAsJsonAsync();

                    logger.Log(LogLevel.Debug, $"OnlyOffice ConvertService for file convert (url: {uri.ToString()}). Response: {json.ToString()}");
                    if (json.ContainsKey("fileUrl"))
                    {
                        resFileUrl = json["fileUrl"];
                    }
                }
                else
                {
                    logger.Log(LogLevel.Error, $"OnlyOffice ERROR while asking for file convert (url: {uri.ToString()}) for file {fileUrl}. Got HTTP {response.StatusCode}");
                }
            }
            return(resFileUrl);
        }