Пример #1
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || !Util.IsMod(target) || parameters.Length == 0)
                return;

            if (!Util.IsValidUsername(parameters[0]))
            {
                target.Send("Invalid username.");
                return;
            }

            if (!Account.Exists(parameters[0]))
            {
                target.Send("Account does not exist.");
                return;
            }

            if (Util.IsAdmin(target.Room, parameters[0]))
            {
                target.Send("Administrators can not be banned.");
                return;
            }

            if (!target.Room.IsWhitelisted)
                target.Room.Unban(parameters[0]);
            else
                target.Room.Ban(parameters[0]);

            target.Send("Account unbanned.");
        }
Пример #2
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsSession || !target.IsRoom || !(target.Room is MafiaRoom))
                return;

            var room = (MafiaRoom)target.Room;
            var userList = new Packets.UserList();

            if (room.IsPlaying)
            {
                foreach (var player in room.Players)
                {
                    userList.AddUser(player.Alias, "0", "Member", "", "", true);
                }
            }
            else
            {
                var sessions = Program.SessionManager.List.Where(s => s.Account != null).ToList();
                var accounts = sessions.Where(s => s.Room == room.RoomInfo.ShortName).Select(s => s.Account).Distinct(new Account.Comparer());

                foreach (var account in accounts)
                {
                    var userId = account.Id.ToString();
                    userList.AddUser(account.Name, userId, "Member", "", "", true);
                }
            }

            userList.Users = userList.Users.OrderBy(u => u.Name).ToList();
            target.Session.Send(userList);
        }
        public void SetUp()
        {
            disposables = new CompositeDisposable
            {
                VirtualClock.Start()
            };

            clockName = Any.CamelCaseName();
            targetId = Any.Word();
            target = new CommandTarget(targetId);
            store = new InMemoryStore<CommandTarget>(
                _ => _.Id,
                id => new CommandTarget(id))
            {
                target
            };

            configuration = new Configuration()
                .UseInMemoryCommandScheduling()
                .UseDependency<IStore<CommandTarget>>(_ => store)
                .UseDependency<GetClockName>(c => _ => clockName)
                .TraceScheduledCommands();

            scheduler = configuration.CommandScheduler<CommandTarget>();

            Command<CommandTarget>.AuthorizeDefault = (commandTarget, command) => true;

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
Пример #4
0
		public Commandform(CommandTarget commandTarget) {
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            m_commandTarget = commandTarget;
		}
Пример #5
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsSession || !target.IsRoom || target.Session.Account == null || !(target.Room is MafiaRoom))
                return;

            var room = (MafiaRoom)target.Room;

            if (room.IsPlaying)
            {
                target.Send("A game is currently in progress. You must wait until it has finished to join.");
                return;
            }

            if (parameters.Length < 1)
            {
                target.Send("You must specify an alias to join the game: /join Brian");
                return;
            }

            if (!Util.IsValidUsername(parameters[0]))
            {
                target.Send(Util.InvalidUsernameMessage);
                return;
            }

            // TODO: add to game
        }
        public void SetUp()
        {
            disposables = new CompositeDisposable
            {
                VirtualClock.Start()
            };

            clockName = Any.CamelCaseName();
            targetId = Any.Word();
            target = new CommandTarget(targetId);
            store = new InMemoryStore<CommandTarget>(
                _ => _.Id,
                id => new CommandTarget(id))
            {
                target
            };

            CommandSchedulerDbContext.NameOrConnectionString =
                @"Data Source=(localdb)\MSSQLLocalDB; Integrated Security=True; MultipleActiveResultSets=False; Initial Catalog=ItsCqrsTestsCommandScheduler";

            configuration = new Configuration()
                .UseInMemoryCommandScheduling()
                .UseDependency<IStore<CommandTarget>>(_ => store)
                .UseDependency<GetClockName>(c => _ => clockName)
                .TraceScheduledCommands();

            scheduler = configuration.CommandScheduler<CommandTarget>();

            Command<CommandTarget>.AuthorizeDefault = (commandTarget, command) => true;

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
Пример #7
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || !Util.IsMod(target) || parameters.Length == 0)
                return;

            if (!Util.IsValidUsername(parameters[0]))
            {
                target.Send("Invalid username.");
                return;
            }

            if (!Account.Exists(parameters[0]))
            {
                target.Send("Account does not exist.");
                return;
            }

            if (Util.IsAdmin(target.Room, parameters[0]))
            {
                target.Send("Administrators can not be banned.");
                return;
            }

            string sourceUser;
            if (target.IsWeb)
                sourceUser = target.Connection.Session.Account.Name;
            else
                sourceUser = string.Format("steam:{0:D}", (ulong)target.SteamId);

            Program.Logger.InfoFormat("User '{0}' unbanning '{1}'", sourceUser, parameters[0]);

            target.Room.Unban(parameters[0]);
            target.Send("Account unbanned.");
        }
Пример #8
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || !Util.IsAdmin(target) || parameters.Length == 0)
                return;

            if (!Util.IsValidUsername(parameters[0]))
            {
                target.Send("Invalid username.");
                return;
            }

            if (!Account.Exists(parameters[0]))
            {
                target.Send("Account does not exist.");
                return;
            }

            if (!target.Room.IsMod(parameters[0]))
            {
                target.Send("Account is not a mod.");
                return;
            }

            target.Room.Demod(parameters[0]);
            target.Send("Account demodded.");
        }
Пример #9
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!Util.IsSuperAdmin(target) || parameters.Length < 1)
                return;

            Program.RoomManager.Broadcast("Broadcast: " + parameters[0]);
        }
Пример #10
0
 public override void Handle(Connection connection)
 {
     // TODO: move implementation here later
     var commandTarget = new CommandTarget(connection, Target);
     var command = new Commands.Users();
     command.Handle(commandTarget, command.Type, new string[0]);
 }
Пример #11
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!Util.IsSuperAdmin(target))
                return;

            Program.Steam.Disconnect(); // should auto-reconnect
        }
Пример #12
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsWeb || !target.IsRoom || parameters.Length == 0)
                return;

            if (Program.DelayManager.AddAndCheck(target.Connection, DelayManager.Message))
                return;

            var username = target.Connection.Session.Account.Name;
            var room = target.Room;
            if (room.IsBanned(username))
            {
                target.Send("You are banned from this room.");
                return;
            }

            var line = new StateLine(
                Util.GetCurrentTimestamp(),
                target.Room.RoomInfo.ShortName,
                "Action",
                username,
                target.Connection.Session.Account.Id.ToString("D"),
                "RohBot",
                "", "0", "",
                string.Format("{0} {1}", username, parameters[0]));

            target.Room.SendLine(line);
        }
Пример #13
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || !(target.Room is ScriptRoom) || !Util.IsSuperAdmin(target))
                return;

            var scriptRoom = (ScriptRoom)target.Room;
            scriptRoom.Recompile();
        }
Пример #14
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!Util.IsSuperAdmin(target))
                return;

            Program.Logger.Info("Reboot requested");
            Environment.Exit(0);
        }
Пример #15
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsWeb || !Util.IsSuperAdmin(target))
                return;

            var sessions = Program.SessionManager.List.Select(s => $"{s.Account.Name} ({s.ConnectionCount})");
            var sessionsText = string.Join(", ", sessions);
            target.Send($"Sessions: {sessionsText}");
        }
Пример #16
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!Util.IsSuperAdmin(target))
                return;

            var sessions = Program.SessionManager.List.Select(s => string.Format("{0} ({1})", s.Account.Name, s.ConnectionCount));
            var sessionsText = string.Join(", ", sessions);
            target.Send(string.Format("Active sessions: {0}", sessionsText));
        }
Пример #17
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || target.IsPrivateChat)
                return;

            var room = target.Room;
            var roomName = room.RoomInfo.ShortName;

            var sessions = Program.SessionManager.List;
            var accounts = sessions.Where(s => s.IsInRoom(roomName))
                                   .Select(s => s.Account)
                                   .Distinct(new Account.Comparer());

            if (target.IsWeb)
            {
                var userList = new Packets.UserList();

                var steamRoom = room as SteamRoom;
                var chat = steamRoom != null && Program.Steam.Status == Steam.ConnectionStatus.Connected ? steamRoom.Chat : null;

                if (chat != null)
                {
                    var steamUsers = chat.Users.Select(p => p.Id)
                                               .Where(i => i != Program.Steam.Bot.SteamId);

                    foreach (var id in steamUsers)
                    {
                        var persona = Program.Steam.Bot.GetPersona(id);
                        var steamId = id.ConvertToUInt64().ToString("D");
                        var groupMember = chat.Group.Members.FirstOrDefault(m => m.Persona.Id == id);
                        var rank = groupMember != null ? GetRankString(groupMember.Rank) : "Guest";
                        var avatar = BitConverter.ToString(persona.Avatar).Replace("-", "").ToLower();
                        var status = GetStatusString(persona.State);
                        userList.AddUser(persona.DisplayName, steamId, rank, avatar, status, persona.PlayingName, false);
                    }
                }

                foreach (var account in accounts)
                {
                    var userId = account.Id.ToString("D");
                    var rank = GetRankString(target.Room, account.Name);
                    userList.AddUser(account.Name, userId, rank, "", "", null, true);
                }

                userList.ShortName = roomName;
                userList.Users = userList.Users.OrderBy(u => u.Name, StringComparer.InvariantCultureIgnoreCase).ToList();
                target.Connection.Send(userList);
            }
            else
            {
                var names = accounts.OrderBy(a => a.Name, StringComparer.InvariantCultureIgnoreCase)
                                    .Select(a => a.Name);

                target.Send("In this room: " + string.Join(", ", names));
            }
        }
Пример #18
0
        public override string Format(CommandTarget target, string type)
        {
            if (!target.IsRoom || !(target.Room is ScriptRoom))
                return "";

            var scriptRoom = (ScriptRoom)target.Room;
            ScriptRoom.CommandHandler command;

            return scriptRoom.Commands.TryGetValue(type, out command) ? command.Format : null;
        }
Пример #19
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsWeb || parameters.Length == 0)
                return;

            if (Program.DelayManager.AddAndCheck(target.Connection, DelayManager.Database))
                return;

            target.Connection.Session.Leave(parameters[0]);
        }
Пример #20
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom)
                return;

            var modded = target.Room.Modded;
            modded.Add(target.Room.RoomInfo.Admin.ToLower());
            modded = modded.OrderBy(n => n).ToList();

            target.Send(string.Format("Mods for this room: {0}", string.Join(", ", modded)));
        }
Пример #21
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsSession || target.Session.Account == null)
                return;

            if (parameters.Length < 1)
            {
                target.Send("Currently in room: " + target.Session.Room);
                return;
            }

            if (Program.DelayManager.AddAndCheck(target.Session, 2.5))
                return;

            switch (parameters[0])
            {
                case "default":
                    {
                        var defaultRoom = target.Session.Account.DefaultRoom;
                        var newRoom = parameters.Length < 2 ? defaultRoom : parameters[1];

                        if (!target.Session.SwitchRoom(newRoom))
                            break;

                        if (parameters.Length >= 2)
                        {
                            target.Session.Account.DefaultRoom = target.Session.Room;
                            target.Session.Account.Save();
                        }

                        target.Send("Switched to room: " + newRoom);
                        break;
                    }

                case "list":
                    {
                        var roomNames = Program.RoomManager.List
                            .Where(r => !r.IsHidden)
                            .Select(r => r.RoomInfo)
                            .Select(r => string.Format("{0} ({1})", r.Name, r.ShortName));
                        target.Send("Available rooms: " + string.Join(", ", roomNames));
                        break;
                    }

                default:
                    {
                        if (!target.Session.SwitchRoom(parameters[0]))
                            break;

                        target.Send("Switched to room: " + parameters[0]);
                        break;
                    }
            }
        }
Пример #22
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsWeb || parameters.Length == 0)
                return;

            if (Program.DelayManager.AddAndCheck(target.Connection, DelayManager.Database))
                return;

            if (!target.Connection.Session.Join(parameters[0]))
                target.Send("Room does not exist.");
        }
Пример #23
0
        private void OnAddItem(object sender, EventArgs e)
        {
            if (this.editingValue == null)
            {
                return;
            }
            SceneNodeProperty sceneNodeProperty = this.editingProperty as SceneNodeProperty;

            if (sceneNodeProperty == null)
            {
                return;
            }
            SceneNodeObjectSet sceneNodeObjectSet = sceneNodeProperty.SceneNodeObjectSet;

            if (sceneNodeObjectSet == null)
            {
                return;
            }
            CommandTarget commandTarget = sceneNodeObjectSet.DesignerContext.ProjectManager as CommandTarget;

            if (commandTarget == null)
            {
                return;
            }
            string   commandName    = "Project_AddExistingItemOfType";
            IProject currentProject = this.GetCurrentProject();

            if (currentProject == null)
            {
                return;
            }
            IDocumentType[] documentTypeArray = this.GetSupportedDocumentTypesFromSelection();
            if (documentTypeArray == UriEditor.multiScaleDocuments)
            {
                List <IDocumentType> list = Enumerable.ToList <IDocumentType>((IEnumerable <IDocumentType>)documentTypeArray);
                list.Remove(sceneNodeObjectSet.DesignerContext.DocumentTypeManager.DocumentTypes[DocumentTypeNamesHelper.DeepZoom]);
                documentTypeArray = list.ToArray();
            }
            commandTarget.SetCommandProperty(commandName, "DocumentTypes", (object)documentTypeArray);
            commandTarget.SetCommandProperty(commandName, "Project", (object)currentProject);
            commandTarget.SetCommandProperty(commandName, "SelectAddedItems", (object)false);
            commandTarget.SetCommandProperty(commandName, "TargetFolder", (object)Microsoft.Expression.Framework.Documents.PathHelper.GetDirectory(sceneNodeObjectSet.ViewModel.Document.DocumentReference.Path));
            commandTarget.SetCommandProperty(commandName, "TemporarilyStopProjectPaneActivation", (object)true);
            using (WorkaroundPopup.LockOpen((DependencyObject)this))
                commandTarget.Execute(commandName, CommandInvocationSource.Palette);
            IProjectItem projectItem = EnumerableExtensions.SingleOrNull <IProjectItem>((IEnumerable <IProjectItem>)commandTarget.GetCommandProperty(commandName, "AddedProjectItems"));

            if (projectItem == null)
            {
                return;
            }
            this.ProjectItemSource = new ProjectItemModel(projectItem, this.DocumentContext, 0);
        }
Пример #24
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            var sessions = Program.SessionManager.List.Where(s => s.Account != null).Select(s => s.Account.Name).ToList();
            var req = sessions.Distinct().Select(n =>
            {
                var count = sessions.Count(s => s == n);
                return n + (count > 1 ? string.Format(" ({0})", count) : "");
            });

            var msg = "Active sessions: " + string.Join(", ", req);
            target.Send(msg);
        }
Пример #25
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsWeb || !Util.IsSuperAdmin(target))
            {
                return;
            }

            var sessions     = Program.SessionManager.List.Select(s => $"{s.Account.Name} ({s.ConnectionCount})");
            var sessionsText = string.Join(", ", sessions);

            target.Send($"Sessions: {sessionsText}");
        }
Пример #26
0
 void AddCommandFilter(IWpfTextView textView, CommandTarget commandTarget)
 {
     if (EditorFactory != null)
     {
         var viewAdapter = EditorFactory.GetViewAdapter(textView);
         if (viewAdapter != null &&
             viewAdapter.AddCommandFilter(commandTarget, out var next) == VSConstants.S_OK &&
             next != null)
         {
             commandTarget.NextCommandTarget = next;
         }
     }
 }
Пример #27
0
 public override void ClearTarget(CommandTarget target)
 {
     if (target == CommandTarget.Translation)
     {
         foreach (Subtitle subtitle in subtitles)
         {
             if (subtitle.HasTranslation)
             {
                 subtitle.Translation.Clear();
             }
         }
     }
 }
Пример #28
0
        /// <summary>
        /// Executes the specified command in MSHTML and returns the result
        /// </summary>
        /// <param name="command"></param>
        /// <returns>object result - The result of the command</returns>
        protected internal object ExecResult(int command)
        {
            object[] retVal = new object[1];

            //Execute the command
            int hr = CommandTarget.Exec(ref Interop.Guid_MSHTML, command, Interop.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, null, retVal);

            if (hr != Interop.S_OK)
            {
                throw new Exception("MSHTMLHelper.ExecResult : Command " + command + " did not return S_OK");
            }
            return(retVal[0]);
        }
Пример #29
0
        public override string Format(CommandTarget target, string type)
        {
            if (!target.IsRoom || !(target.Room is ScriptRoom))
            {
                return("");
            }

            var scriptRoom = (ScriptRoom)target.Room;

            ScriptRoom.CommandHandler command;

            return(scriptRoom.Commands.TryGetValue(type, out command) ? command.Format : null);
        }
Пример #30
0
        public FunctionCommand(CommandTarget target)
        {
            switch (target)
            {
            case CommandTarget.Server:
                _target = Target.Server;
                break;

            case CommandTarget.Client:
            default:
                _target = Target.Client;
                break;
            }
        }
Пример #31
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || !Util.IsMod(target))
            {
                return;
            }

            var modded = target.Room.Modded;

            modded.Add(target.Room.RoomInfo.Admin.ToLower());
            modded = modded.OrderBy(n => n).ToList();

            target.Send($"Mods for this room: {string.Join(", ", modded)}");
        }
Пример #32
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!Util.IsSuperAdmin(target))
                return;

            Program.LoadSettings();

            foreach (var roomName in parameters)
            {
                Program.RoomManager.Get(roomName).Leave();
            }

            target.Send("Done.");
        }
Пример #33
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsWeb || parameters.Length == 0)
            {
                return;
            }

            if (Program.DelayManager.AddAndCheck(target.Connection, DelayManager.Database))
            {
                return;
            }

            target.Connection.Session.Leave(parameters[0]);
        }
Пример #34
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom && !target.IsPrivateChat)
            {
                target.Send("RohBot is not in this room.");
                return;
            }

            if (target.IsSession)
            {
                var roomName = target.Session.Room;
                var room = target.Room;

                var steamRoom = room as SteamRoom;
                var userList = new Packets.UserList();
                var chat = Program.Steam.Status == Steam.ConnectionStatus.Connected && steamRoom != null ? steamRoom.Chat : null;
                var steamUsers = chat != null ? chat.Members.ToList() : new List<SteamID>();
                var sessions = Program.SessionManager.List.Where(s => s.Account != null).ToList();

                foreach (var id in steamUsers.Where(i => i != Program.Steam.Bot.PersonaId))
                {
                    var persona = Program.Steam.Bot.GetPersona(id);
                    var steamId = id.ConvertToUInt64().ToString("D");
                    var groupMember = chat.Group.Members.FirstOrDefault(m => m.Id == id);
                    var rank = groupMember != null ? groupMember.Rank.ToString() : "Member";
                    var avatar = BitConverter.ToString(persona.Avatar).Replace("-", "").ToLower();
                    userList.AddUser(persona.Name, steamId, rank, avatar, persona.PlayingName, false);
                }

                var accounts = sessions.Where(s => s.Room == roomName).Select(s => s.Account).Distinct(new Account.Comparer());

                foreach (var account in accounts)
                {
                    var userId = account.Id.ToString();
                    var rank = Util.GetRank(target.Room, account.Name).ToString();
                    userList.AddUser(account.Name, userId, rank, "", "", true);
                }

                userList.Users = userList.Users.OrderBy(u => u.Name).ToList();
                target.Session.Send(userList);
            }
            else
            {
                var roomName = target.Room.RoomInfo.ShortName;
                var sessions = Program.SessionManager.List.Where(s => s.Account != null).ToList();
                var accounts = sessions.Where(s => s.Room == roomName).Select(s => s.Account).Distinct(new Account.Comparer());
                target.Send("In this room: " + string.Join(", ", accounts.Select(a => a.Name)));
            }
        }
Пример #35
0
        public void OnNodeAdded(Object aChildNode, Object aParentNode, int aIndex)
        {
            // A new Element has been added somewhere. We must find the
            // parent menu and append it. To interoperate with the Content Builder,
            // the DataStore must provide |CommandTarget|s to this method.
            CommandTarget childTarget  = aChildNode as CommandTarget;
            CommandTarget parentTarget = aParentNode as CommandTarget;

            if (childTarget == null && parentTarget == null)
            {
                return;
            }

            int childKey = childTarget.Data.GetHashCode();

            if (!mMenus.ContainsKey(childKey))
            {
                int parentKey = parentTarget.Data.GetHashCode();

                ManticoreMenuItem parentMenu;
                if (mMenus.ContainsKey(parentKey))
                {
                    parentMenu = mMenus[parentKey] as ManticoreMenuItem;
                }
                else
                {
                    parentMenu = mParent as ManticoreMenuItem;
                }

                if (parentMenu != null)
                {
                    String label = childTarget.Label;
                    if (childTarget.AccessKey != "")
                    {
                        label = ManticoreMenuItem.GenerateAccessKeyString(childTarget.Label,
                                                                          childTarget.AccessKey);
                    }
                    ManticoreMenuItem childMenu = new ManticoreMenuItem(label,
                                                                        new EventHandler(OnCommandInternal),
                                                                        "bookmarks-item", childTarget.Data);
                    if (parentMenu != null)
                    {
                        int pos = aIndex == -1 ? parentMenu.MenuItems.Count : aIndex;
                        parentMenu.MenuItems.Add(pos, childMenu);
                        mMenus.Add(childKey, childMenu);
                    }
                }
            }
        }
Пример #36
0
        public void OnNodeRemoved(Object aNodeRemoved)
        {
            CommandTarget childTarget = aNodeRemoved as CommandTarget;

            // Remove |MenuItem| representation of |aChildNode|.
            int childKey = childTarget.Data.GetHashCode();

            if (mMenus.ContainsKey(childKey))
            {
                ManticoreMenuItem childMenu  = mMenus[childKey] as ManticoreMenuItem;
                ManticoreMenuItem parentMenu = childMenu.Parent as ManticoreMenuItem;
                parentMenu.MenuItems.Remove(childMenu);
                mMenus.Remove(childKey);
            }
        }
        void AddCommandFilter(IWpfTextView textView, CommandTarget commandTarget)
        {
            IOleCommandTarget next;

            if (editorFactory != null)
            {
                IVsTextView viewAdapter = editorFactory.GetViewAdapter(textView);
                if (viewAdapter != null &&
                    viewAdapter.AddCommandFilter(commandTarget, out next) == VSConstants.S_OK &&
                    next != null)
                {
                    commandTarget.NextCommandTarget = next;
                }
            }
        }
Пример #38
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!Util.IsSuperAdmin(target))
            {
                return;
            }

            Program.LoadSettings();

            foreach (var roomName in parameters)
            {
                Program.RoomManager.Get(roomName).Leave();
            }

            target.Send("Done.");
        }
Пример #39
0
        public TextEditorControl()
        {
            ElementProvider.Install(new TextEditorElementProvider(this));

            ActiveTextAreaControl.TextArea.DoProcessDialogKey += TextArea_DoProcessDialogKey;
            ActiveTextAreaControl.TextArea.GotFocus           += TextArea_GotFocus;
            ActiveTextAreaControl.TextArea.LostFocus          += TextArea_LostFocus;

            CommandMapper  = new NiCommandMapper();
            _commandTarget = new CommandTarget(CommandMapper);
            FindTarget     = new FindTargetImpl(ActiveTextAreaControl);

            BuildCommands();

            RemoveDefaultKeyBindings();
        }
Пример #40
0
        public TextEditorControl()
        {
            ElementProvider.Install(new TextEditorElementProvider(this));

            ActiveTextAreaControl.TextArea.DoProcessDialogKey += TextArea_DoProcessDialogKey;
            ActiveTextAreaControl.TextArea.GotFocus += TextArea_GotFocus;
            ActiveTextAreaControl.TextArea.LostFocus += TextArea_LostFocus;

            CommandMapper = new NiCommandMapper();
            _commandTarget = new CommandTarget(CommandMapper);
            FindTarget = new FindTargetImpl(ActiveTextAreaControl);

            BuildCommands();

            RemoveDefaultKeyBindings();
        }
        public override async Task Scheduled_commands_are_delivered_immediately_if_past_due_per_the_domain_clock()
        {
            // arrange
            var target = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);

            // act
            await scheduler.Schedule(target.Id,
                                     new TestCommand(),
                                     Clock.Now().AddMinutes(-2));

            //assert
            target = await store.Get(target.Id);

            target.CommandsEnacted.Should().HaveCount(1);
        }
Пример #42
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || !(target.Room is ScriptRoom))
                return;

            var scriptRoom = (ScriptRoom)target.Room;
            ScriptRoom.CommandHandler command;

            if (scriptRoom.Commands.TryGetValue(type, out command))
            {
                scriptRoom.SafeInvoke(() => command.Handler(target, parameters));
                return;
            }

            target.Send("Unknown command.");
        }
Пример #43
0
        public void Recurse(String aRoot, Menu.MenuItemCollection aParentItems)
        {
            IEnumerator items;

            mDataStore.GetElements(aRoot, out items);
            items.Reset();

            MenuItem item;

            while (items.MoveNext())
            {
                // |id| is the item's unique identifier within the DataStore.
                // The handling code can use this to probe for more information
                // about the selected item.
                CommandTarget current = items.Current as CommandTarget;
                if (current != null)
                {
                    String id = current.Data as String;

                    int idKey = id.GetHashCode();

                    if (!mMenus.ContainsKey(idKey))
                    {
                        item = new ManticoreMenuItem(current.Label,
                                                     new EventHandler(OnCommandInternal),
                                                     "bookmarks-item", id);
                        if (aRoot != Root)
                        {
                            aParentItems.Add(item);
                        }
                        else
                        {
                            aParentItems.Add(mInsertionPoint++, item);
                        }
                        mMenus.Add(id.GetHashCode(), item);

                        if (current.IsContainer)
                        {
                            Recurse(current.Data as String, item.MenuItems);
                        }
                    }
                }
            }

            ResetInsertionPoint();
        }
        public override void ClearTarget(CommandTarget target)
        {
            if (target == CommandTarget.Translation)
            {
                ArrayList newReplacedSubtitles = new ArrayList();

                foreach (SubtitleReplaceResult replacedSubtitle in replacedSubtitles)
                {
                    if (replacedSubtitle.Text != null)
                    {
                        newReplacedSubtitles.Add(new SubtitleReplaceResult(replacedSubtitle.Number, replacedSubtitle.Text, null));
                    }
                }

                replacedSubtitles = newReplacedSubtitles;
            }
        }
Пример #45
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsWeb || parameters.Length == 0)
            {
                return;
            }

            if (Program.DelayManager.AddAndCheck(target.Connection, DelayManager.Database))
            {
                return;
            }

            if (!target.Connection.Session.Join(parameters[0]))
            {
                target.Send("Room does not exist.");
            }
        }
        public override async Task When_a_clock_is_advanced_then_commands_are_not_triggered_that_have_not_become_due()
        {
            // arrange
            var target = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);

            // act
            await scheduler.Schedule(target.Id,
                                     new TestCommand(),
                                     Clock.Now().AddDays(2));

            await AdvanceClock(TimeSpan.FromDays(1.1));

            //assert
            target = await store.Get(target.Id);

            target.CommandsEnacted.Should().HaveCount(0);
        }
        public override async Task When_a_clock_is_advanced_its_associated_commands_are_triggered()
        {
            // arrange
            var target = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);

            await scheduler.Schedule(target.Id,
                                     new TestCommand(),
                                     Clock.Now().AddDays(1));

            // act
            await AdvanceClock(25.Hours());

            //assert
            target = await store.Get(target.Id);

            target.CommandsEnacted.Should().HaveCount(1);
        }
Пример #48
0
        public override bool ShouldBuild(CommandTarget aTarget)
        {
            Bookmarks bmks = ServiceManager.Bookmarks;

            if (mFilterAttributes != null)
            {
                IEnumerator criteria = mFilterAttributes.GetEnumerator();
                while (criteria.MoveNext())
                {
                    String[] singleCriteria = criteria.Current as String[];
                    if (bmks.GetBookmarkAttribute(aTarget.Data as String, singleCriteria[0]) != singleCriteria[1])
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        public override void ClearTarget(CommandTarget target)
        {
            if (target == CommandTarget.Translation)
            {
                if (subtitlesBefore != null)
                {
                    foreach (Subtitle subtitle in subtitlesBefore)
                    {
                        if (subtitle.HasTranslation)
                        {
                            subtitle.Translation.Clear();
                        }
                    }
                }

                translationCleared = true;
            }
        }
Пример #50
0
        public void ExecuteCommand(StaticCommand staticCommand, TransmissionEvent transmissionEvent, ExecutionEvent executionEvent,
                                   List <Condition> conditions, CommandTarget target)
        {
            if (conditions != null && conditions.Count == 0)
            {
                conditions = null;
            }

            _serverConnection.SendCommand(new DynamicCommand
            {
                CommandId         = staticCommand.CommandId,
                Target            = target,
                Conditions        = conditions,
                TransmissionEvent = transmissionEvent,
                ExecutionEvent    = executionEvent,
                CommandParameter  = staticCommand.GetCommandParameter().Data,
                PluginHash        = null
            });
        }
Пример #51
0
        private void OnActivateCommand()
        {
            PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.ActivateProjectItem);
            INamedProject namedProject = base.Services.ProjectManager().CurrentSolution.FindProjectContainingOpenItem(this.projectItem.DocumentReference);

            if (namedProject != null && namedProject != this.ProjectItem.Project)
            {
                base.Services.MessageDisplayService().ShowError(StringTable.ProjectItemAlreadyOpenMessage);
                return;
            }
            IView activeView = base.Services.ViewService().ActiveView;

            if (!this.projectItem.DocumentType.CanView)
            {
                if (this.projectItem is FolderStandIn || this.projectItem.DocumentType == base.Services.DocumentTypes()[DocumentTypeNamesHelper.Folder])
                {
                    this.IsExpanded = !this.IsExpanded;
                    return;
                }
                if (activeView != null && this.projectItem.DocumentType.CanInsertTo(this.projectItem, activeView))
                {
                    this.projectItem.DocumentType.AddToDocument(this.projectItem, activeView);
                    return;
                }
                if (Microsoft.Expression.Framework.Documents.PathHelper.FileExists(this.projectItem.DocumentReference.Path))
                {
                    CommandTarget commandTarget = base.Services.ProjectManager() as CommandTarget;
                    if (commandTarget != null)
                    {
                        string str = "Project_EditExternally";
                        commandTarget.SetCommandProperty(str, "TargetDocument", this.ProjectItem);
                        commandTarget.Execute(str, CommandInvocationSource.Palette);
                    }
                }
            }
            else
            {
                using (IDisposable disposable = TemporaryCursor.SetWaitCursor())
                {
                    this.projectItem.OpenView(true);
                }
            }
        }
        public override async Task When_a_command_is_scheduled_but_an_exception_is_thrown_in_a_handler_then_an_error_is_recorded()
        {
            // arrange
            var target = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);

            // act
            await scheduler.Schedule(target.Id,
                                     new TestCommand(isValid : false));

            //assert
            using (var db = new CommandSchedulerDbContext())
            {
                var aggregateId = target.Id.ToGuidV3();
                var error       = db.Errors.Single(e => e.ScheduledCommand.AggregateId == aggregateId);

                error.Error.Should().Contain("CommandValidationException");
            }
        }
Пример #53
0
        protected override void Execute(object sender, EventArgs args)
        {
            if (CommandTarget.AskSaveModifiedRecipe())
            {
                var dlg = new OpenFileDialog {
                    Filter = Constants.RECIPE_FILE_FILTER,
                    Title  = "Open Recipe"
                };

                if (DialogResult.OK == dlg.ShowDialog(FindMainWindow()))
                {
                    CommandTarget.Status = "Loading " + dlg.FileName + "...";
                    CommandTarget.Cursor = Cursors.WaitCursor;
                    RecipeFactory.Load(dlg.FileName);
                    CommandTarget.Cursor = Cursors.Default;
                    CommandTarget.Status = "Ready";
                }
            }
        }
Пример #54
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || !(target.Room is ScriptRoom))
            {
                return;
            }

            var scriptRoom = (ScriptRoom)target.Room;

            ScriptRoom.CommandHandler command;

            if (scriptRoom.Commands.TryGetValue(type, out command))
            {
                scriptRoom.SafeInvoke(() => command.Handler(target, parameters));
                return;
            }

            target.Send("Unknown command.");
        }
Пример #55
0
        /// <summary>
        /// Queries MSHTML for the command info (enabled and checked) for the specified command
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        protected internal HtmlCommandInfo GetCommandInfo(int command)
        {
            //First query the command target for the command status
            int info;

            Interop.tagOLECMD oleCommand = new Interop.tagOLECMD();

            //Create an tagOLDCMD to store the command and receive the result
            oleCommand.cmdID = command;
            int hr = CommandTarget.QueryStatus(ref Interop.Guid_MSHTML, 1, oleCommand, 0);

            Debug.Assert(hr == Interop.S_OK, "IOleCommand.QueryStatus did not return S_OK");

            //Then translate the response from the command status
            //We can just right shift by one to eliminate the supported flag from OLECMDF
            info = oleCommand.cmdf;
            //REVIEW: Do we want to do a mapping instead of playing with the bits?
            return((HtmlCommandInfo)(info >> 1) & (HtmlCommandInfo.Enabled | HtmlCommandInfo.Checked));
        }
        public override async Task Immediately_scheduled_commands_triggered_by_a_scheduled_command_have_their_due_time_set_to_the_causative_command_clock()
        {
            // arrange
            var deliveredTime = new DateTimeOffset();
            var target        = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);

            var clockRepository    = Configuration.Current.SchedulerClockRepository();
            var schedulerClockTime = DateTimeOffset.Parse("2016-02-13 01:00:00 AM");

            clockRepository.CreateClock(clockName, schedulerClockTime);
            Configuration.Current.UseCommandHandler <CommandTarget, TestCommand>(async(_, __) =>
            {
                if (__.ETag == "first")
                {
                    await Configuration.Current.CommandScheduler <CommandTarget>().Schedule(target.Id, new TestCommand
                    {
                        CanBeDeliveredDuringScheduling = true
                    });
                }
                else
                {
                    deliveredTime = Clock.Now();
                }
            });

            // act
            await scheduler.Schedule(target.Id,
                                     new TestCommand
            {
                CanBeDeliveredDuringScheduling = true,
                ETag = "first"
            },
                                     dueTime : DateTimeOffset.Parse("2016-02-13 01:05:00 AM"));

            await Configuration.Current
            .SchedulerClockTrigger()
            .AdvanceClock(clockName, by: 1.Hours());

            // assert
            deliveredTime.Should().Be(DateTimeOffset.Parse("2016-02-13 01:05:00 AM"));
        }
        public override async Task When_command_is_durable_but_immediate_delivery_succeeds_then_it_is_not_redelivered()
        {
            // arrange
            var target = new CommandTarget(Any.CamelCaseName());
            await store.Put(target);

            // act
            await scheduler.Schedule(target.Id,
                                     new TestCommand
            {
                RequiresDurableScheduling = true
            });

            await AdvanceClock(2.Days());

            //assert
            target = await store.Get(target.Id);

            target.CommandsEnacted.Should().HaveCount(1);
        }
Пример #58
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsRoom || !Util.IsMod(target))
                return;

            var banned = target.Room.Banned;
            banned = banned.OrderBy(s => s).ToList();

            if (banned.Count == 0)
            {
                if (!target.Room.IsWhitelisted)
                    target.Send("Nobody is banned.");
                else
                    target.Send("Everybody is banned.");
            }
            else
            {
                if (!target.Room.IsWhitelisted)
                    target.Send(string.Format("Banned: {0}", string.Join(", ", banned)));
                else
                    target.Send(string.Format("Whitelisted: {0}", string.Join(", ", banned)));
            }
        }
Пример #59
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!Util.IsSuperAdmin(target) || parameters.Length == 0)
                return;

            if (!Util.IsValidUsername(parameters[0]))
            {
                target.Send("Invalid username.");
                return;
            }

            var session = Program.SessionManager.Get(parameters[0]);
            if (session == null)
            {
                target.Send("Session does not exist.");
                return;
            }

            var connectionCount = session.ConnectionCount;
            session.Destroy();

            target.Send(string.Format("Kicked session ({0} connections).", connectionCount));
        }
Пример #60
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsSession || target.Session.Account == null || parameters.Length == 0)
                return;

            if (Program.DelayManager.AddAndCheck(target.Session, 1))
                return;

            var room = Program.RoomManager.Get(target.Session.Room);
            if (room == null)
            {
                target.Send("RohBot is not in this room.");
                return;
            }

            if (room.IsBanned(target.Session.Account.Name))
            {
                target.Send("You are banned from this room.");
                return;
            }

            room.Send(string.Format("{0} hugs {1}.", target.Session.Account.Name, parameters[0]));
        }