|
|
|
@ -27,18 +27,16 @@ namespace GBase.DataHandling |
|
|
|
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the async operation</param> |
|
|
|
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the async operation</param> |
|
|
|
/// <returns>Returns true if successful, false if not</returns> |
|
|
|
/// <returns>Returns true if successful, false if not</returns> |
|
|
|
/// <exception cref="Exception">No root element found</exception> |
|
|
|
/// <exception cref="Exception">No root element found</exception> |
|
|
|
public async Task<bool> InitFile(FileStream file, string rootElementName, CancellationToken cancellationToken) |
|
|
|
public async Task InitFile(FileStream file, string rootElementName, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//if the xml file isn't empty, return |
|
|
|
//if the xml file isn't empty, return |
|
|
|
if (file.Length > 3) //> 3 because of BOM |
|
|
|
if (file.Length > 3) //> 3 because of BOM |
|
|
|
return true; //TODO: Don't return bool? |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
XDocument xmlDocument = new XDocument(); |
|
|
|
XDocument xmlDocument = new XDocument(); |
|
|
|
xmlDocument.Add(new XElement(rootElementName)); |
|
|
|
xmlDocument.Add(new XElement(rootElementName)); |
|
|
|
file.Seek(0, SeekOrigin.Begin); //reset stream to it's beginning to be able to save it |
|
|
|
file.Seek(0, SeekOrigin.Begin); //reset stream to it's beginning to be able to save it |
|
|
|
await xmlDocument.SaveAsync(file, SaveOptions.OmitDuplicateNamespaces, cancellationToken); |
|
|
|
await xmlDocument.SaveAsync(file, SaveOptions.OmitDuplicateNamespaces, cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
|