1

无论如何将docushare与Windows商店应用程序集成?我想登录,获取文件/文件夹列表,并有可能下载和上传文件。

4

2 回答 2

1

这是一个简单的代码片段,可以很好地开始使用 DocuShare。所有可能的请求都可以在文档中找到。

身份验证 + 获取 Collection-11 对象的属性

    protected const string UsernameFormFieldName = "username";
    protected const string PasswordFormFieldName = "password";
    protected const string DomainFormFieldName = "domain";

    const string CookieName = "AmberUser";
    const string baseAdress = "http://host:port";
    const string container = "/docushare";

    static Uri CookieUrl = new Uri(new Uri(baseAdress), container);

    const string root = "/xcm/v1/shadow/xcmAPI/root";
    const string FolderInfoUri = "/xcm/v1/shadow/object/{0}/xcmAPI/properties";
    const string ObjectVersion = "/xcm/v1/shadow/object/{0}/xcmAPI/version";

    const string ObjectToTest = "Collection-11";

    const string suffix = "?properties=title,mimetype";

    static void Main(string[] args)
    {
        var token = Authenticate();
        var requestUri = string.Format(container + FolderInfoUri, ObjectToTest) + suffix;
        var response = GetResult(token, requestUri);
        var content = response.Content.ReadAsStringAsync().Result;
    }

    private static string Authenticate()
    {
        const string AuthenticationPath = container + "/dsweb/ApplyLogin";


        var form = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair<string, string>(UsernameFormFieldName, "login"),
            new KeyValuePair<string, string>(PasswordFormFieldName, "password"),
            new KeyValuePair<string, string>(DomainFormFieldName, "domain"),
        });

        string authToken = null;

        Execute((client, handler) =>
        {
            var task = client.PostAsync(AuthenticationPath, form, CancellationToken.None);
            var response = task.Result;
            var content = response.Content.ReadAsStringAsync().Result;
            var cookie = handler.CookieContainer.GetCookies(CookieUrl);
            authToken = cookie[CookieName].Value;
        });

        return authToken;
    }

    private static void Execute(Action<HttpClient, HttpClientHandler> request)
    {
        using (var handler = new HttpClientHandler())
        using (var client = new HttpClient(handler))
        {
            handler.UseCookies = true;
            handler.CookieContainer = new CookieContainer();
            client.BaseAddress = new Uri(baseAdress);

            request(client, handler);
        }
    }

    private static HttpResponseMessage GetResult(string token, string uri)
    {
        HttpResponseMessage response = null;

        Execute((client, handler) =>
        {
            handler.CookieContainer.Add(
                CookieUrl,
                new Cookie(CookieName, token));

            var responseTask = client.GetAsync(uri);
            response = responseTask.Result;
        });

        return response;
    }
于 2016-04-27T13:57:17.107 回答
0

您应该可以使用 Docushare 的 HTML/XML API 来执行此操作。有关 Docushare API 的详细信息,您似乎需要注册DocuShare 开发者网络

一旦您知道 Docushare 期望什么,您应该能够使用HttpClient API 从您的 Windows 应用商店应用程序连接到它。请参阅使用 Windows.Web.Http.HttpClient (XAML) 连接到 HTTP 服务器

于 2014-11-04T02:01:27.870 回答