public void Save(bool checkOutIfNeeded = false)
 {
     if (checkOutIfNeeded)
     {
         if (!Content.IsEditable.GetValueOrDefault())
         {
             Client.CheckOut(Content.Id, true, null);
         }
     }
     Content.Content = _fields.ToString();
     Content         = (ComponentData)Client.Save(Content, ReadOptions);
     Client.CheckIn(Content.Id, null);
 }
        public void Save(bool checkOutIfNeeded = false)
        {
            if (checkOutIfNeeded)
            {
                if (!Content.IsEditable.GetValueOrDefault())
                {
                    Client.CheckOut(Content.Id, true, null);
                }
            }
            if (string.IsNullOrEmpty(Content.Title))
            {
                Content.Title = "No title specified!";
            }
            // Item titles cannot contain backslashes :)
            if (Content.Title.Contains("\\"))
            {
                Content.Title = Content.Title.Replace("\\", "/");
            }
            Content.Content = _fields.ToString();
            TcmUri contentId = new TcmUri(Content.Id);

            if (!contentId.IsVersionless)
            {
                contentId  = new TcmUri(contentId.ItemId, contentId.ItemType, contentId.PublicationId);
                Content.Id = contentId.ToString();
            }
            try
            {
                Content = (ComponentData)Client.Save(Content, ReadOptions);
                Client.CheckIn(Content.Id, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Ooops, something went wrong saving component " + Content.Title);
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #3
0
 public VersionedItemData CheckOut(string id, bool permanentLock, ReadOptions readBackOptions)
 {
     return(_client.CheckOut(id, permanentLock, readBackOptions));
 }
        internal void AddSiteEditToTemplate(string templateId)
        {
            TcmUri uri = new TcmUri(templateId);

            templateId = uri.GetVersionlessUri();
            TemplateData template = (TemplateData)_client.Read(templateId, _readOptions);
            // find siteedit templates
            string context = template.BluePrintInfo.OwningRepository.IdRef;
            TemplateBuildingBlockData tbb;

            // If this is Tridion 6.1 there won't be a building block for SiteEdit yet
            if (Configuration.ServerVersion == ServerVersion.Version6)
            {
                if (!_client.IsExistingObject(Configuration.UrlEnableInlineEditingForContentTbb))
                {
                    string tridionHome      = Environment.GetEnvironmentVariable("TRIDION_CM_HOME");
                    string siteEditAssembly = Path.Combine(tridionHome, "bin", "Tridion.SiteEdit.Templating.dll");
                    if (File.Exists(siteEditAssembly))
                    {
                        string defaultTbbFolder = null;
                        OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData();
                        filter.ItemTypes = new[] { ItemType.Folder };
                        foreach (
                            XElement node in
                            _client.GetListXml(
                                GetUriInBlueprintContext(Configuration.BuildingBlocksFolderId,
                                                         Configuration.TopPublicationId), filter).Nodes())
                        {
                            if (node.Attribute("Title").Value.Equals("Default Templates"))
                            {
                                defaultTbbFolder = node.Attribute("ID").Value;
                                break;
                            }
                        }
                        if (defaultTbbFolder != null)
                        {
                            Console.WriteLine("Uploading SiteEdit TBB Assembly");
                            string tcmUpload  = Path.Combine(tridionHome, "bin", "client", "TcmUploadAssembly.exe");
                            string parameters = string.Format("/folder:{0} /targeturl:{1} \"{2}\"", defaultTbbFolder,
                                                              "http://localhost", siteEditAssembly);
                            Process          process   = new Process();
                            ProcessStartInfo startInfo = new ProcessStartInfo
                            {
                                WindowStyle = ProcessWindowStyle.Minimized,
                                FileName    = tcmUpload,
                                Arguments   = parameters
                            };
                            process.StartInfo = startInfo;
                            process.Start();
                            process.WaitForExit();
                        }
                    }
                }
            }

            if (template is ComponentTemplateData)
            {
                tbb =
                    (TemplateBuildingBlockData)
                    _client.Read(Configuration.UrlEnableInlineEditingForContentTbb, _readOptions);
            }
            else
            {
                tbb = (TemplateBuildingBlockData)_client.Read(Configuration.UrlEnableInlineEditingForPagesTbb, _readOptions);
            }

            string    tbbId   = GetUriInBlueprintContext(tbb.Id, context);
            XDocument content = XDocument.Parse(template.Content);
            // Find default finish actions
            XElement   dfa             = null;
            XNamespace xlink           = XNamespace.Get("http://www.w3.org/1999/xlink");
            XNamespace modularTemplate = XNamespace.Get("http://www.tridion.com/ContentManager/5.3/CompoundTemplate");

            foreach (XElement node in content.Root.Nodes())
            {
                if (node.Element(modularTemplate + "Template").Attribute(xlink + "title").Value.Equals("Default Finish Actions"))
                {
                    dfa = node;
                    break;
                }
            }
            if (dfa != null)
            {
                // Must create Element and insert before
                //  <TemplateInvocation><Template xlink:href="tcm:3-32-2048" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:title="Default Finish Actions" /></TemplateInvocation>

                string fakeSe =
                    "<TemplateInvocation xmlns=\"http://www.tridion.com/ContentManager/5.3/CompoundTemplate\"><Template xlink:href=\"##TBBID##\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:title=\"##TBBTITLE##\" /></TemplateInvocation>";
                if (template is PageTemplateData)
                {
                    fakeSe = "<TemplateInvocation xmlns=\"http://www.tridion.com/ContentManager/5.3/CompoundTemplate\"><Template xlink:href=\"##TBBID##\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:title=\"##TBBTITLE##\"/><TemplateParameters><Parameters xmlns=\"##PARAMETERSCHEMANAMESPACE##\"><SiteEditURL>http://localhost/WebUI/Editors/SiteEdit/</SiteEditURL></Parameters></TemplateParameters></TemplateInvocation>";
                    string     schemaId = tbb.ParameterSchema.IdRef;
                    SchemaData schema   = (SchemaData)_client.Read(schemaId, _readOptions);
                    fakeSe = fakeSe.Replace("##PARAMETERSCHEMANAMESPACE##", schema.NamespaceUri);
                }
                fakeSe = fakeSe.Replace("##TBBID##", tbbId);
                fakeSe = fakeSe.Replace("##TBBTITLE##", tbb.Title);
                //Avoid adding SiteEdit TBB a million times...
                if (!template.Content.Contains(tbb.Title))
                {
                    XElement element = XElement.Parse(fakeSe);
                    dfa.AddBeforeSelf(element);
                    template.Content = content.ToString();
                    _client.CheckOut(template.Id, false, null);
                    _client.Save(template, null);
                    _client.CheckIn(template.Id, null);
                }
            }
        }