Esempio n. 1
1
 public IEnumerable<string> Handle(string input, Match match, IListener listener)
 {
     var tl = new TorrentLeech();
     var movies = tl.GetEntries(TorrentLeech.Movies).Distinct().Take(20).ToArray();
     var names = movies.Select(o => o.Friendly).ToArray();
     Brain.Pipe.ListenOnce((i, m, l) =>
         {
             var movie = m.Groups[1].Value;
             var entry = movies.FirstOrDefault(o => o.Friendly.ToLower().Contains(movie));
             if(entry == null)
                 return;
             if(!entry.Download())
             {
                 Brain.Pipe.ListenNext((s, match1, listener1) =>
                     {
                         if (match1.Value == "yes")
                         {
                             entry.Download(true);
                             listener1.Output(Speech.Yes.Parse());
                             listener1.Output("I shall redownload it.");
                             return;
                         }
                         listener1.Output(Speech.Yes.Parse());
                         listener1.Output("I won't redownload it.");
                     }, "yes", "no");
                 l.Output("You've already downloaded that sir. Do you want to redownload it?");
             }
             else
             {
                 l.Output("Downloading " + entry.Friendly + "...");
             }
         }, "download (.+)");
     yield return "Here are the latest films. Do you want to download any of them?";
     yield return string.Join(", ", names) + "\r\n";
 }
Esempio n. 2
1
        public string Handle(string input, Match match, IListener listener)
        {
            var query = match.Groups[1].Value;
            var tl = new TorrentLeech();
            var results = tl.Search(query);
            var res = string.Empty;
            var count = 0;

            foreach(var result in results)
            {
                if (count > 7)
                    break;
                res += count++ + ": " + result.Title + ": " + result.Size + " MB" + Environment.NewLine;
            }

            Brain.Pipe.ListenNext((input2, match2, listener2) =>
                                      {
                                          if (match2.Value == "cancel" || match2.Value == "none" || match2.Value == "nevermind")
                                              return "Cancelled";

                                          var index = -1;
                                          int.TryParse(match2.Groups[1].Value, out index);
                                          if (index == -1 || index >= results.Count)
                                              return "Cancelled";

                                          var selected = results[index];
                                          selected.Download();
                                          return "Downloading: " + selected.Friendly;
                                      }, "cancel|none|nevermind", @"download (\d+)");
                    return res;
        }
Esempio n. 3
0
 public void RemoveListener(IListener i)
 {
     if (IsListenerContained(i))
     {
         listenerList.Remove(i);
     }
 }
Esempio n. 4
0
 public void AddListener(IListener i)
 {
     if(!IsListenerContained(i))
     {
         listenerList.Add(i);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// StartService
        /// </summary>
        public void StartService(string listener, string userName = "", string password = "", string address = "", string path = "", string command = "", int port = 0)
        {
            try
            {
                Constants.log.Info("Entering Listener Service StartService Method!");
                if (listener == Constants.UDP)
                {
                    Constants.log.Info("Calling UDP Listener");
                    _listener = new UdpListener();
                }
                else if (listener == Constants.SSH)
                {
                    Constants.log.Info("Calling SSH Listener");
                    _listener = new SshListener();
                }
                else if (listener == Constants.SCP)
                {
                    Constants.log.Info("Calling SCP Listener");
                    _listener = new ScpListener();
                }

                _listener.UserName = userName;
                _listener.Password = password;
                _listener.Address = address;
                _listener.Path = path;
                _listener.Command = command;
                _listener.Port = port;

                Constants.log.Info("Exiting Listener Service StartService Method!");
            }
            catch(Exception ex)
            {
                Constants.log.Error(ex.Message);
            }
        }
Esempio n. 6
0
 public IEnumerable<string> Handle(string input, Match match, IListener listener)
 {
     var output = ScheduleTicker.Instance.Tasks
         .Where(o => o.DateTime < DateTime.Now.AddDays(2))
         .Select(task => task.Description + " at " + task.DateTime.ToShortTimeString());
     return output;
 }
Esempio n. 7
0
 public string Handle(string input, Match match, IListener listener)
 {
     var subject = match.Groups[1].Value.Trim();
     var search = new Search(subject);
     Brain.RunnableManager.Runnable = new ProcessRunnable(search.Link);
     return search.Description;
 }
Esempio n. 8
0
 public void UnRegister(IListener listener)
 {
     if (listener is AI.AI)
     {
         UnRegister(listener as AI.AI);
     }
 }
Esempio n. 9
0
        private int runCount = 0; // number of times run has been called

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Bot"/> class.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="userInteraction">The user interaction manager..</param>
        /// <param name="console">The console.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="listener">The listener.</param>
        /// <param name="pluginHandler">The plugin handler.</param>
        /// <param name="moduleLoader">The module loader.</param>
        /// <param name="authorization">The authorization manager.</param>
        public Bot(
            Client client, 
            IUserInteraction userInteraction, 
            IConsole console, 
            IBotSettings settings, 
            IListener listener, 
            IPluginHandler pluginHandler,
            IModuleLoader moduleLoader,
            IAuthorization authorization)
        {
            Guard.Against(client.IsNull(), "client");
            Guard.Against(userInteraction.IsNull(), "userInteraction");
            Guard.Against(console.IsNull(), "console");
            Guard.Against(settings.IsNull(), "settings");
            Guard.Against(listener.IsNull(), "listener");
            Guard.Against(pluginHandler.IsNull(), "pluginHandler");
            Guard.Against(moduleLoader.IsNull(), "moduleLoader");
            Guard.Against(authorization.IsNull(), "authorization");

            this.client = client;
            this.userInteraction = userInteraction;
            this.console = console;
            this.settings = settings;
            this.listener = listener;
            this.pluginHandler = pluginHandler;
            this.moduleLoader = moduleLoader;
            this.authorization = authorization;
            this.SessionStart = DateTime.Now;
        }
 public ResultSetColumnMapping(IResultSetColumnMapping other, IListener listener, IPolicies policies, ICompilerMessageBuilder messageProvider)
 {
     if(ReferenceEquals(other, null))
         throw new ArgumentNullException(nameof(other));
     this.ColumnName = other.ColumnName;
     this.PropertyName = other.PropertyName;
 }
Esempio n. 11
0
        public void Handle(string input, IListener listener)
        {
            if(input == null) return;
            input = input.ToLower();

            if (_next != null)
            {
                var clone = (DynamicCommand) _next.Clone();
                _next = null;
                if(clone.Execute(input, listener))
                    return;
            }
            _next = null;
            foreach (var c in _permanent.ToArray())
            {
                if(c.Execute(input, listener))
                    break;
            }

            foreach (var c in _once.ToArray())
            {
                if(c.Execute(input, listener))
                    _once.Remove(c);

            }
        }
Esempio n. 12
0
        public LcdpServer(ILcdpPacketSerializer lcdpPacketSerializer, IListener listener, IForwarder forwarder, IResolver resolver)
        {
            this.lcdpPacketSerializer = lcdpPacketSerializer;

            this.listener = listener;
            this.forwarder = forwarder;

            this.messages = new ConcurrentDictionary<string, LcdpMessage>();

            this.ChunkExpirationTimeMilliseconds = 5000;

            this.compressors = new Dictionary<byte, ICompressor>();
            this.serializers = new Dictionary<byte, ISerializer>();

            for(byte b = 0; b < byte.MaxValue; ++b)
            {
                ICompressor compressor = resolver.Resolve<ICompressor>(b.ToString());
                if (compressor != null)
                {
                    compressors[b] = compressor;
                }

                ISerializer serializer = resolver.Resolve<ISerializer>(b.ToString());
                if (serializer != null)
                {
                    serializers[b] = serializer;
                }
            }
        }
 private async Task StartAsyncCore(CancellationToken cancellationToken)
 {
     ListenerFactoryContext context = new ListenerFactoryContext(cancellationToken);
     _listener = await _factory.CreateAsync(context);
     _cancellationRegistration = _cancellationSource.Token.Register(_listener.Cancel);
     await _listener.StartAsync(cancellationToken);
 }
Esempio n. 14
0
        private ConnectionManager(IListener listener, IServiceDiscovery serviceDiscovery, TimeSpan? serviceDiscoveryPeriod)
        {
            this.remoteServices = new Dictionary<ServiceUri, PerformanceStatistics>();
            this.Listener = listener;
            if (serviceDiscovery != null)
            {
                this.serviceDiscovery = serviceDiscovery;
                this.serviceDiscoveryPeriod = serviceDiscoveryPeriod ?? new TimeSpan(hours: 0, minutes: 0, seconds: 5);
                this.serviceDiscoveryThread = new Thread(() =>
                {
                    while (!this.shouldStop)
                    {
                        var availableServices = this.serviceDiscovery.GetPerformanceStatistics();
                        lock (this.remoteServicesLock)
                        {
                            this.remoteServices.Clear();
                            foreach (var service in availableServices.Keys)
                            {
                                if (this.Listener==null || !service.Equals(this.Listener.CallbackUri))
                                {
                                    this.remoteServices.Add(service, availableServices[service]);
                                }
                            }
                        }

                        Thread.Sleep(this.serviceDiscoveryPeriod);
                    }
                });

                this.serviceDiscoveryThread.Start();
            }
        }
 public void ListenersWithoutHandlers()
 {
     LogManager.SetupLogManager();
     var emitter = new Emitter();
     var expected = new IListener[] {};
     Assert.Equal(expected, emitter.Listeners("foo").ToArray());
 }
Esempio n. 16
0
 public IDisposable Add(IListener t)
 {
     t.Connected += HandleConnected;
     lock(listeners)
         listeners.Add(t);
     return Disposable.New(o => Remove(o), t);
 }
 public HeartbeatListener(IRecurrentCommand heartbeatCommand,
     IBackgroundExceptionDispatcher backgroundExceptionDispatcher, IListener innerListener)
 {
     _heartbeatCommand = heartbeatCommand;
     _innerListener = innerListener;
     _timer = CreateTimer(backgroundExceptionDispatcher);
 }
Esempio n. 18
0
 public string Handle(string input, Match match, IListener listener)
 {
     var text = match.Groups[1].Value;
     //test code
     ToastView.Create(text, "taimur38", false);
     return text;
 }
 public SingletonListener(MethodInfo method, SingletonAttribute attribute, SingletonManager singletonManager, IListener innerListener)
 {
     _method = method;
     _attribute = attribute;
     _singletonManager = singletonManager;
     _innerListener = innerListener;
 }
Esempio n. 20
0
 public HttpListenerServer(string prefix)
 {
     _contexts = HttpObservable.GetContexts(prefix);
     const string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
     _buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
     Console.WriteLine("Listening on " + prefix);
 }
Esempio n. 21
0
 private void Parse(string q, List<FileInfo> videos, IListener listener)
 {
     videos = videos.Where(o => o.Name.ToLower().Contains(q)).ToList();
     if(videos.Count > 1)
     {
         listener.Output("Which one of these should I play?");
         listener.Output(string.Join("\r\n", videos.Select(o => o.Name.ToLower())));
         Brain.Pipe.ListenNext((input, match, listener1) => Parse(input, videos, listener), "(.+)");
     }
     if (videos.Count == 0)
     {
         listener.Output("I could not find that video sir.");
     }
     if (videos.Count == 1)
     {
         var video = videos.First();
         Process.Start(video.FullName);
         var name = video.Name.Replace(".", " ").Trim().RegexRemove(video.Extension);
         name = name.RegexReplace(@"s(\d+)", "Season $1 ");
         name = name.RegexReplace(@"e(\d+)", "Episode $1 ");
         name = name.Trim().RemoveExtraSpaces();
         name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower());
         listener.Output("Playing " + name);
     }
 }
Esempio n. 22
0
 public string Handle(string input, Match match, IListener listener)
 {
     var output = ScheduleTicker.Instance.Tasks
         .Where(o => o.DateTime < DateTime.Now.AddDays(2))
         .Aggregate("", (current, task) => current + (task.Description + " at " + task.DateTime.ToShortTimeString() + Environment.NewLine));
     return output.Trim();
 }
Esempio n. 23
0
        public void RemoveHandler(IListener<PropertyChangedEventArgs> eventHandler)
        {
            if (eventHandler == null)
                throw new ArgumentNullException("eventHandler", "eventHandler is null.");

            m_Manager.RemoveHandler(eventHandler);
        }
Esempio n. 24
0
 public SerfidCore(IListener listener, IFilter filter, IStorage storage, IUser user)
 {
     _listener = listener;
     _filter = filter;
     _storage = storage;
     _user = user;
 }
 public void Register(IListener listener)
 {
     if (listener.Order == Constants.INVALID_ORDER)
     {
         listener.Order = _listenerList.Count;
         _listenerList.Add(listener);
     }
 }
Esempio n. 26
0
 public IEnumerable<string> Handle(string input, Match match, IListener listener)
 {
     var task = match.Groups[1].Value;
     var time = match.Groups[2].Value;
     var dateTime = RelativeDateParser.Parse(input);
     ScheduleTicker.Instance.AddTask(dateTime,task);
     yield return "I will remind you to {0} at {1}".Template(task, dateTime.ToString());
 }
 public void UnregisterFromAll(IListener listener)
 {
     foreach (var eventType in Listeners.Keys)
     {
         if (Listeners[eventType].Contains(listener))
             Listeners[eventType].Remove(listener);
     }
 }
Esempio n. 28
0
        public Streaming(IRequestAuthorizer authorizer, IListener listener)
        {
            if (authorizer == null) throw new ArgumentNullException(nameof(authorizer));
            if (listener == null) throw new ArgumentNullException(nameof(listener));

            _authorizer = authorizer;
            _listener = listener;
        }
 public void ListenersWithoutHandlers()
 {
     var emitter = new Emitter();
     var expected = new IListener[] {};
     //Assert.AreEqual(expected, emitter.Listeners("foo").ToArray());
     Assert.AreEqual(expected.Count(), emitter.Listeners("foo").ToArray().Count());
     CollectionAssert.AreEqual(expected, emitter.Listeners("foo").ToArray());
 }
Esempio n. 30
0
        public static ILexer Create(string language, IListener listener)
        {
            var key = language.ToLower();
            if (LexerActivators.ContainsKey(key))
                return LexerActivators[key](listener);

            throw new ArgumentOutOfRangeException(language, string.Format("No lexer exists for language '{0}'", language));
        }
Esempio n. 31
0
 public ListenerInfo(IListener source, UserSettings settings)
 {
     ListenerSource = source;
     PropertyChangedEventManager.AddHandler(ListenerSource, ListenerInfo_PropertyChanged, string.Empty);
 }
 public ProbingOnErrorListener(PureEngineIoSocket socket, ImmutableList <Transport> transport, IListener freezeTransport)
 {
     _socket         = socket;
     Transport       = transport;
     FreezeTransport = freezeTransport;
 }
Esempio n. 33
0
 public void SetListener(IListener listener)
 {
     manager = listener;
 }
        public bool Setup(
            IFunctionIndex functions,
            IListenerFactory functionsListenerFactory,
            out IFunctionExecutor hostCallExecutor,
            out IListener listener,
            out HostOutputMessage hostOutputMessage,
            string hostId,
            CancellationToken shutdownToken)
        {
            string sharedQueueName = HostQueueNames.GetHostQueueName(hostId);
            var    sharedQueue     = sharedQueueName;

            IListenerFactory sharedQueueListenerFactory = new HostMessageListenerFactory(_storageServices, sharedQueue,
                                                                                         _exceptionHandler, _loggerFactory, functions,
                                                                                         _functionInstanceLogger, _functionExecutor);

            Guid             hostInstanceId               = Guid.NewGuid();
            string           instanceQueueName            = HostQueueNames.GetHostQueueName(hostInstanceId.ToString("N"));
            var              instanceQueue                = instanceQueueName;
            IListenerFactory instanceQueueListenerFactory = new HostMessageListenerFactory(_storageServices, instanceQueue,
                                                                                           _exceptionHandler, _loggerFactory, functions,
                                                                                           _functionInstanceLogger, _functionExecutor);

            HeartbeatDescriptor heartbeatDescriptor = new HeartbeatDescriptor
            {
                SharedContainerName = HostContainerNames.Hosts,
                SharedDirectoryName = HostDirectoryNames.Heartbeats + "/" + hostId,
                InstanceBlobName    = hostInstanceId.ToString("N"),
                ExpirationInSeconds = (int)HeartbeatIntervals.ExpirationInterval.TotalSeconds
            };

            var dashboardAccount = _storageAccountOptions.GetDashboardStorageAccount();

            var blob = dashboardAccount.CreateCloudBlobClient()
                       .GetContainerReference(heartbeatDescriptor.SharedContainerName)
                       .GetBlockBlobReference(heartbeatDescriptor.SharedDirectoryName + "/" + heartbeatDescriptor.InstanceBlobName);
            IRecurrentCommand heartbeatCommand = new UpdateHostHeartbeatCommand(new HeartbeatCommand(blob));

            IEnumerable <MethodInfo> indexedMethods = functions.ReadAllMethods();
            Assembly hostAssembly = JobHostContextFactory.GetHostAssembly(indexedMethods);
            string   displayName  = hostAssembly != null?AssemblyNameCache.GetName(hostAssembly).Name : "Unknown";

            hostOutputMessage = new JobHostContextFactory.DataOnlyHostOutputMessage
            {
                HostInstanceId      = hostInstanceId,
                HostDisplayName     = displayName,
                SharedQueueName     = sharedQueueName,
                InstanceQueueName   = instanceQueueName,
                Heartbeat           = heartbeatDescriptor,
                WebJobRunIdentifier = WebJobRunIdentifier.Current
            };

            hostCallExecutor = JobHostContextFactory.CreateHostCallExecutor(instanceQueueListenerFactory, heartbeatCommand,
                                                                            _exceptionHandler, shutdownToken, _functionExecutor);
            IListenerFactory hostListenerFactory = new CompositeListenerFactory(functionsListenerFactory,
                                                                                sharedQueueListenerFactory, instanceQueueListenerFactory);

            listener = JobHostContextFactory.CreateHostListener(hostListenerFactory, _sharedQueueHandler, heartbeatCommand, _exceptionHandler, shutdownToken);

            return(true);
        }
Esempio n. 35
0
 public SharedBlobQueueListener(IListener listener, BlobQueueTriggerExecutor executor)
 {
     _listener = listener;
     _executor = executor;
 }
Esempio n. 36
0
 public async Task Help(IListener listener, IRespondable respondTo, IList <string> args, LinkedMessage e)
 {
     LinkedChannel channel = e.channel;
     await channel.respond(">_>");
 }
 public int CompareTo(IListener other) => GetId().CompareTo(other.GetId());
Esempio n. 38
0
 public virtual void DisposeListener(IListener listener)
 {
     this.Listeners.Remove(listener.Topic.ToLower());
 }
Esempio n. 39
0
 public ProbingOnUpgradeListener(FreezeTransportListener freezeTransport, ImmutableList <Transport> transport)
 {
     this._freezeTransport = freezeTransport;
     this._transport       = transport;
 }
Esempio n. 40
0
 public void addListener(IListener listener)
 {
     _listeners.Add(listener);
 }
Esempio n. 41
0
        public static Stream <Maybe <string> > Lookup(Stream <string> sWord)
        {
            StreamSink <Maybe <string> > sDefinition = Stream.CreateSink <Maybe <string> >();
            IListener listener = sWord.Listen(wrd =>
            {
                Task.Run(() =>
                {
                    //System.out.println("look up " + wrd);
                    Maybe <string> def = Maybe.None;
                    try
                    {
                        Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        s.Connect("dict.org", 2628);
                        NetworkStream ns = new NetworkStream(s);
                        StreamReader r   = new StreamReader(ns);
                        StreamWriter w   = new StreamWriter(ns);
                        try
                        {
                            r.ReadLine();
                            w.WriteLine("DEFINE ! " + wrd);
                            w.Flush();

                            string result = r.ReadLine();

                            if (result != null && result.StartsWith("150"))
                            {
                                result = r.ReadLine();
                            }

                            if (result != null && result.StartsWith("151"))
                            {
                                StringBuilder b = new StringBuilder();
                                while (true)
                                {
                                    string l = r.ReadLine();
                                    if (l == ".")
                                    {
                                        break;
                                    }
                                    b.AppendLine(l);
                                }
                                def = Maybe.Some(b.ToString());
                            }
                            else
                            {
                                MessageBox.Show("ERROR: " + result);
                            }
                        }
                        finally
                        {
                            try
                            {
                                s.Close();
                                s.Dispose();
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("ERROR: " + e);
                    }
                    finally
                    {
                        sDefinition.Send(def);
                    }
                });
            });

            return(sDefinition.AttachListener(listener));
        }
Esempio n. 42
0
 public void Add(IListener l)
 {
     this.listeners.Add(l);
 }
Esempio n. 43
0
        public IEventSubscriptionManager AddListener <T>(IListener <T> listener, bool?holdStrongReference)
        {
            AddListener((object)listener, holdStrongReference);

            return(this as IEventSubscriptionManager);
        }
Esempio n. 44
0
 public Tunnel(IListener <IGameObject> scoreListener, IListener <ISoundable> soundListener) : base(scoreListener, soundListener)
 {
 }
Esempio n. 45
0
 public ImportForm(DBAccess saAccess, IListener listener)
 {
     InitializeComponent();
     this.saAccess = saAccess;
     this.listener = listener;
 }
Esempio n. 46
0
 public void AddListener(IListener listener)
 {
     listeners.Add(listener);
 }
Esempio n. 47
0
 public PatchCreator SetListener(IListener listener)
 {
     this.listener = listener;
     return(this);
 }
Esempio n. 48
0
 public void RemoveListener(IListener listener)
 {
     listeners.Remove(listener);
 }
Esempio n. 49
0
 public ReadModelBase(Func <IListener> getListener)
 {
     Ensure.NotNull(getListener, nameof(getListener));
     _listener = getListener();
 }
Esempio n. 50
0
 public void UnSubscribe(IListener listener, EventType eventType)
 {
 }
Esempio n. 51
0
 public ProjectManager SetListener(IListener listener)
 {
     this.listener = listener;
     return(this);
 }
Esempio n. 52
0
 public int CompareTo(IListener other)
 {
     return(this.GetId().CompareTo(other.GetId()));
 }
Esempio n. 53
0
 public ProbingOnErrorListener(Socket socket, ImmutableList <Transport> transport, IListener freezeTransport)
 {
     this._socket          = socket;
     this._transport       = transport;
     this._freezeTransport = freezeTransport;
 }
Esempio n. 54
0
 public void removeListener(IListener listener)
 {
     _listeners.Remove(listener);
 }
Esempio n. 55
0
 public ProbingOnTransportCloseListener(ProbingOnErrorListener onError)
 {
     this._onError = onError;
 }
Esempio n. 56
0
 new public virtual void Unsubscribe(IListener <MonoBehaviour> listener)
 {
     this.listeners.Remove((MonoBehaviourListener)listener);
     this.modifiedSinceLastRaise = true;
 }
 public ConnectionListener(IListener listener)
 {
     _listener = listener;
 }
 public IDisposable Listen(string topic, IListener <TRequest, TResponse> listener)
 {
     return(_messageBus.Listen(topic, listener));
 }
 public TestListener6(Emitter emitter, IListener bListener)
 {
     this._emitter   = emitter;
     this._bListener = bListener;
 }
 public SecondaryClass(IListener listener)
 {
     this.Listener = listener;
 }