public SuperAdminAuthentication(ActionNames redirectToAction = ActionNames.AccessDenied, params string[] roles)
 {
     _redirectToAction = redirectToAction;
     _acceptedRoles    = roles.ToList();
     _acceptedRoles.Add(UserRole.SuperAdmin.ToString());
     _authenticationError = Error.AuthenticationError;
 }
Exemple #2
0
        public void EnumerateActionsStartingWith(ActionNames currentAction, ActionNames expectedAction)
        {
            var enumerator = Action.EnumerateActionsStartingWith(currentAction).GetEnumerator();

            enumerator.MoveNext();             // moves us to currentAction
            enumerator.MoveNext();             // moves us to the first after currentAction
            Assert.That(enumerator.Current, Is.EqualTo(expectedAction));
        }
 public static bool CheckForAction(this Charakter charakter, ActionNames action)
 {
     if (charakter.Actions.Contains(action))
     {
         return(true);
     }
     return(false);
 }
Exemple #4
0
        public static int StartLfMerge(string projectCode, ActionNames action,
                                       string modelVersion, bool allowFreshClone, string configDir = null)
        {
            // Call the correct model version specific LfMerge executable
            if (string.IsNullOrEmpty(modelVersion))
            {
                modelVersion = ModelVersion;
            }

            MainClass.Logger.Notice("Starting LfMerge for model version '{0}'", modelVersion);
            var startInfo = new ProcessStartInfo();
            var argsBldr  = new StringBuilder();

            if (Platform.IsMono)
            {
                startInfo.FileName = "mono";
                argsBldr.Append("--debug LfMerge.exe");
            }
            else
            {
                startInfo.FileName = "LfMerge.exe";
            }

            argsBldr.AppendFormat(" -p {0} --action {1}", projectCode, action);
            if (allowFreshClone)
            {
                argsBldr.Append(" --clone");
            }
            if (FwProject.AllowDataMigration)
            {
                argsBldr.Append(" --migrate");
            }
            if (!string.IsNullOrEmpty(configDir))
            {
                argsBldr.AppendFormat(" --config \"{0}\"", configDir);
            }
            startInfo.Arguments        = argsBldr.ToString();
            startInfo.CreateNoWindow   = true;
            startInfo.ErrorDialog      = false;
            startInfo.UseShellExecute  = false;
            startInfo.WorkingDirectory = GetModelSpecificDirectory(modelVersion);
            try
            {
                using (var process = Process.Start(startInfo))
                {
                    process.WaitForExit();
                    return(process.ExitCode);
                }
            }
            catch (Exception e)
            {
                MainClass.Logger.Error(
                    "{0}-{1}: Unhandled exception trying to start '{2}' '{3}' in '{4}'\n{5}",
                    Assembly.GetEntryAssembly().GetName().Name, ModelVersion, startInfo.FileName,
                    startInfo.Arguments, startInfo.WorkingDirectory, e);
                return(1);                // TODO: Decide what error code to return for unhandled exceptions
            }
        }
Exemple #5
0
        public static IAction GetAction(ActionNames actionName)
        {
            var action         = MainClass.Container.ResolveKeyed <IAction>(actionName);
            var actionAsAction = action as Action;

            if (actionAsAction != null)
            {
                actionAsAction.Name = actionName;
            }
            return(action);
        }
Exemple #6
0
        public void NextAction(QueueNames queueName, ActionNames[] expectedActionNames)
        {
            var actions = new List<ActionNames>();
            for (var sut = Queue.GetQueue(queueName).CurrentAction;
                sut != null;
                sut = sut.NextAction)
            {
                actions.Add(sut.Name);
            }

            Assert.That(actions, Is.EquivalentTo(expectedActionNames));
        }
Exemple #7
0
        public void State(ActionNames actionName, ProcessingState.SendReceiveStates expectedState)
        {
            // Setup
            var lfProj = LanguageForgeProject.Create("proja");
            var sut    = Action.GetAction(actionName);

            // Exercise
            sut.Run(lfProj);

            // Verify
            Assert.That(ProcessState.SavedStates, Is.EqualTo(new[] { expectedState }));
            Assert.That(lfProj.State.SRState, Is.EqualTo(expectedState));
        }
Exemple #8
0
        public void State(ActionNames actionName, ProcessingState.SendReceiveStates expectedState)
        {
            // Setup
            var lfProj = LanguageForgeProject.Create(_env.Settings, "proja");
            var sut = Action.GetAction(actionName);

            // Exercise
            sut.Run(lfProj);

            // Verify
            Assert.That(ProcessState.SavedStates, Is.EqualTo(new[] { expectedState }));
            Assert.That(lfProj.State.SRState, Is.EqualTo(expectedState));
        }
Exemple #9
0
 public static QueueNames GetQueueForAction(ActionNames action)
 {
     switch (action)
     {
         case ActionNames.TransferMongoToFdo:
         case ActionNames.Synchronize:
             return QueueNames.Synchronize;
         case ActionNames.Commit:
         case ActionNames.None:
         case ActionNames.Edit:
         case ActionNames.TransferFdoToMongo:
             break;
     }
     return QueueNames.None;
 }
Exemple #10
0
        public static QueueNames GetQueueForAction(ActionNames action)
        {
            switch (action)
            {
            case ActionNames.TransferMongoToFdo:
            case ActionNames.Synchronize:
                return(QueueNames.Synchronize);

            case ActionNames.Commit:
            case ActionNames.None:
            case ActionNames.Edit:
            case ActionNames.TransferFdoToMongo:
                break;
            }
            return(QueueNames.None);
        }
Exemple #11
0
 public static IQueue GetNextQueueWithWork(ActionNames currentAction)
 {
     foreach (var action in Actions.Action.EnumerateActionsStartingWith(currentAction))
     {
         var queueName = GetQueueForAction(action);
         if (queueName != QueueNames.None)
         {
             var queue = GetQueue(queueName);
             if (!queue.IsEmpty)
             {
                 return(queue);
             }
         }
     }
     return(null);
 }
Exemple #12
0
        public void State_SkipsHoldState(ActionNames actionName)
        {
            // Setup
            var lfProj = LanguageForgeProject.Create("proja");
            var state  = Factory.Deserialize("proja") as ProcessingStateDouble;

            state.SRState = ProcessingState.SendReceiveStates.HOLD;
            state.ResetSavedStates();
            Factory.State = state;
            var sut = Action.GetAction(actionName);

            // Exercise
            sut.Run(lfProj);

            // Verify
            Assert.That(ProcessState.SavedStates, Is.Empty);
        }
Exemple #13
0
        internal static IEnumerable <ActionNames> EnumerateActionsStartingWith(ActionNames currentAction)
        {
            yield return(currentAction);

            var action = currentAction;

            do
            {
                action++;
                if (action > ActionNames.TransferLcmToMongo)
                {
                    action = 0;
                }
                yield return(action);
            } while (action != currentAction);

            yield return(ActionNames.None);
        }
Exemple #14
0
 private async Task DoAction(ActionNames actionName, string actionText, WebSocket socket, WebSocket otherSocket)
 {
     Logger.LogInformation($"Doing action: {actionName}");
     if (actionName == ActionNames.movesMade)
     {
         Game.ThinkStart = DateTime.Now;
         var action = (MovesMadeActionDto)JsonSerializer.Deserialize(actionText, typeof(MovesMadeActionDto));
         if (socket == Client1)
         {
             Game.BlackPlayer.FirstMoveMade = true;
         }
         else
         {
             Game.WhitePlayer.FirstMoveMade = true;
         }
         DoMoves(action);
         await NewTurn(socket);
     }
     else if (actionName == ActionNames.opponentMove)
     {
         var action = (OpponentMoveActionDto)JsonSerializer.Deserialize(actionText, typeof(OpponentMoveActionDto));
         _ = Send(otherSocket, action);
     }
     else if (actionName == ActionNames.undoMove)
     {
         var action = (UndoActionDto)JsonSerializer.Deserialize(actionText, typeof(UndoActionDto));
         _ = Send(otherSocket, action);
     }
     else if (actionName == ActionNames.connectionInfo)
     {
         var action = (ConnectionInfoActionDto)JsonSerializer.Deserialize(actionText, typeof(ConnectionInfoActionDto));
         _ = Send(otherSocket, action);
     }
     else if (actionName == ActionNames.resign)
     {
         var winner = Client1 == otherSocket ? PlayerColor.black : PlayerColor.white;
         _ = Resign(winner);
     }
     else if (actionName == ActionNames.exitGame)
     {
         _ = CloseConnections(socket);
     }
 }
Exemple #15
0
        private void ParseHtmlActionLists(string input)
        {
            var actions = Regex.Split(input, "<p><em><strong>");

            foreach (var action in actions)
            {
                if (!string.IsNullOrEmpty(action))
                {
                    try
                    {
                        var kvp = Regex.Split(action, @"</strong></em>");
                        ActionNames.Add(StripHtmlTags(kvp[0]));
                        ActionValues.Add(StripHtmlTags(kvp[1]));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Exemple #16
0
    public void Show(string newText = "", ActionNames actionName = ActionNames.Default)
    {
        Initialize();

        if (newText != "")
        {
            interractText.text = newText;
        }
        else
        {
            interractText.text = originalInterractText;
        }


        Hide();

        interractText.gameObject.SetActive(true);

        SpriteRenderer xboxIcon     = allIcons.Find(icon => icon.name == ("Xbox" + actionName.ToString()));
        SpriteRenderer keyboardIcon = allIcons.Find(icon => icon.name == ("Keyboard" + actionName.ToString()));



        if (ControllerHelper.IsXboxControllerPluggedIn())
        {
            xboxIcon.enabled     = true;
            keyboardIcon.enabled = false;

            HideAnimationOfIcon(keyboardIcon);
            ShowAnimationOfIcon(xboxIcon);
        }
        else
        {
            keyboardIcon.enabled = true;
            xboxIcon.enabled     = false;

            HideAnimationOfIcon(xboxIcon);
            ShowAnimationOfIcon(keyboardIcon);
        }
    }
        public LGSPSequenceGenerator(IGraphModel model, ActionsTypeInformation actionsTypeInformation,
                                     bool fireDebugEvents, bool emitProfiling)
        {
            this.model = model;

            this.actionNames = new ActionNames(actionsTypeInformation);

            this.env = new SequenceCheckingEnvironmentCompiled(actionNames, actionsTypeInformation, model);

            this.seqHelper = new SequenceGeneratorHelper(model, actionsTypeInformation, env);

            SequenceExpressionGenerator exprGen = new SequenceExpressionGenerator(model, env, seqHelper);

            this.seqHelper.SetSequenceExpressionGenerator(exprGen);

            SequenceComputationGenerator compGen = new SequenceComputationGenerator(model, env, exprGen, seqHelper, fireDebugEvents);

            this.seqGen = new SequenceGenerator(model, env, compGen, exprGen, seqHelper, fireDebugEvents, emitProfiling);

            this.neededEntitiesEmitter = new NeededEntitiesEmitter(seqHelper);

            this.fireDebugEvents = fireDebugEvents;
            this.emitProfiling   = emitProfiling;
        }
Exemple #18
0
 /// <summary>
 /// Creates the environment that sets the context for the sequence parser, containing the entitites and types that can be referenced.
 /// Used for the compiled xgrs.
 /// </summary>
 /// <param name="packageContext">The name of the package the sequence is contained in (defining some context), null if it is not contained in a package.</param>
 /// <param name="actionNames">Contains the names of the different kinds of actions used in the specification.</param>
 /// <param name="model">The model used in the specification.</param>
 public SequenceParserEnvironmentCompiled(String packageContext, ActionNames actionNames, IGraphModel model)
     : base(model)
 {
     this.actionNames    = actionNames;
     this.packageContext = packageContext;
 }
        private async Task DoAction(ActionNames actionName, string actionText, WebSocket socket, WebSocket otherSocket)
        {
            Logger.LogInformation($"Doing action: {actionName}");
            if (actionName == ActionNames.movesMade)
            {
                Game.ThinkStart = DateTime.Now;
                var action = (MovesMadeActionDto)JsonSerializer.Deserialize(actionText, typeof(MovesMadeActionDto));
                if (socket == Client1)
                {
                    Game.BlackPlayer.FirstMoveMade = true;
                }
                else
                {
                    Game.WhitePlayer.FirstMoveMade = true;
                }
                DoMoves(action);
                await NewTurn(socket);
            }
            else if (actionName == ActionNames.opponentMove)
            {
                var action = (OpponentMoveActionDto)JsonSerializer.Deserialize(actionText, typeof(OpponentMoveActionDto));
                _ = Send(otherSocket, action);
            }
            else if (actionName == ActionNames.undoMove)
            {
                var action = (UndoActionDto)JsonSerializer.Deserialize(actionText, typeof(UndoActionDto));
                _ = Send(otherSocket, action);
            }
            else if (actionName == ActionNames.rolled)
            {
                var action = (ActionDto)JsonSerializer.Deserialize(actionText, typeof(ActionDto));
                _ = Send(otherSocket, action);
            }
            else if (actionName == ActionNames.requestedDoubling)
            {
                if (!Game.IsGoldGame)
                {
                    throw new ApplicationException("requestedDoubling should not be possible in a non gold game");
                }

                var action = (DoublingActionDto)JsonSerializer.Deserialize(actionText, typeof(DoublingActionDto));
                action.moveTimer = Game.ClientCountDown;

                Game.ThinkStart = DateTime.Now;
                Game.SwitchPlayer();
                if (AisTurn())
                {
                    if (Engine.AcceptDoubling())
                    {
                        DoDoubling();
                        Game.SwitchPlayer();
                        await Task.Delay(2000);

                        _ = Send(socket, new DoublingActionDto
                        {
                            actionName = ActionNames.acceptedDoubling,
                            moveTimer  = Game.ClientCountDown
                        });
                    }
                    else
                    {
                        await Resign((PlayerColor)Game.OtherPlayer());
                    }
                }
                else
                {
                    _ = Send(otherSocket, action);
                }
            }
            else if (actionName == ActionNames.acceptedDoubling)
            {
                if (!Game.IsGoldGame)
                {
                    throw new ApplicationException("acceptedDoubling should not be possible in a non gold game");
                }
                var action = (DoublingActionDto)JsonSerializer.Deserialize(actionText, typeof(DoublingActionDto));
                action.moveTimer = Game.ClientCountDown;
                Game.ThinkStart  = DateTime.Now;
                DoDoubling();
                Game.SwitchPlayer();
                _ = Send(otherSocket, action);
            }
            else if (actionName == ActionNames.connectionInfo)
            {
                var action = (ConnectionInfoActionDto)JsonSerializer.Deserialize(actionText, typeof(ConnectionInfoActionDto));
                _ = Send(otherSocket, action);
            }
            else if (actionName == ActionNames.resign)
            {
                var winner = Client1 == otherSocket ? PlayerColor.black : PlayerColor.white;
                _ = Resign(winner);
            }
            else if (actionName == ActionNames.exitGame)
            {
                _ = CloseConnections(socket);
            }
        }
Exemple #20
0
 public void GetQueueFromAction(ActionNames action, QueueNames expectedQueue)
 {
     Assert.That(Queue.GetQueueForAction(action), Is.EqualTo(expectedQueue));
 }
Exemple #21
0
        public void CurrentAction_Works(QueueNames queueName, ActionNames expectedAction)
        {
            var sut = Queue.GetQueue(queueName);

            Assert.That(sut.CurrentActionName, Is.EqualTo(expectedAction));
        }
Exemple #22
0
 public void GetQueueFromAction(ActionNames action, QueueNames expectedQueue)
 {
     Assert.That(Options.GetQueueForAction(action), Is.EqualTo(expectedQueue));
 }
Exemple #23
0
 public DisableUser(ActionNames redirectToAction = ActionNames.ForceLogoffUser, ControllerNames redirectToController = ControllerNames.Account)
 {
     _redirectToResult     = redirectToAction;
     _redirectToController = redirectToController;
 }
Exemple #24
0
        public void State_SkipsHoldState(ActionNames actionName)
        {
            // Setup
            var lfProj = LanguageForgeProject.Create(_env.Settings, "proja");
            var state = Factory.Deserialize("proja") as ProcessingStateDouble;
            state.SRState = ProcessingState.SendReceiveStates.HOLD;
            state.ResetSavedStates();
            Factory.State = state;
            var sut = Action.GetAction(actionName);

            // Exercise
            sut.Run(lfProj);

            // Verify
            Assert.That(ProcessState.SavedStates, Is.Empty);
        }
Exemple #25
0
 public BaseStackedWindowControlAction(ActionNames actionName)
 {
     this.actionName = actionName.ToString();
 }
Exemple #26
0
 public IAction this[ActionNames name]
 {
     get { return(this[name.ToString()]); }
 }
Exemple #27
0
 public void GetNextAction(ActionNames currentAction, ActionNames expectedAction)
 {
     var option = new Options();
     Assert.That(option.GetNextAction(currentAction), Is.EqualTo(expectedAction));
 }
Exemple #28
0
        // REVIEW: improve naming of this method. This method returns the next action for the
        // purpose of enumerating over all actions. It doesn't return the next action that should
        // logically be run. That is returned by IAction.NextAction.
        public ActionNames GetNextAction(ActionNames currentAction)
        {
            int nextAction = ((int)currentAction) + 1;

            if (nextAction > (int)ActionNames.TransferFdoToMongo)
                nextAction = 0;
            return (ActionNames)nextAction;
        }
Exemple #29
0
        public static int StartLfMerge(string projectCode, ActionNames action,
                                       string modelVersion, bool allowFreshClone)
        {
            if (string.IsNullOrEmpty(modelVersion))
            {
                // This can happen if we haven't cloned the project yet
                modelVersion = ModelVersion;
            }

            if (!IsSupportedModelVersion(modelVersion))
            {
                var project = LanguageForgeProject.Create(projectCode);
                var message = $"Project '{projectCode}' has unsupported model version '{modelVersion}'.";
                Logger.Error(message);
                project.State.SetErrorState(ProcessingState.SendReceiveStates.ERROR,
                                            ProcessingState.ErrorCodes.UnsupportedModelVersion, message);
                return(2);
            }

            // Call the correct model version specific LfMerge executable
            if (string.IsNullOrEmpty(modelVersion))
            {
                modelVersion = ModelVersion;
            }

            Logger.Notice("Starting LfMerge for model version '{0}'", modelVersion);
            var startInfo = new ProcessStartInfo();
            var argsBldr  = new StringBuilder();
            var startInfoWorkingDirectory = GetModelSpecificDirectory(modelVersion);

            startInfo.FileName = Path.Combine(startInfoWorkingDirectory, "startlfmerge");

            argsBldr.AppendFormat(" -p {0} --action {1}", projectCode, action);
            if (allowFreshClone)
            {
                argsBldr.Append(" --clone");
            }
            if (FwProject.AllowDataMigration)
            {
                argsBldr.Append(" --migrate");
            }
            startInfo.Arguments = argsBldr.ToString();
            Logger.Notice("About to run ({0}) with args ({1})", startInfo.FileName, startInfo.Arguments);
            startInfo.CreateNoWindow   = true;
            startInfo.ErrorDialog      = false;
            startInfo.UseShellExecute  = false;
            startInfo.WorkingDirectory = startInfoWorkingDirectory;
            try
            {
                using (var process = Process.Start(startInfo))
                {
                    process.WaitForExit();
                    return(process.ExitCode);
                }
            }
            catch (Exception e)
            {
                Logger.Error(
                    "{0}-{1}: Unhandled exception trying to start '{2}' '{3}' in '{4}'\n{5}",
                    Assembly.GetEntryAssembly().GetName().Name, ModelVersion, startInfo.FileName,
                    startInfo.Arguments, startInfo.WorkingDirectory, e);
                return(1);                // TODO: Decide what error code to return for unhandled exceptions
            }
        }
Exemple #30
0
        private static string RunAction(string projectCode, ActionNames currentAction)
        {
            LanguageForgeProject project = null;
            var stopwatch = new Stopwatch();

            try
            {
                MainClass.Logger.Notice("ProjectCode {0}", projectCode);
                project = LanguageForgeProject.Create(projectCode);

                project.State.StartTimestamp = CurrentUnixTimestamp();
                stopwatch.Start();

                if (Options.Current.CloneProject)
                {
                    var cloneLocation = project.ProjectDir;
                    if (Directory.Exists(cloneLocation) && !File.Exists(project.FwDataPath))
                    {
                        // If we a .hg directory but no project file it means the previous clone
                        // was not finished, so remove and start over
                        MainClass.Logger.Notice("Cleaning out previous failed clone at {0}", cloneLocation);
                        Directory.Delete(cloneLocation, true);
                        project.State.SRState = ProcessingState.SendReceiveStates.CLONING;
                    }
                }

                var ensureClone = LfMerge.Core.Actions.Action.GetAction(ActionNames.EnsureClone);
                ensureClone.Run(project);

                if (ChorusHelper.RemoteDataIsForDifferentModelVersion)
                {
                    // The repo is for an older model version
                    var chorusHelper = MainClass.Container.Resolve <ChorusHelper>();
                    return(chorusHelper.ModelVersion.ToString());
                }

                if (project.State.SRState != ProcessingState.SendReceiveStates.HOLD &&
                    project.State.SRState != ProcessingState.SendReceiveStates.ERROR &&
                    project.State.SRState != ProcessingState.SendReceiveStates.CLONED)
                {
                    LfMerge.Core.Actions.Action.GetAction(currentAction).Run(project);

                    if (ChorusHelper.RemoteDataIsForDifferentModelVersion)
                    {
                        // The repo is for an older model version
                        var chorusHelper = MainClass.Container.Resolve <ChorusHelper>();
                        return(chorusHelper.ModelVersion.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                MainClass.Logger.Error("Got exception {0}", e.ToString());
                ExceptionLogging.Client.Notify(e);
                if (projectCode == null)
                {
                    MainClass.Logger.Error("Project code was null");
                }

                if (project.State.SRState != ProcessingState.SendReceiveStates.ERROR)
                {
                    MainClass.Logger.Error(string.Format(
                                               "Putting project '{0}' on hold due to unhandled exception: \n{1}",
                                               projectCode, e));
                    if (project != null)
                    {
                        project.State.SetErrorState(ProcessingState.SendReceiveStates.HOLD,
                                                    ProcessingState.ErrorCodes.UnhandledException, string.Format(
                                                        "Putting project '{0}' on hold due to unhandled exception: \n{1}",
                                                        projectCode, e));
                    }
                }
            }
            finally
            {
                stopwatch.Stop();
                if (project != null && project.State != null)
                {
                    project.State.PreviousRunTotalMilliseconds = stopwatch.ElapsedMilliseconds;
                }
                if (project != null && project.State.SRState != ProcessingState.SendReceiveStates.HOLD &&
                    project.State.SRState != ProcessingState.SendReceiveStates.ERROR &&
                    !ChorusHelper.RemoteDataIsForDifferentModelVersion)
                {
                    project.State.SRState = ProcessingState.SendReceiveStates.IDLE;
                }

                // Dispose FDO cache to free memory
                LanguageForgeProject.DisposeFwProject(project);
            }
            return(null);
        }
Exemple #31
0
 public void GetActionFromQueue(QueueNames queue, ActionNames expectedAction)
 {
     Assert.That(Action.GetActionNameForQueue(queue), Is.EqualTo(expectedAction));
 }
Exemple #32
0
 public void GetActionFromQueue(QueueNames queue, ActionNames expectedAction)
 {
     Assert.That(Options.GetActionForQueue(queue), Is.EqualTo(expectedAction));
 }