Beispiel #1
0
        /// <summary>
        /// Glue method to create a bodypart from a MIMEPart instance.
        /// </summary>
        /// <param name="mimePart">The MIMEPart instance to create the bodypart instance from.</param>
        /// <returns>An initialized instance of the Bodypart class.</returns>
        Bodypart BodypartFromMIME(MIMEPart mimePart)
        {
            NameValueCollection contentType = ParseMIMEField(
                mimePart.Headers["Content-Type"]);
            Bodypart p = new Bodypart(null);
            Match    m = Regex.Match(contentType["value"], "(.+)/(.+)");

            if (m.Success)
            {
                p.Type    = ContentTypeMap.fromString(m.Groups[1].Value);
                p.Subtype = m.Groups[2].Value;
            }
            p.Encoding = ContentTransferEncodingMap.fromString(
                mimePart.Headers["Content-Transfer-Encoding"]);
            p.Id = mimePart.Headers["Content-Id"];
            foreach (string k in contentType.AllKeys)
            {
                p.Parameters.Add(k, contentType[k]);
            }
            p.Size = mimePart.MessageText.Length;
            if (mimePart.Headers["Content-Disposition"] != null)
            {
                NameValueCollection disposition = ParseMIMEField(
                    mimePart.Headers["Content-Disposition"]);
                p.Disposition.Type = ContentDispositionTypeMap.fromString(
                    disposition["value"]);
                p.Disposition.Filename = disposition["Filename"];
                foreach (string k in disposition.AllKeys)
                {
                    p.Disposition.Attributes.Add(k, disposition[k]);
                }
            }
            return(p);
        }
Beispiel #2
0
        /// <summary>
        /// Gets all content types (doc types) with associated mapped properties
        /// </summary>
        public IEnumerable <ContentTypeMap> GetContentTypeMap()
        {
            var cts = services.ContentTypeService;

            var allContentTypes = cts.GetAllContentTypes() ?? Enumerable.Empty <IContentType>();

            var mapping = new List <ContentTypeMap>();

            foreach (var ct in allContentTypes.OrderBy(x => x.Name))
            {
                var map = new ContentTypeMap
                {
                    Alias       = ct.Alias,
                    Icon        = ct.Icon,
                    Name        = ct.Name,
                    Id          = ct.Id,
                    Udi         = ct.GetUdi().Guid,
                    Description = ct.Description,
                    Templates   = ct.AllowedTemplates != null?ct.AllowedTemplates.
                                  Select(x => new TemplateMap()
                    {
                        Alias     = x.Alias,
                        Id        = x.Id,
                        Name      = x.Name,
                        Path      = x.VirtualPath,
                        IsDefault = ct.DefaultTemplate != null && ct.DefaultTemplate.Id == x.Id
                    }) : Enumerable.Empty <TemplateMap>(),
                                      Properties = ct.PropertyTypes != null?ct.PropertyTypes.Select(p => new PropertyTypeMap(p)) : Enumerable.Empty <PropertyTypeMap>(),
                                                       CompositionProperties = ct.CompositionPropertyTypes != null?ct.CompositionPropertyTypes.Where(p => ct.PropertyTypes != null && !ct.PropertyTypes.Select(x => x.Id).Contains(p.Id)).Select(pt => new PropertyTypeMap(pt)) : Enumerable.Empty <PropertyTypeMap>(),
                                                                                   Compositions = ct.ContentTypeComposition != null?ct.ContentTypeComposition.
                                                                                                  Select(x => new ContentTypeData()
                    {
                        Alias       = x.Alias,
                        Description = x.Description,
                        Id          = x.Id,
                        Icon        = x.Icon,
                        Name        = x.Name
                    }) : Enumerable.Empty <ContentTypeData>()
                };

                map.AllProperties   = map.Properties.Concat(map.CompositionProperties ?? Enumerable.Empty <PropertyTypeMap>());
                map.HasCompositions = ct.ContentTypeComposition != null && ct.ContentTypeComposition.Any();
                map.HasTemplates    = ct.AllowedTemplates != null && ct.AllowedTemplates.Any();
                map.IsListView      = ct.IsContainer;
                map.AllowedAtRoot   = ct.AllowedAsRoot;
                map.PropertyGroups  = ct.PropertyGroups != null?ct.PropertyGroups.Select(x => x.Name) : Enumerable.Empty <string>();

                mapping.Add(map);
            }

            return(mapping);
        }
Beispiel #3
0
 public DataController()
 {
     map = new ContentTypeMap();
     map[DataTypeEnum.Text]  = "text/plain";
     map[DataTypeEnum.Word]  = "application/msword";
     map[DataTypeEnum.Excel] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
     map[DataTypeEnum.PDF]   = "application/pdf";
     suffixs = new ContentTypeMap();
     suffixs[DataTypeEnum.Text]  = ".txt";
     suffixs[DataTypeEnum.Word]  = ".docx";
     suffixs[DataTypeEnum.Excel] = ".xlsx";
     suffixs[DataTypeEnum.PDF]   = ".pdf";
 }
Beispiel #4
0
        private (string path, string encoding) ParseArguments(EvaluationContext context)
        {
            if (Arguments is LessString str)
            {
                var path = str.GetUnquotedValue();

                var type = ContentTypeMap.GetContentType(path);
                return(type, path);
            }

            var(encArg, pathArg) = UnpackArguments <LessString, LessString>();

            return(encArg.GetUnquotedValue().Split(';').First(), pathArg.GetUnquotedValue());
        }
        public IEnumerable <T> ExtractCards <T>(Activity activity)
        {
            if (activity.Attachments == null || !activity.Attachments.Any())
            {
                yield break;
            }

            var cardType    = typeof(T);
            var contentType = ContentTypeMap.Map(cardType);

            if (string.IsNullOrWhiteSpace(contentType))
            {
                throw new InvalidOperationException($"Cannot get ContentType property of type {cardType.Name}");
            }

            var cardAttachments = activity.Attachments.Where(att => att.ContentType == contentType).ToList();

            var cardsWithContent = cardAttachments.Where(att => att.Content != null).ToList();
            var cardsWithUrls    = cardAttachments.Where(att => att.ContentUrl != null && !cardsWithContent.Contains(att)).ToList();

            var jsonAttachments = new List <string>();

            if (cardsWithContent.Any())
            {
                jsonAttachments.AddRange(cardsWithContent.Select(card => card.Content.ToString()));
            }

            if (cardsWithUrls.Any())
            {
                var urls = cardsWithUrls.Select(tca => tca.ContentUrl).ToArray();
                jsonAttachments.AddRange(_attachmentRetriever.GetAttachmentsFromUrls(urls));
            }

            foreach (var json in jsonAttachments)
            {
                T card;
                try
                {
                    card = JsonConvert.DeserializeObject <T>(json);
                }
                catch (Exception)
                {
                    continue;
                }
                yield return(card);
            }
        }
        public Content AddContent(long subDirectoryId, ContentTypeMap type)
        {
            var resolvedType = _contentTypeService.GetContentTypeFromEnum(type);

            if (resolvedType != null)
            {
                var content = new Content()
                {
                    ContentTypeId      = resolvedType.Id,
                    SubDirectoryId     = subDirectoryId,
                    Timestamp          = DateTime.Now,
                    ExistsOnBlockChain = false
                };
                _contentRepository.Add(content);
                return(content);
            }
            return(null);
        }
        public WebResponse <WebFileInfo> SendFile(Stream fileStream, string fileName)
        {
            var response = new WebResponse <WebFileInfo>();

            using (var client = new HttpClient())
                using (var fsr = new BinaryReader(fileStream))
                {
                    fileStream.Position = 0;

                    var form        = new MultipartFormDataContent();
                    var fileContent = new ByteArrayContent(fsr.ReadBytes((int)fileStream.Length));
                    fileContent.Headers.ContentType =
                        MediaTypeHeaderValue.Parse(ContentTypeMap.ComputeMimeType(fileName));

                    form.Add(fileContent, "file", fileName);

                    using (var result = client.PostAsync(_options.UrlUpload, form))
                    {
                        result.Wait();

                        response.StatusCode = (int)result.Result.StatusCode;
                        response.StatusText = result.Result.StatusCode.ToString();

                        var content = result.Result.Content.ReadAsStringAsync();

                        content.Wait();

                        var resultList = JsonConvert.DeserializeObject <WebFileInfo[]>(content.Result);

                        response.Data          = resultList[0];
                        response.Data.MimeType = fileContent.Headers.ContentType.MediaType;
                    }
                }

            return(response);
        }
 public ContentType GetContentTypeFromEnum(ContentTypeMap type)
 {
     return(_contentTypeRepository.GetAll()
            .FirstOrDefault(x => x.TypeName == type.ToString()));
 }