示例#1
0
        /// <summary>
        /// Changes the local for the session and the user (if logged in)
        /// </summary>
        /// <param name="msg"></param>
        public override void HandleMessage(string msg)
        {
            if (string.IsNullOrWhiteSpace(msg) && KeyLength > 0)
            {
                msg = TextHelper.Truncate(Text[currentLine], KeyLength).Trim();
            }

            base.HandleMessage(msg);
            string l;

            if (codes.TryGetValue(msg.ToUpper(), out l))
            {
                client.locale = l;
                if (client.status == EClientStatus.LoggedIn)
                {
                    using (bbsContext bbs = new bbsContext())
                    {
                        User user = bbs.GetUserByUsername(client.username);
                        user.Locale = locale;
                        bbs.SaveChanges();
                    }
                }
                client.screen = ScreenFactory.Create(client, server, Previous.ModuleName(), Previous.ModuleParams());
                client.screen.Show();
            }
        }
    private void OnOpenScreenRequest(OpenScreenRequestSignal signal)
    {
        // First check if the type of screen is already opened (unless it's forced by setting the 'ForceOpen' property)
        if (!signal.ForceOpen)
        {
            var screenExistsInNavigationStack = _navigationStack.Any(item => item.Type == signal.Type);
            if (screenExistsInNavigationStack)
            {
                return; // If the type of screen does exists in the navigation stack we ignore the request
            }
        }

        var screenController = _screenFactory.Create(signal.Type);

        // Blur the previous screen (if there is one)
        if (_navigationStack.Count > 0)
        {
            _navigationStack.Last().ScreenController.Blur();
        }

        // Push the new screen to the navigation stack and 'open' it
        var newScreenStackItem = new ScreenStackItem
        {
            Type             = signal.Type,
            ScreenController = screenController
        };

        _navigationStack.Push(newScreenStackItem);

        // Focus the new screen
        screenController.Focus();
        _currentFocussed = newScreenStackItem;

        screenController.Open();
    }
        static void Main(string[] args)
        {
            //LAB#2

            //Dependency Injection
            IOutput Output;

            Output = new ConsoleOutput();

            //Instantiate Factories
            var batteryFactory  = new BatteryFactory(Output);
            var chargerFactory  = new ChargerFactory(Output);
            var screenFactory   = new ScreenFactory(Output);
            var playbackFactory = new PlaybackFactory(Output);

            MobilePhone simCorpMobile = SimCorpMobile.Instance;
            int         Index;

            #region BatteryComponent
            //Ask User for an index
            Index = batteryFactory.SelectComponentIndex();
            //Create Component Class based on index
            simCorpMobile.Battery = batteryFactory.Create(Index).MobileComponent as IBattery;
            //Do something
            simCorpMobile.Install();
            #endregion

            #region ChargerComponent
            //Ask User for an index
            Index = chargerFactory.SelectComponentIndex();
            //Create Component Class based on index
            simCorpMobile.Charger = chargerFactory.Create(Index).MobileComponent as ICharger;
            //Do something
            simCorpMobile.Charge();
            #endregion

            #region ScreenComponent
            //Ask User for an index
            Index = screenFactory.SelectComponentIndex();
            //Create Component Class based on index
            simCorpMobile.DisplayScreen = screenFactory.Create(Index).MobileComponent as IScreen;
            simCorpMobile.Show();
            simCorpMobile.TouchScreen = simCorpMobile.DisplayScreen as IScreenTouch;
            simCorpMobile.Touch();
            #endregion

            #region PlaybackComponent
            //Ask User for an index
            Index = playbackFactory.SelectComponentIndex();
            //Create Component Class based on index
            simCorpMobile.Playback = playbackFactory.Create(Index).MobileComponent as IPlayback;
            simCorpMobile.Play();
            #endregion

            System.Console.ReadLine();
        }
示例#4
0
 /// <summary>
 /// Shows help screen
 /// </summary>
 protected override void ShowHelp()
 {
     if (KeyLength > 0)
     {
         client.screen = ScreenFactory.Create(client, server, "Help", "@HelpList", this);
         client.screen.Show();
     }
     else
     {
         base.ShowHelp();
     }
 }
    public ScreenController OpenScreen <T>(IUIAnimation animation = null) where T : ScreenController
    {
        var screen = _screenFactory.Create <T>();

        _navigationStack.Add(screen);

        if (animation != null)
        {
            animation.AnimateOn(screen.GetComponent <RectTransform>());
        }

        return(screen);
    }
示例#6
0
 /// <summary>
 /// Implements Ctrl-C handler
 /// </summary>
 /// <remarks>
 /// Return to previous screen if exists or logout
 /// </remarks>
 protected override void HandleControlC()
 {
     client.inputMode = EInputMode.LineMode;
     if (Previous != null)
     {
         client.screen = Previous;
         client.screen.Show();
     }
     else
     {
         client.screen = ScreenFactory.Create(client, server, "Logout");
         client.screen.Show();
     }
 }
示例#7
0
 /// <summary>
 /// Exec action by name
 /// </summary>
 /// <param name="act">Text entered to trigger the action</param>
 protected void execAction(string act)
 {
     if (Data == null)
     {
         return;
     }
     BBSCodeResult.Action a;
     if (Data.Actions.TryGetValue(act, out a))
     {
         client.screen = ScreenFactory.Create(client, server, a.module, a.data, this);
         client.screen.Show();
     }
     else
     {
         server.ClearLastInput(client);
     }
 }
示例#8
0
        /// <summary>
        /// Dialog events loop
        /// </summary>
        /// <param name="msg"></param>
        public override void HandleMessage(string msg)
        {
            switch (status)
            {
            case states.WaitForUsername:
                username = msg.Trim().ToUpper();
                if (username == string.Empty)
                {
                    break;
                }
                switch (username)
                {
                case "GUEST":
                    client.screen = ScreenFactory.Create(client, server, "TextScreen", "@GuestAccess");
                    client.screen.Show();
                    break;

                case "NEW":
                    client.screen = ScreenFactory.Create(client, server, "NewUser");
                    client.screen.Show();
                    break;

                case "LOGOUT":
                    client.screen = ScreenFactory.Create(client, server, "Logout");
                    client.screen.Show();
                    break;

                default:
                    LnWrite(catalog.GetString("Password") + ": ");
                    status           = states.WaitForPassword;
                    client.inputMode = EInputMode.PasswordMode;
                    break;
                }
                break;

            case states.WaitForPassword:
                string pwd = msg.Trim();
                client.status    = EClientStatus.Guest;
                client.inputMode = EInputMode.LineMode;
                bool success = false;

                using (bbsContext bbs = new bbsContext())
                {
                    User user = bbs.GetUserByUsername(username);
                    if (user != null)
                    {
                        Login login = new Login()
                        {
                            UserId = username, From = client.Remote
                        };
                        if (user.CheckPassword(pwd))
                        {
                            // successful login
                            success            = true;
                            user.LastLoginDate = DateTime.Now;
                            user.LastLoginFrom = client.Remote;
                            login.Success      = true;
                            bbs.Logins.Add(login);
                            try
                            {
                                bbs.SaveChanges();
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                                Console.WriteLine(e.InnerException.Message);
                            }

                            EventLogger.Write(string.Format("Successful login for user '{0}'", username),
                                              client.Remote);
                            client.status = EClientStatus.LoggedIn;
                            if (string.IsNullOrWhiteSpace(client.locale))
                            {
                                client.locale = user.Locale;
                            }
                        }
                        else
                        {
                            login.Success = false;
                            bbs.Logins.Add(login);
                            bbs.SaveChanges();
                            EventLogger.Write(string.Format("Password failed for user '{0}'", username),
                                              client.Remote);
                        }
                    }
                    else
                    {
                        EventLogger.Write(string.Format("Unknown user '{0}'", username),
                                          client.Remote);
                    }
                }

                if (success)
                {
                    client.username = username;
                    client.screen   = ScreenFactory.Create(client, server, "TextScreen", "@LoggedIn");
                    client.screen.Show();
                }
                else
                {
                    if (++tries >= maxtries)
                    {
                        client.screen = ScreenFactory.Create(client, server, "Logout");
                        client.screen.Show();
                    }
                    else
                    {
                        LnWrite(catalog.GetString("Username or password incorrect. Please try again."));
                        LnWrite(catalog.GetString("Username") + ": ");
                        status = states.WaitForUsername;
                    }
                }
                break;

            default:
                break;
            }
        }
示例#9
0
 private static void clientConnected(IBBSClient c)
 {
     EventLogger.Write("CONNECTED: #" + c.id.ToString(), c.Remote);
     c.screen = ScreenFactory.Create(c, Server, "Banner");
     c.screen.Show();
 }
示例#10
0
 /// <summary>
 /// Sets default action to <see cref="LoginScreen"/>
 /// </summary>
 public override void ShowNext()
 {
     client.screen = ScreenFactory.Create(client, server, "LoginScreen");
     client.screen.Show();
 }
示例#11
0
 /// <summary>
 /// Shows help screen
 /// </summary>
 protected virtual void ShowHelp()
 {
     client.screen = ScreenFactory.Create(client, server, "Help", this);
     client.screen.Show();
 }
示例#12
0
        /// <summary>
        /// Dialog events loop
        /// </summary>
        /// <param name="msg"></param>
        public override void HandleMessage(string msg)
        {
            msg = msg.Trim();
            if (string.IsNullOrWhiteSpace(msg))
            {
                if (status == states.WaitForConfirm)
                {
                    msg = catalog.GetString("Yes");
                }
                else if (status != states.WaitForUsername)
                {
                    return;
                }
            }
            switch (status)
            {
            case states.WaitForUsername:
                string username = msg.ToUpper();
                bool   success  = false;
                switch (username)
                {
                case "":
                    client.screen = ScreenFactory.Create(client, server, "LoginScreen");
                    client.screen.Show();
                    break;

                case "LOGOUT":
                    client.screen = ScreenFactory.Create(client, server, "Logout");
                    client.screen.Show();
                    return;

                case "GUEST":
                case "NEW":
                    break;

                default:
                    if (user.AcceptableUsername(username))
                    {
                        using (bbsContext bbs = new bbsContext())
                        {
                            User test = bbs.GetUserByUsername(username);
                            if (test == null)
                            {
                                success = true;
                            }
                        }
                    }
                    break;
                }
                if (success)
                {
                    user.Userid = username;
                    LnWrite(catalog.GetString("Password") + ": ");
                    status           = states.WaitForPassword;
                    client.inputMode = EInputMode.PasswordMode;
                }
                else
                {
                    LnWrite(catalog.GetString("This name is already in use. Try another."));
                    LnWrite(catalog.GetString("Username") + ": ");
                }
                break;

            case states.WaitForPassword:
                password = msg;
                if (user.AcceptablePassword(password))
                {
                    LnWrite(catalog.GetString("Confirm password") + ": ");
                    status = states.WaitForConfirmPassword;
                }
                else
                {
                    LnWrite(catalog.GetString("Password do not meet security criteria."));
                    LnWrite(catalog.GetString("Password") + ": ");
                    status = states.WaitForPassword;
                }
                break;

            case states.WaitForConfirmPassword:
                if (password == msg)
                {
                    user.SetPassword(password);
                    client.status    = EClientStatus.Guest;
                    client.inputMode = EInputMode.LineMode;
                    LnWrite(catalog.GetString("Your real name") + ": ");
                    status = states.WaitForRealName;
                }
                else
                {
                    LnWrite(catalog.GetString("The two passwords do not match. Try again."));
                    LnWrite(catalog.GetString("Password") + ": ");
                    status = states.WaitForPassword;
                }
                break;

            case states.WaitForRealName:
                user.Realname = msg;
                LnWrite(catalog.GetString("Your city") + ": ");
                status = states.WaitForCity;
                break;

            case states.WaitForCity:
                user.City = msg;
                LnWrite(catalog.GetString("Your country") + ": ");
                status = states.WaitForNation;
                break;

            case states.WaitForNation:
                user.Nation = msg;
                LnWrite(catalog.GetString("Confirm new user creation? [{0}]/{1}",
                                          new object[] {
                    catalog.GetString("Yes"), catalog.GetString("No")
                }) + ": ");
                status = states.WaitForConfirm;
                break;

            case states.WaitForConfirm:
                msg = msg.ToUpper();
                if (msg == catalog.GetString("Yes").ToUpper())
                {
                    using (bbsContext bbs = new bbsContext())
                    {
                        bbs.Users.Add(user);
                        bbs.SaveChanges();
                    }
                    string m = catalog.GetString("Created new user '{0}'", user.Userid);
                    EventLogger.Write(m, client.Remote);
                }
                client.screen = ScreenFactory.Create(client, server, "LoginScreen");
                client.screen.Show();
                break;

            default:
                break;
            }
        }