예제 #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //set related templates

            List <string>   usingItems = MainService.GetUsingCurrentItems(this.CurrentMapping, this.TbbTcmId);
            List <ItemInfo> templates  = new List <ItemInfo>();

            foreach (string currTcmId in usingItems)
            {
                IdentifiableObjectData dataItem = MainService.ReadItem(this.CurrentMapping, currTcmId);
                ItemInfo item = dataItem.ToItem();
                if (item != null && (item.ItemType == ItemType.ComponentTemplate || item.ItemType == ItemType.PageTemplate))
                {
                    item.WebDav = ((RepositoryLocalObjectData)dataItem).GetWebDav();
                }
                templates.Add(item);
            }

            if (string.IsNullOrEmpty(this.TestTemplateTcmId))
            {
                this.TestTemplateTcmId = Common.IsolatedStorage.Service.GetFromIsolatedStorage(Common.IsolatedStorage.Service.GetId("DebugTemplate", this.TbbTcmId));
            }

            this.lstTemplates.ItemsSource       = templates;
            this.lstTemplates.DisplayMemberPath = "NamedPathCut";
            this.lstTemplates.SelectedIndex     = templates.FindIndex(x => x.TcmId == this.TestTemplateTcmId);
            if (this.lstTemplates.SelectedIndex < 0)
            {
                this.lstTemplates.SelectedIndex = 0;
            }
        }
        /// <summary>
        /// Reload the <see cref="IdentifiableObject" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.IdentifiableObjectData" />
        /// </summary>
        /// <param name="identifiableObjectData"><see cref="T:Tridion.ContentManager.CoreService.Client.IdentifiableObjectData" /></param>
        protected void Reload(IdentifiableObjectData identifiableObjectData)
        {
            if (identifiableObjectData == null)
            {
                throw new ArgumentNullException("identifiableObjectData");
            }

            mIdentifiableObjectData = identifiableObjectData;
        }
예제 #3
0
        public static LinkToUserData GetCheckedOutUser(this IdentifiableObjectData objectData)
        {
            if (!objectData.GetType().Name.Equals("FolderData") &&
                !objectData.GetType().Name.Equals("StructureGroupData") &&
                !objectData.GetType().Name.Equals("PublicationData"))
            {
                return(((FullVersionInfo)objectData.VersionInfo).CheckOutUser);
            }

            return(null);
        }
예제 #4
0
        public static int?GetVersion(this IdentifiableObjectData objectData)
        {
            if (!objectData.GetType().Name.Equals("FolderData") &&
                !objectData.GetType().Name.Equals("StructureGroupData") &&
                !objectData.GetType().Name.Equals("PublicationData"))
            {
                return(((FullVersionInfo)objectData.VersionInfo).Version);
            }

            return(null);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IdentifiableObject" /> class.
        /// </summary>
        /// <param name="session"><see cref="T:TcmCoreService.Client" /></param>
        /// <param name="identifiableObjectData"><see cref="T:Tridion.ContentManager.CoreService.Client.IdentifiableObjectData" /></param>	
        protected IdentifiableObject(Client client, IdentifiableObjectData identifiableObjectData)
        {
            if (client == null)
                throw new ArgumentNullException("client");

            if (identifiableObjectData == null)
                throw new ArgumentNullException("identifiableObjectData");

            mClient = client;
            mIdentifiableObjectData = identifiableObjectData;
        }
예제 #6
0
        protected static void AddCommonProperties(IdentifiableObjectData item, PeekResult result)
        {
            if (item.VersionInfo == null) return;

            result.CreationDate = DateEntry.From(item.VersionInfo.CreationDate, Resources.LabelCreationDate);

            if (item.VersionInfo.RevisionDate.HasValue && item.VersionInfo.RevisionDate.Value != result.CreationDate.Value)
            {
                result.RevisionDate = DateEntry.From(item.VersionInfo.CreationDate, Resources.LabelRevisionDate);
            }
        }
예제 #7
0
 public static bool?Update(this IdentifiableObjectData objectData)
 {
     try
     {
         Wrapper.Instance.Update(objectData, new ReadOptions());
         return(true);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #8
0
        protected static void AddCommonProperties(IdentifiableObjectData item, PeekResult result)
        {
            if (item.VersionInfo == null)
            {
                return;
            }

            result.CreationDate = DateEntry.From(item.VersionInfo.CreationDate, Resources.LabelCreationDate);

            if (item.VersionInfo.RevisionDate.HasValue && item.VersionInfo.RevisionDate.Value != result.CreationDate.Value)
            {
                result.RevisionDate = DateEntry.From(item.VersionInfo.CreationDate, Resources.LabelRevisionDate);
            }
        }
        public string ResolveUrl(string webdavUrl)
        {
            if (ResolvedUrls.ContainsKey(webdavUrl))
            {
                return(ResolvedUrls[webdavUrl]);
            }
            Stopwatch watch          = new Stopwatch(); watch.Start();
            IdentifiableObjectData i = _client.Read(webdavUrl, _readOptions);

            ResolvedUrls.Add(webdavUrl, i.Id);
            watch.Stop();
            Console.WriteLine("Resolved URL in " + watch.ElapsedMilliseconds + " milliseconds (" + webdavUrl + ")");
            return(i.Id);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IdentifiableObject" /> class.
        /// </summary>
        /// <param name="session"><see cref="T:TcmCoreService.Client" /></param>
        /// <param name="identifiableObjectData"><see cref="T:Tridion.ContentManager.CoreService.Client.IdentifiableObjectData" /></param>
        protected IdentifiableObject(Client client, IdentifiableObjectData identifiableObjectData)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (identifiableObjectData == null)
            {
                throw new ArgumentNullException("identifiableObjectData");
            }

            mClient = client;
            mIdentifiableObjectData = identifiableObjectData;
        }
예제 #11
0
        private void AssertItemRendersWithoutException(IdentifiableObjectData item, IdentifiableObjectData template)
        {
            string testPublicationId = TestContext.Properties["TestPublicationId"].ToString();

            string localisedItemId     = Client.GetTcmUri(item.Id, testPublicationId, null);
            string localisedTemplateId = Client.GetTcmUri(template.Id, testPublicationId, null);

            // We check if the template exists at this publication level as the schema where used query
            // might give us templates that might only exist elsewhere in the blueprint
            if (Client.IsExistingObject(localisedTemplateId) && !this.renderedTemplates.Contains(localisedTemplateId))
            {
                try
                {
                    this.renderedTemplates.Add(localisedTemplateId);
                    RenderedItemData renderedItem = new RenderedItemData();

                    RenderInstructionData renderInstruction = new RenderInstructionData();
                    renderInstruction.RenderMode = RenderMode.PreviewStatic;

                    PublishInstructionData previewInstruction = new PublishInstructionData();
                    ResolveInstructionData resolveInstruction = new ResolveInstructionData();

                    previewInstruction.RenderInstruction  = renderInstruction;
                    previewInstruction.ResolveInstruction = resolveInstruction;

                    stopwatch.Restart();
                    renderedItem = Client.RenderItem(localisedItemId, localisedTemplateId, previewInstruction, "tcm:0-1-65537");
                    long timeToRender = stopwatch.ElapsedMilliseconds;
                    if (renderedItem.Content != null)
                    {
                        string renderedContent = System.Text.Encoding.Default.GetString(renderedItem.Content);
                        this.LogMessage(String.Format("Rendering with template \"{0}\" ({1}) succeeded and took {2} milliseconds.", template.Title, localisedTemplateId, timeToRender));
                        Assert.IsNotNull(renderedContent);
                    }
                    else
                    {
                        this.LogMessage(String.Format("ALERT: Rendering with template \"{0}\" ({1}) resulted in null content and took {2} milliseconds.", template.Title, localisedTemplateId, timeToRender));
                    }
                }
                catch (System.ServiceModel.FaultException ex)
                {
                    string failMessage = String.Format("TEST FAILED! Failed when rendering item {0} ({1}) with template {2} ({3}) {4}. Exception: {5}", item.Id, item.Title, template.Id, template.Title, Environment.NewLine + Environment.NewLine, ex.Message);
                    this.LogMessage(failMessage);
                    Assert.Fail(failMessage);
                }
            }
        }
예제 #12
0
        public override IdentifiableObjectData SaveOrganizationalItem(IdentifiableObjectData organizationalItemData, string itemName)
        {
            if (!(organizationalItemData is FolderData))
            {
                return(null);
            }

            FolderData folderData = (FolderData)organizationalItemData;

            folderData.Title = itemName;

            PreProcess(folderData);
            var result = Client.Save(folderData, new ReadOptions());

            PostProcess(folderData);

            return(result);
        }
예제 #13
0
        public override IdentifiableObjectData SaveOrganizationalItem(IdentifiableObjectData organizationalItemData, string itemName)
        {
            if (!(organizationalItemData is StructureGroupData))
            {
                return(null);
            }

            var structureGroupData = (StructureGroupData)organizationalItemData;

            structureGroupData.Title     = itemName;
            structureGroupData.Directory = Regex.Replace(itemName, @"[^A-Za-z0-9_\.~]+", "-");

            PreProcess(structureGroupData);
            var result = Client.Save(structureGroupData, new ReadOptions());

            PostProcess(structureGroupData);

            return(result);
        }
        public override IdentifiableObjectData SaveOrganizationalItem(IdentifiableObjectData organizationalItemData, string itemName)
        {
            if (!(organizationalItemData is KeywordData))
            {
                return(null);
            }

            KeywordData keywordData = (KeywordData)organizationalItemData;

            keywordData.Title = itemName;
            keywordData.Key   = itemName;

            PreProcess(keywordData);
            var result = Client.Save(keywordData, new ReadOptions());

            PostProcess(keywordData);

            return(result);
        }
예제 #15
0
        public static ImportItem CreateImportItem(IdentifiableObjectData ioData)
        {
            switch (ioData)
            {
            case SchemaData data:
                return(CreateSchema(data));

            case TemplateBuildingBlockData data:
                return(CreateTBB(data));

            case PageTemplateData data:
                return(CreatePageTemplate(data));

            case ComponentTemplateData data:
                return(CreateComponentTemplate(data));

            default:
                return(null);
            }
        }
 /// <summary>
 /// Processes the core service record.
 /// </summary>
 /// <remarks>Used for proper error handling of core service fault exception. </remarks>
 protected override void ProcessCoreServiceRecord()
 {
     if (!string.IsNullOrEmpty(Id))
     {
         IdentifiableObjectData result = CoreServiceClient.Read(Id, null);
         if (!(result is PublishTransactionData))
         {
             throw new ArgumentException(string.Format("Expected item type: {0}.", ItemType.PublishTransaction), "Id");
         }
         WriteObject(result);
     }
     else
     {
         PublishTransactionsFilterData filter = new PublishTransactionsFilterData
         {
             PublisherHost = PublisherHost,
             IsCompleted   = IsCompleted
         };
         WriteObject(CoreServiceClient.GetSystemWideList(filter), true);
     }
 }
예제 #17
0
        public static void UnPublish(this IdentifiableObjectData objectData, string[] purpose, PublishPriority prio = PublishPriority.Low, DateTime?StartAt = null)
        {
            var unPubInst = new UnPublishInstructionData()
            {
                ResolveInstruction = new ResolveInstructionData()
                {
                    IncludeChildPublications = false,
                    Purpose = ResolvePurpose.UnPublish,
                    StructureResolveOption = StructureResolveOption.OnlyItems
                },

                RollbackOnFailure = false
            };

            if (StartAt.HasValue)
            {
                unPubInst.StartAt = StartAt;
            }

            Wrapper.Instance.UnPublish(new string[] { objectData.Id.ToString() }, unPubInst, purpose, PublishPriority.Low, new ReadOptions());
        }
예제 #18
0
        public static TridionObjectInfo GetTridionObject(ICoreServiceFrameworkContext coreService, ItemType itemtype, string parentTcmUri, string searchtext)
        {
            TridionObjectInfo tridionObjectInfo = new TridionObjectInfo();

            try
            {
                IdentifiableObjectData tridionObject = null;
                var filter = new OrganizationalItemItemsFilterData
                {
                    Recursive = true,
                    ItemTypes = new ItemType[] { itemtype }
                };
                var pageList = coreService.Client.GetListXml(parentTcmUri, filter);

                int objectCount = (from e in pageList.Elements()
                                   where e.Attribute("Title").Value.ToLower().Equals(searchtext.ToLower()) || e.Attribute("ID").Value.ToLower() == searchtext.ToLower()
                                   select e.Attribute("ID").Value).Count();

                tridionObjectInfo.ObjectCount = objectCount;
                if (objectCount > 0)
                {
                    var objectUri = (from e in pageList.Elements()
                                     where e.Attribute("Title").Value.ToLower().Equals(searchtext.ToLower()) || e.Attribute("ID").Value.ToLower() == searchtext.ToLower()
                                     select e.Attribute("ID").Value).First();

                    tridionObject = coreService.Client.Read(objectUri, new ReadOptions
                    {
                        LoadFlags = LoadFlags.None
                    });
                    tridionObjectInfo.TridionObject = tridionObject;
                    tridionObjectInfo.TcmUri        = objectUri;
                }
            }
            catch (Exception ex)
            {
            }
            return(tridionObjectInfo);
        }
예제 #19
0
        public static IList <T> GetAllUsages <T>(this IdentifiableObjectData item, Expression <Func <T, bool> > filterPredicate = null, UsingItemsFilterData filter = null) where T : IdentifiableObjectData
        {
            Logger.Debug("Loading usages of {0} for {1}", typeof(T).Name, item.Title);

            string filename  = string.Format("{0} - {1} - {2}.txt", item.GetType().Name, typeof(T).Name, item.Title);
            var    subFolder = "Usages";
            var    items     = FileCache.LoadFromFile <IList <T> >(filename, subFolder);

            if (items == null)
            {
                if (filter == null)
                {
                    filter = new UsingItemsFilterData
                    {
                        ItemTypes          = new[] { ItemTypeResolver.GetItemType(typeof(T)) },
                        IncludedVersions   = VersionCondition.OnlyLatestAndCheckedOutVersions,
                        IncludeLocalCopies = false,
                        BaseColumns        = ListBaseColumns.Extended
                    };
                }
                items = TridionCoreServiceFactory.GetList <T>(item.Id, filter);
                Logger.Debug("Found {0} {1} for {2}", items.Count, typeof(T).Name, item.Title);
                FileCache.SaveToFile(filename, items, subFolder);
            }
            else
            {
                Logger.Debug("Loading usages of {0} for {1} from cache", typeof(T).Name, item.Title);
            }

            if (filterPredicate != null)
            {
                items = items.AsQueryable().Where(filterPredicate).ToList();
            }

            return(items);
        }
예제 #20
0
    //http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011
    public static void UploadImages(string location, string folderTcmId, CoreService2010Client client, log4net.ILog Log)
    {
        //create a reference to the directory of where the images are
        DirectoryInfo directory = new DirectoryInfo(location);
        //create global Tridion Read Options
        ReadOptions readOptions = new ReadOptions();

        //use Expanded so that Tridion exposes the TcmId of the newly created component
        readOptions.LoadFlags = LoadFlags.Expanded;
        try
        {
            //loop through the files
            foreach (FileInfo fileInfo in directory.GetFiles())
            {
                //only allow images
                if (IsAllowedFileType(fileInfo.Extension))
                {
                    try
                    {
                        //create a new multimedia component in the folder specified
                        ComponentData multimediaComponent = (ComponentData)client.GetDefaultData(Tridion.ItemType.Component, folderTcmId);
                        multimediaComponent.Title         = fileInfo.Name.ToLower();
                        multimediaComponent.ComponentType = ComponentType.Multimedia;
                        multimediaComponent.Schema.IdRef  = ConfigurationManager.AppSettings["MultimediaSchemaId"];

                        //create a string to hold the temporary location of the image to use later
                        string tempLocation = "";

                        //use the StreamUpload2010Client to upload the image into Tridion
                        UploadResponse us = new UploadResponse();
                        using (Tridion.StreamUpload2010Client streamClient = new StreamUpload2010Client())
                        {
                            FileStream objfilestream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read);
                            tempLocation = streamClient.UploadBinaryContent(fileInfo.Name.ToLower(), objfilestream);
                        }

                        //creat a new binary component
                        BinaryContentData binaryContent = new BinaryContentData();
                        //set this temporary upload location to the source of this binary
                        binaryContent.UploadFromFile = tempLocation;
                        binaryContent.Filename       = fileInfo.Name.ToLower();

                        //get the multimedia type id
                        binaryContent.MultimediaType = new LinkToMultimediaTypeData()
                        {
                            IdRef = GetMultimediaTypeId(fileInfo.Extension)
                        };

                        multimediaComponent.BinaryContent = binaryContent;

                        //save the image into a new object
                        IdentifiableObjectData savedComponent = client.Save(multimediaComponent, readOptions);

                        //check in using the Id of the new object
                        client.CheckIn(savedComponent.Id, null);
                    }
                    catch (Exception ex)
                    {
                        Log.Debug("Error creating image " + fileInfo.Name, ex);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Log.Error("Error processing images", ex);
        }
        finally
        {
            //clean up temp objects
        }
    }
예제 #21
0
 public abstract IdentifiableObjectData SaveOrganizationalItem(IdentifiableObjectData organizationalItemData, string itemName);
예제 #22
0
 public IdentifiableObjectData Save(IdentifiableObjectData data)
 {
     return this.Client.Save(data, new ReadOptions());
 }
예제 #23
0
        public static int?GetVersion(this ComponentData component)
        {
            IdentifiableObjectData objectData = component;

            return(objectData.GetVersion());
        }
        /// <summary>
        /// Reload the <see cref="IdentifiableObject" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.IdentifiableObjectData" />
        /// </summary>
        /// <param name="identifiableObjectData"><see cref="T:Tridion.ContentManager.CoreService.Client.IdentifiableObjectData" /></param>
        protected void Reload(IdentifiableObjectData identifiableObjectData)
        {
            if (identifiableObjectData == null)
                throw new ArgumentNullException("identifiableObjectData");

            mIdentifiableObjectData = identifiableObjectData;
        }
예제 #25
0
 public static int GetAllUsageCount <T>(this IdentifiableObjectData item, Expression <Func <T, bool> > filterPredicate = null, UsingItemsFilterData filter = null) where T : IdentifiableObjectData
 {
     return(item.GetAllUsages <T>(filterPredicate: filterPredicate).Count);
 }
예제 #26
0
 private static string GetDescription(IdentifiableObjectData item)
 {
     return(item.Title + " (" + item.Id + ")");
 }
예제 #27
0
 public static void UnPublish(this IdentifiableObjectData objectData, string purpose, PublishPriority prio = PublishPriority.Low, DateTime?StartAt = null)
 {
     objectData.UnPublish(new[] { purpose }, prio, StartAt);
 }
예제 #28
0
 /// <summary>
 /// Any post processing required by implementing classes run AFTER the save of the structure group is complete. You can use this method to create related items or anything else which you would typically do after creating the item.
 /// </summary>
 /// <param name="keyword"></param>
 public abstract void PostProcess(IdentifiableObjectData structureGroup);
예제 #29
0
 public override void PostProcess(IdentifiableObjectData keyword)
 {
 }
예제 #30
0
        public static LinkToUserData GetCheckedOutUser(this ComponentData component)
        {
            IdentifiableObjectData objectData = component;

            return(objectData.GetCheckedOutUser());
        }
예제 #31
0
 /// <summary>
 /// Any post processing required by implementing classes run AFTER the save of the folder is complete. You can use this method to create related items or anything else which you would typically do after creating the item.
 /// </summary>
 /// <param name="keyword"></param>
 public abstract void PostProcess(IdentifiableObjectData folder);
예제 #32
0
 public IdentifiableObjectData Save(IdentifiableObjectData deltaData, ReadOptions readBackOptions)
 {
     return(_client.Save(deltaData, readBackOptions));
 }
 /// <summary>
 /// Any post processing required by implementing classes run AFTER the save of the keyword is complete. You can use this method to create related items or anything else which you would typically do after creating the item.
 /// </summary>
 /// <param name="keyword"></param>
 public abstract void PostProcess(IdentifiableObjectData keyword);