private void ClearContacts() { if (!_feature.ClearContacts) { using (IStorageItem item = GetIndexItem()) item?.Delete(); return; } if (Contacts != null) { try { Contacts.Delete(); } catch (Exception e) { Logger.Instance.Warning(this, "Error clearing contacts folder for {0}: {1}", DisplayName, e); // There was an error deleting the contacts folder, try clearing it using (IStorageItem index = GetIndexItem()) { index?.Delete(); } Contacts.Clear(); } CleanupContactsObject(); } }
private static async Task TestItemRoundtrip(IStorageItem item) { var expectedContent = GetRandomItemContent(); Assert.False(await item.Exists()); Assert.Null(await item.Get()); Assert.False(await item.Delete()); await item.PutText(expectedContent); var actualContent = await item.GetText(); Assert.Equal(expectedContent, actualContent); Assert.True(await item.Exists()); Assert.True(await item.Delete()); Assert.False(await item.Exists()); Assert.Null(await item.Get()); Assert.False(await item.Delete()); }
public void DetermineSequence() { try { // Find the newest chunk ChunkIndex?newestChunkIndex = FindNewestChunkIndex(); if (newestChunkIndex == null) { CurrentSequence = null; } else { Logger.Instance.Trace(this, "Newest chunk: {0}", newestChunkIndex.Value); int?currentSequence = CurrentSequence; if (!currentSequence.HasValue || currentSequence.Value != newestChunkIndex?.numberOfChunks) { // Sequence has changed. Delete contacts Logger.Instance.Trace(this, "Rechunked, deleting contacts"); ClearContacts(); // Determine new sequence if (newestChunkIndex == null) { using (IStorageItem index = GetIndexItem()) { if (index != null) { index.Delete(); } } } else { int numberOfChunks = newestChunkIndex.Value.numberOfChunks; using (IStorageItem index = GetIndexItem()) { index.SetUserProperty(PROP_CURRENT_SEQUENCE, numberOfChunks); index.SetUserProperty(PROP_LAST_PROCESSED, CreateChunkStateString(numberOfChunks)); index.Save(); } } } } } catch (Exception e) { Logger.Instance.Trace(this, "Exception determining sequence: {0}", e); // Delete the index item using (IStorageItem index = GetIndexItem()) index?.Delete(); return; } Logger.Instance.Trace(this, "Current sequence: {0}", CurrentSequence); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { return(AfpResultCode.FPObjectNotFound); } IStorageItem deleteItem = null; if (!string.IsNullOrEmpty(pathName)) { deleteItem = container.Content(pathName); } if (deleteItem == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer deleteContainer = (deleteItem as IStorageContainer); if (deleteContainer != null && deleteContainer.Contents().Count() > 0) { return(AfpResultCode.FPDirNotEmpty); } deleteItem.Delete(); return(AfpResultCode.FPNoErr); }