public void SaveComponent(double topLoc, double leftLoc, double height, double width, string content)
        {
            if (componentFactory != null)
            {
                if (Components == null)
                {
                    Components = new ObservableCollection <Component>();
                }

                if (selectedComponentSelected.ToLower() == "button")
                {
                    Components.Add(componentFactory.CreateComponent(FactoryPatternLib.Enums.Components.Button, height, width, topLoc, leftLoc, content));
                }
                else if (selectedComponentSelected.ToLower() == "circle")
                {
                    Components.Add(componentFactory.CreateComponent(FactoryPatternLib.Enums.Components.Circle, height, width, topLoc, leftLoc, content));
                }
                else if (selectedComponentSelected.ToLower() == "textbox")
                {
                    Components.Add(componentFactory.CreateComponent(FactoryPatternLib.Enums.Components.Textbox, height, width, topLoc, leftLoc, content));
                }
                else if (selectedComponentSelected.ToLower() == "image")
                {
                    Components.Add(componentFactory.CreateComponent(FactoryPatternLib.Enums.Components.Image, height, width, topLoc, leftLoc, content));
                }
            }
            else
            {
                ObservableCollection <string> list = (ObservableCollection <string>)selectedComponentsListBox.ItemsSource;

                list.Remove(selectedComponentsListBox.SelectedValue.ToString());
                selectedComponentsListBox.ItemsSource = list;
            }
        }
        public static VisualComponent CreateSimpleVisualElement()
        {
            var componentTemplateProvider = new ComponentTemplateProvider();
            var componentFactory          = new ComponentFactory(componentTemplateProvider);

            return(componentFactory.CreateComponent <VisualComponent>());
        }
        public static TComponent CreateComponent <TComponent>() where TComponent : class, IComponent
        {
            var componentTemplateProvider = new ComponentTemplateProvider();
            var componentFactory          = new ComponentFactory(componentTemplateProvider);

            return(componentFactory.CreateComponent <TComponent>());
        }
        public async void UpdateComponentAsAdminDescriptionTooShortTest()
        {
            //create location and location
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            //begin building new component
            Dictionary <string, StringValues> formdata = new Dictionary <string, StringValues>();

            formdata.Add("Name", "Stippentrap");
            formdata.Add("Description", "X");
            formdata.Add("Exercises", "1");
            AddExerciseToDatabase(1);

            HttpRequest requestmessage = await HttpRequestFactory.CreateFormDataRequest(formdata, HttpMethod.Put);

            ObjectResult result = (ObjectResult)await this.componentController.ComponentUpdateById(requestmessage, 1, 1, this.adminClaim);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 400 "Description must be at least 2 characters"
            Assert.Equal(400, result.StatusCode);
            Assert.Equal("Description must be at least 2 characters", errorResponse.Message);
        }
        public async void UpdateComponentAsAdminNameTooLongTest()
        {
            //create location and location
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            //begin building new component
            Dictionary <string, StringValues> formdata = new Dictionary <string, StringValues>();

            formdata.Add("Name", "Stippentrap gelegen naast de glijbaan in de skillgarden van Almere");
            formdata.Add("Description", "Leg jij behendig als een antilope het stippenparcour af?");
            formdata.Add("Exercises", "1");
            AddExerciseToDatabase(1);

            HttpRequest requestmessage = await HttpRequestFactory.CreateFormDataRequest(formdata, HttpMethod.Put);

            ObjectResult result = (ObjectResult)await this.componentController.ComponentUpdateById(requestmessage, 1, 1, this.adminClaim);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 401 UNAUTHORIZED
            Assert.Equal(400, result.StatusCode);
            Assert.Equal("Name can not be longer than 50 characters", errorResponse.Message);
        }
        public async void UpdateComponentAsAdminComponentNotFoundTest()
        {
            //create location and location
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            //begin building new component
            Dictionary <string, StringValues> formdata = new Dictionary <string, StringValues>();

            formdata.Add("Name", "Stippentrap");
            formdata.Add("Description", "Leg jij behendig als een antilope het stippenparcour af?");
            formdata.Add("Exercises", "1");
            AddExerciseToDatabase(1);

            HttpRequest requestmessage = await HttpRequestFactory.CreateFormDataRequest(formdata, HttpMethod.Put);

            ObjectResult result = (ObjectResult)await this.componentController.ComponentUpdateById(requestmessage, 1, 5, this.adminClaim);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 404 not found
            Assert.Equal(404, result.StatusCode);
            Assert.Equal(ErrorCode.COMPONENT_NOT_FOUND, errorResponse.ErrorCodeEnum);
        }
        public async void GetAllComponentsByLocationIdTest()
        {
            Location location1 = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            Location location2 = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(2));

            // create components for location 1
            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(2, location1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(3, location1));

            //create components for location 2
            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(4, location2));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(5, location2));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            //get all components location 1
            ObjectResult result = (ObjectResult)await this.componentController.ComponentsGetAll(request, 1);

            List <Component> components = (List <Component>)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // amount of found locations should be 3 for location 1
            Assert.Equal(3, components.Count);
        }
        public async void UpdateComponentAsNonAdminTest()
        {
            //create location and location
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            //begin building new component
            Dictionary <string, StringValues> formdata = new Dictionary <string, StringValues>();

            formdata.Add("Name", "Fiets parcour");
            formdata.Add("Description", "Race jij het snelst door de blauwe racebaan heen?");
            formdata.Add("Exercises", "1");
            AddExerciseToDatabase(1);

            HttpRequest requestmessage = await HttpRequestFactory.CreateFormDataRequest(formdata, HttpMethod.Put);

            ObjectResult resultUser = (ObjectResult)await this.componentController.ComponentUpdateById(requestmessage, 1, 1, this.userClaim);

            ObjectResult resultOrganiser = (ObjectResult)await this.componentController.ComponentUpdateById(requestmessage, 1, 1, this.organiserClaim);

            ErrorResponse errorMessageUser      = (ErrorResponse)resultUser.Value;
            ErrorResponse errorMessageOrganiser = (ErrorResponse)resultOrganiser.Value;

            // status code should be 403 FORBIDDEN
            Assert.Equal(403, resultUser.StatusCode);
            Assert.Equal(403, resultOrganiser.StatusCode);

            Assert.Equal(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS, errorMessageUser.ErrorCodeEnum);
            Assert.Equal(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS, errorMessageOrganiser.ErrorCodeEnum);
        }
        public async void UpdateComponentAsAdminTest()
        {
            //create location and location
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            //begin building new component
            Dictionary <string, StringValues> formdata = new Dictionary <string, StringValues>();

            formdata.Add("Name", "Fiets parcour");
            formdata.Add("Description", "Race jij het snelst door de blauwe racebaan heen?");
            formdata.Add("Exercises", "1");
            AddExerciseToDatabase(1);

            HttpRequest requestmessage = await HttpRequestFactory.CreateFormDataRequest(formdata, HttpMethod.Put);

            ObjectResult result = (ObjectResult)await this.componentController.ComponentUpdateById(requestmessage, 1, 1, this.adminClaim);

            ComponentResponse resultComponent = (ComponentResponse)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            Assert.Equal("Fiets parcour", resultComponent.Name);
        }
        /// <summary>
        /// Starts this Master Controller.
        /// </summary>
        public void Initialise()
        {
            _controllers = new List <InstanceController>();
            try {
                _config = BuildStatusConfig.Load();
            } catch (Exception ex) {
                throw new LogApplicationException("Could not load the Configuration File.", ex);
            }

            // Using the Data, Load and Instantiate each of the Visualisers and Monitors.
            // ---------------------------------------------------------------------------
            if (_config != null)
            {
                FileLogger.Logger.LogVerbose("Loading Controllers.");

                foreach (var controller in _config.Controllers)
                {
                    FileLogger.Logger.LogInformation("Controller: {0} with Monitor={1} and Visualiser={2}", controller.Name, controller.Monitor, controller.Visualiser);

                    if (_visualiser.Contains(controller.Visualiser))
                    {
                        throw new ApplicationException("A visualiser cannot be used more than once.");
                    }
                    if (_config.Visualisers[controller.Visualiser] == null)
                    {
                        throw new ApplicationException("Invalid Visualiser Specified: " + controller.Visualiser);
                    }
                    if (_config.Monitors[controller.Monitor] == null)
                    {
                        throw new ApplicationException("Invalid Monitor Specified: " + controller.Monitor);
                    }
                    if (_config.Transitions[controller.Transition] == null)
                    {
                        throw new ApplicationException("Invalid Transition Specified: " + controller.Transition);
                    }

                    var monitorInfo    = _config.Monitors[controller.Monitor];
                    var visualiserInfo = _config.Visualisers[controller.Visualiser];

                    if (monitorInfo != null && visualiserInfo != null)
                    {
                        var monitor = ComponentFactory <IMonitor> .CreateComponent(monitorInfo);

                        var visualiser = ComponentFactory <IVisualiser> .CreateComponent(visualiserInfo);

                        if (monitor != null && visualiser != null)
                        {
                            visualiser.Transitions = _config.Transitions[controller.Transition];
                            _controllers.Add(new InstanceController(controller.Name, monitor, visualiser));
                        }
                    }
                    else
                    {
                        FileLogger.Logger.LogError("Invalid Monitor and/or Visualiser Data in Config file.");
                        throw new ApplicationException("Invalid Monitor and/or Visualiser Data in Config File");
                    }
                }
                _schedules = _config.Schedules;
            }
        }
Beispiel #11
0
        public Task <List <RenderFragment>?> RenderPlaceholders(string?placeholder, CancellationToken cancellationToken = default)
        {
            return(Task.Run(() =>
            {
                List <RenderFragment> list = new List <RenderFragment>();

                try
                {
                    IList <KeyValuePair <string, IList <Placeholder> > >?placeHoldersList = _blazorStateMachine.CurrentPlaceholders?.Where(ph => ph.Key.ExtractPlaceholderName() == placeholder).ToList();

                    if (placeHoldersList == null)
                    {
                        return null;
                    }

                    foreach (KeyValuePair <string, IList <Placeholder> > keyVal in placeHoldersList)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        foreach (Placeholder placeholderData in keyVal.Value)
                        {
                            cancellationToken.ThrowIfCancellationRequested();

                            if (placeholderData == null)
                            {
                                continue;
                            }

                            string keyName = $"{keyVal.Key}-{placeholderData.ComponentName}";

                            if (ComponentsInDynamicPlaceholdersAlreadyRenderedPerStateChanged.Any(comp => comp == keyName))
                            {
                                continue;
                            }

                            var component = _componentFactory.CreateComponent(placeholderData);

                            if (component == null)
                            {
                                continue;
                            }

                            list.Add(component);

                            if (keyVal.Key.IsDynamicPlaceholder())
                            {
                                ComponentsInDynamicPlaceholdersAlreadyRenderedPerStateChanged.Add(keyName);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error RenderPlaceholders {ex.Message}");
                }

                return list;
            }, cancellationToken));
        }
Beispiel #12
0
        private static PersonalComputer ConfigurePersonalComputer(ComponentFactory componentFactory, ProductFactory productFactory)
        {
            string           answer;
            PersonalComputer personalComputer;

            PCTower pcTower = ConfigurePCTower(componentFactory, productFactory);

            if (!pcTower.IsValidProduct())
            {
                return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer);
            }

            PCScreen pcScreen = ConfigurePCScreen(productFactory);

            if (!pcScreen.IsValidProduct())
            {
                return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer);
            }

            Console.WriteLine("Set the size of the Hard Disk\n");
            answer = Console.ReadLine();

            HardDrive hardDrive = componentFactory.CreateComponent("HardDrive") as HardDrive;

            if (!hardDrive.SetValue(answer))
            {
                WrongInput();
                return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer);
            }

            personalComputer = productFactory.CreateProduct("PersonalComputer") as PersonalComputer;
            if (!personalComputer.SetScreen(pcScreen))
            {
                WrongInput();
                return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer);
            }

            if (!personalComputer.SetPCTower(pcTower))
            {
                WrongInput();
                return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer);
            }
            ;
            if (!personalComputer.SetHardDrive(hardDrive))
            {
                WrongInput();
                return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer);
            }

            if (!personalComputer.IsValidProduct())
            {
                return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer);
            }

            return(personalComputer);
        }
        public void TestMonitorInstantiation()
        {
            var settings = new Settings();

            settings.Add("Host", "nzakledci01:8080");
            settings.Add("ProjectID", "project8");
            var instance = ComponentFactory <IMonitor> .CreateComponent(new Monitor("TestMonitor", "BuildStatusMonitor", "BuildStatusMonitor.Monitors.TeamCityMonitor", settings));

            Assert.IsNotNull(instance);
        }
Beispiel #14
0
        private static PCTower ConfigurePCTower(ComponentFactory componentFactory, ProductFactory productFactory)
        {
            string  answer;
            PCTower pcTower;

            Console.WriteLine("Insert CPU frequency in GHz\n");
            answer = Console.ReadLine();
            CPU cpu = componentFactory.CreateComponent("CPU") as CPU;

            if (!cpu.SetValue(answer))
            {
                WrongInput();
                return(productFactory.CreateProduct("PCTower") as PCTower);
            }

            Console.WriteLine("Insert size of Memory Ram in GB\n");
            answer = Console.ReadLine();
            MemoryRam memoryRam = componentFactory.CreateComponent("MemoryRam") as MemoryRam;

            if (!memoryRam.SetValue(answer))
            {
                WrongInput();
                return(productFactory.CreateProduct("PCTower") as PCTower);
            }

            pcTower = productFactory.CreateProduct("PCTower") as PCTower;
            if (!pcTower.SetMemoryRam(memoryRam))
            {
                //handle exception demek
                WrongInput();
                return(productFactory.CreateProduct("PCTower") as PCTower);
            }
            if (!pcTower.SetCPU(cpu))
            {
                //handle exception
                WrongInput();
                return(productFactory.CreateProduct("PCTower") as PCTower);
            }
            return(pcTower);
        }
        public Task <List <RenderFragment> > RenderPlaceholders(string placeholder, CancellationToken cancellationToken = default)
        {
            return(Task.Run(() =>
            {
                List <RenderFragment> list = new List <RenderFragment>();


                try
                {
                    IEnumerable <KeyValuePair <string, IList <Placeholder> > > placeHoldersList = _routeService.FlattenPlaceholders.Where(fp => fp.Key.ExtractPlaceholderName() == placeholder);

                    foreach (KeyValuePair <string, IList <Placeholder> > keyVal in placeHoldersList)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        foreach (Placeholder placeholderData in keyVal.Value)
                        {
                            cancellationToken.ThrowIfCancellationRequested();

                            if (placeholderData == null)
                            {
                                continue;
                            }

                            string keyName = $"{keyVal.Key}-{placeholderData.ComponentName}";

                            if (RenderedComponentsInDynamicPlaceholdersPerStateChanged.Any(comp => comp == keyName))
                            {
                                continue;
                            }


                            list.Add(_componentFactory.CreateComponent(placeholderData));

                            if (keyVal.Key.IsDynamicPlaceholder())
                            {
                                RenderedComponentsInDynamicPlaceholdersPerStateChanged.Add(keyName);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error RenderPlaceholders {ex.Message}");
                }

                return list;
            }, cancellationToken));
        }
Beispiel #16
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price,
                                   double overallPerformance, int generation)
        {
            CheckComputerExisting(computerId);
            if (this.components.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingComponentId);
            }
            IComponent comp = componentFactory.CreateComponent(id, componentType, manufacturer, model, price,
                                                               overallPerformance, generation);

            this.components.Add(comp);
            this.computers.First(x => x.Id == computerId).AddComponent(comp);
            return($"Component {componentType} with id {id} added successfully in computer with id {computerId}.");
        }
        public async void GetSpecificComponentNotFoundTest()
        {
            Location location1 = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location1));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.componentController.ComponentsGetById(request, 1, 5);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 200 OK
            Assert.Equal(404, result.StatusCode);
            // should return component not found errorresponse
            Assert.Equal(ErrorCode.COMPONENT_NOT_FOUND, errorResponse.ErrorCodeEnum);
        }
        public async void DeleteComponentAsAdminTest()
        {
            //create location and component
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            // create delete request
            HttpRequest deleteRequest = HttpRequestFactory.CreateDeleteRequest();

            OkResult result = (OkResult)await this.componentController.ComponentDelete(deleteRequest, 1, 1, this.adminClaim);

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // the account should be removed
            Assert.Empty(await this.componentRepository.ListAsync());
        }
        public async void DeleteComponentAsAdminNotFoundTest()
        {
            //create location and component
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            // create delete request
            HttpRequest deleteRequest = HttpRequestFactory.CreateDeleteRequest();

            ObjectResult result = (ObjectResult)await this.componentController.ComponentDelete(deleteRequest, 1, 5, this.adminClaim);

            ErrorResponse errorResponse = (ErrorResponse)result.Value;

            // status code should be 404 not found
            Assert.Equal(404, result.StatusCode);
            Assert.Equal(ErrorCode.COMPONENT_NOT_FOUND, errorResponse.ErrorCodeEnum);
        }
        public async void GetSpecificComponentTest()
        {
            Location location1 = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(2, location1));

            HttpRequest request = HttpRequestFactory.CreateGetRequest();

            ObjectResult result = (ObjectResult)await this.componentController.ComponentsGetById(request, 1, 1);

            ComponentResponse component = (ComponentResponse)result.Value;

            // status code should be 200 OK
            Assert.Equal(200, result.StatusCode);
            // check if the right location was found
            Assert.Equal(1, component.Id);
        }
        public async void UpdateComponentAsAdminImageToBigTest()
        {
            //create location and location
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            //begin building new component
            Dictionary <string, StringValues> formdata = new Dictionary <string, StringValues>();

            formdata.Add("Name", "Stippentrap");
            formdata.Add("Description", "Leg jij behendig als een antilope het stippenparcour af?");
            formdata.Add("Exercises", "1");
            AddExerciseToDatabase(1);

            HttpRequest requestmessage = await HttpRequestFactory.CreateFormDataRequest(formdata, HttpMethod.Put, "toBigImage");

            ObjectResult result = (ObjectResult)await this.componentController.ComponentUpdateById(requestmessage, 1, 1, this.adminClaim);

            // status code should be 400
            Assert.Equal(400, result.StatusCode);
        }
        public async void DeleteComponentAsNonAdminTest()
        {
            //create location and component
            Location location = await this.locationRepository.CreateAsync(LocationFactory.CreateLocation(1));

            await this.componentRepository.CreateAsync(ComponentFactory.CreateComponent(1, location));

            // create delete request
            HttpRequest deleteRequest = HttpRequestFactory.CreateDeleteRequest();

            ObjectResult resultUser = (ObjectResult)await this.componentController.ComponentDelete(deleteRequest, 1, 1, this.userClaim);

            ObjectResult resultOrganiser = (ObjectResult)await this.componentController.ComponentDelete(deleteRequest, 1, 1, this.organiserClaim);

            ErrorResponse errorMessageUser      = (ErrorResponse)resultUser.Value;
            ErrorResponse errorMessageOrganiser = (ErrorResponse)resultOrganiser.Value;

            // status code should be 403 FORBIDDEN
            Assert.Equal(403, resultUser.StatusCode);
            Assert.Equal(403, resultOrganiser.StatusCode);

            Assert.Equal(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS, errorMessageUser.ErrorCodeEnum);
            Assert.Equal(ErrorCode.UNAUTHORIZED_ROLE_NO_PERMISSIONS, errorMessageOrganiser.ErrorCodeEnum);
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            ComponentFactory componentFactory = new ComponentFactory();
            ProductFactory   productFactory   = new ProductFactory();
            SoftwareTypes    softwareTypes    = new SoftwareTypes();

            bool exit = false;

            while (!exit)
            {
                Console.WriteLine("Welcome to Our E-shop");
                Console.WriteLine("What would you like to buy ?\n " +
                                  "press 'a' for  PC tower\n" +
                                  "press 'b' for a PC screen\n" +
                                  "press 'c' for a Personal Computer\n" +
                                  "press 'd' for a Workstation\n" +
                                  "press 'e' to exit\n");


                string answer = Console.ReadLine();

                if (answer.Equals("a"))
                {
                    PCTower pcTower = ConfigurePCTower(componentFactory, productFactory);
                    if (!pcTower.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(pcTower);
                }
                else if (answer.Equals("b"))
                {
                    PCScreen pcScreen = ConfigurePCScreen(productFactory);
                    if (!pcScreen.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(pcScreen);
                }
                else if (answer.Equals("c"))
                {
                    PersonalComputer personalComputer = ConfigurePersonalComputer(componentFactory, productFactory);
                    if (!personalComputer.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(personalComputer);
                }
                else if (answer.Equals("d"))
                {
                    PersonalComputer personalComputer = ConfigurePersonalComputer(componentFactory, productFactory);
                    if (!personalComputer.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    Console.WriteLine("Please select one of the available softwares\n");
                    foreach (var type in softwareTypes.Types)
                    {
                        Console.WriteLine(type.Value + "\n");
                    }
                    answer = Console.ReadLine();
                    Software software = componentFactory.CreateComponent("Software") as Software;
                    if (!software.SetValue(answer))
                    {
                        WrongInput();
                        continue;
                    }

                    Workstation workstation = productFactory.CreateProduct("Workstation") as Workstation;
                    if (!workstation.SetPersonalComputer(personalComputer) || !workstation.SetSoftware(software))
                    {
                        continue;
                    }

                    if (!workstation.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }
                    PrintReceiptInfo(workstation);
                }
                else if (answer.Equals("e"))
                {
                    exit = true;
                }
                else
                {
                    WrongInput();
                }
            }
        }
        public BasicTestData(IElementTree componentTree)
        {
            var componentTemplateCollection = new ComponentTemplateProvider();
            var componentFactory            = new ComponentFactory(componentTemplateCollection);

            ComponentRoot                 = componentFactory.CreateComponent <VisualComponent>();
            ComponentRoot.Name            = "Root";
            ComponentRoot.Width           = RelativeLength.Infinity;
            ComponentRoot.Height          = RelativeLength.Infinity;
            ComponentRoot.LayoutDirection = LayoutDirection.Vertical;
            //componentTree.RootComponent = ComponentRoot;

            ComponentTop                  = componentFactory.CreateComponent <VisualComponent>();
            ComponentTop.Name             = "Top";
            ComponentTop.Width            = RelativeLength.Infinity;
            ComponentTop.Height           = new RelativeLength(50, UnitType.Pixel);
            ComponentRoot.LayoutDirection = LayoutDirection.Vertical;
            ComponentRoot.Children.Add(ComponentTop);

            ComponentBottom                 = componentFactory.CreateComponent <VisualComponent>();
            ComponentBottom.Name            = "Bottom";
            ComponentBottom.Width           = RelativeLength.Infinity;
            ComponentBottom.Height          = RelativeLength.Infinity;
            ComponentBottom.LayoutDirection = LayoutDirection.Horizontal;
            ComponentRoot.Children.Add(ComponentBottom);

            // LEFT
            ComponentLeft                 = componentFactory.CreateComponent <VisualComponent>();
            ComponentLeft.Name            = "Left";
            ComponentLeft.Width           = new RelativeLength(1, UnitType.Ratio);
            ComponentLeft.Height          = RelativeLength.NaN;
            ComponentLeft.LayoutDirection = LayoutDirection.Vertical;
            ComponentBottom.Children.Add(ComponentLeft);

            ComponentLeft1                = componentFactory.CreateComponent <VisualComponent>();
            ComponentLeft1.Name           = "Left1";
            ComponentLeft1.Width          = RelativeLength.Infinity;
            ComponentLeft1.Height         = new RelativeLength(40, UnitType.Pixel);
            ComponentRoot.LayoutDirection = LayoutDirection.Vertical;
            ComponentLeft.Children.Add(ComponentLeft1);

            ComponentLeft2                = componentFactory.CreateComponent <VisualComponent>();
            ComponentLeft2.Name           = "Left2";
            ComponentLeft2.Width          = RelativeLength.Infinity;
            ComponentLeft2.Height         = new RelativeLength(40, UnitType.Pixel);
            ComponentRoot.LayoutDirection = LayoutDirection.Vertical;
            ComponentLeft.Children.Add(ComponentLeft2);

            // RIGHT
            ComponentRight                 = componentFactory.CreateComponent <VisualComponent>();
            ComponentRight.Name            = "Right";
            ComponentRight.Width           = new RelativeLength(3, UnitType.Ratio);
            ComponentRight.Height          = RelativeLength.Infinity;
            ComponentRight.LayoutDirection = LayoutDirection.Vertical;
            ComponentBottom.Children.Add(ComponentRight);

            ComponentRight1               = componentFactory.CreateComponent <VisualComponent>();
            ComponentRight1.Name          = "Right1";
            ComponentRight1.Width         = RelativeLength.Infinity;
            ComponentRight1.Height        = new RelativeLength(40, UnitType.Pixel);
            ComponentRoot.LayoutDirection = LayoutDirection.Vertical;
            ComponentRight.Children.Add(ComponentRight1);

            ComponentRight2               = componentFactory.CreateComponent <VisualComponent>();
            ComponentRight2.Name          = "Right2";
            ComponentRight2.Width         = RelativeLength.Infinity;
            ComponentRight2.Height        = new RelativeLength(80, UnitType.Pixel);
            ComponentRoot.LayoutDirection = LayoutDirection.Vertical;
            ComponentRight.Children.Add(ComponentRight2);

            //componentTree.Restructure();
        }
Beispiel #25
0
        public static void Main()
        {
            List <Hardware> components = new List <Hardware>();
            List <Hardware> dump       = new List <Hardware>();
            string          input      = Console.ReadLine();

            while (input != "System Split")
            {
                if (input.StartsWith("Register"))
                {
                    input = input.Replace("Register", String.Empty);
                    try
                    {
                        ComponentFactory.CreateComponent(input, components);
                    }
                    catch (ArgumentException ex)
                    {
                        //Console.WriteLine(ex.Message);
                    }
                }
                else if (input.StartsWith("Release"))
                {
                    ComponentDestroyer.DestroyComponent(input, components);
                }
                else if (input.StartsWith("Analyze"))
                {
                    Console.WriteLine(SystemAnalizator.AnalyzeSystem(components));
                }
                else if (input.StartsWith("Dump"))
                {
                    if (input.StartsWith("DumpAnalyze"))
                    {
                        Console.WriteLine(SystemAnalizator.AnalyzeDump(dump));
                    }
                    else
                    {
                        ComponentDestroyer.DumpComponent(input, components, dump);
                    }
                }
                else if (input.StartsWith("Restore"))
                {
                    ComponentDestroyer.RestoreComponent(input, components, dump);
                }
                else if (input.StartsWith("Destroy"))
                {
                    ComponentDestroyer.DestroyComponentPermanently(input, dump);
                }
                else
                {
                    throw new ArgumentException("Invalid input");
                }

                input = Console.ReadLine();
            }

            var orderedHardwareComponents = components.OrderByDescending(x => x.GetType().Name);

            foreach (var comp in orderedHardwareComponents)
            {
                Console.WriteLine("Hardware Component - " + comp.Name);
                Console.WriteLine("Express Software Components - "
                                  + comp.SoftwareComponents.Count(x => x.GetType().Name == "ExpressSoftware"));
                Console.WriteLine("Light Software Components - "
                                  + comp.SoftwareComponents.Count(x => x.GetType().Name == "LightSoftware"));
                Console.WriteLine("Memory Usage: {0} / {1}", comp.SoftwareComponents.Sum(x => x.MemoryConsumption), comp.MaxMemory);
                Console.WriteLine("Capacity Usage: {0} / {1}", comp.SoftwareComponents.Sum(x => x.CapacityConsumption), comp.MaxCapacity);
                Console.WriteLine("Type: " + comp.GetType().Name.Replace("Hardware", String.Empty));
                if (comp.SoftwareComponents.Any())
                {
                    Console.WriteLine("Software Components: " + string.Join(", ", comp.SoftwareComponents.Select(x => x.Name)));
                }
                else
                {
                    Console.WriteLine("Software Components: None");
                }
            }
        }
Beispiel #26
0
    static void Main(string[] args)
    {
        List <HardwareComponent> hardwareComponents = new List <HardwareComponent>();
        List <SoftwareComponent> softwareComponents = new List <SoftwareComponent>();
        List <HardwareComponent> dumpedComponents   = new List <HardwareComponent>();
        string input = Console.ReadLine();

        while (input != "System Split")
        {
            if (input == "Analyze()")
            {
                AnalyzeData(hardwareComponents);
                input = Console.ReadLine();
                continue;
            }
            else if (input == "DumpAnalyze")
            {
                input = Console.ReadLine();
                continue;
            }

            string[]  commands         = input.Split(new char[] { ',', ' ', '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
            Component currentComponent = ComponentFactory.CreateComponent(input);

            string            targetedHardwareName = commands[1];
            HardwareComponent targetedComponent    = dumpedComponents.FirstOrDefault(x => x.Name == targetedHardwareName);
            if (input.Contains("Release"))
            {
                ReleaseSoftwareFromHardware(commands, hardwareComponents, softwareComponents);
            }
            else if (input.Contains("Dump") && commands.Length > 1)
            {
                dumpedComponents.Add(targetedComponent);
                hardwareComponents.Remove(targetedComponent);
            }
            else if (input.Contains("Restore"))
            {
                hardwareComponents.Add(targetedComponent);
                dumpedComponents.Remove(targetedComponent);
            }
            else if (input.Contains("Destroy"))
            {
                dumpedComponents.Remove(targetedComponent);
            }
            else if (input.Contains("Hardware"))
            {
                hardwareComponents.Add(currentComponent as HardwareComponent);
            }
            else if (input.Contains("Software"))
            {
                HardwareComponent desiredComponent = hardwareComponents.FirstOrDefault(x => x.Name == targetedHardwareName);
                softwareComponents.Add(currentComponent as SoftwareComponent);
                desiredComponent.ImportSoftware(currentComponent as SoftwareComponent);
            }
            input = Console.ReadLine();
        }
        foreach (var hardwareComponent in hardwareComponents.OrderByDescending(x => x.Type))
        {
            Console.WriteLine(hardwareComponent);
        }
    }
Beispiel #27
0
        public JsonDocEntity ProcessDocument()
        {
            var processComponent = ComponentFactory.CreateComponent(_docEntity.Type, _docConvertComponent);

            return(processComponent.ParseHtmlToEntity(processComponent.ConvertToHtml(_docEntity)));
        }