Example #1
0
        /// <summary>
        /// Creates a session asynchronously given specific options.
        /// </summary>
        /// <param name="uuid"></param>
        /// <param name="options">If null, the default session options are used.</param>
        /// <returns></returns>
        public async Task<Uri> CreateAsync(string uuid, CreateSessionOptions options)
        {
            if (uuid == null) throw new ArgumentNullException("uuid");
            if (string.IsNullOrEmpty(uuid)) throw new ArgumentException("Parameter cannot be an empty string.", "uuid");

            var data = new Dictionary<string, string>();
            data.Add(Parameters.Token, Token);
            data.Add(Parameters.Uuid, uuid);

            if (options != null)
            {
                AddOptions(data, options);
            }

            var content = new FormUrlEncodedContent(data);
            HttpResponseMessage responseMessage = await PostAsync(Path, Methods.Create, content);

            if (!responseMessage.IsSuccessStatusCode)
            {
                var exception = await ReadAsException(responseMessage);
                throw exception;
            }

            var response = await responseMessage.Content.ReadJsonAsAsync<SessionResponse>();
            Uri responseUri = GetSessionUrl(response.Session);

            return responseUri;
        }
Example #2
0
        private void AddOptions(Dictionary<string, string> data, CreateSessionOptions options)
        {
            Contract.Requires(data != null);
            Contract.Requires(options != null);

            if (options.Editable)
            {
                data.Add(CreateSessionOptionalParameters.Editable, "true");

                // TODO: when editable, user is required
            }

            if (!string.IsNullOrEmpty(options.User))
            {
                data.Add(CreateSessionOptionalParameters.User, options.User);
            }

            if (!string.IsNullOrEmpty(options.Filter) && options.Filter != CreateSessionOptions.FilterAll)
            {
                data.Add(CreateSessionOptionalParameters.Filter, options.Filter);
            }

            if (options.Admin)
            {
                data.Add(CreateSessionOptionalParameters.Admin, "true");
            }

            if (options.Downloadable)
            {
                data.Add(CreateSessionOptionalParameters.Downloadable, "true");
            }

            if (options.CopyProtected)
            {
                data.Add(CreateSessionOptionalParameters.CopyProtected, "true");
            }

            if (options.Demo)
            {
                data.Add(CreateSessionOptionalParameters.Demo, "true");
            }

            switch (options.Sidebar)
            {
                case CreateSessionSidebarOptions.None:
                    break;
                case CreateSessionSidebarOptions.Collapse:
                    data.Add(CreateSessionOptionalParameters.Sidebar, "collapse");
                    break;
                case CreateSessionSidebarOptions.Visible:
                    data.Add(CreateSessionOptionalParameters.Sidebar, "visible");
                    break;
                case CreateSessionSidebarOptions.Auto:
                    data.Add(CreateSessionOptionalParameters.Sidebar, "auto");
                    break;
            }
        }