예제 #1
0
파일: XmlRW.cs 프로젝트: a1101x/sync2sync
        public static void AddNewJob(string name, string source, string destination)
        {
            if (File.Exists(SETTINGS_PATH + "Jobs.xml"))
            {
                List<Job> jobs = GetAllJobs();
                jobs.Add(new Job(name, source, destination));

                using (Stream fs = new FileStream(SETTINGS_PATH + "Jobs.xml", FileMode.Open, FileAccess.Write, FileShare.None))
                {
                    XmlSerializer xmlFormat = new XmlSerializer(typeof(List<Job>));
                    xmlFormat.Serialize(fs, jobs);
                }
            }
            else
            {
                using (Stream fs = new FileStream(SETTINGS_PATH + "Jobs.xml", FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    List<Job> jobs = new List<Job>();
                    Job newJob = new Job(name, source, destination);
                    jobs.Add(newJob);
                    XmlSerializer xmlFormat = new XmlSerializer(typeof(List<Job>));
                    xmlFormat.Serialize(fs, jobs);
                }
            }
            MainWindow.mainWindow.JobListUpdate();
        }
예제 #2
0
        private async Task CopyAllFilesAsync(Job job)
        {
            foreach (string dir in Directory.GetDirectories(job.Source, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(dir.Replace(job.Source, job.Where));
                foreach (string filename in Directory.EnumerateFiles(dir))
                {
                    using (FileStream srcStream = File.Open(filename, FileMode.Open))
                    {
                        using (FileStream stream = File.Create(filename.Replace(job.Source, job.Where)))
                        {
                            await srcStream.CopyToAsync(stream);
                        }
                    }
                }
            }

            foreach (string filename in Directory.EnumerateFiles(job.Source))
            {
                using (FileStream srcStream = File.Open(filename, FileMode.Open))
                {
                    using (FileStream stream = File.Create(job.Where + filename.Substring(filename.LastIndexOf('\\'))))
                    {
                        await srcStream.CopyToAsync(stream);
                    }
                }
            }
        }
예제 #3
0
 private bool CheckPath(Job job)
 {
     if(Directory.Exists(job.Source) && Directory.Exists(job.Where))
     {
         return true;
     }
     return false;
 }
예제 #4
0
 private bool CheckIsDirEmpty(Job job)
 {
     if(Directory.GetDirectories(job.Where).Length + Directory.GetFiles(job.Where).Length == 0)
     {
         return true;
     }
     return false;
 }
예제 #5
0
 public FilesWatcher(Job job)
 {
     _source = job.Source;
     _destination = job.Where;
 }