Esempio n. 1
0
        public static RecordDataModel.FolderDataModel GetFolderMd5Hash(string strFolderFullPATH)
        {
            logger.Debug($"Got follderpath \"{strFolderFullPATH}\", generating FolderData instance");
            RecordDataModel.FolderDataModel data = new RecordDataModel.FolderDataModel();

            DirectoryInfo folder = new DirectoryInfo(strFolderFullPATH);

            data.folderName = folder.Name;
            data.fileDatas  = new List <RecordDataModel.FileDataModel>();
            //foreach (FileInfo file in folder.GetFiles())
            for (int c = 0; c < folder.GetFiles().Length; c++)
            {
                FileInfo file = folder.GetFiles()[c];
                logger.Debug($"<Folder: {data.folderName}>Starting generate FileData for file {file.Name}");
                File(file, data);
                //logger.Debug($"<Folder: {data.folderName}>FileData generated: {data.fileDatas[data.fileDatas.Count - 1].fileName}, Md5Hash: {data.fileDatas[data.fileDatas.Count - 1].Md5Hash}");
            }
            bool check = false;

            Task.WhenAll(tasks).ContinueWith((s) => { check = true; });


            while (true)
            {
                if (check)
                {
                    return(data);
                }
            }
        }
Esempio n. 2
0
        private static async void File(FileInfo file, RecordDataModel.FolderDataModel data)
        {
            RecordDataModel.FileDataModel fileData = null;


            Task t = Task.Run(() =>
            {
                void callback(IAsyncResult are)
                {
                    Func <string, RecordDataModel.FileDataModel> func1 = are.AsyncState as Func <string, RecordDataModel.FileDataModel>;
                    fileData = func1.EndInvoke(are);
                    data.fileDatas.Add(fileData);
                }

                Func <string, RecordDataModel.FileDataModel> func = (path) =>
                {
                    string Md5 = GetFileMd5Hash(file.FullName);

                    return(new RecordDataModel.FileDataModel()
                    {
                        fileName = file.Name, Md5Hash = Md5
                    });
                };

                var ar = func.BeginInvoke(file.FullName, callback, func);
            });
            await t;

            tasks.Add(t);
        }