public void scanAllFilesAttributes() { // get local path LocalDB readLocalDB = new LocalDB(); readLocalDB = readLocalDB.readfromfile(); string clientSynFolderPath = readLocalDB.getPath(); string[] filePaths = Directory.GetFiles(clientSynFolderPath, "*", SearchOption.AllDirectories); //return filePaths; //foreach (string file in filePaths) //{ // try // { // // get file attributes // Client.LocalFileSysAccess.getFileAttributes getFileAttr = new Client.LocalFileSysAccess.getFileAttributes(file); // string md5 = getFileAttr.md5Value; // DateTime dt = getFileAttr.lastModified; // } // catch (System.IO.IOException e) // { // Console.WriteLine(e.Message); // MessageBox.Show(e.Message); // return; // } foreach (string file in filePaths) { try { // new a FileInfo instance to hold each file's metadata Client.LocalFileSysAccess.FileInfo tmp = null; // get file attributes Client.LocalFileSysAccess.getFileAttributes getFileAttr = new Client.LocalFileSysAccess.getFileAttributes(file); tmp = new Client.LocalFileSysAccess.FileInfo(); tmp.time = getFileAttr.lastModified; tmp.md5r = getFileAttr.md5Value; // add to fileList Client.LocalFileSysAccess.FileList.fileInfoDic[file] = tmp; } catch (System.IO.IOException e) { Console.WriteLine(e.Message); return; } } }
// add single file to file list public void addSingleFileToFileList(string filePath) { Client.LocalFileSysAccess.FileInfo tmp = null; // get file attributes Client.LocalFileSysAccess.getFileAttributes getFileAttr = new Client.LocalFileSysAccess.getFileAttributes(filePath); tmp = new Client.LocalFileSysAccess.FileInfo(); tmp.time = getFileAttr.lastModified; tmp.md5r = getFileAttr.md5Value; // add to fileList Client.LocalFileSysAccess.FileList.fileInfoDic[filePath] = tmp; }
private bool ListWithContainerUri() { try { CloudBlobContainer container = new CloudBlobContainer(new Uri(sasUri)); string blobPrefix = null; bool useFlatBlobListing = true; var blobs = container.ListBlobs(blobPrefix, useFlatBlobListing, BlobListingDetails.None); foreach (IListBlobItem item in blobs) { if (item is CloudBlobDirectory) { Console.WriteLine("this is folder"); Console.WriteLine(item.Uri); } else { CloudBlockBlob file = (CloudBlockBlob)item; file.FetchAttributes(); string fileFullPath = clientSynFolderPath + @"\"+ file.Metadata["filePath"]; DateTime blobDataTime = new DateTime(); Program.ClientForm.addtoConsole("file.MetaData: " + (file.Metadata["timestamp"]).ToString()); //Program.ClientForm.addtoConsole("using parser:" + DateTime.Parse((file.Metadata["timestamp"]).ToString())); //blobDataTime = DateTime.ParseExact(file.Metadata["timestamp"], "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture); blobDataTime = DateTime.Parse(file.Metadata["timestamp"]); if(File.Exists(fileFullPath)) { getFileAttributes fileAttributes = new getFileAttributes(fileFullPath); /* DateTime blobDataTime = new DateTime(); blobDataTime = DateTime.ParseExact(file.Metadata["timestamp"], "MM-dd-yyyy HH:mm:ss", null); */ // if need to poll Program.ClientForm.addtoConsole("Comparing Datetime for "+fileFullPath); Program.ClientForm.addtoConsole("blobDateTime: "+blobDataTime); Program.ClientForm.addtoConsole("lastModified: "+ fileAttributes.lastModified.ToUniversalTime() ); if (DateTime.Compare(blobDataTime, fileAttributes.lastModified.ToUniversalTime()) > 0) { Program.ClientForm.addtoConsole("Comparing HashValue"); Program.ClientForm.addtoConsole("Remote: " + file.Metadata["hashValue"]); Program.ClientForm.addtoConsole("Local: "+ fileAttributes.md5Value); if (fileAttributes.md5Value != file.Metadata["hashValue"]) { //it means there some change at server Program.ClientForm.addtoConsole("Poll function called"); pollFile(file, fileFullPath, blobDataTime); } Program.ClientForm.addtoConsole("Hash Value Matched.No need to Download"); } else if(DateTime.Compare(blobDataTime, fileAttributes.lastModified.ToUniversalTime()) < 0) { Program.ClientForm.addtoConsole("Comparing HashValue"); Program.ClientForm.addtoConsole("Remote: " + file.Metadata["hashValue"]); Program.ClientForm.addtoConsole("Local: " + fileAttributes.md5Value); if (fileAttributes.md5Value != file.Metadata["hashValue"]) { //it means there is some change at client which has yet not uploaded string eventType = "change"; //LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(file); fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails(); eventdet.datetime = fileAttributes.lastModified; eventdet.filepath = fileFullPath; eventdet.eventType = eventType; if (Client.Program.filesInUse.alreadyPresent(eventdet)) { //return; Program.ClientForm.addtoConsole("Already Present in the event list"); } else { Client.Program.filesInUse.addToList(eventdet); Uploader upload = new Uploader(); upload.start(fileFullPath, "change", null,fileAttributes.lastModified); Program.ClientForm.addtoConsole("Upload Thread Started for:"+ fileFullPath); } } Program.ClientForm.addtoConsole("Hash Value Matched.No need to upload"); } Program.ClientForm.addtoConsole("Timestamp Matched."); } else { Program.ClientForm.addtoConsole("File Doesnot Exist"); Program.ClientForm.addtoConsole("Poll function Called"); pollFile(file, fileFullPath, blobDataTime); } } } } catch (Exception e) { Program.ClientForm.addtoConsole("Poll Exception:" + e.Message); Console.WriteLine(e.Message); MessageBox.Show(e.Message); return false; } return true; }