protected override void Execute(NativeActivityContext context)
        {
            var displayName  = ContentDisplayName.Get(context);
            var originalName = ContentOriginalName.Get(context);

            var newName = ContentNamingProvider.GetNameFromDisplayName(originalName, displayName);

            Result.Set(context, newName);
        }
Exemplo n.º 2
0
        protected override void Execute(NativeActivityContext context)
        {
            var ext = context.GetExtension <ContentWorkflowExtension>();

            var parent = Node.LoadNode(ParentPath.Get(context));

            if (parent == null)
            {
                throw new ApplicationException("Cannot create content because parent does not exist. Path: " + ParentPath.Get(context));
            }

            var name        = Name.Get(context);
            var displayName = ContentDisplayName.Get(context);

            if (string.IsNullOrEmpty(name))
            {
                name = ContentNamingHelper.GetNameFromDisplayName(displayName);
            }

            var content = ContentManager.CreateContentFromRequest(GetContentTypeName(context), name, ParentPath.Get(context), true);

            if (!string.IsNullOrEmpty(displayName))
            {
                content.DisplayName = displayName;
            }

            var fieldValues = FieldValues.Get(context);

            if (fieldValues != null)
            {
                foreach (var key in fieldValues.Keys)
                {
                    content[key] = fieldValues[key];
                }
            }

            SetContentFields(content, context);

            content.ContentHandler.DisableObserver(typeof(WorkflowNotificationObserver));

            try
            {
                content.Save();
            }
            catch (Exception e)
            {
                throw new ApplicationException(String.Concat("Cannot create content. See inner exception. Expected path: "
                                                             , ParentPath.Get <string>(context), "/", Name.Get(context)), e);
            }

            Result.Set(context, new WfContent(content.ContentHandler));
        }
Exemplo n.º 3
0
        protected override void Execute(NativeActivityContext context)
        {
            var message     = Message.Get(context);
            var parentPath  = ParentPath.Get(context);
            var overwrite   = OverwriteExistingContent.Get(context);
            var displayName = ContentDisplayName.Get(context);
            var name        = ContentName.Get(context);

            if (string.IsNullOrEmpty(name))
            {
                name = ContentNamingProvider.GetNameFromDisplayName(displayName) + ".eml";
            }

            var parent = Node.LoadNode(parentPath);

            if (parent == null)
            {
                throw new ApplicationException("Cannot create content because parent does not exist. Path: " + parentPath);
            }

            // check existing file
            var  node = Node.LoadNode(RepositoryPath.Combine(parentPath, name));
            File file;

            if (node == null)
            {
                // file does not exist, create new one
                file = new File(parent);
                if (!string.IsNullOrEmpty(displayName))
                {
                    file.DisplayName = displayName;
                }
                file.Name = name;
            }
            else
            {
                // file exists
                if (overwrite)
                {
                    // overwrite it, so we open it
                    file = node as File;

                    // node exists and it is not a file -> delete it and create a new one
                    if (file == null)
                    {
                        node.ForceDelete();
                        file = new File(parent);
                    }
                    file.DisplayName = displayName;
                    file.Name        = name;
                }
                else
                {
                    // do not overwrite it
                    file = new File(parent);
                    if (!string.IsNullOrEmpty(displayName))
                    {
                        file.DisplayName = displayName;
                    }
                    file.Name = name;
                    file.AllowIncrementalNaming = true;
                }
            }

            try
            {
                using (var memoryStream = new System.IO.MemoryStream(message.MimeContent.Content))
                {
                    var binaryData = new BinaryData();
                    binaryData.SetStream(memoryStream);
                    file.Binary = binaryData;

                    file.Save();
                }
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);
            }
        }
Exemplo n.º 4
0
        protected override void Execute(NativeActivityContext context)
        {
            var message     = Message.Get(context);
            var parentPath  = ParentPath.Get(context);
            var overwrite   = OverwriteExistingContent.Get(context);
            var displayName = ContentDisplayName.Get(context);
            var name        = ContentName.Get(context);

            if (string.IsNullOrEmpty(name))
            {
                name = ContentNamingHelper.GetNameFromDisplayName(displayName) + ".eml";
            }

            var parent = Node.LoadNode(parentPath);

            if (parent == null)
            {
                throw new ApplicationException("Cannot create content because parent does not exist. Path: " + parentPath);
            }

            // check existing file
            var  node = Node.LoadNode(RepositoryPath.Combine(parentPath, name));
            File file;

            if (node == null)
            {
                // file does not exist, create new one
                file = new File(parent);
                if (!string.IsNullOrEmpty(displayName))
                {
                    file.DisplayName = displayName;
                }
                file.Name = name;
            }
            else
            {
                // file exists
                if (overwrite)
                {
                    // overwrite it, so we open it
                    file = node as File;

                    // node exists and it is not a file -> delete it and create a new one
                    if (file == null)
                    {
                        try
                        {
                            node.ForceDelete();
                        }
                        catch
                        {
                            Logger.WriteError(Logger.EventId.NotDefined, "Mail processor workflow: content could not be deleted during saving the email. Path: " + node.Path);
                            return;
                        }

                        file = new File(parent);
                    }
                    file.DisplayName = displayName;
                    file.Name        = name;
                }
                else
                {
                    // do not overwrite it
                    file = new File(parent);
                    if (!string.IsNullOrEmpty(displayName))
                    {
                        file.DisplayName = displayName;
                    }
                    file.Name = name;
                    file.AllowIncrementalNaming = true;
                }
            }

            try
            {
                var binaryData = new BinaryData()
                {
                    FileName = name
                };
                binaryData.SetStream(Tools.GetStreamFromString(message.Body));

                file.Binary = binaryData;
                file.Save();
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
            }
        }