Publishing with WorkflowManager

Posted by Community Admin on 04-Aug-2018 14:11

Publishing with WorkflowManager

All Replies

Posted by Community Admin on 21-Nov-2013 00:00

Hi

I've been working through API examples for creating pages, adding controls, etc.
But can never get "WorkflowManager.MessageWorkflow" to run without error

(SF 6.147 tested on Localhost and IIS 7.5 on Windows 7)

// Example
var bag = new Dictionary<string, string>();
bag.Add("ContentType", typeof(PageNode).FullName);
WorkflowManager.MessageWorkflow(pageNodeId, typeof(PageNode),  null, "Publish", false, bag);

Typically the error is:
The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

All code works up to that point

See full code Example below:

        public void AddControlToPage(Guid pageNodeId, Control control, string placeHolder, string caption)
       
            SecurityManager.AuthenticateUser(string.Empty, "UserName", "password", false);

            PageManager pageManager = PageManager.GetManager();

            pageManager.Provider.SuppressSecurityChecks = true;

            var page = pageManager.GetPageNodes().Where(p => p.Id == pageNodeId).SingleOrDefault();

            if (page != null)
           
                var temp = pageManager.EditPage(page.Page.Id);

                if (temp != null)
               
                    if (string.IsNullOrEmpty(control.ID))
                   
                        control.ID = GenerateUniqueControlIdForPage(temp);
                   

                    var pageControl = pageManager.CreateControl<PageDraftControl>(control, placeHolder);
                    pageControl.Caption = caption;
                    pageControl.SiblingId = GetLastControlInPlaceHolderInPageId(temp, placeHolder);

                    pageManager.SetControlDefaultPermissions(pageControl);
                    temp.Controls.Add(pageControl);

                    pageManager.PagesLifecycle.CheckIn(temp);
                    pageManager.SaveChanges();

                    // Publish through Workflow
                    var bag = new Dictionary<string, string>();
                    bag.Add("ContentType", typeof(PageNode).FullName);
                    WorkflowManager.MessageWorkflow(pageNodeId, typeof(PageNode),  null, "Publish", false, bag);


               

           
            SecurityManager.Logout();

        
       
Regards

Martin

Posted by Community Admin on 26-Nov-2013 00:00

Hello Martin,

You could find and try this code example for creation of page with control:

public void CreatePageWithControl()
    Label label = new Label() Text = "Test label" ; 
 
    AddControlToPage(myPageId, label, "content", "Caption");
 
public static void AddControlToPage(Guid pageId, Control control, string placeHolder, string caption)
    var pageManager = PageManager.GetManager();
    var page = pageManager.GetPageNodes().Where(p => p.Id == pageId).SingleOrDefault();
 
    if (page != null)
    
        var master = pageManager.EditPage(page.Page.Id);
 
        if (master != null)
        
            if (string.IsNullOrEmpty(control.ID))
            
                control.ID = GenerateUniqueControlIdForPage(master, null);
            
 
            var pageControl = pageManager.CreateControl<PageDraftControl>(control, placeHolder);
            pageControl.Caption = caption;
            pageControl.SiblingId = GetLastControlInPlaceHolderInPageId(master, placeHolder);
            pageManager.SetControlDefaultPermissions(pageControl);
            master.Controls.Add(pageControl);
 
            master = pageManager.PagesLifecycle.CheckIn(master);
            pageManager.SaveChanges();
 
            var bag = new Dictionary<string, string>();
            bag.Add("ContentType", typeof(PageNode).FullName);
            WorkflowManager.MessageWorkflow(pageId, typeof(PageNode), null, "Publish", false, bag);
        
    
 
//helper method 1
public static string GenerateUniqueControlIdForPage(PageDraft pageNode, string culture)
    int controlsCount = 0;
 
    if (pageNode != null)
    
        controlsCount = pageNode.Controls.Count;
    
 
    string cultureSufix = (string.IsNullOrEmpty(culture)) ? string.Empty : string.Format("_" + culture);
 
    return String.Format("C" + controlsCount.ToString().PadLeft(3, '0') + cultureSufix);
 
//helper method 2
public static Guid GetLastControlInPlaceHolderInPageId(PageDraft page, string placeHolder)
    var id = Guid.Empty;
    PageDraftControl control;
 
    var controls = new List<PageDraftControl>(page.Controls.Where(c => c.PlaceHolder == placeHolder));
 
    while (controls.Count > 0)
    
        control = controls.Where(c => c.SiblingId == id).SingleOrDefault();
        id = control.Id;
 
        controls.Remove(control);
    
 
    return id;

Regards,
Svetoslav Manchev
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 27-Nov-2013 00:00

Many thanks Svetoslav

I'll try out the code when I get chance :
Then I'll hopefully close the issue

Kind Regards

Martin

This thread is closed