Exemple #1
0
        public IList <ComponentInfo> Find()
        {
            Guid solutionId = GetSolutionId();

            _onlyUnmanaged = Prompter.YesNo("Only get unmanaged", true);
            _skipBase      = Prompter.YesNo("Skip \"(base)\" attributes", true);
            _runDepricator = Prompter.YesNo("Depricate attributes with no dependencies", true);

            IEnumerable <SolutionComponent> attributeComponents = SolutionComponentDao.GetSolutionComponents(
                _orgSvc,
                solutionId,
                componenttype.Attribute);

            IList <ComponentInfo> cInfos = new List <ComponentInfo>();

            foreach (SolutionComponent component in attributeComponents)
            {
                ComponentInfo cInfo = ProcessSolutionComponent(component.ObjectId.Value);
                if (cInfo != null)
                {
                    cInfos.Add(cInfo);
                }
            }

            SaveFile();

            return(cInfos);
        }
Exemple #2
0
        public void Create()
        {
            Guid solutionId     = GetSolutionId();
            bool detailedReport = Prompter.YesNo("Detailed report", true);

            IEnumerable <SolutionComponent> allComponents = SolutionComponentDao.GetSolutionComponents(_orgSvc, solutionId);

            foreach (SolutionComponent component in allComponents)
            {
                IEnumerable <Dependency> dependencies = SolutionComponentDao.GetDependencies(
                    _orgSvc,
                    component.ComponentType.Value,
                    component.ObjectId.Value);

                PrintDependencySummary(dependencies.Count(), component);

                //A more complete report requires more code
                if (dependencies.Any() && detailedReport)
                {
                    foreach (Dependency d in dependencies)
                    {
                        PrintDependencyDetails(d, component);
                    }
                }
            }
        }
 public void Process(IList <ComponentInfo> cInfos)
 {
     foreach (ComponentInfo cInfo in cInfos)
     {
         if (Prompt == false || Prompter.YesNo("Depricate Attribute", true))
         {
             AttributeDao.Deprecate(_orgSvc, cInfo);
             Console.WriteLine($"{cInfo.Name} - Attribute Depricated");
         }
     }
 }
Exemple #4
0
 private Guid GetSolutionId()
 {
     while (true)
     {
         string solutionName = Prompter.SolutionName();
         Guid?  solutionId   = SolutionDao.GetId(_orgSvc, solutionName);
         if (solutionId != null)
         {
             return(solutionId.Value);
         }
     }
 }
Exemple #5
0
        private void SaveFile()
        {
            bool tryAgain = true;

            while (tryAgain)
            {
                try
                {
                    File.WriteAllText(@"report.csv", _sb.ToString());
                    tryAgain = false;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed to write to file: {ex.Message}");
                    Console.WriteLine(ex.StackTrace);

                    tryAgain = Prompter.YesNo("Try again", true);
                }
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            try
            {
                string connectionString = Properties.Settings.Default.CrmConnectionString;
                using (OrganizationServiceProxy orgSvc = CrmConnectorUtil.Connect(connectionString) as OrganizationServiceProxy)
                {
                    // This statement is required to enable early-bound type support.
                    orgSvc.EnableProxyTypes();

                    FunctionType functionType = Prompter.ChooseFunction();
                    switch (functionType)
                    {
                    case FunctionType.ShowSolutionDependencies:
                    {
                        new SolutionComponentDependencyReport(orgSvc).Create();
                        break;
                    }

                    case FunctionType.MarkAttributesAsDepricated:
                    {
                        var reporter = new AttributeNoDependencyReport(orgSvc);
                        IList <ComponentInfo> componentInfos = reporter.Find();

                        bool prompt     = Prompter.YesNo("Prompt before marking depricated", true);
                        var  depricator = new AttributeDeprecator(orgSvc, prompt);
                        depricator.Process(componentInfos);

                        break;
                    }

                    case FunctionType.ShowAttributesWithNoDependencies:
                    {
                        var reporter = new AttributeNoDependencyReport(orgSvc);
                        IList <ComponentInfo> componentInfos = reporter.Find();
                        break;
                    }

                    case FunctionType.ShowGlobalOptionSetDependecies:
                    {
                        new GlobalOptionSetDependecyReport(orgSvc).Create();
                        break;
                    }

                    default:
                    {
                        throw new NotImplementedException($"Function type {functionType} is not implemented");
                    }
                    }
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp);
                Console.WriteLine("Code: {0}", ex.Detail.ErrorCode);
                Console.WriteLine("Message: {0}", ex.Detail.Message);
                Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText);
                Console.WriteLine("Inner Fault: {0}",
                                  null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
            }
            catch (TimeoutException ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine("Message: {0}", ex.Message);
                Console.WriteLine("Stack Trace: {0}", ex.StackTrace);
                Console.WriteLine("Inner Fault: {0}", ex.InnerException.Message ?? "No Inner Fault");
            }
            catch (Exception ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine(ex.Message);

                // Display the details of the inner exception.
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    FaultException <OrganizationServiceFault> fe = ex.InnerException
                                                                   as FaultException <OrganizationServiceFault>;
                    if (fe != null)
                    {
                        Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp);
                        Console.WriteLine("Code: {0}", fe.Detail.ErrorCode);
                        Console.WriteLine("Message: {0}", fe.Detail.Message);
                        Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText);
                        Console.WriteLine("Inner Fault: {0}",
                                          null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
                    }
                }
            }
            // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException,
            // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException.
            finally
            {
                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }