private static void deleteAllAccessFiles() { foreach (var file in Directory.GetFiles(GetInfo.GetAppDataPath() + "Access Files")) { File.Delete(file); } }
public static void CompareLauncherVersions() { int launcherVersion = GetInfo.GetFrontEndLauncherVersion(); int currentLauncherVersion = GetInfo.GetCurrentLauncherVersion(); if (currentLauncherVersion != launcherVersion) { Console.WriteLine("Updating launcher version..."); FrontEndUpdater.UpdateLauncher(); } }
//This method will be called every 5 minutes while the application is running. //Stateinfo is required for the timer callback delegate. private void checkForUpdateTimerCallBack(object stateInfo) { //1. Check for applicable updates to the backend.xml this._needsUpdate = UpdateChecker.CompareUserInfo(this._user); //2. check for lockout signal this._lockout = GetInfo.LockoutIsEnabled(); //3. If either return true, trigger the autoEvent. if (this._needsUpdate || this._lockout) { _timer.Dispose(); this._autoEvent.Set(); } }
//This determines whether access locks currently exist on the launcher's access files. This is an effective way to //determine whether or not any of the files is currently open. private bool accessLocksExist() { var locks = from filePath in Directory.EnumerateFiles(GetInfo.GetAppDataPath() + "Access Files") where filePath.EndsWith(".laccdb") select new FileInfo(filePath); if (locks.Count() > 0) { return(true); } else { return(false); } }
public void Excecute() { //1. instantiate _autoEvent so it can be used later. _autoEvent = new AutoResetEvent(false); //2. Put text on Console for background operation and disable the "x" button. disableConsoleClose(); //3. Initial check for Access locks _accessIsOpen = accessLocksExist(); //4. Watch local access files for locks. While they exist:. FileSystemWatcher watcher = new FileSystemWatcher(GetInfo.GetAppDataPath() + "\\Access Files"); watcher.Deleted += new FileSystemEventHandler(onDeleted); watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Size; //4. Run a timer that will call a specific callback method every 5 minutes. watcher.EnableRaisingEvents = true; TimerCallback tcb = checkForUpdateTimerCallBack; this._timer = new Timer(tcb, null, new TimeSpan(0, 2, 0), new TimeSpan(0, 2, 0)); //5. Wait for an autoevent to be raised to continue execution this._autoEvent.WaitOne(); this._timer.Dispose(); //6. If autoevent is triggered, then... if (_lockout) { lockUserOut(); } else if (_needsUpdate) { updateUser(); } else { watcher.Dispose(); return; } }
//This will lock the console window from being closed and notify the user Access is running. //It will also change the console color to blue... for funzies. private void disableConsoleClose() { Console.BackgroundColor = ConsoleColor.DarkBlue; Console.ForegroundColor = ConsoleColor.White; Console.Title = "P&B Database Launcher - This window must stay open."; IntPtr hMenu = Process.GetCurrentProcess().MainWindowHandle; IntPtr hSystemMenu = GetSystemMenu(hMenu, false); EnableMenuItem(hSystemMenu, SC_CLOSE, MF_GRAYED); RemoveMenu(hSystemMenu, SC_CLOSE, MF_BYCOMMAND); Console.Clear(); Console.WriteLine("The P&B Access Database is now running. Please leave this window open. \n"); Console.WriteLine("Current user: {0} \nCurrent UserType: {1} \nCurrent RolloutVersion: {2} \nCurrent Launcher Version {3}", _user.Name, _user.UserType, GetDataFromXml.GetFrontEndSettings().RolloutVersionString, GetInfo.GetCurrentLauncherVersion()); MinimizeConsoleWindow(hMenu); }
private static void extractZipFile(DTO.Enums.UserTypeEnum userType) { ZipFile.ExtractToDirectory(GetDataFromXml.GetLatestRollout(userType, DTO.Enums.BackEndOrFrontEndEnum.FrontEnd).ZipPath, GetInfo.GetAppDataPath() + "\\Access Files\\"); }