public UsersController(IRestaurantInteractor restaurantInteractor, IDishInteractor dishInteractor, IUserInteractor userInteractor, IDishReviewInteractor dishReviewInteractor)
 {
     _restaurantInteractor = restaurantInteractor;
     _dishInteractor       = dishInteractor;
     _userInteractor       = userInteractor;
     _dishReviewInteractor = dishReviewInteractor;
 }
Esempio n. 2
0
        public static void Initialization(IUserAccount user, CancellationTokenSource cToken,
                                          IUserInteractor GUI)
        {
            if (!isInitialized)
            {
                userAccount = user;

                token = cToken;

                mainWindowGUI = GUI;

                lock (myLock)
                {
                    instance = new Server();
                }
                isInitialized = true;
            }
        }
Esempio n. 3
0
        public override void LoadFromNewProjectInformation(INewProjectInformation info)
        {
            if (info == null || info is TemplateSpecifiedNewProjectInformation == false)
            {
                return;
            }

            // At the moment, only NHibernate Helper has an inherited version of TemplateSpecifiedNewProjectInformation.
            // If we ever add inherit from TemplateSpecifiedNewProjectInformation in the Entity Provider,
            // then we'll need to re-think this code below:
            if (info.GetType() != typeof(TemplateSpecifiedNewProjectInformation))
            {
                return;
            }

            IUserInteractor userInteractor = customUserInteractor ?? editModelScreen;

            var newProjectInfo = (TemplateSpecifiedNewProjectInformation)info;

            newProjectInfo.RunCustomNewProjectLogic(this, userInteractor);
        }
Esempio n. 4
0
 public IUserInteractorProgressUpdatorAdapter(IUserInteractor interactor)
 {
     this.interactor = interactor;
 }
Esempio n. 5
0
 public Game()
 {
     Level          = 1;
     userInteractor = ConsoleInteractor.Single();
 }
Esempio n. 6
0
 public TopicMet(FileMaster fileMaster, IUserInteractor userInteractor)
 {
     this.fileMaster     = fileMaster;
     this.userInteractor = userInteractor;
 }
        public GameResult HostTheGame(
            PlayerInitializer playerInitializer1,
            PlayerInitializer playerInitializer2,
            IUserInteractor playerInteractor1,
            IUserInteractor playerInteractor2)
        {
            logger.Log(LogType.Arbiter, LogSeverity.Info, "Game started");

            this.playerInteractor1 = playerInteractor1;
            this.playerInteractor2 = playerInteractor2;
            var deckValidation1 = deckValidator.ValidateDeck(playerInitializer1.Deck, playerInitializer1.Class);
            var deckValidation2 = deckValidator.ValidateDeck(playerInitializer2.Deck, playerInitializer2.Class);

            if (!deckValidation1.IsOk || !deckValidation2.IsOk)
            {
                //TODO: figure out where to log the validator messages
                return(new GameResult()
                {
                    IsOk = false
                });
            }

            player1State = gameStatePreparator.Initialize(playerInitializer1);
            player2State = gameStatePreparator.Initialize(playerInitializer2);

            //TODO: gamble the right of first turn.
            //TODO: implement mulligan and initial draw here
            //TODO: add service for draws and fatigue
            for (int i = 0; i < ruleSet.HandStartingSize; i++)
            {
                var randomCardIndex = new Random().Next(0, player1State.Deck.Count);
                var card            = player1State.Deck[randomCardIndex];
                player1State.Deck.RemoveAt(randomCardIndex);
                player1State.Hand.Add(card);

                var randomCardIndex2 = new Random().Next(0, player2State.Deck.Count);
                var card2            = player2State.Deck[randomCardIndex2];
                player2State.Deck.RemoveAt(randomCardIndex2);
                player2State.Hand.Add(card);
            }

            isPlayerOneActive = true;
            var internalTurnNumber = 1;

            while (internalTurnNumber++ < ruleSet.TurnMaxCountPerGame)
            {
                var state = new ServerGameState()
                {
                    Me  = ActivePlayerState,
                    Opp = PassivePlayerState
                };

                state.Me.Events.Add(internalTurnNumber, new List <EventBase>());

                logger.Log(LogType.Arbiter, LogSeverity.Info, $"Turn {internalTurnNumber / 2} started for {state.Me.Player.Name}");

                // Add new non-empty mana crystal
                if (state.Me.Mana.PermanentManaCrystals < ruleSet.ManaStorageMaxCrystals)
                {
                    state.Me.Mana.AddManaCrystals(1, false);
                }

                // Refresh Permanent Mana Crystals
                state.Me.Mana.RefreshPermanentManaCrystals();

                //TODO: draw the card from the deck
                var randomCardIndex = new Random().Next(0, state.Me.Deck.Count);
                var card            = state.Me.Deck[randomCardIndex];
                state.Me.Deck.RemoveAt(randomCardIndex);
                state.Me.Hand.Add(card);

                //TODO: start of turn events here
                //TODO: update the state to both users
                //TODO: send the events
                var stateForActiveUser = gameStatePreparator.PrepareGameState(state);
                ActivePlayerInteractor.Update(stateForActiveUser);

                //TODO: add time limit for a user to interact
                while (true)
                {
                    var interaction           = ActivePlayerInteractor.Interact();
                    var interactionValidation = userInteractionProcessor.ValidateInteraction(stateForActiveUser, interaction);
                    if (!interactionValidation.IsOk)
                    {
                        //TODO: figure out where to log the validator messages
                        return(new GameResult()
                        {
                            IsOk = false
                        });
                    }

                    if (interaction is InteractionEndTurn)
                    {
                        break;
                    }

                    //TODO: send the events to other user
                    userInteractionProcessor.ProcessInteraction(state, interaction);
                    if (state.Me.LastTurnEvents.Any(x => x is EventCharacterDied && (x as EventCharacterDied).DiedCharacter == state.Opp.Player.Id))
                    {
                        logger.Log(LogType.Arbiter, LogSeverity.Info, $"{state.Me.Player.Name} Won");
                        logger.Log(LogType.Arbiter, LogSeverity.Info, $"After Game State: {JsonConvert.SerializeObject(state)}");

                        // TODO: find a more approriate way to stop the game
                        return(new GameResult()
                        {
                            IsOk = true,
                            IsFirstPlayerWon = isPlayerOneActive,
                            FinalState = state
                        });
                    }

                    stateForActiveUser = gameStatePreparator.PrepareGameState(state);
                    ActivePlayerInteractor.Update(stateForActiveUser);
                }

                // Burn Unused Mana
                state.Me.Mana.BurnTemporaryCrystals();

                //TODO: end of turn events here
                isPlayerOneActive = !isPlayerOneActive;
            }

            return(null);
        }
        public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor)
        {
            NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo;
            providerInfo.Clear();
            providerInfo.NhConfigFile = this.NhConfigFile;
            userInteractor.ShowWaitScreen("Loading from your existing NHibernate project");
            // Run this in its own thread
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork
                += (s, args) =>
                {
                    try
                    {
                        var loader = new ProjectLoader(new FileController(), new IUserInteractorProgressUpdatorAdapter(userInteractor), userInteractor);
                        var result = loader.LoadEntityModelFromCSProj(Filename, this.NhConfigFile);
                        args.Result = new RunResult { MappingSet = result.MappingSet, DatabaseLoader = result.DatabaseLoader, NhConfigFile = result.NhConfigFile, CsProjFile = result.CsProjFile };
                    }
                    catch (NHibernateLoaderException e)
                    {
                        //var sb = new StringBuilder();
                        //sb.Append("The HBM files [").Append(e.Filenames).AppendLine(
                        //    "] could not be loaded due to the following errors:");
                        //e.Errors.ForEach(err => sb.AppendLine(err.Message));
                        //sb.AppendLine("Please send this file to [email protected] so we can make our HBM Loader better.");

                        args.Result = new RunResult { ErrorOccurred = true, Exception = e };
                    }
                    catch (Exception e)
                    {
                        throw new NHibernateLoaderException(e.Message + Environment.NewLine + e.StackTrace, null, null);
                    }
                };

            worker.RunWorkerCompleted
                += (s, args) =>
                    {
                        if (args.Error != null)
                        {
                            userInteractor.RemoveWaitScreen();
                            providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();
                            throw new Exception("An error occurred in RunCustomNewProjectLogic. The inner exception is: " + args.Error.StackTrace, args.Error);
                            //System.Windows.Forms.Clipboard.SetText(args.Error.StackTrace);
                            //userInteractor.ShowError("An Error Occurred", args.Error.Message + Environment.NewLine + Environment.NewLine + "The stacktrace has been copied to the clipboard. Please email to [email protected]");
                            //providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();
                        }
                        else
                        {
                            var result = (RunResult)args.Result;
                            if (result.ErrorOccurred)
                            {
                                userInteractor.RemoveWaitScreen();
                                providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();

                                string errorMessage = string.Format("Unsupported elements or Schema Validation Errors occurred. Please submit this error.\nFiles: {0}", result.Exception.Filenames);
                                throw new Exception(errorMessage, result.Exception);
                                //var form = new NHibernateHBMLoadErrorView();
                                //form.Title = "Unsupported elements or Schema Validation Errors occurred";
                                //form.NameOfFileWithError = result.Exception.Filename;
                                //form.SetErrors(result.Exception.Errors);

                                //userInteractor.ShowDialog(form);

                            }
                            else
                            {
                                // Set the MappingSet to the result of our work.
                                providerInfo.EntityProviderInfo.MappingSet = result.MappingSet;
                                providerInfo.NhConfigFile = result.NhConfigFile;
                                providerInfo.CsProjFile = result.CsProjFile;

                                if (!string.IsNullOrEmpty(providerInfo.CsProjFile.GetProjectGuid()))
                                    ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectGuid", providerInfo.CsProjFile.GetProjectGuid());

                                ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("CacheProviderClass", providerInfo.NhConfigFile.cache_provider_class);

                                // Then run the validation rules
                                userInteractor.UpdateWaitScreen("Runnng Model Validation");
                                //var rulesEngine = new ValidationRulesEngine(result.MappingSet);
                                //var database = result.DatabaseLoader.LoadDatabase();
                                //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database));
                                providerInfo.EntityProviderInfo.RunValidationRules();//rulesEngine);

                                userInteractor.RemoveWaitScreen();
                            }
                        }
                    };

            worker.RunWorkerAsync();
        }
Esempio n. 9
0
 public Manager(IUserInteractor userInteractor)
 {
     this.userInteractor = userInteractor;
 }
Esempio n. 10
0
 public Input(FileMaster fileMaster, IUserInteractor userInteractor, TopicMet topicMet)
 {
     this.fileMaster     = fileMaster;
     this.userInteractor = userInteractor;
     this.topicMet       = topicMet;
 }
Esempio n. 11
0
 public ModeSelector(IUserInteractor userInteractor)
 {
     this.userInteractor = userInteractor;
 }
Esempio n. 12
0
 public ProjectLoader(IFileController fileController, IProgressUpdater progress, IUserInteractor userInteractor)
     : this(fileController)
 {
     _progress = progress;
     _userInteractor = userInteractor;
 }
Esempio n. 13
0
 public ServerManager(Socket listener, IUserInteractor userInteractor)
 {
     this.manager  = userInteractor;
     this.listener = listener;
 }
 public IUserInteractorProgressUpdatorAdapter(IUserInteractor interactor)
 {
     this.interactor = interactor;
 }
Esempio n. 15
0
        public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor)
        {
            //if (theProviderInfo is ArchAngel.Providers.EntityModel.ProviderInfo)
            //{
            //    ArchAngel.Providers.EntityModel.ProviderInfo providerInfo = (ArchAngel.Providers.EntityModel.ProviderInfo)theProviderInfo;
            //    providerInfo.Clear();
            //    return;
            //}

            try
            {
                log.Debug("Loading project...");
                userInteractor.UpdateWaitScreen("Loading project...");

                NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo;
                providerInfo.Clear();

                log.Debug("Loading database...");
                Database          database    = DatabaseLoader.LoadDatabase(DatabaseLoader.DatabaseObjectsToFetch, null);
                DatabaseProcessor dbProcessor = new DatabaseProcessor();
                dbProcessor.LogErrors = true;
                log.Debug("Creating relationships...");
                dbProcessor.CreateRelationships(database);

                if (dbProcessor.Errors.Count > 0)
                {
                    log.Debug("Database errors exist..." + dbProcessor.Errors.Count.ToString());
                    UI.FormErrors form = new UI.FormErrors("<b><font color='Red'>Note:</font></b> Database problems exist. Please <b>fix</b> these problems (or <b>omit the tables</b> in question) before trying again.", dbProcessor.Errors);
                    form.ShowDialog();
                    return;
                }
                log.Debug("Creating 1 to 1 mappings...");
                var mappingSet = new MappingProcessor(new OneToOneEntityProcessor())
                                 .CreateOneToOneMapping(database, this.TablePrefixes, this.ColumnPrefixes, this.TableSuffixes, this.ColumnSuffixes);

                foreach (var entity in mappingSet.EntitySet.Entities)
                {
                    ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.ExistingPropertyNames = new List <string>();

                    foreach (Property prop in entity.Properties)
                    {
                        IColumn mappedCol = prop.MappedColumn();

                        ArchAngel.Interfaces.Scripting.NHibernate.Model.IColumn scriptCol = new Interfaces.Scripting.NHibernate.Model.IColumn()
                        {
                            IsNullable = mappedCol.IsNullable,
                            //IsText =
                            Length       = mappedCol.Size,
                            Name         = mappedCol.Name,
                            ScriptObject = mappedCol,
                            Type         = mappedCol.OriginalDataType
                        };
                        prop.Name = ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.GetPropertyName(scriptCol);
                    }
                }
                providerInfo.EntityProviderInfo.MappingSet = mappingSet;
                /////////////////////////////////
                providerInfo.EntityProviderInfo.Engine.AddModule(new NHibernateProjectLoaderModule(database));
                // Then run the validation rules
                log.Debug("Validating model...");
                userInteractor.UpdateWaitScreen("Validating model...");
                //var rulesEngine = new ValidationRulesEngine(mappingSet);
                //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database));
                log.Debug("Running validation rules...");
                providerInfo.EntityProviderInfo.RunValidationRules();                //rulesEngine);
            }
            //catch (Exception ex)
            //{
            //    MessageBox.
            //}
            finally
            {
                log.Debug("Removing wait screen...");
                userInteractor.RemoveWaitScreen();
            }
        }
Esempio n. 16
0
 public abstract void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo providerInfo, IUserInteractor userInteractor);
Esempio n. 17
0
        public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor)
        {
            NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo;
            providerInfo.Clear();
            providerInfo.NhConfigFile = this.NhConfigFile;
            userInteractor.ShowWaitScreen("Loading from your existing NHibernate project");
            // Run this in its own thread
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork
                += (s, args) =>
                {
                try
                {
                    var loader = new ProjectLoader(new FileController(), new IUserInteractorProgressUpdatorAdapter(userInteractor), userInteractor);
                    var result = loader.LoadEntityModelFromCSProj(Filename, this.NhConfigFile);
                    args.Result = new RunResult {
                        MappingSet = result.MappingSet, DatabaseLoader = result.DatabaseLoader, NhConfigFile = result.NhConfigFile, CsProjFile = result.CsProjFile
                    };
                }
                catch (NHibernateLoaderException e)
                {
                    //var sb = new StringBuilder();
                    //sb.Append("The HBM files [").Append(e.Filenames).AppendLine(
                    //    "] could not be loaded due to the following errors:");
                    //e.Errors.ForEach(err => sb.AppendLine(err.Message));
                    //sb.AppendLine("Please send this file to [email protected] so we can make our HBM Loader better.");

                    args.Result = new RunResult {
                        ErrorOccurred = true, Exception = e
                    };
                }
                catch (Exception e)
                {
                    throw new NHibernateLoaderException(e.Message + Environment.NewLine + e.StackTrace, null, null);
                }
                };

            worker.RunWorkerCompleted
                += (s, args) =>
                {
                if (args.Error != null)
                {
                    userInteractor.RemoveWaitScreen();
                    providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();
                    throw new Exception("An error occurred in RunCustomNewProjectLogic. The inner exception is: " + args.Error.StackTrace, args.Error);
                    //System.Windows.Forms.Clipboard.SetText(args.Error.StackTrace);
                    //userInteractor.ShowError("An Error Occurred", args.Error.Message + Environment.NewLine + Environment.NewLine + "The stacktrace has been copied to the clipboard. Please email to [email protected]");
                    //providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();
                }
                else
                {
                    var result = (RunResult)args.Result;
                    if (result.ErrorOccurred)
                    {
                        userInteractor.RemoveWaitScreen();
                        providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();

                        string errorMessage = string.Format("Unsupported elements or Schema Validation Errors occurred. Please submit this error.\nFiles: {0}", result.Exception.Filenames);
                        throw new Exception(errorMessage, result.Exception);
                        //var form = new NHibernateHBMLoadErrorView();
                        //form.Title = "Unsupported elements or Schema Validation Errors occurred";
                        //form.NameOfFileWithError = result.Exception.Filename;
                        //form.SetErrors(result.Exception.Errors);

                        //userInteractor.ShowDialog(form);
                    }
                    else
                    {
                        // Set the MappingSet to the result of our work.
                        providerInfo.EntityProviderInfo.MappingSet = result.MappingSet;
                        providerInfo.NhConfigFile = result.NhConfigFile;
                        providerInfo.CsProjFile   = result.CsProjFile;

                        if (!string.IsNullOrEmpty(providerInfo.CsProjFile.GetProjectGuid()))
                        {
                            ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectGuid", providerInfo.CsProjFile.GetProjectGuid());
                        }

                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("CacheProviderClass", providerInfo.NhConfigFile.cache_provider_class);

                        // Then run the validation rules
                        userInteractor.UpdateWaitScreen("Runnng Model Validation");
                        //var rulesEngine = new ValidationRulesEngine(result.MappingSet);
                        //var database = result.DatabaseLoader.LoadDatabase();
                        //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database));
                        providerInfo.EntityProviderInfo.RunValidationRules();                                        //rulesEngine);

                        userInteractor.RemoveWaitScreen();
                    }
                }
                };

            worker.RunWorkerAsync();
        }
Esempio n. 18
0
 public abstract void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo providerInfo, IUserInteractor userInteractor);
Esempio n. 19
0
 public ProjectLoader(IFileController fileController, IProgressUpdater progress, IUserInteractor userInteractor)
     : this(fileController)
 {
     _progress       = progress;
     _userInteractor = userInteractor;
 }
        public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor)
        {
            //if (theProviderInfo is ArchAngel.Providers.EntityModel.ProviderInfo)
            //{
            //    ArchAngel.Providers.EntityModel.ProviderInfo providerInfo = (ArchAngel.Providers.EntityModel.ProviderInfo)theProviderInfo;
            //    providerInfo.Clear();
            //    return;
            //}

            try
            {
                log.Debug("Loading project...");
                userInteractor.UpdateWaitScreen("Loading project...");

                NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo;
                providerInfo.Clear();

                log.Debug("Loading database...");
                Database database = DatabaseLoader.LoadDatabase(DatabaseLoader.DatabaseObjectsToFetch, null);
                DatabaseProcessor dbProcessor = new DatabaseProcessor();
                dbProcessor.LogErrors = true;
                log.Debug("Creating relationships...");
                dbProcessor.CreateRelationships(database);

                if (dbProcessor.Errors.Count > 0)
                {
                    log.Debug("Database errors exist..." + dbProcessor.Errors.Count.ToString());
                    UI.FormErrors form = new UI.FormErrors("<b><font color='Red'>Note:</font></b> Database problems exist. Please <b>fix</b> these problems (or <b>omit the tables</b> in question) before trying again.", dbProcessor.Errors);
                    form.ShowDialog();
                    return;
                }
                log.Debug("Creating 1 to 1 mappings...");
                var mappingSet = new MappingProcessor(new OneToOneEntityProcessor())
                    .CreateOneToOneMapping(database, this.TablePrefixes, this.ColumnPrefixes, this.TableSuffixes, this.ColumnSuffixes);

                foreach (var entity in mappingSet.EntitySet.Entities)
                {
                    ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.ExistingPropertyNames = new List<string>();

                    foreach (Property prop in entity.Properties)
                    {
                        IColumn mappedCol = prop.MappedColumn();

                        ArchAngel.Interfaces.Scripting.NHibernate.Model.IColumn scriptCol = new Interfaces.Scripting.NHibernate.Model.IColumn()
                        {
                            IsNullable = mappedCol.IsNullable,
                            //IsText =
                            Length = mappedCol.Size,
                            Name = mappedCol.Name,
                            ScriptObject = mappedCol,
                            Type = mappedCol.OriginalDataType
                        };
                        prop.Name = ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.GetPropertyName(scriptCol);
                    }
                }
                providerInfo.EntityProviderInfo.MappingSet = mappingSet;
                /////////////////////////////////
                providerInfo.EntityProviderInfo.Engine.AddModule(new NHibernateProjectLoaderModule(database));
                // Then run the validation rules
                log.Debug("Validating model...");
                userInteractor.UpdateWaitScreen("Validating model...");
                //var rulesEngine = new ValidationRulesEngine(mappingSet);
                //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database));
                log.Debug("Running validation rules...");
                providerInfo.EntityProviderInfo.RunValidationRules();//rulesEngine);
            }
            //catch (Exception ex)
            //{
            //    MessageBox.
            //}
            finally
            {
                log.Debug("Removing wait screen...");
                userInteractor.RemoveWaitScreen();
            }
        }