/// <summary> /// Apaga um ficheiro de um utilizador /// </summary> /// <param name="id"></param> /// <param name="filename"></param> private static void DeleteUserFile(int id, string filename) { DataBaseManager db = new DataBaseManager(); var filepath = AppDomain.CurrentDomain.BaseDirectory + "Users\\" + db.GetUsername(id) + "\\" + filename; if (File.Exists(filepath)) { db.RemoveFilettl(id, filename); File.Delete(filepath); } }
/// <summary> /// Verifica o tempo de vida de todos os ficheiros /// </summary> /// <param name="uid"></param> /// <returns></returns> public static bool VerifyUFilesDate(int uid) { DataBaseManager db = new DataBaseManager(); List <Filettl> f = db.GetUFiles(uid); List <Filettl> toRemove = f.FindAll(x => DateTime.Now.Subtract(x.FVal) > new TimeSpan(0, 0, 0)); toRemove.ForEach(x => { DeleteUserFile(x.Uid, x.FName); db.RemoveFilettl(x.Uid, x.FName); }); return(null != toRemove); //DataBaseManager db = new DataBaseManager(); //List<Filettl> f = db.GetUFiles(uid); //List<Filettl> toRemove = f.FindAll(x => DateTime.Now.Subtract(x.FVal) > new TimeSpan(0, 0, 0)); //if (f != null) //{ // toRemove.ForEach(x => // { // DeleteUserFile(x.Uid, x.FName); // db.RemoveFilettl(x.Uid, x.FName); // }); // return true; //} //else return false; //DataBaseManager db = new DataBaseManager(); //List<Filettl> f = db.GetUFiles(uid); //if (f != null) //{ // foreach (Filettl t in f) // { // DateTime now = DateTime.Now; // TimeSpan diff = now.Subtract(t.FVal); // if (diff > new TimeSpan(0, 0, 0)) // { // DeleteUserFile(t.Uid, t.FName); // db.RemoveFilettl(t.Uid,t.FName); // return true; // } // } //} //return false; }
static Random rand = new Random(); //Gerador de números á sorte para os tokens #endregion #region Methods /// <summary> /// Verfica se os ficheiros de um dado utilizador estão dentro do prazo de vida /// </summary> /// <param name="uid"></param> /// <param name="filename"></param> /// <returns></returns> public static bool VerifyUFilesDate(int uid, string filename) { DataBaseManager db = new DataBaseManager(); List <Filettl> f = db.GetUFiles(uid); if (f != null) { foreach (Filettl t in f) { if (t.FName.CompareTo(filename) == 0) { DateTime now = DateTime.Now; TimeSpan diff = now.Subtract(t.FVal); if (diff > new TimeSpan(0, 0, 0)) { DeleteUserFile(t.Uid, t.FName); db.RemoveFilettl(uid, t.FName); return(true); } } } } return(false); }