Exemple #1
0
        public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
        {
            if (onlyOnce) { return true; }
            onlyOnce = true;

            if (command is Join)
            {
                user.IrcDaemon.Commands.Send(new NoticeArgument(user, user, channel.Name, "This channel automatically translates your messages, use the LANGUAGE command to set your preferred language"));
            }
            if (!channel.Modes.HandleEvent(command, channel, user, args))
            {
                onlyOnce = false;
                return false;
            }
            if (command is PrivateMessage || command is Notice)
            {

                var translateDelegate = new GoogleTranslate.TranslateMultipleDelegate(translator.TranslateText);
                translateDelegate.BeginInvoke(args[1], channel.Users.Select(u => u.Languages.First()).Distinct(), TranslateCallBack, Tuple.Create(channel, user, command));

                onlyOnce = false;
                return false;
            }

            onlyOnce = false;
            return true;
        }
        /// <summary>Executes the supplied command</summary>
        /// <param name="command">The command to execute.</param>
        /// <param name="context">The context passed to the command</param>
        public virtual void Execute(CommandBase<CommandContext> command, CommandContext context)
        {
            var args = new CommandProcessEventArgs { Command = command, Context = context };
            if (CommandExecuting != null)
                CommandExecuting.Invoke(this, args);

            logger.Info(args.Command.Name + " processing " + args.Context);
            using (var tx = persister.Repository.BeginTransaction())
            {
                try
                {
                    args.Command.Process(args.Context);
                    tx.Commit();

                    if (CommandExecuted != null)
                        CommandExecuted.Invoke(this, args);
                }
                catch (StopExecutionException)
                {
                    tx.Rollback();
                }
                catch (Exception ex)
                {
                    tx.Rollback();
                    logger.Error(ex);
                    throw;
                }
                finally
                {
                    logger.Info(" -> " + args.Context);
                }
            }
        }
 /// <summary>
 /// For testing purposes
 /// </summary>
 /// <param name="guardedCommand"></param>
 /// <param name="commandId"></param>
 /// <param name="cookieExpirationDays"></param>
 /// <param name="now"></param>
 internal CookieGuardedCommand(CommandBase guardedCommand, string commandId, int cookieExpirationDays, DateTime? now)
 {
     _guardedCommand = guardedCommand;
     _commandId = commandId;
     _cookieExpirationDays = cookieExpirationDays;
     _now = now;
 }
 /// <summary>Executes the supplied command</summary>
 /// <param name="command">The command to execute.</param>
 /// <param name="context">The context passed to the command</param>
 public virtual void Execute(CommandBase<CommandContext> command, CommandContext context)
 {
     logger.Info(command.Name + " processing " + context);
     using (var tx = persister.Repository.BeginTransaction())
     {
         try
         {
             command.Process(context);
             tx.Commit();
         }
         catch (StopExecutionException)
         {
             tx.Rollback();
         }
         catch (Exception ex)
         {
             tx.Rollback();
             logger.Error(ex);
             throw;
         }
         finally
         {
             logger.Info(" -> " + context);
         }
     }
 }
Exemple #5
0
        public CommandFactory(IPersister persister, ISecurityManager security, IVersionManager versionMaker, IEditUrlManager editUrlManager, IContentAdapterProvider adapters, StateChanger changer)
        {
            this.persister = persister;
            makeVersionOfMaster = On.Master(new MakeVersionCommand(versionMaker));
            replaceMaster = new ReplaceMasterCommand(versionMaker);
            makeVersion = new MakeVersionCommand(versionMaker);
            useNewVersion = new UseNewVersionCommand(versionMaker);
            updateObject = new UpdateObjectCommand();
            delete = new DeleteCommand(persister.Repository);
            showPreview = new RedirectToPreviewCommand(adapters);
            showEdit = new RedirectToEditCommand(editUrlManager);
            useMaster = new UseMasterCommand();
            clone = new CloneCommand();
            validate = new ValidateCommand();
            this.security = security;
            save = new SaveCommand(persister);
            incrementVersionIndex = new IncrementVersionIndexCommand(versionMaker);
            draftState = new UpdateContentStateCommand(changer, ContentState.Draft);
            publishedState = new UpdateContentStateCommand(changer, ContentState.Published);
            saveActiveContent = new ActiveContentSaveCommand();
			moveToPosition = new MoveToPositionCommand();
			unpublishedDate = new EnsureNotPublishedCommand();
			publishedDate = new EnsurePublishedCommand();
			updateReferences = new UpdateReferencesCommand();
        }
 public bool Process(CommandBase command)
 {
     if (command.CurrentState == CommandState.Pending)
     {
         return ProcessFilters(command);
     }
     return false;
 }
Exemple #7
0
        public void Send(CommandBase command)
        {
            busyService.MarkAsBusy();

            var commands = new List<CommandBase> {command};

            var service = new NAdCommandServiceClient();
            //service.ExecuteCompleted += OnExecuteCompleted;
            //service.ExecuteAsync(new ObservableCollection<Command>(commands), commands);
        }
        public Command(CommandBase.commVals inCommandInstruction, Object inValue)
        {
            switch (inCommandInstruction)
                {
                    case commVals.Load:
                        this.Code = (int)inCommandInstruction;
                        try
                        {
                            if (inValue.GetType() == typeof(int))
                            {
                                this.leftOperand = null;
                                this.MemoryCellNeeded = (int)inValue;
                            }
                            else
                                this.leftOperand = (PBNumber)inValue;
                        }
                        catch (Exception ex)
                        {
                            throw new IncorrectOperandType("Command(" + inCommandInstruction + ", " + inValue + ")=[ " + ex.Message + " ]");
                        }

                        break;
                    case commVals.Mem:
                        this.Code = (int)inCommandInstruction;
                        try
                        {
                            this.MemoryCellUsed = (int)inValue;
                        }
                        catch (Exception ex)
                        {
                            throw new IncorrectMemoryCellAddress("Command(" + inCommandInstruction + ", " + (String)inValue + ")=[ " + ex.Message + " ]");
                        }

                        break;
                    default :
                        this.Code = (int)inCommandInstruction;
                        try
                        {
                            if (inValue.GetType() == typeof(int))
                            {
                                this.leftOperand = null;
                                this.MemoryCellNeeded = (int)inValue;
                            }
                            else
                                this.leftOperand = (PBNumber)inValue;
                        }
                        catch (Exception ex)
                        {
                            throw new IncorrectOperandType("Command(" + inCommandInstruction + ", " + inValue + ")=[ " + ex.Message + " ]");
                        }
                        break;
                }
        }
 public OrderedCommandsFilter(CommandBase[] commands, Dictionary<ICommandBase, bool> commandsTracking)
 {
     _commands = commands;
     _commandsTracking = commandsTracking;
     CompletedCommandsObserver = Observer.Create<CommandBase>(c =>
                                                     {
                                                         if (commandsTracking.ContainsKey(c))
                                                         {
                                                             commandsTracking[c] = true;
                                                         }
                                                         if (commandsTracking.Values.All(v => v)) Dispose();
                                                     });
 }
		public UninstallCommand(CommandBase<ExecutionContext> parentCommand): base(parentCommand) {}
 public CookieGuardedCommand(CommandBase guardedCommand, string commandId, int cookieExpirationDays = 365)
     : this(guardedCommand, commandId, cookieExpirationDays, null)
 {
 }
        /// <summary>
        /// Converts the string representation of a Message to its Message. A return value indicates whether the operation succeeded
        /// </summary>
        /// <param name="s">A string containing a messsage to convert.</param>
        /// <param name="result">When this method returns, contains the Message value equivalent to the date and time contained in s, if the conversion succeeded, or Null if the conversion failed. The conversion fails if the s parameter is a null reference (Nothing in Visual Basic), or does not contain a valid string representation of a message. This parameter is passed uninitialized</param>
        /// <returns>true if the s parameter was converted successfully; otherwise, false. </returns>
        public bool ParseMessage(string s, out CommandBase result)
        {
            string rxSpace = @"[\t ]+";
            string rxOrigin = @"(?<origin>[A-Z][A-Z\-]*)";
            string rxDestination = @"((?<destination>[A-Z][A-Z\-]*)" + rxSpace + ")?";
            string rxCommand = @"(?<cmd>[a-z][a-zA-Z0-9\-_]*)";
            string rxParam = @"(?<param>(\x22[^\x00\0x22@]*\x22)|(\w(\w|\t|\.|-)*\w))";
            //string rxParam = @"(?<param>(\x22[^\x00\0x22@]*\x22)|(\w[^\x22\x00@]*\w))";
            //string rxParam = @"(?<param>\x22[a-zA-Z0-9\-_ \t\.]*\x22)";
            string rxSuccess = @"(" + rxSpace + "(?<success>1|0))?";
            string rxId = "(" + rxSpace + @"\@(?<id>\d+)[\t ]*)?";
            Match m;
            Regex rx;
            ModuleClient origin;
            ModuleClient destination;
            string command;
            string param;
            string success;
            string id;
            string msg;

            result = null;
            rx = new Regex(rxOrigin + rxSpace + rxDestination + "(?<msg>(" + rxCommand + rxSpace + rxParam + rxSuccess + "))" + rxId, RegexOptions.Compiled);
            m = rx.Match(s.Trim());
            if (!m.Success) return false;
            origin = getModule(m.Result("${origin}"));
            //m = new Message();
            destination = getModule(m.Result("${destination}"));
            command = m.Result("${cmd}");
            param = m.Result("${param}");
            success = m.Result("${success}");
            id = m.Result("${id}");
            msg = m.Result("${msg}");
            if (origin == null)
            {
                if (MessageReceived != null) MessageReceived(result);
                return false;
            }
            if (MessageReceived != null)
                MessageReceived(result);
            //if (destination != null)
            //	RedirectMsg(origin, destination, m);

            if (command != "")
                Process(origin, command, param, id);
            //else Process(origin, str, id);
            return true;
        }
 private bool ProcessFilters(CommandBase command)
 {
     IFilter[] localFilters = null;
     while (true)
     {
         lock (holdChanges)
         {
             localFilters = Filters.OrderBy(f => f.Order).ToArray();
             _filtersChanged = false;
         }
         if (!localFilters.Any()) return true;
         int index = 0;
         while (index < localFilters.Count() && !_filtersChanged)
         {
             bool result = localFilters[index++].Process(command);
             if (!result) return false;
         }
         if (!_filtersChanged) return true;
     }
 }
 public void LogEvent(CommandBase command)
 {
     throw new NotImplementedException();
 }
Exemple #15
0
        /// <summary>
        /// Reply Code 212
        /// </summary>
        /// <param name="info"></param>
        /// <param name="command"></param>
        public void SendStatsCommands(UserInfo info, CommandBase command)
        {
            BuildMessageHeader(info, ReplyCode.StatsCommands);

            response.Append(" ");
            response.Append(command.Name);
            response.Append(" ");
            response.Append(command.CallCountIn);
            response.Append(" ");
            response.Append(command.ByteCountIn + command.ByteCountOut);
            response.Append(" ");
            response.Append(command.CallCountOut);

            info.WriteLine(response);
        }
		public UpdateCommand(CommandBase<ExecutionContext> parentCommand): base(parentCommand) {}
Exemple #17
0
 private static void Register(CommandBase cmd)
 {
     _commands[cmd.Name().ToLower()] = cmd;
 }
Exemple #18
0
        private string MakeDesc(CommandBase cmd, int longestNameLength)
        {
            var args = cmd.Args().Select(x => string.Format("[{0}]", x)).ToDelimitedString(" ");

            return string.Format("{0} {1}", cmd.Name().PadRight(longestNameLength), args);
        }