private void ProcessDirectoryDataCallBack(object state) { BackupFolder bc = state as BackupFolder; DirectoryData dc = new DirectoryData(); ThreadPoolQueueUsage++; lock (workItemsThreadLock) { currentWorkItems.Add(bc.UniqueId); } ComputeDirecoryData(bc.Directory, dc, bc.UniqueId); bc.Files = dc.FilesTotal; bc.DataSize = dc.TotalFileSize; bc.SubFolders = dc.SubDirectories; bc.RequireUpdate = false; bc.TriggerFullUpdate(); ThreadPoolQueueUsage--; if (workerThread.ThreadState == ThreadState.WaitSleepJoin && ThreadPoolQueueUsage < MaxThreadPoolQueue) { threadPoolResetEvent.Set(); } }
/// <summary> /// Compresses the files in the nominated folder, and creates a zip file on disk named as BackupStoreFoldername. /// </summary> /// <returns></returns> public void CreateBackup() { if (!Directory.Exists(BackupStoreFolder)) { Directory.CreateDirectory(Path.GetDirectoryName(BackupStoreFolder)); } string backupfile = BackupStoreFolder + @"\" + string.Format(BackupFileNameFormat, DateTime.Now); FileStream fsOut = File.Create(backupfile); ZipOutputStream zipStream = new ZipOutputStream(fsOut); zipStream.SetLevel(CompressionLevel); //0-9, 9 being the highest level of compression zipStream.Password = BackupFilePassword; // optional. Null is the same as not setting. Required if using AES. // This setting will strip the leading part of the folder path in the entries, to // make the entries relative to the starting folder. // To include the full path for each entry up to the drive root, assign folderOffset = 0. int folderOffset = BackupFolder.Length + (BackupFolder.EndsWith("\\") ? 0 : 1); CompressFolder(BackupFolder, zipStream, folderOffset); zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream zipStream.Close(); BackupState = File.Exists(backupfile) ? true : false; }
private void ProcessBackupFolderUpdateQueue() { while (runWorkerThread) { while (backupFolderUpdateQueue.Count > 0) { BackupFolder bc = null; lock (threadLock) { bc = backupFolderUpdateQueue.Dequeue(); } if (bc != null && !bc.WasDeleted) { if (ThreadPoolQueueUsage >= MaxThreadPoolQueue) { threadPoolResetEvent.Reset(); threadPoolResetEvent.WaitOne(); } ThreadPool.QueueUserWorkItem(ProcessDirectoryDataCallBack, bc); } } resetEvent.Reset(); resetEvent.WaitOne(); } }
public async Task <IActionResult> AddNewFolder(int remoteId, [FromBody] AddFolderFormData data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = _contextFactory.CreateContext()) { var remote = await context.BackupRemotes.FindAsync(remoteId); if (remote == null) { return(NotFound()); } var backupFolder = new BackupFolder(data.Path, remote) { Name = data.Name, RemoteBaseFolder = data.RemoteFolder, SyncTime = TimeValue.Parse(data.SyncTime), SyncTimeSpan = TimeSpan.Parse(data.SyncTimeSpan) }; await context.BackupFolders.AddAsync(backupFolder); await context.SaveChangesAsync(); await _mediator.Publish(new FolderCreatedNotification(backupFolder)); return(Created(Request.Path.ToString() + "/" + backupFolder.BackupFolderId, backupFolder)); } }
private void RetrieveDirectories(BackupFolder root, List <String> backupFoldersloadedFromDatabase) { try { var tempList = new DirectoryInfo(root.Fullname).GetDirectories(); foreach (DirectoryInfo d in tempList) { BackupFolder b; if (backupFoldersloadedFromDatabase.Contains(d.FullName)) { b = new BackupFolder { Fullname = d.FullName, IsChecked = true } } ; else { b = new BackupFolder { Fullname = d.FullName, IsChecked = false } }; root.Children.Add(b); RetrieveDirectories(b, backupFoldersloadedFromDatabase); } } catch (Exception) { } }
private static void ScheduleSyncNowIfNecessary(BackupFolder info, IJobDetail baseJob) { var triggerTimeToday = DateTime.Parse(info.SyncTime.ToString()); if (triggerTimeToday < DateTime.Now) { // if we choose closest time, could never happen //var triggerTimeTomorrow = triggerTimeToday.AddDays(1); //var todayDiff = DateTime.Now - triggerTimeToday; //var tomorrowDiff = triggerTimeTomorrow - DateTime.Now; //var shouldTriggerNow = todayDiff < tomorrowDiff; //if (shouldTriggerNow) //{ //} //_logger.Info($"Trigger for sync job {info.Name} is at {triggerTimeToday:t} which is in the past and closer to current time than tomorrow. Scheduling to run now."); //var triggerNow = TriggerBuilder.Create() // .ForJob(baseJob) // .StartNow() // .Build(); //_scheduler.ScheduleJob(triggerNow); } }
public void ComputeBackupFolderData(BackupFolder bc) { lock (threadLock) { backupFolderUpdateQueue.Enqueue(bc); } resetEvent.Set(); }
void UpdateChildren(BackupFolder folder, bool?newValue) { foreach (var c in folder.Children) { c.IsChecked = newValue; UpdateChildren(c, newValue); } }
public IJobDetail CreateJob(BackupFolder folder, string id) { var job = JobBuilder.Create <DiscoverFilesJob>() .WithIdentity(id, DiscoverFilesJob.JobGroupName) .Build(); job.JobDataMap["Folder"] = folder; return(job); }
internal void CancelWorkItem(BackupFolder bc) { lock (workItemsThreadLock) { if (currentWorkItems.Contains(bc.UniqueId)) { currentWorkItems.Remove(bc.UniqueId); } } }
public BindingList <BackupFolder> FillFolderTreeviewContentList() { var root = new BackupFolder { Fullname = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify) }; var backupFoldersloadedFromDatabase = clientbackup.Serialization.deserializeXML("folders.xml"); RetrieveDirectories(root, backupFoldersloadedFromDatabase); return(new BindingList <BackupFolder>(root.Children)); }
public async Task Execute(IJobExecutionContext jobContext) { Folder = (BackupFolder)jobContext.MergedJobDataMap["Folder"] ?? throw new ArgumentNullException(nameof(Folder)); _logger.LogInformation("Executing Check Files Job, fired at {date} for folder {path}", jobContext.FireTimeUtc.ToLocalTime(), Folder.Path); var job = new BackupFolderJob(Folder); try { using (var context = _contextFactory.CreateContext()) { // check if already running a job for this folder and return if so if (context.BackupJobs.Any(j => j.BackupFolderId == Folder.BackupFolderId && (j.Status == BackupFolderJobStatus.InProgress || j.Status == BackupFolderJobStatus.Pending))) { _logger.LogInformation("Job found already in progress, skipping..."); return; } var files = await GetFilesToTransfer(); if (files.Count == 0) { _logger.LogInformation($"{Folder.Path} All Files Unchanged. Skipping Sync."); return; } ; _logger.LogInformation($"{Folder.Path} Found {files.Count} files that need to be transferred."); context.Entry(job.Folder).State = EntityState.Unchanged; job.NumFiles = files.Count; context.Attach(Folder); Folder.LastSync = DateTime.UtcNow; await context.BackupJobs.AddAsync(job); await context.SaveChangesAsync(jobContext.CancellationToken); QueueFilesAsPending(files, job); } } catch (Exception ex) { using (var context = _contextFactory.CreateContext()) { context.BackupJobs.Attach(job); job.Status = BackupFolderJobStatus.Errored; await context.SaveChangesAsync(); } _logger.LogCritical(ex, "Exception while running job: {message}. {innerException} \n {stackTrace}", ex.Message, ex.InnerException?.Message, ex.StackTrace); throw; } }
public Dictionary <string, string> ToDictionary() { return(new Dictionary <string, string> { { nameof(DeployFolder), DeployFolder.ToString() }, { nameof(DeployLogsFolder), DeployLogsFolder.ToString() }, { nameof(BackupFolder), BackupFolder.ToString() }, { nameof(Logs), Logs.ToString() }, { nameof(Configs), Configs.ToString() }, { nameof(Data), Data.ToString() } }); }
void SelectName_PageEnter(object sender, PageChangedArgs args) { m_wrapper = new WizardSettingsWrapper(m_settings); BackupFolder.Setup(Program.DataConnection, true, true); if (!m_valuesAutoLoaded) { BackupName.Text = m_wrapper.ScheduleName; BackupFolder.SelectedFolder = m_wrapper.SchedulePath; } try { BackupName.Focus(); } catch { } }
public static void checkFolders() { Directory.CreateDirectory(LastExportFolder.cleanPath()); Directory.CreateDirectory(WorkoutsByDateFolder.cleanPath()); Directory.CreateDirectory(BackupFolder.cleanPath()); Directory.CreateDirectory(TempFolder.cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Indoor cycling").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Indoor swimming").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Outdoor cycling").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Outdoor swimming").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Rope").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Running").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Tennis").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Trail run").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Treadmill").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Walking").cleanPath()); Directory.CreateDirectory(workoutSportNameFolder("Unknown").cleanPath()); }
/// <summary> /// Parcours les noeuds enfant récursivement. /// Si un noeud est coché, il est ajouté à "list" /// </summary> /// <param name="item"></param> /// <param name="list"></param> private void ProcessNode(BackupFolder item, List <string> list) { if (item.IsChecked == true) { list.Add(item.Fullname); } foreach (var i in item.Children) { if (i.IsChecked == null) { ProcessNode(i, list); continue; } if ((bool)i.IsChecked == true) { list.Add(i.Fullname); ProcessNode(i, list); } } }
private void BackupFolderList_KeyUp(object sender, KeyEventArgs e) { Queue <BackupFolder> deleteQueue = new Queue <BackupFolder>(); if (e.KeyData == Keys.Delete) { foreach (DataGridViewRow row in dataGridViewBackupFolders.SelectedRows) { BackupFolder bc = row.DataBoundItem as BackupFolder; if (bc != null) { deleteQueue.Enqueue(bc); } } e.Handled = true; while (deleteQueue.Count > 0) { Settings.BackupFolders.Remove(deleteQueue.Dequeue()); } } }
public ScheduleJobForFolderRequest(BackupFolder folder) { Folder = folder; }
// ---------------- static public int Cmp(BackupFolder a, BackupFolder b) { return(string.Compare(b.name, a.name)); }
public FolderChangedNotification(BackupFolder folder) { Folder = folder; }
private void button1_Click(object sender, EventArgs e) { BackupFolder.SelectedFolder = null; //BackupFolder.Focus(); BackupFolder.AddFolder(null).BeginEdit(); }
public FolderCreatedNotification(BackupFolder folder) { Folder = folder; }
public SyncFolderNowRequest(BackupFolder folder) { Folder = folder; }