Esempio n. 1
0
        private void CompleteCopy(int _nb, string _sourceDirectory, string _targetDirectory)
        {
            //Search directory info from source and target path
            var diSource = new DirectoryInfo(_sourceDirectory);
            var diTarget = new DirectoryInfo(_targetDirectory);

            //Calculate the number of file in the source directory and the total size of it
            int  nbFiles       = SourceDirectoryInfo.GetFilesNumberInSourceDirectory(diSource);
            long directorySize = SourceDirectoryInfo.GetSizeInSourceDirectory(diSource);

            CreateLogLine(nbFiles + " files to save found from " + _sourceDirectory + ",Total size of the directory: " + directorySize + " Bytes");

            //update the state File
            string json = File.ReadAllText("state.json");

            saveWorkList = JsonConvert.DeserializeObject <List <SaveWork> >(json);
            saveWorkList[_nb - 1].CreateSaveProgress(nbFiles, directorySize, nbFiles, 0, directorySize);
            saveWorkList[_nb - 1].isActive = true;
            String stringjson = JsonConvert.SerializeObject(saveWorkList, Formatting.Indented);

            File.WriteAllText("state.json", stringjson);


            //initiate Copy from the source directory to the target directory
            CreateLogLine("Saving file from " + _sourceDirectory + " to " + _targetDirectory + " ...");
            CompleteCopyAll(_nb, diSource, diTarget);
            CreateLogLine("Closing complete save work program ...");
        }
Esempio n. 2
0
        public List <SaveWork> modifyTheOrderOfTheList(List <SaveWork> list, Priority p)
        {
            List <SaveWork> priorityList = new List <SaveWork>();

            String[]      extentions = p.ExtentionList.Split(" ");
            DirectoryInfo directorySource;
            int           j             = 0;
            long          directorySize = 0;

            for (int i = 0; i < list.Count; i++)
            {
                while (Directory.GetFiles(list[i].SrcPath, extentions[j]).Length != 0 && j < extentions.Length)
                {
                    j++;
                }
                if (j >= extentions.Length)
                {
                    directorySource = new DirectoryInfo(list[i].SrcPath);
                    //Calculate the total size of th file
                    directorySize = SourceDirectoryInfo.GetSizeInSourceDirectory(directorySource);

                    //converte kiloByte in byte
                    if (directorySize < int.Parse(p.SizeFile) * 1000)
                    {
                        priorityList.Add(list[i]);
                    }
                }
            }
            if (priorityList.Count == 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    directorySource = new DirectoryInfo(list[i].SrcPath);
                    //Calculate the total size of th file
                    directorySize = SourceDirectoryInfo.GetSizeInSourceDirectory(directorySource);

                    //converte kiloByte in byte
                    if (directorySize < int.Parse(p.SizeFile) * 1000)
                    {
                        priorityList.Add(list[i]);
                    }
                }
            }
            if (priorityList.Count == 0)
            {
                return(list);
            }
            else
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (!priorityList.Contains(list[i]))
                    {
                        priorityList.Add(list[i]);
                    }
                }
                return(priorityList);
            }
        }
Esempio n. 3
0
        private void DifferencialCopy(int _nb, string _sourceDirectory, string _targetDirectory)
        {
            //Search directory info from source and target path
            var diSource = new DirectoryInfo(_sourceDirectory);
            var diTarget = new DirectoryInfo(_targetDirectory);

            //Calculate the number of file in the source directory and the total size of it (of all )
            int  nbFiles       = SourceDirectoryInfo.DifferencialGetFilesNumberInSourceDirectory(diSource, diTarget);
            long directorySize = SourceDirectoryInfo.DifferencialGetSizeInSourceDirectory(diSource, diTarget);

            //If there is at least one file to save then initiate the differencial saving protocol
            if (nbFiles != 0)
            {
                CreateLogLine(nbFiles + " files to save found from " + _sourceDirectory + ",Total size of the directory: " + directorySize + " Bytes");
                //update the state File
                string json = File.ReadAllText("state.json");
                saveWorkList = JsonConvert.DeserializeObject <List <SaveWork> >(json);
                saveWorkList[_nb - 1].CreateSaveProgress(nbFiles, directorySize, nbFiles, 0, directorySize);
                saveWorkList[_nb - 1].isActive = true;
                String stringjson = JsonConvert.SerializeObject(saveWorkList, Formatting.Indented);
                File.WriteAllText("state.json", stringjson);



                //initiate Copy from the source directory to the target directory (only the file / directory that has been modified or are new)
                CreateLogLine("Saving file from " + _sourceDirectory + " to " + _targetDirectory + " ...");
                DifferencialCopyAll(_nb, diSource, diTarget);
            }
            //If there is no file to save then cancel the saving protocol
            else
            {
                CreateLogLine("There is no file to save in the target directory");
            }

            CreateLogLine("Closing differencial save work program ...");
        }