MoveFile() public static method

public static MoveFile ( string aNameOld, string aNameNew ) : bool
aNameOld string
aNameNew string
return bool
Esempio n. 1
0
        public RrdDb GetDb()
        {
            const int heartBeat = 5 * 60;             // * 1000

            string _dbPath = Settings.Default.GetAppDataPath() + "xgsnapshots.db";

            try
            {
                var db           = new RrdDb(_dbPath);
                var sourcesToAdd = new HashSet <int>();

                for (int a = 0; a <= 29; a++)
                {
                    if (!db.containsDs(a + ""))
                    {
                        sourcesToAdd.Add(a);
                    }
                }

                if (sourcesToAdd.Count > 0)
                {
                    db.close();
                    foreach (int a in sourcesToAdd)
                    {
                        var dsDef = new DsDef(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue);
                        RrdToolkit.addDatasource(_dbPath, _dbPath + ".new", dsDef);
                        FileSystem.DeleteFile(_dbPath);
                        FileSystem.MoveFile(_dbPath + ".new", _dbPath);
                    }
                    db = new RrdDb(_dbPath);
                }

                return(db);
            }
            catch (FileNotFoundException)
            {
                var rrdDef = new RrdDef(_dbPath, heartBeat);
                for (int a = 0; a <= 29; a++)
                {
                    rrdDef.addDatasource(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue);
                }

                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 1, 12 * 24);                 // one day > 1 step = 5 minutes, 12 times per hour * 24 hours
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 12, 24 * 7);                 // one week > 12 steps = 1 hour, 24 times per day * 7 days
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 4 * 12, 6 * 31);             // one month > 4 * 12 steps = 4 hours, 6 times per day * 31 days
                rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 2 * 24 * 12, 183);           // one year > 2 * 24 * 12 steps = 2 days, 183 days

                try
                {
                    new RrdDb(rrdDef).close();
                }
                catch (NullReferenceException) {}
                return(new RrdDb(_dbPath));
            }
        }
        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);
                }
            }
        }