Beispiel #1
0
        static void Main(string[] args)
        {
            var skipped = new List <string>();
            var updated = new List <string>();
            var failed  = new List <FailureNotice>();
            int current = 0;

            _whatIf = (args.Length > 0 && args[0].ToLowerInvariant() == "-whatif");

            Console.CursorVisible = false;

            using (var client = new SessionAwareCoreServiceClient())
            {
                var publications = client.GetSystemWideList(new PublicationsFilterData());
                int total        = publications.Length;

                if (_whatIf)
                {
                    Console.WriteLine(Resources.NoChangesWillBeMade);
                }

                Console.WriteLine(GetResource(@"StartSummary"), total);

                Console.WriteLine();
                ShowProgress(0, total);

                foreach (var publication in publications)
                {
                    var amPublication = new Publication(new UserContext(), new TcmUri(publication.Id));
                    if (amPublication.Exists)
                    {
                        try
                        {
                            if (!_whatIf)
                            {
                                TopologyHelper.UpdateTopology(amPublication);
                            }
                            updated.Add(GetDescription(publication));
                        }
                        catch (Exception ex)
                        {
                            failed.Add(new FailureNotice
                            {
                                Title = GetDescription(publication),
                                Error = ex.Message
                            });
                        }
                    }
                    else
                    {
                        skipped.Add(GetDescription(publication));
                    }

                    ShowProgress(++current, total);
                }
            }

            OutputSummary(updated, failed, skipped);
            Quit();
        }
        /// <summary>
        /// Get publishing targets for any given publication
        /// </summary>
        /// <param name="publicationID"></param>
        /// <returns></returns>
        public static Dictionary <string, List <string> > GetPublishingTargets(List <string> publicationIDs)
        {
            cs_client = CoreServiceProvider.CreateCoreService();
            Dictionary <string, List <string> > resultTargets = new Dictionary <string, List <string> >();
            var pubTargets = cs_client.GetSystemWideList(new PublicationTargetsFilterData());

            foreach (var publicationID in publicationIDs)
            {
                foreach (PublicationTargetData pubTargetdata in pubTargets)
                {
                    List <string>           targetIds    = new List <string>();
                    PublicationTargetData   target       = (PublicationTargetData)cs_client.Read(pubTargetdata.Id, new ReadOptions());
                    LinkToPublicationData[] pubDataItems = target.Publications;
                    foreach (LinkToPublicationData publicationData in pubDataItems)
                    {
                        if (publicationData.IdRef == publicationID)
                        {
                            if (resultTargets.ContainsKey(publicationData.Title))
                            {
                                resultTargets[publicationData.Title].Add(pubTargetdata.Id);
                            }

                            else
                            {
                                targetIds.Add(pubTargetdata.Id);
                                resultTargets.Add(publicationData.Title, targetIds);
                            }
                        }
                    }
                }
            }

            return(resultTargets);
        }
Beispiel #3
0
        private static WorkItemData[] GetUserWorkflowItems(SessionAwareCoreServiceClient client)
        {
            var userWorkItemsFilter = new UserWorkItemsFilterData()
            {
                ActivityState = ActivityState.Started | ActivityState.Assigned,
            };

            var workItemDataList = new List <WorkItemData>();

            client.GetSystemWideList(userWorkItemsFilter).ToList().ForEach(idObject => workItemDataList.Add(idObject as WorkItemData));
            return(workItemDataList.ToArray());
        }
Beispiel #4
0
        public string GetLatestItems(LatestItemsRequest request)
        {
            // Create a new, null Core Service Client
            SessionAwareCoreServiceClient client = null;

            try
            {
                // Creates a new core service client
                client = new SessionAwareCoreServiceClient("netTcp_2013");
                // Gets the current user so we can impersonate them for our client
                string username = GetUserName();
                client.Impersonate(username);

                // Start building up a string of html to return, including headings for the table that the html will represent.
                string html = "<div class=\"usingItems results\" id=\"latestItemsList\">";
                html += CreateItemsHeading();

                var filter = new SearchQueryData();

                // TODO: Add check for valid start and end times:

                if (String.IsNullOrEmpty(request.startTime))
                {
                    filter.ModifiedAfter = DateTime.Now.AddDays(-1);
                }
                else
                {
                    filter.ModifiedAfter = Convert.ToDateTime(request.startTime);
                }

                if (String.IsNullOrEmpty(request.endTime))
                {
                    filter.ModifiedBefore = DateTime.Now;
                }
                else
                {
                    filter.ModifiedBefore = Convert.ToDateTime(request.endTime);
                }

                filter.IncludeLocationInfoColumns = true;

                if (!string.IsNullOrEmpty(request.pathOfContainer) && !request.pathOfContainer.Equals("(All)"))
                {
                    // Assume publication field is valid publication name
                    // TODO: Validate here
                    string containerId = client.GetTcmUri(ConvertPathToWebdav(request.pathOfContainer), null, null);
                    //string pubTcm = client.GetTcmUri("/webdav/" + request.publication, null, null);
                    filter.SearchIn = new LinkToIdentifiableObjectData {
                        IdRef = containerId
                    };
                }

                if (!string.IsNullOrEmpty(request.user) && !request.user.Equals("(All)"))
                {
                    // TODO: Find a more efficient way of doing this than simply looking at all users.

                    var users = client.GetSystemWideList(new UsersFilterData {
                        BaseColumns = ListBaseColumns.IdAndTitle, IsPredefined = false
                    });

                    string userId = string.Empty;

                    foreach (var ud in users)
                    {
                        if (ud.Title == request.user)
                        {
                            userId = ud.Id;
                        }
                    }

                    // If userId is not found, allow an empty string to be passed, which will trigger and error message.
                    filter.Author = new LinkToUserData()
                    {
                        IdRef = userId
                    };
                }

                filter.ItemTypes = new[] { ItemType.Schema,
                                           ItemType.Component,
                                           ItemType.TemplateBuildingBlock,
                                           ItemType.ComponentTemplate,
                                           ItemType.PageTemplate,
                                           ItemType.Category,
                                           ItemType.Folder,
                                           ItemType.Keyword,
                                           ItemType.Page,
                                           ItemType.StructureGroup,
                                           ItemType.VirtualFolder,
                                           ItemType.Publication };

                filter.BlueprintStatus = SearchBlueprintStatus.Local;

                var searchResults = client.GetSearchResults(filter);

                filter.BlueprintStatus = SearchBlueprintStatus.Localized;

                var searchResults2 = client.GetSearchResults(filter);

                // Merge the two searchResults arrays (local and localized; union goes into searchResults):
                int array1OriginalLength = searchResults.Length;
                Array.Resize <IdentifiableObjectData>(ref searchResults, array1OriginalLength + searchResults2.Length);
                Array.Copy(searchResults2, 0, searchResults, array1OriginalLength, searchResults2.Length);

                int row = 0;

                foreach (IdentifiableObjectData item in searchResults)
                {
                    row++;

                    string path = "";
                    if (item is RepositoryLocalObjectData)
                    {
                        path = ((RepositoryLocalObjectData)item).LocationInfo.Path;
                    }

                    bool outputItem = true;

                    // If user is not empty or set to (All), then run some logic to see if items match selected user within specified time range.
                    // This is necessary to account for scenarios where one user creates an item, but another edits it at a later time, for instance.
                    // If no specific user is specified, DO NOT run these checks as they are expensive and not necessary in that case!
                    // Only perform this check for Versioned Items (i.e. not folders, etc.).
                    ////if (!string.IsNullOrEmpty(request.user) && !request.user.Equals("(All)") && (item is VersionedItemData))
                    ////{
                    ////    // Set flag to false by default and set back to true if we find a match.
                    ////    outputItem = false;

                    ////    VersionsFilterData versionsFilter = new VersionsFilterData();
                    ////    versionsFilter.IncludeRevisorDescriptionColumn = true;
                    ////    IdentifiableObjectData[] versionList = client.GetList(item.Id, versionsFilter);

                    ////    foreach (IdentifiableObjectData objectData in versionList)
                    ////    {
                    ////        var versionInfo = (FullVersionInfo)objectData.VersionInfo;

                    ////        // Check 2 things:
                    ////        // 1) that versionInfo.Revisor.Title == request.user
                    ////        // 2) that versionInfo.RevisionDate.Value is between filter.ModifiedAfter and filter2.ModifiedBefore
                    ////        // If we find a match, set outputItem to true and break the foreach loop.

                    ////        if (versionInfo.Revisor.Title == request.user)
                    ////        {
                    ////            if ((objectData.VersionInfo.RevisionDate >= filter.ModifiedAfter) && (objectData.VersionInfo.RevisionDate <= filter.ModifiedBefore))
                    ////            {
                    ////                outputItem = true;
                    ////                break;
                    ////            }
                    ////        }
                    ////    }
                    ////}

                    if (outputItem)
                    {
                        string currItemHtml = "<div class=\"item\">";

                        // Some JS magic is needed here to retrieve the icon and add it to the url by string replacement.
                        // We need to do this in JS because the core service provides no access to an item's icon.
                        currItemHtml += "<script>var icon = $models.getItem(\"" + item.Id + "\").getInfo().Icon;</script>";
                        currItemHtml += "<div id=\"tempIconId" + row + "\" class=\"icon\" style=\"background-image: url(/WebUI/Editors/CME/Themes/Carbon2/icon_v7.1.0.66.627_.png?name=" + "****" + "&size=16)\">" + "" + "</div>";
                        currItemHtml += "<script>document.getElementById('tempIconId" + row + "').outerHTML = document.getElementById('tempIconId" + row + "').outerHTML.replace(\"****\", icon);</script>";

                        currItemHtml += "<div class=\"name\">" + item.Title + "</div>";
                        currItemHtml += "<div class=\"path\">" + path + "</div>";
                        currItemHtml += "<div class=\"id\">" + item.Id + "</div>";
                        currItemHtml += "</div>";

                        html += currItemHtml;
                    }
                }

                // Close the div we opened above
                html += "</div>";

                // Explicitly abort to ensure there are no memory leaks.
                client.Abort();

                // Return the html we've built.
                return(html);
            }
            catch (Exception ex)
            {
                // Proper way of ensuring that the client gets closed... we close it in our try block above,
                // then in a catch block if an exception is thrown we abort it.
                if (client != null)
                {
                    client.Abort();
                }

                // We are rethrowing the original exception and just letting webapi handle it.
                throw ex;
            }
        }
Beispiel #5
0
        private string ImportSingleItem(IEclUri eclUri)
        {
            string id = "tcm:0-0-0";
            IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)_eclContentLibraryContext.GetItem(eclUri);
            string       extension = eclItem.Filename.Substring(eclItem.Filename.LastIndexOf('.') + 1);
            MemoryStream ms        = null;
            string       tempPath;

            try
            {
                // create some template attributes
                IList <ITemplateAttribute> attributes = CreateTemplateAttributes(eclItem);

                // determine if item has content or is available online
                string publishedPath = eclItem.GetDirectLinkToPublished(attributes);
                if (string.IsNullOrEmpty(publishedPath))
                {
                    // we can directly get the content
                    IContentResult content = eclItem.GetContent(attributes);
                    ms = new MemoryStream();
                    content.Stream.CopyTo(ms);
                    ms.Position = 0;
                }
                else
                {
                    // read the content from the publish path
                    using (WebClient webClient = new WebClient())
                    {
                        byte[] thumbnailData = webClient.DownloadData(publishedPath);
                        ms = new MemoryStream(thumbnailData, false);
                    }
                }

                // upload binary (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI)
                using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012"))
                {
                    tempPath = suClient.UploadBinaryContent(eclItem.Filename, ms);
                }
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                }
            }

            // create tcm item
            var mmComponent = new ComponentData
            {
                Id     = id,
                Title  = eclItem.Title,
                Schema = new LinkToSchemaData {
                    IdRef = _schemaUri
                },
                LocationInfo = new LocationInfo {
                    OrganizationalItem = new LinkToOrganizationalItemData {
                        IdRef = _folderUri
                    }
                }
            };

            // put binary data in tcm item (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI)
            using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012"))
            {
                // impersonate with current user
                client.Impersonate(_username);

                // set metadata
                var schemaFields = client.ReadSchemaFields(_schemaUri, true, new ReadOptions());
                if (schemaFields.MetadataFields.Any())
                {
                    var fields = Fields.ForMetadataOf(schemaFields, mmComponent);
                    if (!string.IsNullOrEmpty(eclItem.MetadataXml))
                    {
                        XNamespace ns       = GetNamespace(eclItem.MetadataXml);
                        XDocument  metadata = XDocument.Parse(eclItem.MetadataXml);
                        var        children = metadata.Element(ns + "Metadata").Descendants();
                        for (int i = 0; i < children.Count(); i++)
                        {
                            fields.AddFieldElement(new ItemFieldDefinitionData {
                                Name = "data"
                            });
                            var embeddedFields = fields["data"].GetSubFields(i);
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData {
                                Name = "key"
                            });
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData {
                                Name = "value"
                            });
                            embeddedFields["key"].Value   = children.ElementAt(i).Name.LocalName;
                            embeddedFields["value"].Value = children.ElementAt(i).Value;
                        }
                    }
                    mmComponent.Metadata = fields.ToString();
                }

                // find multimedia type
                var list           = client.GetSystemWideList(new MultimediaTypesFilterData());
                var multimediaType = list.OfType <MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension));

                // set BinaryContent of a component
                mmComponent.BinaryContent = new BinaryContentData
                {
                    UploadFromFile = tempPath,
                    Filename       = eclItem.Filename,
                    MultimediaType = new LinkToMultimediaTypeData {
                        IdRef = multimediaType.Id
                    }
                };

                // create (and save) component
                ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions());
                id = data.Id;
            }

            //string result = string.Format("created {0}, from {1}, in {2}, using {3}, for {4}", id, eclUri, _folderUri, _schemaUri, _username);
            return(id);
        }
        private string ImportSingleItem(IEclUri eclUri)
        {
            string id = "tcm:0-0-0";
            IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)_eclContentLibraryContext.GetItem(eclUri);
            string extension = eclItem.Filename.Substring(eclItem.Filename.LastIndexOf('.') + 1);
            MemoryStream ms = null;
            string tempPath;
            try
            {
                // create some template attributes
                IList<ITemplateAttribute> attributes = CreateTemplateAttributes(eclItem);

                // determine if item has content or is available online
                string publishedPath = eclItem.GetDirectLinkToPublished(attributes);
                if (string.IsNullOrEmpty(publishedPath))
                {
                    // we can directly get the content 
                    IContentResult content = eclItem.GetContent(attributes);
                    ms = new MemoryStream();
                    content.Stream.CopyTo(ms);
                    ms.Position = 0;
                }
                else
                {
                    // read the content from the publish path
                    using (WebClient webClient = new WebClient())
                    {
                        byte[] thumbnailData = webClient.DownloadData(publishedPath);
                        ms = new MemoryStream(thumbnailData, false);
                    }
                }

                // upload binary (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) 
                using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012"))
                {
                    tempPath = suClient.UploadBinaryContent(eclItem.Filename, ms);
                }
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                }
            }

            // create tcm item
            var mmComponent = new ComponentData
            {
                Id = id,
                Title = eclItem.Title,
                Schema = new LinkToSchemaData { IdRef = _schemaUri },
                LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = _folderUri } }
            };

            // put binary data in tcm item (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) 
            using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012"))
            {
                // impersonate with current user
                client.Impersonate(_username);

                // set metadata
                var schemaFields = client.ReadSchemaFields(_schemaUri, true, new ReadOptions());
                if (schemaFields.MetadataFields.Any())
                {
                    var fields = Fields.ForMetadataOf(schemaFields, mmComponent);
                    if (!string.IsNullOrEmpty(eclItem.MetadataXml))
                    {
                        XNamespace ns = GetNamespace(eclItem.MetadataXml);
                        XDocument metadata = XDocument.Parse(eclItem.MetadataXml);
                        var children = metadata.Element(ns + "Metadata").Descendants();
                        for (int i = 0; i < children.Count(); i++)
                        {
                            fields.AddFieldElement(new ItemFieldDefinitionData { Name = "data" });
                            var embeddedFields = fields["data"].GetSubFields(i);
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "key" });
                            embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "value" });
                            embeddedFields["key"].Value = children.ElementAt(i).Name.LocalName;
                            embeddedFields["value"].Value = children.ElementAt(i).Value;
                        }
                    }
                    mmComponent.Metadata = fields.ToString();
                }

                // find multimedia type
                var list = client.GetSystemWideList(new MultimediaTypesFilterData());
                var multimediaType = list.OfType<MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension));

                // set BinaryContent of a component
                mmComponent.BinaryContent = new BinaryContentData
                {
                    UploadFromFile = tempPath,
                    Filename = eclItem.Filename,
                    MultimediaType = new LinkToMultimediaTypeData { IdRef = multimediaType.Id }
                };

                // create (and save) component
                ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions());
                id = data.Id;
            }

            //string result = string.Format("created {0}, from {1}, in {2}, using {3}, for {4}", id, eclUri, _folderUri, _schemaUri, _username);
            return id;
        }