Inheritance: AObject
コード例 #1
0
ファイル: Files.cs プロジェクト: lformella/xdcc-grabscher
 public bool Add(string aName, Int64 aSize)
 {
     var tFile = new File(aName, aSize);
     if (File(tFile.TmpName) == null)
     {
         return Add(tFile);
     }
     return false;
 }
コード例 #2
0
        public static void FinishFile(XG.Model.Domain.File aFile)
        {
            lock (aFile)
            {
                if (aFile.MissingSize > 0)
                {
                    return;
                }

                #region DISABLE ALL MATCHING PACKETS

                string        fileName       = XG.Model.Domain.Helper.ShrinkFileName(aFile.Name, 0);
                List <Packet> matchedPackets = (from server in Servers.All from channel in server.Channels from bot in channel.Bots from packet in bot.Packets where packet.Enabled && (XG.Model.Domain.Helper.ShrinkFileName(packet.RealName, 0).EndsWith(fileName) || XG.Model.Domain.Helper.ShrinkFileName(packet.Name, 0).EndsWith(fileName)) select packet).ToList();
                foreach (Packet tPack in matchedPackets)
                {
                    Log.Info("FinishFile(" + aFile + ") disabling " + tPack + " from " + tPack.Parent);
                    tPack.Enabled = false;
                    tPack.Commit();
                }

                #endregion

                string tmpPath   = Settings.Default.TempPath + aFile.TmpName;
                string readyPath = Settings.Default.ReadyPath + aFile.Name;

                try
                {
                    if (FileSystem.MoveFile(tmpPath, readyPath))
                    {
                        Files.Remove(aFile);

                        // great, all went right, so lets check what we can do with the file
                        var thread = new Thread(() => HandleFile(readyPath));
                        thread.Name = "HandleFile|" + aFile.Name;
                        thread.Start();
                    }
                    else
                    {
                        Log.Fatal("FinishFile(" + aFile + ") cant move file");
                    }
                }
                catch (Exception ex)
                {
                    Log.Fatal("FinishFile(" + aFile + ") cant finish file", ex);

                    FireNotificationAdded(Notification.Types.FileFinishFailed, aFile);
                }
            }
        }
コード例 #3
0
        public static XG.Model.Domain.File GetFileOrCreateNew(string aName, Int64 aSize)
        {
            var tFile = TryGetFile(aName, aSize);

            if (tFile != null)
            {
                return(tFile);
            }

            tFile = new XG.Model.Domain.File(aName, aSize);
            try
            {
                System.IO.File.Create(Settings.Default.TempPath + tFile.TmpName).Close();
                Files.Add(tFile);
            }
            catch (Exception ex)
            {
                Log.Fatal("GetFileOrCreateNew(" + aName + ", " + aSize + ")", ex);
                tFile = null;
            }

            return(tFile);
        }
コード例 #4
0
ファイル: Dao.cs プロジェクト: scottc/xdcc-grabscher
        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;
            }
        }
コード例 #5
0
ファイル: FileActions.cs プロジェクト: Jaglag/xdcc-grabscher
        public static XG.Model.Domain.File GetFileOrCreateNew(string aName, Int64 aSize)
        {
            var tFile = TryGetFile(aName, aSize);
            if (tFile != null)
            {
                return tFile;
            }

            tFile = new XG.Model.Domain.File(aName, aSize);
            try
            {
                System.IO.File.Create(Settings.Default.TempPath + tFile.TmpName).Close();
                Files.Add(tFile);
            }
            catch (Exception ex)
            {
                Log.Fatal("GetFileOrCreateNew(" + aName + ", " + aSize + ")", ex);
                tFile = null;
            }

            return tFile;
        }
コード例 #6
0
ファイル: AParser.cs プロジェクト: lformella/xdcc-grabscher
        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);
        }
コード例 #7
0
ファイル: Files.cs プロジェクト: lformella/xdcc-grabscher
 public bool Remove(File aFile)
 {
     return base.Remove(aFile);
 }
コード例 #8
0
ファイル: Files.cs プロジェクト: lformella/xdcc-grabscher
 public bool Add(File aFile)
 {
     return base.Add(aFile);
 }