Beispiel #1
0
        /// <inheritdoc />
        protected override void Execute(Context context)
        {
            var query    = @"<fetch top='1' no-lock='true' >
  <entity name='annotation' >
    <attribute name='mimetype' />
    <attribute name='documentbody' />
    <filter>
      <condition attribute='filename' operator='eq' value='" + FileName.Get(context) + @"' />
      <condition attribute='objectid' operator='eq' value='" + EntityIdString.Get(context) + @"' />
    </filter>
    <order attribute='createdon' descending='true' />
  </entity>
</fetch>";
            var service  = ExecureAsSystem.Get(context) ? context.SystemService : context.Service;
            var response = service.RetrieveMultiple(new FetchExpression(query));

            if (response.Entities.Count < 1)
            {
                return;
            }
            var annotation = response.Entities.First();

            FileMimeType.Set(context, annotation.GetAttributeValue <string>("mimetype"));
            FileBase64Content.Set(context, annotation.GetAttributeValue <string>("documentbody"));
        }
        /// <inheritdoc />
        protected override void Execute(Context context)
        {
            var entityId = new Guid(EntityIdString.Get(context));

            context.Service.Create(new Entity(Metadata.Annotation.LogicalName)
            {
                ["objectid"]     = new EntityReference(EntityLogicalName.Get(context), entityId),
                ["subject"]      = Subject.Get(context),
                ["notetext"]     = Content.Get(context),
                ["filename"]     = FileName.Get(context),
                ["mimetype"]     = FileMimeType.Get(context),
                ["documentbody"] = FileBase64Content.Get(context)
            });
        }
        public override ComponentLine BuildLine()
        {
            StringBuilder output = new StringBuilder();

            output.Append(FileMimeType.GetDescription());

            if (!string.IsNullOrEmpty(FileLocation))
            {
                output.Append(";" + CalendarValueType.Url.GetDescription());
                output.Append(":" + UrlNormalization.Instance.Normalize(FileLocation));
            }
            else
            {
                output.Append(";" + EncodingType.Base64.GetDescription());
                output.Append(";" + CalendarValueType.Binary.GetDescription());
                output.Append(":");
                output.Append(AttachmentBody);
            }

            return(new ComponentLine("ATTACH;", output.ToString()));
        }
        /// <inheritdoc />
        protected override void Execute(Context context)
        {
            var entityId = new Guid(EntityIdString.Get(context));
            var entity   = new Entity(Metadata.Annotation.LogicalName)
            {
                ["objectid"] = new EntityReference(EntityLogicalName.Get(context), entityId),
                ["subject"]  = Subject.Get(context),
                ["notetext"] = Content.Get(context)
            };
            var fileName = FileName.Get(context);

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                entity["filename"]     = fileName;
                entity["mimetype"]     = FileMimeType.Get(context);
                entity["documentbody"] = FileBase64Content.Get(context);
            }
            var service = ExecureAsSystem.Get(context) ? context.SystemService : context.Service;

            service.Create(entity);
        }
 public AttachmentElement(string fileLocation, FileMimeType mime, byte[] body)
 {
     FileLocation   = fileLocation;
     FileMimeType   = mime;
     AttachmentBody = body;
 }