Inheritance: AObject
Exemple #1
0
        public bool IsVisible(Packet aPacket)
        {
            if (Guid == SearchDownloads)
            {
                return aPacket.Connected;
            }

            if (Guid == SearchEnabled)
            {
                return aPacket.Enabled;
            }

            return aPacket.Name.ContainsAll(Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
        }
Exemple #2
0
 public bool RemovePacket(Packet aPacket)
 {
     return Remove(aPacket);
 }
Exemple #3
0
 public bool AddPacket(Packet aPacket)
 {
     return Add(aPacket);
 }
Exemple #4
0
 public virtual bool RemovePacket(Packet aPacket)
 {
     return Remove(aPacket);
 }
Exemple #5
0
 public virtual bool AddPacket(Packet aPacket)
 {
     return Add(aPacket);
 }
Exemple #6
0
        public void DaoWriteObjectsTest()
        {
            var dao = new XG.DB.Dao();
            dao.Scheduler = new StdSchedulerFactory().GetScheduler();
            dao.Start("Dao");

            var files = dao.Files;
            for (int a = 0; a < Count; a++)
            {
                var file = new File("test" + a, 1000000 * (a + 1));
                file.CurrentSize = 700000 * (a + 1);
                files.Add(file);
            }

            var servers = dao.Servers;
            for (int a = 1; a < Count; a++)
            {
                var server = new Server
                {
                    Connected = random.Next(1, 3) == 1,
                    Name = "irc.test.com" + a,
                    Port = 6666 + a
                };

                for (int b = 1; b < Count; b++)
                {
                    var channel = new Channel
                    {
                        Connected = random.Next(1, 3) == 1,
                        Name = "#test" + a + "-" + b
                    };

                    for (int c = 1; c < Count; c++)
                    {
                        var bot = new Bot
                        {
                            Name = "Bot " + a + "-" + b + "-" + c,
                            InfoSpeedCurrent = random.Next(100000, 1000000),
                            InfoSpeedMax = random.Next(1000000, 10000000),
                            InfoSlotCurrent = random.Next(1, 10),
                            InfoSlotTotal = random.Next(10, 100),
                            InfoQueueCurrent = random.Next(1, 10),
                            InfoQueueTotal = random.Next(10, 1000),
                            HasNetworkProblems = random.Next(1, 10) > 7,
                            LastMessage = "This is a test message that should be long enough for the most of the table and cell width test cases which are there for testing purposes.",
                            LastMessageTime = DateTime.Now.AddMinutes(random.Next(10000, 100000))
                        };

                        int rand = random.Next(1, 4);
                        if (rand == 1)
                        {
                            bot.Connected = true;
                            bot.State = Bot.States.Active;
                            bot.HasNetworkProblems = false;
                        }
                        else if (rand == 2)
                        {
                            bot.Connected = random.Next(1, 3) == 1;
                            bot.State = Bot.States.Idle;
                        }
                        else if (rand == 3)
                        {
                            bot.Connected = true;
                            bot.State = Bot.States.Waiting;
                            bot.QueueTime = random.Next(10, 100);
                            bot.QueuePosition = random.Next(1, 10);
                        }

                        for (int d = 1; d < Count; d++)
                        {
                            var ending = new string[]{"rar", "mkv", "mp3", "tar", "avi", "wav", "jpg", "bmp"};

                            var packet = new Packet
                            {
                                Name = "Pack " + a + "-" + b + "-" + c + "-" + d + "." + ending[random.Next(0, ending.Length)],
                                Id = a + b + c + d,
                                Size = random.Next(1000000, 10000000),
                                LastUpdated = DateTime.Now.AddDays(random.Next(1, 10) * -1),
                                LastMentioned = DateTime.Now.AddDays(random.Next(10, 100) * -1)
                            };

                            if (d == 1)
                            {
                                if (bot.State == Bot.States.Active)
                                {
                                    packet.Enabled = true;
                                    packet.Connected = true;
                                }
                                else if (bot.State == Bot.States.Waiting)
                                {
                                    packet.Enabled = true;
                                }
                            }
                            else if (d == 2)
                            {
                                if (bot.State == Bot.States.Waiting)
                                {
                                    packet.Enabled = true;
                                }
                            }

                            bot.AddPacket(packet);
                        }

                        channel.AddBot(bot);
                    }

                    server.AddChannel(channel);
                }

                servers.Add(server);

                var channelToDrop = server.Channels.First();
                server.RemoveChannel(channelToDrop);
            }

            var searches = dao.Searches;
            for (int a = 0; a < Count; a++)
            {
                var search = new Search
                {
                    Name = "test" + random.Next(1000, 10000)
                };

                searches.Add(search);

                search.Name = "Pack " + a;
            }
        }
Exemple #7
0
 Packet createPacket(int aId)
 {
     var packet = new Packet { Id = aId };
     return packet;
 }
Exemple #8
0
        protected AParser()
        {
            Server = new Server
            {
                Name = "test.bitpir.at"
            };

            Channel = new Channel
            {
                Name = "#test"
            };
            Server.AddChannel(Channel);

            Bot = new Bot
            {
                Name = "[XG]TestBot"
            };
            Channel.AddBot(Bot);

            Packet = new Packet
            {
                Name = "Testfile.with.a.long.name.mkv",
                RealName = "Testfile.with.a.long.name.mkv",
                Id = 1,
                Enabled = true,
                RealSize = 975304559
            };
            Bot.AddPacket(Packet);

            Connection = new XG.Plugin.Irc.IrcConnection();
            Connection.Server = Server;

            FileActions.Files = new Files();
            File = new File("Testfile.with.a.long.name.mkv", 975304559);
            FileActions.Files.Add(File);
        }
Exemple #9
0
        object ExecuteDownloadRequest(Request.PacketDownload request)
        {
            try
            {
                // checking server
                Server serv = Helper.Servers.Server(request.Server);
                if (serv == null)
                {
                    Helper.Servers.Add(request.Server);
                    serv = Helper.Servers.Server(request.Server);
                }
                serv.Enabled = true;

                // checking channel
                Channel chan = serv.Channel(request.Channel);
                if (chan == null)
                {
                    serv.AddChannel(request.Channel);
                    chan = serv.Channel(request.Channel);
                }
                chan.Enabled = true;

                // checking bot
                Bot tBot = chan.Bot(request.Bot);
                if (tBot == null)
                {
                    tBot = new Bot { Name = request.Bot };
                    chan.AddBot(tBot);
                }

                // checking packet
                Packet pack = tBot.Packet(request.PacketId);
                if (pack == null)
                {
                    pack = new Packet { Id = request.PacketId, Name = request.PacketName };
                    tBot.AddPacket(pack);
                }
                pack.Enabled = true;

                return CreateSuccessResponseAndUpdateApiKey();
            }
            catch (Exception ex)
            {
                return CreateErrorResponseAndUpdateApiKey(ex.Message);
            }
        }
        public void ParseXdccLink(string aLink)
        {
            string[] link = aLink.Substring(7).Split('/');
            string serverName = link[0];
            string channelName = link[2];
            string botName = link[3];
            int packetId = int.Parse(link[4].Substring(1));

            // checking server
            Server serv = Helper.Servers.Server(serverName);
            if (serv == null)
            {
                Helper.Servers.Add(serverName);
                serv = Helper.Servers.Server(serverName);
            }
            serv.Enabled = true;

            // checking channel
            Channel chan = serv.Channel(channelName);
            if (chan == null)
            {
                serv.AddChannel(channelName);
                chan = serv.Channel(channelName);
            }
            chan.Enabled = true;

            // checking bot
            Bot tBot = chan.Bot(botName);
            if (tBot == null)
            {
                tBot = new Bot { Name = botName };
                chan.AddBot(tBot);
            }

            // checking packet
            Packet pack = tBot.Packet(packetId);
            if (pack == null)
            {
                pack = new Packet { Id = packetId, Name = link[5] };
                tBot.AddPacket(pack);
            }
            pack.Enabled = true;
        }
Exemple #11
0
        public XdccLink()
        {
            Get["/api/{apiKey}/parseXdccLink/{server}/{servername}/{channel}/{bot}/{id}/{file}/"] = _ => {
                if (!IsApiKeyValid(_.apiKey))
                {
                    return new JsonResponse(new Result { ReturnValue = -1 }, new JsonNetSerializer());
                }

                // TODO validate
                try
                {
                    string serverName = _.server;
                    string channelName = _.channel;
                    string botName = _.bot;
                    int packetId = int.Parse(_.id);

                    // checking server
                    Server serv = SignalR.Hub.Helper.Servers.Server(serverName);
                    if (serv == null)
                    {
                        SignalR.Hub.Helper.Servers.Add(serverName);
                        serv = SignalR.Hub.Helper.Servers.Server(serverName);
                    }
                    serv.Enabled = true;

                    // checking channel
                    Channel chan = serv.Channel(channelName);
                    if (chan == null)
                    {
                        serv.AddChannel(channelName);
                        chan = serv.Channel(channelName);
                    }
                    chan.Enabled = true;

                    // checking bot
                    Bot tBot = chan.Bot(botName);
                    if (tBot == null)
                    {
                        tBot = new Bot { Name = botName };
                        chan.AddBot(tBot);
                    }

                    // checking packet
                    Packet pack = tBot.Packet(packetId);
                    if (pack == null)
                    {
                        pack = new Packet { Id = packetId, Name = _.file };
                        tBot.AddPacket(pack);
                    }
                    pack.Enabled = true;

                    IncreaseSuccessCount(_.apiKey);
                    return new JsonResponse(new Result { ReturnValue = 1 }, new JsonNetSerializer());
                }
                catch (Exception)
                {
                    IncreaseErrorCount(_.apiKey);
                    return new JsonResponse(new Result { ReturnValue = 0 }, new JsonNetSerializer());
                }
            };
        }
Exemple #12
0
 static void UpdateIndex(Packet aPacket)
 {
     _writer.UpdateDocument(new Term("Guid", aPacket.Guid.ToString()), PacketToDocument(aPacket));
     _saveNeeded = true;
 }
Exemple #13
0
 static void RemoveFromIndex(Packet aPacket)
 {
     _writer.DeleteDocuments(new TermQuery(new Term("Guid", aPacket.Guid.ToString())));
     _packets.Remove(aPacket.Guid.ToString());
     _saveNeeded = true;
 }
Exemple #14
0
        static Document PacketToDocument(Packet aPacket)
        {
            var name = aPacket.RealName != null && aPacket.RealName != "" ? aPacket.RealName : aPacket.Name;

            var doc = new Document();
            doc.Add(new Field("Guid", aPacket.Guid.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Id", "" + aPacket.Id, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Name", name.Replace("_", " ").Replace("-", " ").Replace(".", " "), Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Size", aPacket.Size.ToString(SIZE_STRING), Field.Store.YES, Field.Index.NOT_ANALYZED ));
            doc.Add(new Field("Speed", "" + (aPacket.File != null ? aPacket.File.Speed : 0), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("TimeMissing", "" + (aPacket.File != null ? aPacket.File.TimeMissing : 0), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("LastMentioned", "" + aPacket.LastMentioned.ToTimestamp(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Online", aPacket.Parent.Connected ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Enabled", aPacket.Enabled ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Connected", aPacket.Connected ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            return doc;
        }
		public void XdccSend(Packet aPacket)
		{
			try
			{
				_client.SendMessage(SendType.Message, aPacket.Parent.Name, "XDCC SEND " + aPacket.Id);
			}
			catch (NotConnectedException) {}
		}