Exemplo n.º 1
0
        static void Main(string[] args)
        {
            coreServiceHandler = new CoreServiceHandler(configFilename);
            core = coreServiceHandler.GetNewNetTcpClient();
            if (core == null)
            {
                Console.WriteLine("Could not login, please check config for credentials");
                return;
            }
            else
            {
                Console.WriteLine("Start scan with Tridion for VBScript legacy code");
            }

            //https://code.google.com/p/tridion-practice/wiki/LINQQueries

            var           ppList   = GetPublicationAndTheirParents();
            StringBuilder sbReport = new StringBuilder();
            bool          backupVbScriptCodeToFile = coreServiceHandler.GetAppSetting("saveTemplateCode").Equals("true", StringComparison.OrdinalIgnoreCase);
            int           ptAllCount = 0;
            int           ctAllCount = 0;

            foreach (var publication in ppList)
            {
                int ptCount = 0;
                int ctCount = 0;
                Console.WriteLine(Environment.NewLine + "Scanning publication " + publication.Title);
                sbReport.Append(Environment.NewLine + "Scanning publication " + publication.Title + Environment.NewLine);

                var listOfPt = GetListOfType(publication.TcmId, ItemType.PageTemplate);
                var pubID    = GetPublicationId(publication.TcmId);
                foreach (var ptitem in listOfPt.Items)
                {
                    var ptd = core.Read(ptitem.TcmId, readOpts) as PageTemplateData;
                    if (ptd != null && ptd.TemplateType != "CompoundTemplate")
                    {
                        ptCount++;
                        var templateId = GetPublicationId(ptd.Id);

                        // only report local templates
                        if (pubID == templateId)
                        {
                            int    pageCount = 0;
                            string pages     = GetPagesUsedByAPageTemplate(ptd.Id, out pageCount);
                            if (pageCount > 0)
                            {
                                sbReport.AppendFormat("{0} ({1}) is {2} used in {3} pages:", ptd.LocationInfo.WebDavUrl, ptd.Id, ptd.TemplateType, pageCount).Append(Environment.NewLine);
                                sbReport.AppendLine(pages);
                                sbReport.AppendFormat("----------------------------").Append(Environment.NewLine);
                            }
                            else
                            {
                                sbReport.AppendFormat("{0} ({1}) is {2} is not used in pages", ptd.LocationInfo.WebDavUrl, ptd.Id, ptd.TemplateType).Append(Environment.NewLine);
                            }
                            if (backupVbScriptCodeToFile)
                            {
                                File.WriteAllText(ptd.Title + ".tpts.txt", ptd.Content);
                            }
                        }
                    }
                    Console.Write(".");
                }

                var listOfCt = GetListOfType(publication.TcmId, ItemType.ComponentTemplate);
                foreach (var ctitem in listOfCt.Items)
                {
                    var ctd = core.Read(ctitem.TcmId, readOpts) as ComponentTemplateData;

                    if (ctd != null && ctd.TemplateType != "CompoundTemplate")
                    {
                        ctCount++;
                        var    templateId = GetPublicationId(ctd.Id);
                        int    pageCount  = 0;
                        string pages      = GetPagesUsedByAPageTemplate(ctd.Id, out pageCount);

                        // only report local templates
                        if (pubID == templateId)
                        {
                            if (pageCount > 0)
                            {
                                sbReport.AppendFormat("{0} ({1}) is {2} used in {3} pages:", ctd.LocationInfo.WebDavUrl, ctd.Id, ctd.TemplateType, pageCount).Append(Environment.NewLine);
                                sbReport.AppendLine(pages);
                                sbReport.AppendFormat("----------------------------").Append(Environment.NewLine);
                            }
                            else
                            {
                                sbReport.AppendFormat("{0} ({1}) is {2} is not used in pages", ctd.LocationInfo.WebDavUrl, ctd.Id, ctd.TemplateType).Append(Environment.NewLine);
                            }
                        }
                        if (backupVbScriptCodeToFile)
                        {
                            File.WriteAllText(ctd.Title + ".tcts.txt", ctd.Content);
                        }
                    }
                    Console.Write(".");
                }

                ctAllCount += ctCount;
                ptAllCount += ptCount;

                sbReport.AppendFormat("Found {0} PT's and {1} CT's with VBScript in publication '{2}'" + Environment.NewLine, ptCount, ctCount, publication.Title);
            }

            sbReport.AppendFormat(Environment.NewLine + "Found {0} PT's and {1} CT's with VBScript in all publications" + Environment.NewLine, ptAllCount, ctAllCount);

            Console.WriteLine("");
            Console.WriteLine(sbReport.ToString());
            Console.WriteLine("--------------------------");


            File.WriteAllText(reportFile, sbReport.ToString());

            Console.WriteLine("Saved report to " + reportFile);
            Console.WriteLine("Done..");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            coreServiceHandler = new CoreServiceHandler(configFilename);
            core = coreServiceHandler.GetNewNetTcpClient();
            if (core == null)
            {
                Console.WriteLine("Could not login, please check config for credentials");
                return;
            }
            else
            {
                Console.WriteLine("Start scan with Tridion for VBScript legacy code");
            }

            //https://code.google.com/p/tridion-practice/wiki/LINQQueries

            var ppList = GetPublicationAndTheirParents();
            StringBuilder sbReport = new StringBuilder();
            bool backupVbScriptCodeToFile = coreServiceHandler.GetAppSetting("saveTemplateCode").Equals("true", StringComparison.OrdinalIgnoreCase);
            int ptAllCount = 0;
            int ctAllCount = 0;

            foreach (var publication in ppList)
            {
                int ptCount = 0;
                int ctCount = 0;
                Console.WriteLine(Environment.NewLine + "Scanning publication " + publication.Title);
                sbReport.Append(Environment.NewLine + "Scanning publication " + publication.Title + Environment.NewLine);

                var listOfPt = GetListOfType(publication.TcmId, ItemType.PageTemplate);
                var pubID = GetPublicationId(publication.TcmId);
                foreach (var ptitem in listOfPt.Items)
                {
                    var ptd = core.Read(ptitem.TcmId, readOpts) as PageTemplateData;
                    if (ptd != null && ptd.TemplateType != "CompoundTemplate")
                    {
                        ptCount++;
                        var templateId = GetPublicationId(ptd.Id);

                        // only report local templates
                        if (pubID == templateId)
                        {
                            int pageCount = 0;
                            string pages = GetPagesUsedByAPageTemplate(ptd.Id, out pageCount);
                            if (pageCount > 0) {
                                sbReport.AppendFormat("{0} ({1}) is {2} used in {3} pages:", ptd.LocationInfo.WebDavUrl, ptd.Id, ptd.TemplateType, pageCount).Append(Environment.NewLine);
                                sbReport.AppendLine(pages);
                                sbReport.AppendFormat("----------------------------").Append(Environment.NewLine);
                            }else {
                                sbReport.AppendFormat("{0} ({1}) is {2} is not used in pages", ptd.LocationInfo.WebDavUrl, ptd.Id, ptd.TemplateType).Append(Environment.NewLine);
                            }
                            if (backupVbScriptCodeToFile)
                            {
                                File.WriteAllText(ptd.Title + ".tpts.txt", ptd.Content);
                            }
                        }

                    }
                    Console.Write(".");
                }

                var listOfCt = GetListOfType(publication.TcmId, ItemType.ComponentTemplate);
                foreach (var ctitem in listOfCt.Items)
                {
                    var ctd = core.Read(ctitem.TcmId, readOpts) as ComponentTemplateData;

                    if (ctd != null && ctd.TemplateType != "CompoundTemplate")
                    {
                        ctCount++;
                        var templateId = GetPublicationId(ctd.Id);
                        int pageCount = 0;
                        string pages = GetPagesUsedByAPageTemplate(ctd.Id, out pageCount);

                        // only report local templates
                        if (pubID == templateId)
                        {
                            if (pageCount > 0)
                            {
                                sbReport.AppendFormat("{0} ({1}) is {2} used in {3} pages:", ctd.LocationInfo.WebDavUrl, ctd.Id, ctd.TemplateType, pageCount).Append(Environment.NewLine);
                                sbReport.AppendLine(pages);
                                sbReport.AppendFormat("----------------------------").Append(Environment.NewLine);
                            }
                            else
                            {
                                sbReport.AppendFormat("{0} ({1}) is {2} is not used in pages", ctd.LocationInfo.WebDavUrl, ctd.Id, ctd.TemplateType).Append(Environment.NewLine);
                            }
                        }
                        if (backupVbScriptCodeToFile)
                        {
                            File.WriteAllText(ctd.Title + ".tcts.txt", ctd.Content);
                        }

                    }
                    Console.Write(".");
                }

                ctAllCount += ctCount;
                ptAllCount += ptCount;

                sbReport.AppendFormat("Found {0} PT's and {1} CT's with VBScript in publication '{2}'" + Environment.NewLine, ptCount, ctCount, publication.Title);

            }

            sbReport.AppendFormat(Environment.NewLine + "Found {0} PT's and {1} CT's with VBScript in all publications" + Environment.NewLine, ptAllCount, ctAllCount);

            Console.WriteLine("");
            Console.WriteLine(sbReport.ToString());
            Console.WriteLine("--------------------------");

            File.WriteAllText(reportFile, sbReport.ToString());

            Console.WriteLine("Saved report to " + reportFile);
            Console.WriteLine("Done..");
            Console.ReadLine();
        }