Exemplo n.º 1
0
        // 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));
            }
        }
Exemplo n.º 2
0
        // 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;
        }
Exemplo n.º 3
0
        // 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));
            }
        }
        // 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;
        }
        // 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));
            }
        }
        // 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));
            }
        }
Exemplo n.º 7
0
 public static void UploadingFile(object sender, ApplyingBlobEventArgs args)
 {
 }
 public static void UploadingFile(object sender, ApplyingBlobEventArgs args)
 {
 }