public override void InsertItem( object itemData, IEnumerable <SyncId> changeUnitsToCreate, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem ) { IFileDataRetriever dataRetriever = (IFileDataRetriever)itemData; string path = dataRetriever.FileData.RelativePath; keyAndUpdatedVersion = null; commitKnowledgeAfterThisItem = false; try { NotifyChange("Uploading {0}...", path); SyncedNodeAttributes attrs = api.InsertNode(dataRetriever.FileData, path, dataRetriever.FileData.IsDirectory ? null : dataRetriever.FileStream); keyAndUpdatedVersion = new ItemFieldDictionary(); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), attrs.Name)); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_ID, typeof(string), attrs.Id)); } catch (ApplicationException e) { NotifyError(e); recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
// Called by the framework when an item needs to be deleted. public override void DeleteItem( ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out bool commitKnowledgeAfterThisItem ) { commitKnowledgeAfterThisItem = false; IDictionary <uint, ItemField> expectedFields = (IDictionary <uint, ItemField>)keyAndExpectedVersion; string name = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; ApplyingBlobEventArgs args = new ApplyingBlobEventArgs(ChangeType.Delete, name); EventHandler <ApplyingBlobEventArgs> applyingDelegate = ApplyingChange; applyingDelegate(this, args); DateTime expectedLastUpdate = DateTime.FromBinary((long)(ulong)expectedFields[ItemFields.CUSTOM_FIELD_TIMESTAMP].Value); try { DataStore.DeleteFile(name, expectedLastUpdate); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
// Called by the framework when an item (file) needs to be updated. public override void UpdateItem( object itemData, IEnumerable <SyncId> changeUnitsToUpdate, ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem ) { keyAndUpdatedVersion = null; commitKnowledgeAfterThisItem = false; IFileDataRetriever dataRetriever = (IFileDataRetriever)itemData; IDictionary <uint, ItemField> expectedFields = (IDictionary <uint, ItemField>)keyAndExpectedVersion; DateTime expectedLastUpdate = DateTime.FromBinary((long)(ulong)expectedFields[ItemFields.CUSTOM_FIELD_TIMESTAMP].Value); string oldName = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; try { Stream dataStream = null; if (!dataRetriever.FileData.IsDirectory) { dataStream = dataRetriever.FileStream; } string newName = CreateNewName(dataRetriever.FileData); SyncedBlobAttributes attrs; if (IsMoveOrRename(oldName, newName)) { ApplyingBlobEventArgs args = new ApplyingBlobEventArgs(ChangeType.Rename, oldName, newName); EventHandler <ApplyingBlobEventArgs> applyingDelegate = ApplyingChange; applyingDelegate(this, args); // Handle moves and renames as a delete and create. DataStore.DeleteFile(oldName, expectedLastUpdate); attrs = DataStore.InsertFile(dataRetriever.FileData, dataRetriever.RelativeDirectoryPath, dataStream); } else { ApplyingBlobEventArgs args = new ApplyingBlobEventArgs(ChangeType.Update, dataRetriever.FileData.Name); EventHandler <ApplyingBlobEventArgs> applyingDelegate = ApplyingChange; applyingDelegate(this, args); attrs = DataStore.UpdateFile(oldName, dataRetriever.FileData, dataRetriever.RelativeDirectoryPath, dataStream, expectedLastUpdate); } // Record new data after update. keyAndUpdatedVersion = new ItemFieldDictionary(); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), attrs._name)); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_TIMESTAMP, typeof(ulong), (ulong)attrs._lastModifiedTime.ToBinary())); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } commitKnowledgeAfterThisItem = false; }
public override void UpdateItem( object itemData, IEnumerable <SyncId> changeUnitsToUpdate, ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem ) { keyAndUpdatedVersion = null; commitKnowledgeAfterThisItem = false; IFileDataRetriever dataRetriever = (IFileDataRetriever)itemData; IDictionary <uint, ItemField> expectedFields = (IDictionary <uint, ItemField>)keyAndExpectedVersion; string path = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; string id = (string)expectedFields[ItemFields.CUSTOM_FIELD_ID].Value; try { SyncedNodeAttributes attrs; if (IsMoveOrRename(path, dataRetriever.FileData.RelativePath)) { NotifyChange("Moving {0} to {1}...", path, dataRetriever.FileData.RelativePath); attrs = api.MoveFile(path, dataRetriever.FileData.RelativePath, id); } else { NotifyChange("Updating {0}...", path); attrs = api.UpdateFile(path, dataRetriever.FileData, dataRetriever.FileData.IsDirectory ? null : dataRetriever.FileStream, id); } keyAndUpdatedVersion = new ItemFieldDictionary(); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), attrs.Name)); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_ID, typeof(string), attrs.Id)); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); NotifyError(e); } commitKnowledgeAfterThisItem = false; }
// ListBlobs is called by AzureBlobSyncProvider.EnumerateItems. It walks through the items in the store building up the necessary information // to detect changes. internal List <ItemFieldDictionary> ListBlobs() { List <ItemFieldDictionary> items = new List <ItemFieldDictionary>(); // Include all items in the listing including those with path like ('/') file names BlobRequestOptions opts = new BlobRequestOptions(); opts.UseFlatBlobListing = true; foreach (IListBlobItem o in Container.ListBlobs(opts)) { CloudBlob blob = Container.GetBlobReference(o.Uri.ToString()); blob.FetchAttributes(); ItemFieldDictionary dict = new ItemFieldDictionary(); dict.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), o.Uri.ToString())); dict.Add(new ItemField(ItemFields.CUSTOM_FIELD_TIMESTAMP, typeof(ulong), (ulong)blob.Properties.LastModifiedUtc.ToBinary())); items.Add(dict); } return(items); }
// Called by the framework when an item (file) needs to be added to the store. public override void InsertItem( object itemData, IEnumerable <SyncId> changeUnitsToCreate, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem ) { IFileDataRetriever dataRetriever = (IFileDataRetriever)itemData; string relativePath = dataRetriever.RelativeDirectoryPath; keyAndUpdatedVersion = null; commitKnowledgeAfterThisItem = false; ApplyingBlobEventArgs args = new ApplyingBlobEventArgs(ChangeType.Create, dataRetriever.FileData.Name); EventHandler <ApplyingBlobEventArgs> applyingDelegate = ApplyingChange; applyingDelegate(this, args); try { Stream dataStream = null; if (!dataRetriever.FileData.IsDirectory) { dataStream = dataRetriever.FileStream; } SyncedBlobAttributes attrs = DataStore.InsertFile(dataRetriever.FileData, dataRetriever.RelativeDirectoryPath, dataStream); keyAndUpdatedVersion = new ItemFieldDictionary(); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), attrs._name)); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_TIMESTAMP, typeof(ulong), (ulong)attrs._lastModifiedTime.ToBinary())); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
//This is where we load data to provide to the other endpoint. public override object LoadChangeData( ItemFieldDictionary keyAndExpectedVersion, IEnumerable <SyncId> changeUnitsToLoad, RecoverableErrorReportingContext recoverableErrorReportingContext ) { IDictionary <uint, ItemField> expectedFields = (IDictionary <uint, ItemField>)keyAndExpectedVersion; string name = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; DateTime expectedLastUpdate = DateTime.FromBinary((long)(ulong)expectedFields[ItemFields.CUSTOM_FIELD_TIMESTAMP].Value); object changeData = null; try { changeData = DataStore.GetFileRetriever(name, expectedLastUpdate); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } return(changeData); }
public override void DeleteItem( ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out bool commitKnowledgeAfterThisItem ) { commitKnowledgeAfterThisItem = false; IDictionary <uint, ItemField> expectedFields = (IDictionary <uint, ItemField>)keyAndExpectedVersion; string name = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; string id = (string)expectedFields[ItemFields.CUSTOM_FIELD_ID].Value; try { NotifyChange("Deleting {0}...", name); api.DeleteFile(name, id); } catch (ApplicationException e) { NotifyError(e); recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
public override object LoadChangeData( ItemFieldDictionary keyAndExpectedVersion, IEnumerable <SyncId> changeUnitsToLoad, RecoverableErrorReportingContext recoverableErrorReportingContext ) { IDictionary <uint, ItemField> expectedFields = (IDictionary <uint, ItemField>)keyAndExpectedVersion; string name = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; string id = (string)expectedFields[ItemFields.CUSTOM_FIELD_ID].Value; object changeData = null; try { NotifyChange("Downloading {0}...", name); changeData = api.GetFileRetriever(name, id); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); NotifyError(e); } return(changeData); }
public override void InsertItem( object itemData, IEnumerable<SyncId> changeUnitsToCreate, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem ) { IFileDataRetriever dataRetriever = (IFileDataRetriever)itemData; string path = dataRetriever.FileData.RelativePath; keyAndUpdatedVersion = null; commitKnowledgeAfterThisItem = false; try { NotifyChange("Uploading {0}...", path); SyncedNodeAttributes attrs = api.InsertNode(dataRetriever.FileData, path, dataRetriever.FileData.IsDirectory ? null : dataRetriever.FileStream); keyAndUpdatedVersion = new ItemFieldDictionary(); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), attrs.Name)); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_ID, typeof(string), attrs.Id)); } catch (ApplicationException e) { NotifyError(e); recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
public override void DeleteItem( ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out bool commitKnowledgeAfterThisItem ) { commitKnowledgeAfterThisItem = false; IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion; string name = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; string id = (string)expectedFields[ItemFields.CUSTOM_FIELD_ID].Value; try { NotifyChange("Deleting {0}...", name); api.DeleteFile(name, id); } catch (ApplicationException e) { NotifyError(e); recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
public override object LoadChangeData( ItemFieldDictionary keyAndExpectedVersion, IEnumerable<SyncId> changeUnitsToLoad, RecoverableErrorReportingContext recoverableErrorReportingContext ) { IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion; string name = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; string id = (string)expectedFields[ItemFields.CUSTOM_FIELD_ID].Value; object changeData = null; try { NotifyChange("Downloading {0}...", name); changeData = api.GetFileRetriever(name, id); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); NotifyError(e); } return changeData; }
// Called by the framework when an item needs to be deleted. public override void DeleteItem(ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out bool commitKnowledgeAfterThisItem) { commitKnowledgeAfterThisItem = false; IDictionary<uint, ItemField> expectedFields = keyAndExpectedVersion; var name = (string) expectedFields[ItemFields.CustomFieldName].Value; var args = new ApplyingBlobEventArgs(ChangeType.Delete, name); var applyingDelegate = ApplyingChange; applyingDelegate(this, args); var expectedLastUpdate = DateTime.FromBinary((long) (ulong) expectedFields[ItemFields.CustomFieldTimestamp].Value); try { DataStore.DeleteFile(name, expectedLastUpdate); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
public void MergeConstraintConflict(object itemData, ConflictVersionInformation conflictVersionInformation, IEnumerable <SyncId> changeUnitsToMerge, ItemFieldDictionary localConflictingItem, ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary updatedKeyAndVersion) { throw new NotImplementedException(); }
public override void DeleteItem(ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out bool commitKnowledgeAfterThisItem) { throw new NotImplementedException(); }
public void ResolveLocalDeleteRemoteUpdateConflict(object itemData, IEnumerable <SyncId> changeUnitsToUpdate, RecoverableErrorReportingContext recoverableErrorReportingContext, out bool itemWasDeletedAsResultOfResolution, out ItemFieldDictionary updatedVersion) { throw new NotImplementedException(); }
// ListBlobs is called by AzureBlobSyncProvider.EnumerateItems. It walks through the items in the store building up the necessary information // to detect changes. internal List<ItemFieldDictionary> ListBlobs() { var items = new List<ItemFieldDictionary>(); // Include all items in the listing including those with path like ('/') file names var opts = new BlobRequestOptions { UseFlatBlobListing = true }; foreach (var o in Container.ListBlobs(opts)) { var blob = Container.GetBlobReference(o.Uri.ToString()); blob.FetchAttributes(); var dict = new ItemFieldDictionary(); dict.Add(new ItemField(ItemFields.CustomFieldName, typeof (string), o.Uri.ToString())); dict.Add(new ItemField(ItemFields.CustomFieldTimestamp, typeof (ulong), (ulong) blob.Properties.LastModifiedUtc.ToBinary())); items.Add(dict); } return items; }
public void ModifyLocalItem(ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary updatedKeyAndVersion) { throw new NotImplementedException(); }
public void ModifyAndUpdateRemoteItem(object itemData, IEnumerable <SyncId> changeUnitsToUpdate, ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary updatedKeyAndVersion) { throw new NotImplementedException(); }
public override void UpdateItem( object itemData, IEnumerable<SyncId> changeUnitsToUpdate, ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem ) { keyAndUpdatedVersion = null; commitKnowledgeAfterThisItem = false; IFileDataRetriever dataRetriever = (IFileDataRetriever)itemData; IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion; string path = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; string id = (string)expectedFields[ItemFields.CUSTOM_FIELD_ID].Value; try { SyncedNodeAttributes attrs; if (IsMoveOrRename(path, dataRetriever.FileData.RelativePath)) { NotifyChange("Moving {0} to {1}...", path, dataRetriever.FileData.RelativePath); attrs = api.MoveFile(path, dataRetriever.FileData.RelativePath, id); } else { NotifyChange("Updating {0}...", path); attrs = api.UpdateFile(path, dataRetriever.FileData, dataRetriever.FileData.IsDirectory ? null : dataRetriever.FileStream, id); } keyAndUpdatedVersion = new ItemFieldDictionary(); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), attrs.Name)); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_ID, typeof(string), attrs.Id)); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); NotifyError(e); } commitKnowledgeAfterThisItem = false; }
// Called by the framework when an item needs to be deleted. public override void DeleteItem( ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out bool commitKnowledgeAfterThisItem ) { commitKnowledgeAfterThisItem = false; IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion; string name = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; ApplyingBlobEventArgs args = new ApplyingBlobEventArgs(ChangeType.Delete, name); EventHandler<ApplyingBlobEventArgs> applyingDelegate = ApplyingChange; applyingDelegate(this, args); DateTime expectedLastUpdate = DateTime.FromBinary((long)(ulong)expectedFields[ItemFields.CUSTOM_FIELD_TIMESTAMP].Value); try { DataStore.DeleteFile(name, expectedLastUpdate); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
//This is where we load data to provide to the other endpoint. public override object LoadChangeData( ItemFieldDictionary keyAndExpectedVersion, IEnumerable<SyncId> changeUnitsToLoad, RecoverableErrorReportingContext recoverableErrorReportingContext ) { IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion; string name = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; DateTime expectedLastUpdate = DateTime.FromBinary((long)(ulong)expectedFields[ItemFields.CUSTOM_FIELD_TIMESTAMP].Value); object changeData = null; try { changeData = DataStore.GetFileRetriever(name, expectedLastUpdate); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } return changeData; }
public void ResolveUpdateUpdateConflict(object itemData, IEnumerable <SyncId> changeUnitsToMerge, IEnumerable <SyncId> changeUnitsToUpdate, ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary updatedVersion) { throw new NotImplementedException(); }
public override void UpdateItem(object itemData, IEnumerable <SyncId> changeUnitsToUpdate, ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem) { throw new NotImplementedException(); }
// ListBlobs is called by AzureBlobSyncProvider.EnumerateItems. It walks through the items in the store building up the necessary information // to detect changes. internal List<ItemFieldDictionary> ListBlobs() { List<ItemFieldDictionary> items = new List<ItemFieldDictionary>(); // Include all items in the listing including those with path like ('/') file names BlobRequestOptions opts = new BlobRequestOptions(); opts.UseFlatBlobListing = true; foreach (IListBlobItem o in Container.ListBlobs(opts)) { CloudBlob blob = Container.GetBlobReference(o.Uri.ToString()); blob.FetchAttributes(); ItemFieldDictionary dict = new ItemFieldDictionary(); dict.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), o.Uri.ToString())); dict.Add(new ItemField(ItemFields.CUSTOM_FIELD_TIMESTAMP, typeof(ulong), (ulong)blob.Properties.LastModifiedUtc.ToBinary())); items.Add(dict); } return items; }
public void ResolveLocalUpdateRemoteDeleteConflict(ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out bool itemWasDeletedAsResultOfResolution) { throw new NotImplementedException(); }
// Called by the framework when an item (file) needs to be added to the store. public override void InsertItem( object itemData, IEnumerable<SyncId> changeUnitsToCreate, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem ) { IFileDataRetriever dataRetriever = (IFileDataRetriever)itemData; string relativePath = dataRetriever.RelativeDirectoryPath; keyAndUpdatedVersion = null; commitKnowledgeAfterThisItem = false; ApplyingBlobEventArgs args = new ApplyingBlobEventArgs(ChangeType.Create, dataRetriever.FileData.Name); EventHandler<ApplyingBlobEventArgs> applyingDelegate = ApplyingChange; applyingDelegate(this, args); try { Stream dataStream = null; if (!dataRetriever.FileData.IsDirectory) { dataStream = dataRetriever.FileStream; } SyncedBlobAttributes attrs = DataStore.InsertFile(dataRetriever.FileData, dataRetriever.RelativeDirectoryPath, dataStream); keyAndUpdatedVersion = new ItemFieldDictionary(); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), attrs._name)); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_TIMESTAMP, typeof(ulong), (ulong)attrs._lastModifiedTime.ToBinary())); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } }
internal List<ItemFieldDictionary> ListNodes() { List<ItemFieldDictionary> items = new List<ItemFieldDictionary>(); var helpers = GetFilesAndDirectories(); foreach (var h in helpers) { ItemFieldDictionary dict = new ItemFieldDictionary(); dict.Add(new ItemField(ItemFields.CUSTOM_FIELD_ID, typeof(string), h.Node.Id)); dict.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), h.Path)); items.Add(dict); } return items; }
// Called by the framework when an item (file) needs to be updated. public override void UpdateItem( object itemData, IEnumerable<SyncId> changeUnitsToUpdate, ItemFieldDictionary keyAndExpectedVersion, RecoverableErrorReportingContext recoverableErrorReportingContext, out ItemFieldDictionary keyAndUpdatedVersion, out bool commitKnowledgeAfterThisItem ) { keyAndUpdatedVersion = null; commitKnowledgeAfterThisItem = false; IFileDataRetriever dataRetriever = (IFileDataRetriever)itemData; IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion; DateTime expectedLastUpdate = DateTime.FromBinary((long)(ulong)expectedFields[ItemFields.CUSTOM_FIELD_TIMESTAMP].Value); string oldName = (string)expectedFields[ItemFields.CUSTOM_FIELD_NAME].Value; try { Stream dataStream = null; if (!dataRetriever.FileData.IsDirectory) { dataStream = dataRetriever.FileStream; } string newName = CreateNewName(dataRetriever.FileData); SyncedBlobAttributes attrs; if (IsMoveOrRename(oldName, newName)) { ApplyingBlobEventArgs args = new ApplyingBlobEventArgs(ChangeType.Rename, oldName, newName); EventHandler<ApplyingBlobEventArgs> applyingDelegate = ApplyingChange; applyingDelegate(this, args); // Handle moves and renames as a delete and create. DataStore.DeleteFile(oldName, expectedLastUpdate); attrs = DataStore.InsertFile(dataRetriever.FileData, dataRetriever.RelativeDirectoryPath, dataStream); } else { ApplyingBlobEventArgs args = new ApplyingBlobEventArgs(ChangeType.Update, dataRetriever.FileData.Name); EventHandler<ApplyingBlobEventArgs> applyingDelegate = ApplyingChange; applyingDelegate(this, args); attrs = DataStore.UpdateFile(oldName, dataRetriever.FileData, dataRetriever.RelativeDirectoryPath, dataStream, expectedLastUpdate); } // Record new data after update. keyAndUpdatedVersion = new ItemFieldDictionary(); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_NAME, typeof(string), attrs._name)); keyAndUpdatedVersion.Add(new ItemField(ItemFields.CUSTOM_FIELD_TIMESTAMP, typeof(ulong), (ulong)attrs._lastModifiedTime.ToBinary())); } catch (ApplicationException e) { recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(e)); } commitKnowledgeAfterThisItem = false; }
public override object LoadChangeData(ItemFieldDictionary keyAndExpectedVersion, IEnumerable <SyncId> changeUnitsToLoad, RecoverableErrorReportingContext recoverableErrorReportingContext) { throw new NotImplementedException(); }