private void OnStoreResult()
        {
            var facade   = FacadeFactory.Create();
            var overview = facade.Get <ResultOverview>(Bootstrap.Results) as ResultOverview;

            if (overview != null)
            {
                // Build the result and store it
                var paoResult = new PAOResult();
                foreach (var item in RecentCards)
                {
                    var resultItem = new PAOResultItem();
                    FillResultItem(item, resultItem);

                    paoResult.Items.Add(resultItem);
                }

                // Add it to the overview.
                paoResult.Comment   = "Added at " + DateTime.Now.ToShortDateString();
                paoResult.DeckTitle = CurrentDeck.Title;
                overview.Add(paoResult);

                //TODO: Fire event that a reload is required in the result overview?
                var eventManager      = facade.Get <EventController>(Bootstrap.EventManager);
                var newCardGameResult = eventManager.GetEvent(Bootstrap.EventNewCardGame);

                newCardGameResult.Trigger();
            }
        }
Esempio n. 2
0
        public void Close(string pageId)
        {
            TabItem currentItem = null;

            var items = tabControl.Items;

            foreach (TabItem item in items)
            {
                if (item.Name.Equals(pageId))
                {
                    currentItem = item;
                    break;
                }
            }

            if (currentItem != null)
            {
                // Remove the TabItem
                tabControl.Items.Remove(currentItem);

                // Remove the associated view model
                var containerHelper = FacadeFactory.Create();
                containerHelper.Remove(pageId);
            }
        }
        public ResultPage(string id)
        {
            InitializeComponent();

            pageId = id;
            var containerFacade = FacadeFactory.Create();
            var vm = containerFacade.Get <ResultOverviewViewModel>(id);

            DataContext = vm;
        }
        private void InternalSaveFile(string filename)
        {
            var facade    = FacadeFactory.Create();
            var ioService = facade.Get <IIOService>(Bootstrap.IoService);

            if (ioService != null)
            {
                var results = resultDict.Values;
                ioService.SaveResult(results, filename);
            }
        }
Esempio n. 5
0
        public CardGame(string id)
        {
            InitializeComponent();

            this.id = id;

            var containerFacade = FacadeFactory.Create();
            var vm = containerFacade.Get <CardGameViewModel>(id);

            DataContext = vm;
        }
Esempio n. 6
0
        public Help(string id)
        {
            InitializeComponent();

            var containerHelper = FacadeFactory.Create();
            var vm = containerHelper.Get <HelpViewModel>(id);

            DataContext = vm;

            this.id = id;
        }
Esempio n. 7
0
        /// <summary>
        /// Closes the view model and the view.
        /// </summary>
        protected void InternalClose()
        {
            var id = page.GetId();

            var helper    = FacadeFactory.Create();
            var uiService = helper.Get <IUiService>();

            if (uiService != null)
            {
                uiService.Close(id);
            }
        }
        private IEnumerable <PAOResult> InternalLoadFile(string filename)
        {
            var facade    = FacadeFactory.Create();
            var ioService = facade.Get <IIOService>(Bootstrap.IoService);

            if (ioService != null)
            {
                var result = ioService.LoadResult(filename);
                return(result);
            }

            return(null);
        }
        private void OnSaveFile()
        {
            var facade    = FacadeFactory.Create();
            var uiService = facade.Get <IUiService>();

            try
            {
                InternalSaveFile(Source);
            }
            catch (IOServiceException serviceException)
            {
                uiService.ShowDialog(serviceException.Message, "Error");
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Construtor
        /// </summary>
        /// <param name="configuration">Configurações gerais da aplicação, passado por injeção de dependencia registrada no startup.cs</param>
        /// <param name="byCepSettings">Configurações da api utilizada para buscar cidades por CEP (Opção registrada no startup.cs)</param>
        /// <param name="autocompleteSettings">Configurações da api utilizada para buscar cidades para autocomplete (Opção registrada no startup.cs)</param>
        /// <param name="generalSettings">Configurações de funcionamento da aplicação (Opção registrada no startup.cs)</param>
        public CitiesController(IConfiguration configuration,
                                IOptionsSnapshot <CityByCepApiSettings> byCepSettings,
                                IOptionsSnapshot <CityAutocompleteApiSettings> autocompleteSettings,
                                IOptionsSnapshot <GeneralSettings> generalSettings)
        {
            _configuration   = configuration;
            _generalSettings = generalSettings.Value;

            _cityRepository        = new CityRepository(_configuration);
            _temperatureRepository = new TemperatureRepository(_configuration);

            _bycepFacade = FacadeFactory <City> .Create(byCepSettings.Value);

            _autocompleteFacade = FacadeFactory <City> .Create(autocompleteSettings.Value);
        }
        private void OnApplyChanges()
        {
            var facade = FacadeFactory.Create();

            resultOverview = facade.Get <ResultOverview>(Bootstrap.Results);
            if (resultOverview != null)
            {
                // Get the ID of the current id and get the instance
                var id   = CurrentResultOverview.Id;
                var item = resultOverview.PAOResults.Skip(id).First();

                item.Comment   = CurrentComment;
                item.DeckTitle = CurrentDeck;
                OnRefresh();
            }
        }
        //private void OnSelectedSource()
        //{
        //    var facade = new ContainerFacade();
        //    var uiService = facade.Get<IUiService>();

        //    var result = uiService.ShowOpenFileDialog();
        //    if (result != null)
        //    {
        //        Source = result;
        //        RaisePropertyChange("Source");
        //    }
        //}

        private void OnLoadFile()
        {
            var facade    = FacadeFactory.Create();
            var uiService = facade.Get <IUiService>();

            try
            {
                // Load the resutls and refresh the view
                var result = InternalLoadFile(Source);
                resultOverview = facade.Get <ResultOverview>(Bootstrap.Results);
                resultOverview.Reload(result);
                OnRefresh();
            }
            catch (IOServiceException serviceException)
            {
                uiService.ShowDialog(serviceException.Message, "Error");
            }
        }
        public ResultOverviewViewModel()
        {
            Close        = new DefaultCommand(OnClose);
            Refresh      = new DefaultCommand(OnRefresh);
            SaveFile     = new DefaultCommand(OnSaveFile);
            LoadFile     = new DefaultCommand(OnLoadFile);
            ApplyChanges = new DefaultCommand(OnApplyChanges, IsContentChanged);

            //SelectSource = new DefaultCommand(OnSelectedSource);

            var facade       = FacadeFactory.Create();
            var eventManager = facade.Get <EventController>(Bootstrap.EventManager);
            var newDataEvent = eventManager.GetEvent(Bootstrap.EventNewCardGame);

            newDataEvent.AddListener(this);


            OnRefresh();
        }
        private void OnRefresh()
        {
            var facade = FacadeFactory.Create();

            resultOverview = facade.Get <ResultOverview>(Bootstrap.Results);
            if (resultOverview != null)
            {
                Source = resultOverview.Source;

                // Create a list and and an ID integer to play with later.
                var list = new List <PAOResultOverview>();
                int id   = 0;

                // Use a temporary list instead of the enumeration of the instance, because we need to add tests items maybe.
                resultDict = new Dictionary <int, PAOResult>();
                var results = new List <PAOResult>();
                results.AddRange(resultOverview.PAOResults);

                //
                //  Create some fake results for debugging if enabled
                //
                AddDebugValues(results);
                foreach (var paoResult in results)
                {
                    var paoResultOverview = new PAOResultOverview(id);
                    paoResultOverview.Comment = paoResult.Comment;
                    paoResultOverview.Deck    = paoResult.DeckTitle;

                    list.Add(paoResultOverview);
                    resultDict.Add(id, paoResult);
                    id++;
                }

                // Refresh the UI
                Results = new ObservableCollection <PAOResultOverview>(list);
                RaisePropertyChange("Results");

                oldComment     = null;
                oldCurrentDeck = null;
                ApplyChanges.Refresh();
            }
        }
Esempio n. 15
0
        private void OpenPage(PageViewModel viewModel, PageSelection pageSelection)
        {
            var helper    = FacadeFactory.Create();
            var uiService = helper.Get <IUiService>();

            if (uiService != null)
            {
                var newId = name_prefix + nextId;

                // Step one: Creata a new view model
                helper.Add(viewModel, newId);

                // Step two : Create a new UI Element
                var page = uiService.CreatePage(pageSelection, newId);

                // Step three:  Add a link between them
                viewModel.Init(page);

                nextId++;
            }
        }
Esempio n. 16
0
        private void OnOpenResultOverview()
        {
            var helper    = FacadeFactory.Create();
            var uiService = helper.Get <IUiService>();

            if (uiService != null)
            {
                // Create or resuse the view model and view
                if (!helper.Exists(name_resultOverview))
                {
                    var viewModel = new ResultOverviewViewModel();
                    helper.Add(viewModel, name_resultOverview);
                    var page = uiService.ShowResultOverview(name_resultOverview);
                    viewModel.Init(page);
                }
                else
                {
                    uiService.ShowResultOverview(name_resultOverview);
                }
            }
        }
Esempio n. 17
0
        public void InitSettings()
        {
            var settings     = new GameSetting();
            var overview     = new ResultOverview();
            var ioService    = new IoService();
            var eventManager = new EventController();

            // Init the environment
            loader.InitDecks(settings);
            loader.InitResultOverview(overview, ioService);

            // Adds internal events for the app
            eventManager.Add(new Event(EventNewCardGame));

            // Finally add it to the IOC container
            var facade = FacadeFactory.Create();

            facade.AddUnique(settings, Settings);
            facade.AddUnique(overview, Results);
            facade.AddUnique(ioService, IoService);
            facade.AddUnique(eventManager, EventManager);
        }
Esempio n. 18
0
        public CardGameViewModel()
        {
            NextCards    = new DefaultCommand(OnNextCards);
            New          = new DefaultCommand(OnNew);
            Close        = new DefaultCommand(OnClose);
            MarkAsOk     = new DefaultCommand(() => OnMarkAs(true), IsRecallMode);
            MarkAsFailed = new DefaultCommand(() => OnMarkAs(false), IsRecallMode);
            MarkFlip     = new DefaultCommand(OnMarkFlip);
            SelectDeck   = new ParameterCommand(OnSelectDeck);
            Restart      = new DefaultCommand(OnRestart);
            StoreResult  = new DefaultCommand(OnStoreResult, IsRecallMode);

            // Init the decks
            var facade   = FacadeFactory.Create();
            var settings = facade.Get <GameSetting>(Bootstrap.Settings) as GameSetting;

            AvailableDecks = new ObservableCollection <DeckConfiguration>(settings.AvailableDecks);
            CurrentDeck    = AvailableDecks.First();

            // Start the game
            OnNew();
        }
Esempio n. 19
0
 protected T Facade <T>() where T : class, IFacade
 {
     return(FacadeFactory.Create <T>());
 }
Esempio n. 20
0
        private void MessageReceivedEvent(object sender, EventArgs e)
        {
            IResponseSender responseSender    = null;
            ReceivedMessage message           = null;
            string          rawMessageContent = String.Empty;

            try
            {
                message = (e as MessageEventArgs).Message;

                _log.DebugFormat("{0} Message Received: {1}", _processId, message);

                rawMessageContent = Helper.ConvertToTextBasedOnEncoding(message.Content, message.MessageContentType);

                _log.DebugFormat("{0} ReportRequest converted to text: {1}", _processId, rawMessageContent);

                object reportRequest = Activities.RequestHandler.Deserialize(rawMessageContent);

                ValidadeRequestData(reportRequest as ReportRequest, rawMessageContent);

                _log.DebugFormat("{0} ReportRequest deserialized", _processId);

                var facade = FacadeFactory.Create(reportRequest as ReportRequest);

                var data = facade.GetIt(reportRequest as ReportRequest);

                responseSender = ResponseSenderFactory.Create(reportRequest as ReportRequest);

                if (data == null)
                {
                    // send 204 no content
                    var response = CreateResponseForNoContentReport(reportRequest as ReportRequest);
                    responseSender.Send(response);
                    return;
                }


                var writer = ReportWriterFactory.Create(reportRequest as ReportRequest);

                //any time the writer finish creating the report, we automatically will send the status to the client
                writer.ReportCreated += responseSender.Send;

                writer.Write(data, reportRequest as ReportRequest);

                _log.DebugFormat("{0} MessageEventArgs", _processId);
            }
            catch (BadPayloadException ex)
            {
                //in this case, it is not possible to reply to the sender, since the payload has problems
                //so we will send a message to the async reports exception queue using an
                //appropriate routing key
                _log.Error(ex.BadPayloadMessage.Status.Message);
                _log.Error(ex.BadPayloadMessage.Status.Detail);
                _log.Error(ex.BadPayloadMessage.RawRequestData);


                var queueSender = ResponseSenderFactory.Create(ResponseProvider.MessageQueue);
                queueSender.Send(ex.BadPayloadMessage);
            }

            catch (RequestException ex)
            {
                _log.Error(ex.ResponseData.Status.Detail, ex);
                if (responseSender != null)
                {
                    responseSender.Send(ex.ResponseData);
                }
            }
            catch (Exception ex)
            {
                _log.Error("Unknown error", ex);
                var queueSender = ResponseSenderFactory.Create(ResponseProvider.MessageQueue);

                var statusData = new ComplexTypes.ResponseStatus();
                statusData.Detail     = Helpers.Response.AggregateExceptionMessages(ex);
                statusData.Message    = "Unknown Error";
                statusData.StatusCode = StatusCode._500_Internal_Server_Error;

                var badPayloadMessage = new BadPayloadMessage()
                {
                    RawRequestData = rawMessageContent,
                    Status         = statusData
                };


                queueSender.Send(badPayloadMessage);

                throw ex;
            }
        }
Esempio n. 21
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(ExceptionHandling));
            });

            services.AddSingleton(typeof(IConfiguration), Configuration);

            #region Configure external api's adapters dependecy injections

            services.Configure <CityByCepApiSettings>(Configuration.GetSection("CityByCepApiSettings"));
            services.Configure <TemperatureApiSettings>(Configuration.GetSection("TemperatureApiSettings"));
            services.Configure <CityAutocompleteApiSettings>(Configuration.GetSection("CityAutocompleteApiSettings"));
            services.Configure <GeneralSettings>(Configuration.GetSection("GeneralSettings"));

            #endregion

            #region Configure monitoring service (servive updates temperatures)

            var defaultTemperatureApiSettings = new TemperatureApiSettings();
            Configuration.Bind("TemperatureApiSettings", defaultTemperatureApiSettings);

            var generalSettings = new GeneralSettings();
            Configuration.Bind("GeneralSettings", generalSettings);

            services.AddSingleton(typeof(IHostedService), new MonitoringService(Configuration, generalSettings, FacadeFactory <Temperature> .Create(defaultTemperatureApiSettings)));

            #endregion

            #region Configure Swagger
            // Configurando o serviço de documentação do Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1",
                             new Info
                {
                    Title       = "Desafio Stone Pagamentos, monitoramento de temperaturas",
                    Version     = "v1",
                    Description = "Monitoramento de temperaturas das cidades cadastradas",
                    Contact     = new Contact
                    {
                        Name = "Leonardo Fernandes",
                        Url  = ""
                    }
                });

                string caminhoAplicacao =
                    PlatformServices.Default.Application.ApplicationBasePath;
                string nomeAplicacao =
                    PlatformServices.Default.Application.ApplicationName;
                string caminhoXmlDoc =
                    Path.Combine(caminhoAplicacao, $"{nomeAplicacao}.xml");

                c.IncludeXmlComments(caminhoXmlDoc);
            });

            #endregion
        }