Ejemplo n.º 1
0
 public void setDataPrinter(IDataPrinter printer)
 {
     if (printer != null)
     {
         this.printer = printer;
     }
 }
Ejemplo n.º 2
0
 public DataService(DataRepository data)
 {
     this.data = data;
     printer   = new SimpleCollectionPrinter();
 }
Ejemplo n.º 3
0
        // Main
        static void Main(string[] args)
        {
            // Try to load AppSettings.json configuration file first
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Environment.CurrentDirectory)
                          .AddJsonFile(_AppSettingsFileName);

            // Read the AppSettings file and create a ConfigurationRoot object
            var configs = builder.Build();


            // Get the Employee Hierarchy filename from the AppSettings file
            var employeeHierarchyFileName = configs[_AppSetting_HierarchyFileName];

            // Throw exception if there was a problem
            if (String.IsNullOrEmpty(employeeHierarchyFileName))
            {
                throw new ApplicationException($"ERROR :: Problem reading App Setting '{_AppSetting_HierarchyFileName}'!");
            }


            // Create filepath to Employee Hierarchy json file
            var employeeHierarchyFilePath = Path.Combine(Environment.CurrentDirectory, employeeHierarchyFileName);


            // Convert AppSettings parameter 'SortHierarchyOutput' to Boolean
            var castSortEmployeeHierarchySuccess = bool.TryParse(configs[_AppSetting_SortHierarchyOutput], out bool sortEmployeeHierarchy);

            if (castSortEmployeeHierarchySuccess == false)
            {
                throw new ApplicationException($"ERROR :: Problem reading App Setting '{_AppSetting_SortHierarchyOutput}'!");
            }


            // Use the Composition Root & Dependency Injection patterns to compose the application's functionality
            // IFormatReader formatReader = new MockFormatReader();
            IFormatReader formatReader     = new JsonFormatReader(employeeHierarchyFilePath);
            IDataReader   dataReader       = new DataReader(formatReader);
            IDataPrinter  hierarchyPrinter = null;


            // If AppSettings parameter 'SortHierarchyOutput' set to True: create 'SortedHierarchyPrinter'
            //  otherwise, create an unsorted 'HierarchyPrinter'
            if (sortEmployeeHierarchy)
            {
                hierarchyPrinter = new SortedHierarchyPrinter();
            }
            else
            {
                hierarchyPrinter = new HierarchyPrinter();
            }


            // Create the Salaray Requirement Printer
            IDataPrinter salaryRequirementPrinter = new SalaryRequirementPrinter();


            // Read Employee data from the data source
            var rootManager = dataReader.Read();


            // Get String representations for the Employee Hierarchy & Salary Requirement
            var hierarchyString         = hierarchyPrinter.PrintString(rootManager);
            var salaryRequirementString = salaryRequirementPrinter.PrintString(rootManager);


            // Print the Employee Hierarchy & Salary Requirement
            Console.WriteLine(hierarchyString);
            Console.WriteLine(salaryRequirementString);

            // Keep the console window open
            Console.WriteLine("\n\nPress 'enter' to exit...");
            Console.ReadLine();
        }