/// <summary> /// Offersa transaction to the read end /// </summary> /// <param name="rd">The reader entry.</param> protected async Task <bool> Offer(ReaderEntry rd) { Exception tex = null; bool accept = false; System.Diagnostics.Debug.Assert(rd.Source == m_readerQueue[0].Source); try { accept = (rd.Source == null || rd.Source.Task.Status == TaskStatus.WaitingForActivation) && (rd.Offer == null || await rd.Offer.OfferAsync(this)); } catch (Exception ex) { tex = ex; // Workaround to support C# 5.0, with no await in catch clause } if (tex != null) { rd.Source.TrySetException(tex); m_readerQueue.RemoveAt(0); return(false); } if (!accept) { if (rd.Source != null) { rd.Source.TrySetCanceled(); } m_readerQueue.RemoveAt(0); return(false); } return(true); }
public static void Set(this AssetPropertiesViewModel vm, ReaderEntry entry) { Application.Current.Dispatcher.Invoke(delegate { string ext = string.Join(" ", entry.GetExtension(), entry.Uexp?.GetExtension(), entry.Ubulk?.GetExtension()); string offsets; string tSize; if (entry is ReaderEntry pakEntry) { offsets = string.Join(" ", "0x" + (pakEntry.Offset + pakEntry.StructSize).ToString("X2"), entry.Uexp != null ? "0x" + (pakEntry.Uexp?.Offset + pakEntry.StructSize)?.ToString("X2") : string.Empty, entry.Ubulk != null ? "0x" + (pakEntry.Ubulk?.Offset + pakEntry.StructSize)?.ToString("X2") : string.Empty); tSize = Strings.GetReadableSize(pakEntry.Size + (pakEntry.Uexp?.Size ?? 0) + (pakEntry.Ubulk?.Size ?? 0)); } else { offsets = string.Empty; tSize = string.Empty; } vm.AssetName = entry.GetNameWithExtension(); vm.PartOf = entry.ContainerName; vm.IncludedExtensions = ext.TrimEnd(); vm.Offsets = offsets.TrimEnd(); vm.TotalSize = tSize; if (entry is FPakEntry c1) { vm.IsEncrypted = c1.Encrypted ? Properties.Resources.Yes : Properties.Resources.No; vm.CompMethod = ((ECompressionFlags)c1.CompressionMethodIndex).ToString(); } else if (entry is FIoStoreEntry c2) { vm.IsEncrypted = c2.Encrypted ? Properties.Resources.Yes : Properties.Resources.No; vm.CompMethod = c2.CompressionMethodString; } });
public static string GetJsonProperties(ReaderEntry entry, string mount, bool loadContent) { Package p = GetPackage(entry, mount, loadContent); if (!p.Equals(default))
public static string GetJsonProperties(ReaderEntry entry, string mount) => GetJsonProperties(entry, mount, false);
/// <summary> /// Registers a desire to read from the channel /// </summary> /// <param name="offer">A callback method for offering an item, use null to unconditionally accept</param> /// <param name="timeout">The time to wait for the operation, use zero to return a timeout immediately if no items can be read. Use a negative span to wait forever.</param> public async Task <T> ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null) { var rd = new ReaderEntry(offer, new TaskCompletionSource <T>(), timeout.Ticks <= 0 ? Timeout.InfiniteDateTime : DateTime.Now + timeout); using (await m_asynclock.LockAsync()) { if (m_isRetired) { ThreadPool.QueueItem(() => rd.Source.SetException(new RetiredException())); return(await rd.Source.Task); } m_readerQueue.Add(rd); if (!await MatchReadersAndWriters(true, rd.Source.Task)) { System.Diagnostics.Debug.Assert(m_readerQueue[m_readerQueue.Count - 1].Source == rd.Source); // If this was a probe call, return a timeout now if (timeout.Ticks >= 0 && rd.Expires < DateTime.Now) { m_readerQueue.RemoveAt(m_readerQueue.Count - 1); ThreadPool.QueueItem(() => rd.Source.TrySetException(new TimeoutException())); } else { // Make room if we have too many if (m_maxPendingReaders > 0 && (m_readerQueue.Count - 1) >= m_maxPendingReaders) { switch (m_pendingReadersOverflowStrategy) { case QueueOverflowStrategy.FIFO: { var exp = m_readerQueue[0].Source; m_readerQueue.RemoveAt(0); ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); } break; case QueueOverflowStrategy.LIFO: { var exp = m_readerQueue[m_readerQueue.Count - 2].Source; m_readerQueue.RemoveAt(m_readerQueue.Count - 2); ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); } break; case QueueOverflowStrategy.Reject: default: { var exp = m_readerQueue[m_readerQueue.Count - 1].Source; m_readerQueue.RemoveAt(m_readerQueue.Count - 1); ThreadPool.QueueItem(() => exp.TrySetException(new ChannelOverflowException())); await rd.Source.Task; } return(await rd.Source.Task); } } // If we have expanded the queue with a new batch, see if we can purge old entries m_readerQueueCleanup = await PerformQueueCleanupAsync(m_readerQueue, true, m_readerQueueCleanup); if (rd.Expires != Timeout.InfiniteDateTime) { ExpirationManager.AddExpirationCallback(rd.Expires, () => ExpireItemsAsync().FireAndForget()); } } } } return(await rd.Source.Task); }