Beispiel #1
0
        /// <summary>
        /// Creates a new action link parameters that can be shared on the Web.
        /// </summary>
        /// <param name="actionLink">An object that configures the action link will be created.</param>
        /// <returns>
        /// The link.
        /// </returns>
        public static string UrlTokenEncode(ActionLink actionLink)
        {
            if (actionLink == null)
            {
                throw new ArgumentNullException(nameof(actionLink));
            }

            var customUri = actionLink.CustomUri != null?UriUtility.Normalize(actionLink.CustomUri) : default(string);

            var builder = new StringBuilder();

            builder.Append(GetChecksum(actionLink.ActionId, actionLink.ContactId, customUri));
            builder.Append(ValueSeparator);
            builder.Append(actionLink.ActionId);

            if (actionLink.ContactId != null)
            {
                builder.Append(ValueSeparator);
                builder.Append(actionLink.ContactId);
            }

            if (actionLink.CustomUri != null)
            {
                builder.Append('/');
                builder.Append(customUri);
            }

            return(builder.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Asynchronously reads the bytes from the current stream and writes them to a file stream.
        /// </summary>
        /// <param name="stream">The stream to read.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A task that represents the asynchronous save operation.
        /// </returns>
        public async Task CreateFileAsync(Stream stream, CancellationToken cancellationToken)
        {
            string dirName  = DateTime.UtcNow.ToString("yyyy-MM-dd");
            string fileName = UriUtility.Normalize(Path.GetFileName(RelativePath));
            string filePath = GetFileName(Path.Combine(CreateDirectory(dirName), fileName));

            using (var fileStream = new FileStream(filePath, FileMode.CreateNew))
            {
                await stream.CopyToAsync(fileStream, 81920, cancellationToken);
            }

            RelativePath = Path.Combine(dirName, fileName);
            AbsolutePath = filePath;
        }
        public async Task <IHttpActionResult> PostAsync([FromBody] MediaPlaylist model, CancellationToken cancellationToken)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                ModelState.Remove("model.ContactId");
                ModelState.Remove("model.Uri");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var uri         = string.Join("-", ProjectIdentity.Id.ToString("x"), UriUtility.Normalize(model.Name));
            var oldPlaylist = await _services.Media.FindByUriAsync(uri, cancellationToken);

            if (oldPlaylist != null)
            {
                uri = string.Join("-", ProjectIdentity.Id.ToString("x"), Guid.NewGuid().ToString("n"));
            }
            model = new MediaPlaylist
            {
                ContactId   = ProjectIdentity.Id,
                Uri         = uri,
                Name        = model.Name,
                EditMode    = model.EditMode,
                DefaultList = model.DefaultList,
                Published   = true
            };
            await _services.Media.CreateAsync(model, cancellationToken);

            await _services.SaveAsync(cancellationToken);

            return(CreatedAtRoute("Media.Playlists.GetById", new RouteValueDictionary {
                { "id", model.Id }
            }, model));
        }
Beispiel #4
0
        public async Task <IHttpActionResult> PostAsync(
            [FromUri(BinderType = typeof(ActionLinkModelBinder))] ActionLink linkParams,
            [FromUri(BinderType = typeof(AuthTicketModelBinder))] AuthTicket authTicket,
            [FromBody] WorkflowDto model,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            ContactItem contact;

            if (model == null)
            {
                contact = await GetContactAsync(linkParams, authTicket, cancellationToken);

                return(await ExecuteActionAsync(linkParams, authTicket, contact, null, cancellationToken));
            }
            if (model.Name != null)
            {
                linkParams.CustomUri = UriUtility.Normalize(model.Name);
            }
            if (model.Contact != null)
            {
                contact = model.Contact.ToContact();
            }
            else
            {
                contact = await GetContactAsync(linkParams, authTicket, cancellationToken);
            }

            var result = await ExecuteActionAsync(linkParams, authTicket, contact, null, cancellationToken);

            if (model.Invitation != null)
            {
                await InviteAsync(linkParams, authTicket, contact, model.Invitation, cancellationToken);
            }
            return(result);
        }
Beispiel #5
0
 /// <summary>
 /// Returns a normalized representation of the specified <paramref name="uri" />.
 /// </summary>
 /// <param name="uri">The uri to normalize.</param>
 /// <returns>
 /// A normalized representation of the specified <paramref name="uri" />.
 /// </returns>
 /// <exception cref="System.ArgumentNullException"></exception>
 public string Normalize(string uri) => UriUtility.Normalize(uri);