Revision 73cdd135 trunk/Pithos.Network/TreeHash.cs
b/trunk/Pithos.Network/TreeHash.cs | ||
---|---|---|
132 | 132 |
} |
133 | 133 |
|
134 | 134 |
//Saves the Json representation to a file |
135 |
public Task Save(string filePath) |
|
135 |
public async Task Save(string filePath)
|
|
136 | 136 |
{ |
137 | 137 |
if (String.IsNullOrWhiteSpace(filePath)) |
138 | 138 |
throw new ArgumentNullException("filePath"); |
... | ... | |
142 | 142 |
var path = Path.Combine(filePath, fileName); |
143 | 143 |
if (!Directory.Exists(filePath)) |
144 | 144 |
Directory.CreateDirectory(filePath); |
145 |
|
|
146 |
return Task.Factory |
|
147 |
.StartNew<string>(ToJson) |
|
148 |
.ContinueWith(jsonTask=> |
|
149 |
FileAsync.WriteAllText(path, jsonTask.Result)).Unwrap(); |
|
145 |
|
|
146 |
var json=await TaskEx.Run(()=>ToJson()); |
|
147 |
await FileAsync.WriteAllText(path, json); |
|
150 | 148 |
} |
151 | 149 |
|
152 |
public static Task<TreeHash> LoadTreeHash(string dataPath,Guid fileId) |
|
150 |
public static async Task<TreeHash> LoadTreeHash(string dataPath,Guid fileId)
|
|
153 | 151 |
{ |
154 | 152 |
var fileName = fileId.ToString("N"); |
155 | 153 |
var path = Path.Combine(dataPath, fileName); |
156 |
return FileAsync.ReadAllText(path).ContinueWith(loadTask => |
|
157 |
{ |
|
158 |
var json = loadTask.Result; |
|
159 |
var treeHash = Parse(json); |
|
160 |
treeHash.FileId = fileId; |
|
161 |
return treeHash; |
|
162 |
}); |
|
154 |
|
|
155 |
var json=await FileAsync.ReadAllText(path); |
|
156 |
var treeHash = Parse(json); |
|
157 |
treeHash.FileId = fileId; |
|
158 |
return treeHash; |
|
163 | 159 |
} |
164 | 160 |
|
165 | 161 |
public static TreeHash Empty = new TreeHash(DEFAULT_HASH_ALGORITHM) |
Also available in: Unified diff