Custom module dynamic publishing

Posted by Community Admin on 04-Aug-2018 22:06

Custom module dynamic publishing

All Replies

Posted by Community Admin on 21-Feb-2012 00:00

Hello I used the module builder to make a custom module that will be a physician directory.  I then wrote a script to import a CSV and create 762 new physicians which I'll post after this.  My problem is this:  I tell it to publish with 

dynamicModuleManager.Lifecycle.Publish(physicianItem);
dynamicModuleManager.SaveChanges();
and it's doing something weird.  First of all it's publishing the items but they don't show as published in the backend.  Also they don't show published if i look at the
lifecycle.IsPublished
 property of one of the ones I added.  I'm able to go into the backend and publish them manually so I know I'm not missing a required property or anything.  When I look at the widget they all show up however as if they were published.. Sorry for that link, I haven't actually gotten around to building a custom paged widget for it yet so it takes a while to load the whole list.  So publishing these manually in the backend is really not that big of deal.  My big problem is that one of the values is called "Photo" and it stores the physician photo.  We uploaded all of these to a library so that I would be able to query them with their filename from the csv.  I successfully associate the image with the correct Photo value with something kind of like this:
var photoID = libraryManager.GetImages().Where(i => i.Title.ToString() == input && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).FirstOrDefault().Id;
 
physicianItem.AddImage("Photo", photoID);

When I go to view the physician in the backend it has the photo associated with it:
http://twitpic.com/8mxrds/full
It does not however show up on the backend listing: http://twitpic.com/8mxrpq/full
and it does not show up on the single physician widget: http://twitpic.com/8mxr8x/full
If I go back into the item and select another image then select the same one again everything works right: http://twitpic.com/8mxrrz/fullhttp://twitpic.com/8mxru0/full, and http://twitpic.com/8mxry0/full

Anyone have any ideas?  I'm going to put my whole import codebehind below and here's an example of a couple of rows from my CSV:
LastName,middleinitial,FirstName,Degree,Street,City,State,Zip,Phone,facility,Photo,specialty1,specialty2,type,address2,phone2,certification,medical_school,gender,fellowship,email,state2,city2,zip2,fax2,interests,Insurances,additional_comments,residency,languages
Mayes,,Sunnye,PhD,"1200 N. Phillips Avenue, 10th Floor, Suite 10000",Oklahoma City,OK,73104-5008,(405) 271-5311 ,OU Children's Physicians Building,MayesSunnye-Phych.jpg,Psychology - Pediatric,Hematology / Oncology - Pediatric,OU Medicine,,,,University of Kansas Clinical Child Psychology Program ,Female,Clinical Psychology Fellowship - University of Oklahoma College of Medicine ,,,,,,Psychology;Pediatric Psychology;Behavioral Medicine,Visit www.oumedicine.com/insuranceplans,Munroe-Meyer University of Nebraska Medical Center - Internship in professional psychology,,
Rettig,J,Philip,MD,"1200 Children's Avenue, 7th Floor, Suite 7500",Oklahoma City,OK,73104,(405) 271-6208 ,OU Children's Physicians Building,RettigPhillip-Infec.jpg,Adolescent Medicine,Infectious Diseases,OU Medicine,"OU Children's Physicians Building, 5th Floor, Suite 5100",(405) 271-6208 ,American Board of Pediatrics;American Board of Pediatrics (Sub: Infectious Disease);American Board of Pediatrics (Sub:Adolescent Medicine),Harvard Medical School,Male,Southwestern Medical Center,,OK,Oklahoma City,73104,,Adolescent Medicine; reproductive health issues in teens; infectious diseases; sexually transmitted diseases; primary care,Visit www.oumedicine.com/insuranceplans,,Yale-New Haven Hospital;Boston's Children's Hospital,Spanish
Lawrence,,Shelley,MD,"1200 N Phillips, 5th floor, suite 5100",Oklahoma City,OK,73104,,OU Children's Physicians Building,LawrenceShelley-neonat.jpg,Neonatal-Perinatal Medicine,,OU Medicine,,,American Board of Pediatrics,University of Oklahoma College of Medicine,Female,"Universityof Texas Health Science Center, San Antonio; OU College of Medicine",,,,,,,visit www.oumedicine.com/insurance,,University of Oklahoma College of Medicine,


pardon my commented out areas.. I really only wanted to use this one time before we publish the site next week then clean it up for a blog post.. I haven't cleaned it up yet.

public void CreatePhysician(string last, string first, string mi, string degree, string specs, string facils, string addy, string cert, string gender, string inter, string insur, string comm, string lang, string secSpec, string photo)
        
            string inputSeq = "";
            try
            
                
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                Type physicianType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PhysicianDirectory.Physician");
                DynamicContent physicianItem = dynamicModuleManager.CreateDataItem(physicianType);
                inputSeq = "Photo";
                if (photo != "")
                
                    string jpg = ".jpg";
                     
                    var photoID = checkTaxonI(photo.TrimEnd(jpg.ToCharArray()));
                    lblFirst.Text = photo.TrimEnd(jpg.ToCharArray());
                     
                         
 
                    if (photoID.ToString() != "12345678-1234-1234-1234-123456789012")
                    
                         
                        physicianItem.AddImage("Photo", photoID);
                        lblFirst.Text += "<br />" + photoID.ToString();
                    
                    else
                    
                        //lblError.Text += "<p>Image not found</p>";
                        //lblError.Text += "<p>Failed to find Image: " + photo + "</p>";
                        lblError.Text += photo + "<br />";
                    
                
                 
                inputSeq = "Language";
                if (lang != "")
                
                    List<Guid> langs = new List<Guid>();
                    string[] strLangs = lang.Split(';');
                    if (strLangs.Length > 1)
                    
                        foreach (string strLang in strLangs)
                        
                            inputSeq += ": " + strLang;
                            //langs.Add(taxonomyManager.GetTaxa<FlatTaxon>().Where(t => t.Taxonomy.Name == strLang).Single().Id);
                            var langGUID = checkTaxon(strLang.Trim().Replace("/", string.Empty).Replace(' ', '-'));
                            if (langGUID.ToString() == "12345678-1234-1234-1234-123456789012")
                                langGUID = checkTaxon(strLang.Trim());
                            if (langGUID.ToString() == "12345678-1234-1234-1234-123456789012")
                                lblError.Text += "<p>Failed to find Language: " + lang + "</p>";
 
                            if (langGUID.ToString() != "12345678-1234-1234-1234-123456789012")
                            
                                physicianItem.Organizer.AddTaxa("languages", langGUID);
                            
                        
 
                    
                    else
                    
                        inputSeq += ": " + lang;
                        var langGUID = checkTaxon(lang.Replace("/", string.Empty).Replace(' ', '-'));
                        if (langGUID.ToString() == "12345678-1234-1234-1234-123456789012")
                            langGUID = checkTaxon(lang);
                        if (langGUID.ToString() == "12345678-1234-1234-1234-123456789012")
                            lblError.Text += "<p>Failed to find Language: " + lang + "</p>";
                        if (langGUID.ToString() != "12345678-1234-1234-1234-123456789012")
                        
                            physicianItem.Organizer.AddTaxa("languages", langGUID);
                        
                    
                
 
 
                inputSeq = "Specialties";
 
                if (specs != "")
                
                    var Specialty = checkTaxon(specs.Replace("/", string.Empty).Replace(' ', '-'));
                    if (Specialty.ToString() == "12345678-1234-1234-1234-123456789012")
                        Specialty = checkTaxon(specs);
                    if (Specialty.ToString() == "12345678-1234-1234-1234-123456789012")
                        lblError.Text += "<p>Failed to find Specialty: "+ specs + "</p>";
 
                    if (Specialty.ToString() != "12345678-1234-1234-1234-123456789012")
                    
 
                        physicianItem.Organizer.AddTaxa("Specialties", Specialty);
                    
                    else
                    
                        lblError.Text += "<p>Specialty not found</p>";
                    
                
                 
                inputSeq = "Facilities";
                if (facils == "")
                    facils = "N A";
                 
                 
                    var taxonId = checkTaxon(facils.Replace("/", string.Empty).Replace(' ', '-'));
                    if (taxonId.ToString() == "12345678-1234-1234-1234-123456789012")
                        taxonId = checkTaxon(facils);
                    if (taxonId.ToString() == "12345678-1234-1234-1234-123456789012")
                        lblError.Text += "<p>Failed to find Facility: " + facils + "</p>";
                    if (taxonId.ToString() != "12345678-1234-1234-1234-123456789012")
                    
                        physicianItem.Organizer.AddTaxa("Facilities", taxonId);
                    
                 
                 
 
                // This is how values for the properties are set
                physicianItem.SetValue("Last", last);
                physicianItem.SetValue("First", first);
                physicianItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
                physicianItem.SetValue("MI", mi);
                physicianItem.SetValue("Degree", degree);
                physicianItem.SetValue("PublicationDate", DateTime.Now);
                physicianItem.SetValue("SecondSpecialty", secSpec);
                // Set the selected value
                 
                //var Facility = taxonomyManager.GetTaxa<FlatTaxon>().Where(t => t.Taxonomy.Name == "facilities").FirstOrDefault();
                 
 
                //lblTest.Text = taxonId.ToString();
                physicianItem.SetValue("Address", addy);
                //LibrariesManager libraryManager = LibrariesManager.GetManager();
                //var image = libraryManager.GetImages().FirstOrDefault();
                //if (image != null)
                //
                //    physicianItem.AddImage("Photo", image.Id);
                //
                physicianItem.SetValue("Certification", cert);
                // Set the selected value
                string option = "";
                if(gender == "Male")
                    option = "Option1";
                else if(gender == "Female")
                    option = "Option2";
                else
                    option = "Option1";
                physicianItem.SetValue("Gender", new string[] gender );
                physicianItem.SetValue("Interests", inter);
 
                 
                //if (Language != null)
                //
                //    physicianItem.Organizer.AddTaxa("languages", Language);
                //
                //else
                //
                //    lblTest.Text += "<p>Language not found</p>";
                //
                physicianItem.SetValue("Insurances", insur);
                physicianItem.SetValue("Comments", comm);
                inputSeq = "Categories";
                TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
                Guid credentialed = new Guid();
                credentialed = checkTaxonH("OU-Physicians-Credentialed");
                //This is the GUID I grabbed for OU Physicians Credentialed taxon
                
                physicianItem.Organizer.AddTaxa("Category", credentialed);
                //var Category = taxonomyManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Taxonomy.Name == "Categories").FirstOrDefault();
                //if (Category != null)
                //
                //    physicianItem.Organizer.AddTaxa("Category", Category.Id);
                //
 
                physicianItem.UrlName = last + "-" + first;
                // You need to call SaveChanges() in order for the items to be actually persisted to data store
                dynamicModuleManager.Lifecycle.Publish(physicianItem);
                 
                dynamicModuleManager.SaveChanges();
                 
                 
                lblTest.Text += "<p>Changes saved successfully</p>";
                 
            
            catch (Exception ex)
            
                lblError.Text += "<p>" + inputSeq + ":" +  ex.Message.ToString() + " <strong>:</strong> " + last + "</p>";
                  
            
        
protected Guid checkTaxon(string input)
        
            TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
             
 
            try
            
                var taxonId = taxonomyManager.GetTaxa<FlatTaxon>().Where(t => t.Name.Trim() == input).Single().Id;
                taxonGUID.Text = taxonId.ToString();
                return taxonId;
            
            catch (Exception ex)
            
                Guid fail = new Guid("12345678-1234-1234-1234-123456789012");
                taxonGUID.Text = ex.Message;
                return fail;
            
 
        
        protected Guid checkTaxonH(string input)
        
            TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
 
 
            try
            
                var taxonId = taxonomyManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name.Trim() == input).Single().Id;
                taxonGUID.Text = taxonId.ToString();
                return taxonId;
            
            catch (Exception ex)
            
                Guid fail = new Guid("12345678-1234-1234-1234-123456789012");
                taxonGUID.Text = ex.Message;
                return fail;
            
 
        
protected Guid checkTaxonI(string input)
        
            LibrariesManager libraryManager = LibrariesManager.GetManager();
 
 
            try
            
 
                var test = libraryManager.GetImages().Where(i => i.Title.ToString() == input && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).FirstOrDefault().Id;
 
                return test;
            
            catch (Exception ex)
            
                Guid fail = new Guid("12345678-1234-1234-1234-123456789012");
                taxonGUID.Text = ex.Message;
                return fail;
            
 
        

Posted by Community Admin on 23-Feb-2012 00:00

Hello,

 There is a difference between Lifecycle.Publish and publishing trough SitefinityWorkflow.
After calling 

dynamicModuleManager.Lifecycle.Publish(YourItem);  
            dynamicModuleManager.SaveChanges();
then the item passes lifecycle, but was not passed trough the workflow to have a status of published. Refer to this documentation for reference.

To publish add this after synamicModuleManager.SaveChanges();
var bag = new Dictionary<string, string>();
            bag.Add("ContentType", YourType.FullName);
            WorkflowManager.MessageWorkflow(physicianItem.Id, titoType, null, "Publish", false, bag);
This will publish the item.

Kind regards,
Stanislav Velikov
the Telerik team
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 06-Aug-2012 00:00

@Tony,
  Did you ever figure this out?  I can't get the images to showup.  I've tried using both AddImage overloads, ID and the object, both show nothing in Master list view

Steve

This thread is closed