Exemplo n.º 1
0
        private void SyncFoldersStructure(Action <string> syncText, string path = "")
        {
            syncText("Синхронизация папок...");
            var folders = ServerFiles.GetDirectories(x => x.IsSync);

            if (folders != null)
            {
                foreach (var folder in folders)
                {
                    if (folder.IsDeleted)
                    {
                        if (Client.DirectoryExists(folder.ServerPath))
                        {
                            try
                            {
                                Client.DeleteDirectory(folder.ServerPath);
                            }
                            catch { }
                        }
                        folder.IsSync = false;
                    }
                    else
                    {
                        try
                        {
                            Client.CreateDirectory(folder.ServerPath);
                        }
                        catch { }
                        folder.IsSync = false;
                    }
                }
            }
            syncText("Синхронизация папок завершена...");
        }
Exemplo n.º 2
0
        private void SyncDeletedFiles(Action <string> syncText, string path = "")
        {
            syncText("Удаление лишних папок...");
            var folders = ServerFiles.GetDirectories(x => true);

            if (folders != null)
            {
                foreach (var folder in folders)
                {
                    folder.IsDeleted = !Directory.Exists(folder.EnviromentPath);
                    folder.IsSync    = folder.IsSync || folder.IsDeleted;
                }
            }
            syncText("Удаление лишних файлов...");
            var files = ServerFiles.GetFiles(x => true);

            if (files != null)
            {
                foreach (var file in files)
                {
                    file.IsDeleted = !File.Exists(file.EnviromentPath);
                    file.IsSync    = file.IsSync || file.IsDeleted;
                }
            }
            syncText("Удаление файлов и папок завершено...");
        }
Exemplo n.º 3
0
        public void Initialize()
        {
            Directory.CreateDirectory("www");
            File.WriteAllText("www/index.html", "Index test contents");

            Directory.CreateDirectory("www/testFolder");
            File.WriteAllText("www/testFolder/testFile.txt", "Test text content");

            Files           = new ServerFiles();
            Files.FilesRoot = "./www";
        }
Exemplo n.º 4
0
        private void SyncFilesStructure(Action <string> syncText, string path = "")
        {
            syncText("Синхронизация файлов...");
            var files = ServerFiles.GetFiles(x => x.IsSync);

            if (files != null)
            {
                foreach (var file in files)
                {
                    if (file.IsDeleted)
                    {
                        if (Client.FileExists(file.ServerPath))
                        {
                            try
                            {
                                Client.DeleteFile(file.ServerPath);
                            }
                            catch {  }
                        }
                        file.IsSync = false;
                    }
                    else
                    {
                        if (Client.FileExists(file.ServerPath))
                        {
                            try
                            {
                                Client.DeleteFile(file.ServerPath);
                            }
                            catch { }
                        }
                        try
                        {
                            syncText("Загружается файл...\n" + file.Path);
                            Client.UploadFile(file.EnviromentPath, file.ServerPath);
                            file.Md5Hash = CalcMd5HashLocal(file);
                            file.IsSync  = false;
                        }
                        catch {  }
                    }
                }
            }
            syncText("Синхронизация файлов завершена...");
        }
Exemplo n.º 5
0
        public void DownloadFiles(Action <string> syncText)
        {
            syncText("Скачивание файлов...");
            var files = ServerFiles.GetFiles(x => true).ToList();
            int index = 1;

            foreach (var file in files)
            {
                try
                {
                    syncText("Скачивается файл...\n" + file.Path);
                    Client.DownloadFile(file.EnviromentPath, file.ServerPath, overwrite: true);
                    byte[] f = File.ReadAllBytes(file.EnviromentPath);
                    file.Md5Hash  = mD5.ComputeHash(f);
                    file.FileSize = f.LongLength;
                }
                catch { }

                index++;
            }
            syncText("Файлы загружены...");
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Save(News model, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                return(View("NewsForm", model));
            }

            if (file != null && !string.IsNullOrWhiteSpace(file.FileName))
            {
                model.ImagePath = await ServerFiles.SaveImageToLocalFiles(_environment, file, ServerFiles.news);
            }

            if (model.Id == 0)
            {
                _repository.Create(model);
            }
            else
            {
                _repository.Update(model);
            }

            return(RedirectToAction("Index", "News"));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> Save(DoctorsViewModel model, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                model.DoctorCategories = _categories.Get();
                return(View("DoctorsForm", model));
            }

            if (file != null && !string.IsNullOrWhiteSpace(file.FileName))
            {
                model.Doctor.ImagePath = await ServerFiles.SaveImageToLocalFiles(_environment, file, ServerFiles.doctors);
            }

            if (model.Doctor.Id == 0)
            {
                _repository.Create(model.Doctor);
            }
            else
            {
                _repository.Update(model.Doctor);
            }

            return(RedirectToAction("Index", "Doctors"));
        }
Exemplo n.º 8
0
        private void SyncFile(string fileName)
        {
            //MessageBox.Show("Sync - " + fileName);
            fileName = fileName.Replace(@"\\", @"\");

            string[] paths      = fileName.Split('\\');
            string   parentPath = "";

            foreach (var s in paths)
            {
                if (s != "")// Рут директорию не нужно обрабатывать
                {
                    string fileFullPath = (parentPath + @"\" + s).Replace(@"\\", @"\");
                    if (s.Contains('.'))
                    {
                        var n = ServerFiles.GetFiles(x => x.LocalPath == fileFullPath).FirstOrDefault();
                        if (n != null)
                        {
                            Console.WriteLine("Found File - " + fileFullPath);
                            if (n.Md5Hash == null)
                            {
                                Console.WriteLine("Md5Hash is null");
                                n.IsSync = true;
                            }
                            else
                            {
                                n.IsSync = !(Convert.ToBase64String(CalcMd5HashLocal(n)) == Convert.ToBase64String(n.Md5Hash));
                            }
                            Console.WriteLine(n.IsSync ? "Something Changed On - " + fileFullPath : "Nothing Changed On - " + fileFullPath);
                        }
                        else
                        {
                            var d = ServerFiles.GetDirectories(x => x.LocalPath == parentPath).FirstOrDefault();
                            if (d != null)
                            {
                                Console.WriteLine("Found Dir Of File and Add - " + fileFullPath);
                                Node sync = new Node(true, fileFullPath, LocalRootDirectory);
                                sync.IsSync = true;
                                d.AddNode(sync);
                            }
                            else
                            {
                                Console.WriteLine("Dont Found DiR!!!");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Try Find Directory - '" + fileFullPath + "'");

                        var dir = ServerFiles.GetDirectories(x => x.LocalPath == fileFullPath).FirstOrDefault();
                        if (dir != null)
                        {
                            Console.WriteLine("Found Dir - Ok - " + fileFullPath);
                        }
                        else //Если не найдена директория нужно добавить к предку этой директории
                        {
                            Console.WriteLine("Not Found Dir Go Add To Parent - " + fileFullPath);
                            var parentDir = ServerFiles.GetDirectories(x => x.LocalPath == parentPath).FirstOrDefault();
                            if (parentDir != null)
                            {
                                Node sync = new Node(false, fileFullPath, LocalRootDirectory);
                                sync.IsSync = true;
                                parentDir.AddNode(sync);
                            }
                        }
                    }
                }
                parentPath = (parentPath + @"\" + s).Replace(@"\\", @"\");
            }
        }