public static Dictionary <string, SyncItem> GetHashList() { Dictionary <string, SyncItem> Hashlist = new Dictionary <string, SyncItem> (); //get remote hash data string HashJSON = getHashData(); //read JSON JsonTextParser parser = new JsonTextParser(); JsonObject hashes = parser.Parse(HashJSON); foreach (JsonObject field in hashes as JsonObjectCollection) { if (field.GetValue().GetType().Name != "String") { List <JsonObject> obj = (List <JsonObject>)field.GetValue(); SyncFile sf = new SyncFile(field.Name.ToString(), obj); Hashlist.Add(field.Name, sf); } else { //Console.WriteLine(field.Name, field.GetValue().ToString()); } } return(Hashlist); }
public static Dictionary<string, SyncItem> GetHashList() { Dictionary<string,SyncItem> Hashlist = new Dictionary<string,SyncItem> (); //get remote hash data string HashJSON = getHashData (); //read JSON JsonTextParser parser = new JsonTextParser (); JsonObject hashes = parser.Parse(HashJSON); foreach (JsonObject field in hashes as JsonObjectCollection) { if(field.GetValue().GetType().Name !="String" ){ List<JsonObject> obj = (List<JsonObject>)field.GetValue(); SyncFile sf =new SyncFile(field.Name.ToString(), obj); Hashlist.Add (field.Name, sf); } else{ //Console.WriteLine(field.Name, field.GetValue().ToString()); } } return Hashlist; }
public void loadSyncList(string directory) { SyncFile file; string key; ///Load the cahche file if (HashList.Count == 0 && File.Exists (Settings.HashCache)) { try{ JsonObject hashes = new JsonTextParser().Parse(File.ReadAllText(Settings.HashCache)); Console.WriteLine("using cache"); foreach (JsonObject field in hashes as JsonObjectCollection) { HashList.Add (field.Name, new SyncFile(field.Name,(JsonObject)field.GetValue())); } } catch(Exception ex){ //supress warning about timestamp and date //Console.WriteLine(ex.Message); } } foreach (String filename in Directory.GetFiles (directory)) { try{ key =filename.Replace (path, "").Replace("\\","/"); //Dont hash if the file update date is the same as the cahced version. if(HashList.ContainsKey(key) && HashList[key].ModifiedDate == File.GetLastWriteTimeUtc(filename)){ continue; } //is teh file known? if(!HashList.ContainsKey(key)){ //new files get added file = new SyncFile (filename); HashList.Add (key, file); } else{ //does it still exist if(HashList[key].CheckForRemoval()){ HashList.Remove(key); } else{ //only update if the file changed since last run. if(HashList[key].CheckForModified()){ file = new SyncFile (filename); HashList[key] = file; } } } } catch(Exception ex){ //Console.WriteLine ("skipped: " + filename + " because :" +ex.Message); } } foreach (String dir in Directory.GetDirectories(directory)) { loadSyncList (dir); } }
public void loadSyncList(string directory) { SyncFile file; string key; ///Load the cahche file if (HashList.Count == 0 && File.Exists(Settings.HashCache)) { try{ JsonObject hashes = new JsonTextParser().Parse(File.ReadAllText(Settings.HashCache)); Console.WriteLine("using cache"); foreach (JsonObject field in hashes as JsonObjectCollection) { HashList.Add(field.Name, new SyncFile(field.Name, (JsonObject)field.GetValue())); } } catch (Exception ex) { //supress warning about timestamp and date //Console.WriteLine(ex.Message); } } foreach (String filename in Directory.GetFiles(directory)) { try{ key = filename.Replace(path, "").Replace("\\", "/"); //Dont hash if the file update date is the same as the cahced version. if (HashList.ContainsKey(key) && HashList[key].ModifiedDate == File.GetLastWriteTimeUtc(filename)) { continue; } //is teh file known? if (!HashList.ContainsKey(key)) { //new files get added file = new SyncFile(filename); HashList.Add(key, file); } else { //does it still exist if (HashList[key].CheckForRemoval()) { HashList.Remove(key); } else { //only update if the file changed since last run. if (HashList[key].CheckForModified()) { file = new SyncFile(filename); HashList[key] = file; } } } } catch (Exception ex) { //Console.WriteLine ("skipped: " + filename + " because :" +ex.Message); } } foreach (String dir in Directory.GetDirectories(directory)) { loadSyncList(dir); } }