コード例 #1
0
        public ServiceProcess Execute(string publicationId)
        {
            if (string.IsNullOrEmpty(publicationId))
            {
                throw new ArgumentNullException("Publication ID is null");
            }

            DuplicateBinariesParameters arguments = new DuplicateBinariesParameters
            {
                PublicationId = publicationId
            };

            return(ExecuteAsync(arguments));
        }
        public ServiceProcess Execute(string publicationId)
        {

            if (string.IsNullOrEmpty(publicationId))
            {
                throw new ArgumentNullException("Publication ID is null");
            }

            DuplicateBinariesParameters arguments = new DuplicateBinariesParameters
            {
                PublicationId = publicationId
            };
            return ExecuteAsync(arguments);
        }
コード例 #3
0
        public override void Process(ServiceProcess process, object arguments)
        {
            _duplicateData = new List <DuplicateBinariesData>();
            fileNames      = new Dictionary <string, string>();
            DuplicateBinariesParameters parameters = (DuplicateBinariesParameters)arguments;

            //_duplicateBinariesData = new DuplicateBinariesData();
            //_duplicateBinariesData.PublicationId = parameters.PublicationId;

            process.SetCompletePercentage(10);
            process.SetStatus("working");

            using (var coreService = Client.GetCoreService())
            {
                try
                {
                    process.SetCompletePercentage(15);
                    process.SetStatus("Creating publication filter");

                    // Create a filter to only fetch multimedia components from the publication
                    RepositoryItemsFilterData filter = new RepositoryItemsFilterData();
                    filter.ItemTypes      = new[] { ItemType.Component };
                    filter.ComponentTypes = new[] { ComponentType.Multimedia };
                    XElement   mmComponentsListXml = coreService.GetListXml(parameters.PublicationId, filter);
                    XNamespace tcm = "http://www.tridion.com/ContentManager/5.0";

                    double progressIncrement = mmComponentsListXml.Value.Length == 0 ? 0 : 80 / mmComponentsListXml.Value.Length; //nasty progress calculation
                    int    i = 1;

                    // keep a list of all the file names from the items in the publication
                    // the if a file already exists in the filenames, it is considered a 'duplicate file name'
                    foreach (XElement itemElem in mmComponentsListXml.Descendants(tcm + "Item"))
                    {
                        string itemId         = itemElem.Attribute("ID").Value;
                        string binaryFileName = GetFileNameFromComponent(coreService, itemId);

                        fileNames.Add(itemId, binaryFileName);

                        int progressPercentage = (int)(20 + i * progressIncrement); // some more nasty progress calculation
                        process.SetCompletePercentage(progressPercentage);
                        i++;
                    }

                    var duplicateValues = fileNames.ToLookup(a => a.Value).
                                          Where(b => b.Count() > 1);

                    // todo - refactor this below item to select the id's and values from the file
                    // name list

                    foreach (var group in duplicateValues)
                    {
                        foreach (KeyValuePair <string, string> kvp in group)
                        {
                            _duplicateData.Add(new DuplicateBinariesData
                            {
                                ItemTcmId    = kvp.Key,
                                ItemFileName = kvp.Value,
                            });
                        }
                    }

                    process.Complete("Done");
                }
                catch (Exception ex)
                {
                    // TODO: Update the GUI that there has been error - solution below is temporary
                    process.Failed = true;
                    process.Complete(string.Format("Failure finding duplicate items reason: {0}", ex.Message));
                    return;
                }
            }
        }