public bool Combine(IWriteOperation other) { WriteBytesOperation write_op = other as WriteBytesOperation; if (write_op == null) return false; int offset = bytes.Count; foreach (var op in write_op.bytes) { bytes.Add (op); } if (write_op.callback != null) { if (callback == null && callbacks == null) callback = write_op.callback; else { if (callbacks == null) { callbacks = new List<CallbackInfo> (); callbacks.Add (new CallbackInfo (offset - 1, callback)); callback = null; } callbacks.Add (new CallbackInfo (bytes.Count - 1, write_op.callback)); } } return true; }
protected TResult ExecuteOperation <TResult>(IWriteOperation <TResult> operation, bool useImplicitSession = false) { using (var binding = CreateReadWriteBinding(useImplicitSession)) using (var bindingHandle = new ReadWriteBindingHandle(binding)) { return(operation.Execute(bindingHandle, CancellationToken.None)); } }
protected void VerifySessionIdWasSentWhenSupported <TResult>(IWriteOperation <TResult> operation, string commandName, bool async) { VerifySessionIdWasSentWhenSupported( (binding, cancellationToken) => operation.ExecuteAsync(binding, cancellationToken), (binding, cancellationToken) => operation.Execute(binding, cancellationToken), commandName, async); }
protected async Task <TResult> ExecuteOperationAsync <TResult>(IWriteOperation <TResult> operation) { using (var binding = CoreTestConfiguration.GetReadWriteBinding(_session.Fork())) using (var bindingHandle = new ReadWriteBindingHandle(binding)) { return(await operation.ExecuteAsync(bindingHandle, CancellationToken.None)); } }
#pragma warning restore 649 CacheEntry GetCacheEntry(IWriteOperation operation, BuildSettings settings, BuildUsageTagGlobal globalUsage) { var entry = new CacheEntry(); entry.Type = CacheEntry.EntryType.Data; entry.Guid = HashingMethods.Calculate("WriteSerializedFiles", operation.Command.internalName).ToGUID(); entry.Hash = HashingMethods.Calculate(Version, operation.GetHash128(), settings.GetHash128(), globalUsage).ToHash128(); return(entry); }
public bool Combine(IWriteOperation other) { WriteBytesOperation write_op = other as WriteBytesOperation; if (write_op == null) return false; foreach (var op in write_op.Bytes) { Bytes.Add (op); } return true; }
#pragma warning restore 649 CacheEntry GetCacheEntry(IWriteOperation operation, BuildSettings settings, BuildUsageTagGlobal globalUsage, bool onlySaveFirstSerializedObject) { var entry = new CacheEntry(); entry.Type = CacheEntry.EntryType.Data; entry.Guid = HashingMethods.Calculate("WriteSerializedFiles").ToGUID(); entry.Hash = HashingMethods.Calculate(Version, operation.GetHash128(), settings.GetHash128(), globalUsage, onlySaveFirstSerializedObject).ToHash128(); entry.Version = Version; return(entry); }
/// <summary> /// Executes a write operation using a channel source. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="operation">The write operation.</param> /// <param name="channelSource">The channel source.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A Task whose result is the result of the operation.</returns> public static async Task <TResult> ExecuteAsync <TResult>( this IWriteOperation <TResult> operation, IChannelSourceHandle channelSource, CancellationToken cancellationToken) { Ensure.IsNotNull(operation, "operation"); using (var writeBinding = new ChannelSourceReadWriteBinding(channelSource.Fork(), ReadPreference.Primary)) { return(await operation.ExecuteAsync(writeBinding, cancellationToken).ConfigureAwait(false)); } }
protected TResult ExecuteOperation <TResult>(IWriteOperation <TResult> operation, bool async, bool useImplicitSession = false) { if (async) { return(ExecuteOperationAsync(operation, useImplicitSession).GetAwaiter().GetResult()); } else { return(ExecuteOperation(operation, useImplicitSession)); } }
protected TResult ExecuteOperation <TResult>(IWriteOperation <TResult> operation, bool async) { if (async) { return(ExecuteOperationAsync(operation).GetAwaiter().GetResult()); } else { return(ExecuteOperation(operation)); } }
protected TResult ExecuteOperation <TResult>(IWriteOperation <TResult> operation, IReadWriteBinding binding, bool async) { if (async) { return(operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult()); } else { return(operation.Execute(binding, CancellationToken.None)); } }
/// <summary> /// Executes a write operation using a channel source. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="operation">The write operation.</param> /// <param name="channelSource">The channel source.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The result of the operation.</returns> public static TResult Execute <TResult>( this IWriteOperation <TResult> operation, IChannelSourceHandle channelSource, CancellationToken cancellationToken) { Ensure.IsNotNull(operation, nameof(operation)); using (var writeBinding = new ChannelSourceReadWriteBinding(channelSource.Fork(), ReadPreference.Primary)) { return(operation.Execute(writeBinding, cancellationToken)); } }
private void StartSending() { if (current_write_op == null) { return; } bool cont = true; while (cont) { if (disabledsending) { sending = false; return; } cont = false; if (current_write_op.IsComplete) { current_write_op.EndWrite(this); if (write_ops.Count > 0) { IWriteOperation op = write_ops.Dequeue(); sending = false; op.BeginWrite(this); current_write_op = op; current_write_op.HandleWrite(this); lock (this) { if (!sending) { cont = true; } } } else { current_write_op = null; } } else { current_write_op.HandleWrite(this); lock (this) { if (!sending) { cont = true; } } } } }
CacheEntry GetCacheEntry(IWriteOperation operation, BuildSettings settings, BuildUsageTagGlobal globalUsage, bool onlySaveFirstSerializedObject) { using (m_Log.ScopedStep(LogLevel.Verbose, "GetCacheEntry", operation.Command.fileName)) { var entry = new CacheEntry(); entry.Type = CacheEntry.EntryType.Data; entry.Guid = HashingMethods.Calculate("WriteSerializedFiles", operation.Command.fileName).ToGUID(); entry.Hash = HashingMethods.Calculate(Version, operation.GetHash128(m_Log), settings.GetHash128(), globalUsage, onlySaveFirstSerializedObject, GetPlayerSettingsHash128(settings.target)).ToHash128(); entry.Version = Version; return(entry); } }
public static async Task <TResult> ExecuteAsync <TResult>( this IWriteOperation <TResult> operation, IConnectionSourceHandle connectionSource, TimeSpan timeout, CancellationToken cancellationToken) { Ensure.IsNotNull(operation, "operation"); using (var writeBinding = new ConnectionSourceReadWriteBinding(connectionSource.Fork(), ReadPreference.Primary)) { return(await operation.ExecuteAsync(writeBinding, timeout, cancellationToken)); } }
private TResult ExecuteOperation <TResult>(IWriteOperation <TResult> operation, bool async) { using (var binding = CoreTestConfiguration.GetReadWriteBinding()) { if (async) { return(operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult()); } else { return(operation.Execute(binding, CancellationToken.None)); } } }
protected void VerifySessionIdWasNotSentIfUnacknowledgedWrite <TResult>( IWriteOperation <TResult> operation, string commandName, bool async, bool useImplicitSession) { VerifySessionIdSending( (binding, cancellationToken) => operation.ExecuteAsync(binding, cancellationToken), (binding, cancellationToken) => operation.Execute(binding, cancellationToken), AssertSessionIdWasNotSentIfUnacknowledgedWrite, commandName, async, useImplicitSession); }
public void QueueWriteOperation(IWriteOperation op) { EnableWriting(); UpdateExpires(); write_ops.Enqueue(op); if (current_write_op == null) { current_write_op = write_ops.Dequeue(); current_write_op.BeginWrite(this); } }
private void QueueWriteOperation(IWriteOperation op) { if (chunk_encode) { SocketStream.QueueWriteOperation(op); return; } if (write_ops == null) { write_ops = new Queue <IWriteOperation> (); } write_ops.Enqueue(op); }
public void QueueWriteOperation(IO.IWriteOperation op) { lock (write_ops) { write_ops.Enqueue(op); if (current_write_op == null) { current_write_op = write_ops.Dequeue(); op.BeginWrite(this); StartSending(); } } }
public void QueueWriteOperation(IWriteOperation op) { EnableWriting(); UpdateExpires(); // We try to combine the op in case they are both byte buffers // that could be sent as a single scatter/gather operation if (write_ops.Count < 1 || !write_ops.Last().Combine(op)) { write_ops.Enqueue(op); } if (current_write_op == null) { current_write_op = write_ops.Dequeue(); } }
void IRunCachedCallbacks <Item> .ProcessUncached(WorkItem <Item> item) { IWriteOperation op = m_WriteData.WriteOperations[item.Index]; string targetDir = m_UseCache != null?m_UseCache.GetCachedArtifactsDirectory(item.entry) : m_Parameters.TempOutputFolder; Directory.CreateDirectory(targetDir); using (m_Log.ScopedStep(LogLevel.Info, $"Writing {op.GetType().Name}", op.Command.fileName)) item.Context.Result = op.Write(targetDir, m_BuildSettings, m_GlobalUsage); item.Context.MetaData = CalculateFileMetadata(ref item.Context.Result); if (ScriptableBuildPipeline.slimWriteResults) { SlimifySerializedObjects(ref item.Context.Result); } }
CachedInfo GetCachedInfo(CacheEntry entry, IWriteOperation operation, WriteResult result) { var info = new CachedInfo(); info.Asset = entry; var dependencies = new HashSet <CacheEntry>(); #if !UNITY_2019_3_OR_NEWER var sceneBundleOp = operation as SceneBundleWriteOperation; if (sceneBundleOp != null) { dependencies.Add(m_Cache.GetCacheEntry(sceneBundleOp.ProcessedScene)); } var sceneDataOp = operation as SceneDataWriteOperation; if (sceneDataOp != null) { dependencies.Add(m_Cache.GetCacheEntry(sceneDataOp.ProcessedScene)); } #else var sceneBundleOp = operation as SceneBundleWriteOperation; if (sceneBundleOp != null) { dependencies.Add(m_Cache.GetCacheEntry(sceneBundleOp.Scene)); } var sceneDataOp = operation as SceneDataWriteOperation; if (sceneDataOp != null) { dependencies.Add(m_Cache.GetCacheEntry(sceneDataOp.Scene)); } #endif foreach (var serializeObject in operation.Command.serializeObjects) { dependencies.Add(m_Cache.GetCacheEntry(serializeObject.serializationObject)); } info.Dependencies = dependencies.ToArray(); SlimifySerializedObjects(ref result); info.Data = new object[] { result }; return(info); }
private void FinishCurrentWrite() { if (current_write_op == null) { return; } current_write_op.EndWrite(this); if (write_ops.Count > 0) { IWriteOperation op = write_ops.Dequeue(); op.BeginWrite(this); current_write_op = op; } else { current_write_op = null; DisableWriting(); } }
void InitializeTransfer() { stream.DisableWriting(); Libeio.Libeio.fstat(fd, (r, stat, err) => { if (r == -1) { OnComplete(-1, err); } else { Length = stat.st_size; var chunkHeader = string.Format("{0:x}\r\n", Length); var headerBytes = Encoding.ASCII.GetBytes(chunkHeader); currentPrefixBlock = new SendBytesOperation(new[] { new ByteBuffer(headerBytes, 0, headerBytes.Length) }, null); stream.EnableWriting(); currentPrefixBlock.BeginWrite(stream); } }); }
public void HandleWrite(IIOStream stream) { this.stream = (ISocketStream)stream; if (currentPrefixBlock != null && !currentPrefixBlock.IsComplete) { currentPrefixBlock.HandleWrite(stream); if (currentPrefixBlock.IsComplete) { currentPrefixBlock.EndWrite(stream); currentPrefixBlock.Dispose(); currentPrefixBlock = null; } } if (fd == -1) { OpenFile(); } else if (Length == -1) { if (!Chunked) { stream.DisableWriting(); } else { InitializeTransfer(); } } else if (position != Length) { SendNextBlock(); } else { OnComplete(0, 0); } }
protected void SendNextBlock() { stream.DisableWriting(); Libeio.read(fd, transferBuffer, position, transferBuffer.Length, (len, buf, err) => { if (position == Length) { OnComplete(len, err); } if (len > 0) { position += len; currentPrefixBlock = new SendBytesOperation(new[] { new ByteBuffer(transferBuffer, 0, len) }, null); currentPrefixBlock.BeginWrite(stream); } else { OnComplete(len, err); } stream.EnableWriting(); }); }
public TResult ExecuteWriteOperation <TResult>(IWriteBinding binding, IWriteOperation <TResult> operation, CancellationToken cancellationToken) { _calls.Enqueue(new WriteCall <TResult> { Binding = binding, Operation = operation, CancellationToken = cancellationToken }); if (_results.Count > 0) { var result = _results.Dequeue(); var exception = result as Exception; if (exception != null) { throw exception; } return((TResult)result); } return(default(TResult)); }
public bool Combine(IWriteOperation other) { SendBytesOperation send_op = other as SendBytesOperation; if (send_op == null) { return(false); } int offset = bytes.Count; foreach (var op in send_op.bytes) { bytes.Add(op); } if (send_op.callback != null) { if (callback == null && callbacks == null) { callback = send_op.callback; } else { if (callbacks == null) { callbacks = new List <CallbackInfo> (); callbacks.Add(new CallbackInfo(offset - 1, callback)); callback = null; } callbacks.Add(new CallbackInfo(bytes.Count - 1, send_op.callback)); } } return(true); }
private void QueueWriteOperation(IWriteOperation op) { if (chunk_encode) { SocketStream.QueueWriteOperation (op); return; } if (write_ops == null) write_ops = new Queue<IWriteOperation> (); write_ops.Enqueue (op); }
public void QueueWriteOperation (IWriteOperation op) { // We try to combine the op in case they are both byte buffers // that could be sent as a single scatter/gather operation if (write_ops.Count < 1 || !write_ops.Last ().Combine (op)) write_ops.Enqueue (op); EnableWriting (); }
void InitializeTransfer() { stream.DisableWriting (); Libeio.Libeio.fstat (fd, (r, stat, err) => { if (r == -1) { OnComplete (-1, err); } else { Length = stat.st_size; var chunkHeader = string.Format ("{0:x}\r\n", Length); var headerBytes = Encoding.ASCII.GetBytes (chunkHeader); currentPrefixBlock = new SendBytesOperation (new[] { new ByteBuffer (headerBytes, 0, headerBytes.Length) }, null); stream.EnableWriting (); currentPrefixBlock.BeginWrite (stream); } }); }
public Task <TResult> ExecuteWriteOperationAsync <TResult>(IWriteBinding binding, IWriteOperation <TResult> operation, CancellationToken cancellationToken) { return(operation.ExecuteAsync(binding, cancellationToken)); }
protected void SendNextBlock() { stream.DisableWriting (); Libeio.read(fd, transferBuffer, position, transferBuffer.Length, (len, buf, err) => { if (position == Length) { OnComplete (len, err); } if (len > 0) { position += len; currentPrefixBlock = new SendBytesOperation (new[] { new ByteBuffer (transferBuffer, 0, len) }, null); currentPrefixBlock.BeginWrite (stream); } else { OnComplete (len, err); } stream.EnableWriting (); }); }
public void HandleWrite(IIOStream stream) { this.stream = (ISocketStream) stream; if (currentPrefixBlock != null && !currentPrefixBlock.IsComplete) { currentPrefixBlock.HandleWrite (stream); if (currentPrefixBlock.IsComplete) { currentPrefixBlock.EndWrite (stream); currentPrefixBlock.Dispose (); currentPrefixBlock = null; } } if (fd == -1) { OpenFile (); } else if (Length == -1) { if (!Chunked) { stream.DisableWriting (); } else { InitializeTransfer (); } } else if (position != Length) { SendNextBlock (); } else { OnComplete (0, 0); } }
private void StartSending() { if (current_write_op == null) return; bool cont = true; while (cont) { if (disabledsending) { sending = false; return; } cont = false; if (current_write_op.IsComplete) { current_write_op.EndWrite(this); if (write_ops.Count > 0) { IWriteOperation op = write_ops.Dequeue(); sending = false; op.BeginWrite(this); current_write_op = op; current_write_op.HandleWrite(this); lock (this) { if (!sending) cont = true; } } else { current_write_op = null; } } else { current_write_op.HandleWrite(this); lock (this) { if (!sending) cont = true; } } } }
public TResult ExecuteWriteOperation <TResult>(IWriteBinding binding, IWriteOperation <TResult> operation, CancellationToken cancellationToken) { return(operation.Execute(binding, cancellationToken)); }
public void QueueWriteOperation(IWriteOperation op) { EnableWriting (); UpdateExpires (); // We try to combine the op in case they are both byte buffers // that could be sent as a single scatter/gather operation if (write_ops.Count < 1 || !write_ops.Last ().Combine (op)) write_ops.Enqueue (op); if (current_write_op == null) current_write_op = write_ops.Dequeue (); }
private void FinishCurrentWrite() { if (current_write_op == null) return; current_write_op.EndWrite (this); if (write_ops.Count > 0) { IWriteOperation op = write_ops.Dequeue (); op.BeginWrite (this); current_write_op = op; } else { current_write_op = null; DisableWriting (); } }
protected async Task <TResult> ExecuteOperationAsync <TResult>(IWriteOperation <TResult> operation, IWriteBinding binding) { return(await operation.ExecuteAsync(binding, CancellationToken.None)); }
public bool Combine(IWriteOperation other) { return false; }