public int CompareTo(object obj) { DirKey dk = (DirKey)obj; if (this.SortID > dk.SortID) { return(-1); } else if (this.SortID == dk.SortID) { return(0); } else { return(1); } }
protected void Page_Load(object sender, EventArgs e) { Master.SelectedTab = tabID.tabAdmin; CheckAdmin(Profile.GetUser(Page.User.Identity.Name).CanManageData); bool fNumericKeySort = true; string szRoot = util.GetStringParam(Request, "r"); if (!Enum.TryParse <MFBImageInfo.ImageClass>(szRoot, out MFBImageInfo.ImageClass imageClass)) { imageClass = MFBImageInfo.ImageClass.Flight; } CurrentSource = imageClass; switch (CurrentSource) { case MFBImageInfo.ImageClass.Flight: m_szLinkTemplate = "~/member/logbookNew.aspx/{0}?a=1"; break; case MFBImageInfo.ImageClass.Aircraft: m_szLinkTemplate = "~/member/EditAircraft.aspx?a=1&id={0}"; break; case MFBImageInfo.ImageClass.Endorsement: case MFBImageInfo.ImageClass.OfflineEndorsement: fNumericKeySort = false; break; case MFBImageInfo.ImageClass.BasicMed: break; } szBase = MFBImageInfo.BasePathFromClass(CurrentSource); bool fIsSync = (util.GetIntParam(Request, "sync", 0) != 0); bool fIsS3Orphan = (util.GetIntParam(Request, "dels3orphan", 0) != 0); int cAutoMigrate = util.GetIntParam(Request, "automigrate", 0); List <DirKey> lstDk = null; if (!IsPostBack) { if (fIsSync) { lstDk = new List <DirKey>(); if (!String.IsNullOrEmpty(szBase)) { DirectoryInfo dir = new DirectoryInfo(System.Web.Hosting.HostingEnvironment.MapPath(szBase)); DirectoryInfo[] rgSubDir = dir.GetDirectories(); int i = 0; foreach (DirectoryInfo di in rgSubDir) { // Delete the directory if it is empty FileInfo[] rgfi = di.GetFiles(); DirectoryInfo[] rgdi = di.GetDirectories(); if (rgfi.Length == 0 && rgdi.Length == 0) { di.Delete(); continue; } DirKey dk = new DirKey { Key = di.Name }; if (fNumericKeySort) { if (Int32.TryParse(dk.Key, out int num)) { dk.SortID = num; } else { dk.SortID = i; } } else { dk.SortID = i; } i++; lstDk.Add(dk); } } lstDk.Sort(); } else if (cAutoMigrate == 0) { // Get the total # of image rows DBHelper dbh = new DBHelper(String.Format(CultureInfo.InvariantCulture, "SELECT COUNT(DISTINCT imagekey) AS NumRows FROM images WHERE virtpathid={0}", (int)CurrentSource)); dbh.ReadRow((comm) => { }, (dr) => { TotalImageRows = Convert.ToInt32(dr["NumRows"], CultureInfo.InvariantCulture); }); CurrentImageRowOffset = 0; } } if (fIsSync) { SyncImages(lstDk); } else if (fIsS3Orphan) { DeleteS3Orphans(); } else if (cAutoMigrate != 0) { txtLimitFiles.Text = Math.Min(Math.Max(cAutoMigrate, 10), 100).ToString(CultureInfo.CurrentCulture); btnMigrateImages_Click(sender, e); } else { UpdateGrid(); } }
protected void Page_Load(object sender, EventArgs e) { Master.SelectedTab = tabID.tabAdmin; if (!MyFlightbook.Profile.GetUser(Page.User.Identity.Name).CanManageData) { util.NotifyAdminEvent("Attempt to view admin page", String.Format("User {0} tried to hit the admin page.", Page.User.Identity.Name), ProfileRoles.maskSiteAdminOnly); Response.Redirect("~/HTTP403.htm"); } bool fNumericKeySort = true; string szRoot = util.GetStringParam(Request, "r"); CurrentSource = MFBImageInfo.ImageClass.Flight; try { CurrentSource = (MFBImageInfo.ImageClass)Enum.Parse(typeof(MFBImageInfo.ImageClass), szRoot); } catch { } switch (CurrentSource) { case MFBImageInfo.ImageClass.Flight: m_szLinkTemplate = "~/member/logbookNew.aspx/{0}?a=1"; break; case MFBImageInfo.ImageClass.Aircraft: m_szLinkTemplate = "~/member/EditAircraft.aspx?a=1&id={0}"; break; case MFBImageInfo.ImageClass.Endorsement: fNumericKeySort = false; break; case MFBImageInfo.ImageClass.BasicMed: break; } szBase = MFBImageInfo.BasePathFromClass(CurrentSource); bool fIsSync = (util.GetIntParam(Request, "sync", 0) != 0); bool fIsS3Orphan = (util.GetIntParam(Request, "dels3orphan", 0) != 0); int cAutoMigrate = util.GetIntParam(Request, "automigrate", 0); List <DirKey> lstDk = null; if (!IsPostBack) { if (fIsSync) { lstDk = new List <DirKey>(); if (!String.IsNullOrEmpty(szBase)) { DirectoryInfo dir = new DirectoryInfo(System.Web.Hosting.HostingEnvironment.MapPath(szBase)); DirectoryInfo[] rgSubDir = dir.GetDirectories(); int i = 0; foreach (DirectoryInfo di in rgSubDir) { // Delete the directory if it is empty FileInfo[] rgfi = di.GetFiles(); DirectoryInfo[] rgdi = di.GetDirectories(); if (rgfi.Length == 0 && rgdi.Length == 0) { di.Delete(); continue; } DirKey dk = new DirKey(); dk.Key = di.Name; if (fNumericKeySort) { try { dk.SortID = Convert.ToInt32(dk.Key); } catch { dk.SortID = i; } } else { dk.SortID = i; } i++; lstDk.Add(dk); } } lstDk.Sort(); } else if (cAutoMigrate == 0) { // Get the total # of image rows DBHelper dbh = new DBHelper(String.Format("SELECT COUNT(DISTINCT imagekey) AS NumRows FROM images WHERE virtpathid={0}", (int)CurrentSource)); dbh.ReadRow((comm) => { }, (dr) => { TotalImageRows = Convert.ToInt32(dr["NumRows"]); }); CurrentImageRowOffset = 0; } } if (fIsSync) { SyncImages(lstDk); } else if (fIsS3Orphan) { DeleteS3Orphans(); } else if (cAutoMigrate != 0) { txtLimitFiles.Text = Math.Min(Math.Max(cAutoMigrate, 10), 100).ToString(); btnMigrateImages_Click(sender, e); } else { UpdateGrid(); } }