public T GetService <T>(PipeContext context) where T : class { var container = context.GetPayload <Scope>(); return(container.GetInstance <T>()); }
public T GetService <T>(PipeContext context) where T : class { var kernel = context.GetPayload <IKernel>(); return(kernel.Resolve <T>()); }
/// <summary> /// Extracts property data from the given <see cref="MessageContext"/>. /// </summary> /// <param name="pipe"></param> /// <returns></returns> static MessageBusMessageContext FromMessageContext(PipeContext pipe) { var context = pipe?.GetPayload <MessageContext>(); if (context == null) { return(null); } else { return new MessageBusMessageContext { MessageBusConversationId = context.ConversationId, CorrelationId = context.CorrelationId, MessageBusDestinationAddress = context.DestinationAddress, MessageBusExpirationTime = context.ExpirationTime, MessageBusFaultAddress = context.FaultAddress, MessageBusInitiatorId = context.InitiatorId, MessageBusMessageId = context.MessageId, MessageBusRequestId = context.RequestId, MessageBusResponseAddress = context.ResponseAddress, MessageBusSourceAddress = context.SourceAddress, MessageBusSentTime = context.SentTime } }; } }
public override LLVMValueRef Emit(PipeContext <LLVMBuilderRef> context) { // Ensure target struct exists on the symbol table. if (!context.SymbolTable.structs.Contains(this.TargetIdentifier)) { throw new Exception($"Reference to undefined struct named '${this.TargetIdentifier}'"); } // Retrieve the symbol from the symbol table. StructSymbol symbol = context.SymbolTable.structs[this.TargetIdentifier]; // Retrieve the target struct's LLVM reference value from the symbol. LLVMTypeRef structDef = symbol.Value; // Create a value buffer list. List <LLVMValueRef> values = new List <LLVMValueRef>(); // Populate body properties. foreach (StructProperty property in this.Body) { // Emit and append the value to the buffer list. values.Add(property.Value.Emit(context)); } // Create the resulting struct assignment value. LLVMValueRef assignment = LLVM.ConstNamedStruct(structDef, values.ToArray()); // Return the resulting struct assignment instruction. return(assignment); }
/// <summary> /// Extracts property data from the given <see cref="MessageContext"/>. /// </summary> /// <param name="context"></param> /// <returns></returns> static object FromMessageContext(PipeContext pipe) { var context = pipe?.GetPayload <MessageContext>(); if (context == null) { return(null); } else { return new { context.ConversationId, context.CorrelationId, context.DestinationAddress, context.ExpirationTime, context.FaultAddress, context.InitiatorId, context.MessageId, context.RequestId, context.ResponseAddress, context.SourceAddress, } }; } }
public T GetService <T>(PipeContext context) where T : class { var lifetimeScope = context.GetPayload <ILifetimeScope>(); return(ActivatorUtils.GetOrCreateInstance <T>(lifetimeScope)); }
public ConsumeContextScope(ConsumeContext context, params object[] payloads) : base(context) { _context = context; _payloadCache = new ListPayloadCache(payloads); }
public override async Task <bool> Process(PipeContext context) { if (context == null) { throw new System.ArgumentNullException("context"); } if (context.assets == null) { context.assets = new List <AssetEntry>(); } List <string> files = CollectAssetsToBuild(TargetPath); for (int i = 0; i < files.Count; i++) { string assetPath = files[i]; Object obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)); var type = PipleUtility.GetAssetType(obj); context.assets.Add(new AssetEntry() { assetPath = assetPath, type = type }); } await Task.FromResult(true); return(true); }
public static PipeValue Replace(PipeContext context) { string needle = (string)context.TakeArgument(); string replacement = null; PipeLambda fn = context.TakeFunction(); if (fn == null) { replacement = (string)context.TakeArgument(); } EcmaScriptRegex re; if (EcmaScriptRegex.TryParse(needle, out re)) { if (fn != null) { return(re.Replace((string)context.Value, fn)); } return(re.Replace((string)context.Value, replacement)); } string str = (string)context.Value; int pos = str.IndexOf(needle); if (pos >= 0) { return(String.Concat(str.Substring(0, pos), replacement, str.Substring(pos + needle.Length))); } return(context.Value); }
public override async Task <bool> Process(PipeContext context) { if (context == null) { throw new ArgumentNullException("context"); } var setting = context.setting; var currentGroups = setting.groups.ToArray(); for (int i = 0; i < currentGroups.Length; i++) { var g = currentGroups[i]; if (g.Default) { continue; } var bundleSchema = g.GetSchema <BundledAssetGroupSchema>(); if (bundleSchema == null) { continue; } if (g.entries.Count == 0) { setting.RemoveGroup(g); } } await Task.FromResult(true); return(true); }
public StateMachineEventContext(PipeContext context, StateMachine <TInstance> machine, TInstance instance, Event @event) : base(context) { _machine = machine; _instance = instance; _event = @event; }
/// <summary> /// Using a filter-supplied context type, block so that the one time code is only executed once regardless of how many /// threads are pushing through the pipe at the same time. /// </summary> /// <typeparam name="T">The payload type, should be an interface</typeparam> /// <param name="context">The pipe context</param> /// <param name="setupMethod">The setup method, called once regardless of the thread count</param> /// <param name="payloadFactory">The factory method for the payload context, optional if an interface is specified</param> /// <returns></returns> public static async Task OneTimeSetup <T>(this PipeContext context, Func <T, Task> setupMethod, PayloadFactory <T> payloadFactory = null) where T : class { OneTime <T> newContext = null; var existingContext = context.GetOrAddPayload <OneTimeSetupContext <T> >(() => { var payload = payloadFactory?.Invoke() ?? TypeMetadataCache <T> .InitializeFromObject(new {}); newContext = new OneTime <T>(payload); return(newContext); }); if (newContext == existingContext) { try { await setupMethod(newContext.Payload).ConfigureAwait(false); newContext.SetReady(); } catch (Exception exception) { newContext.SetFaulted(exception); throw; } } else { await existingContext.Ready.ConfigureAwait(false); } }
public override LLVMValueRef Emit(PipeContext <LLVMBuilderRef> context) { // Variable is nested within a struct (struct property). if (this.Path.nodes.Count >= 2 && context.SymbolTable.localScope.ContainsKey(this.Path.FirstNode)) { // TODO: Add support for nested properties more than 1 level. if (this.Path.nodes.Count > 2) { throw new NotImplementedException("Support for deeply nested nodes has not been implemented"); } // Retrieve the struct from the local scope in the symbol table. LLVMValueRef @struct = context.SymbolTable.localScope[this.Path.FirstNode]; // TODO: Index is hard-coded, need method to determine index from prop identifier (in local scope). // Create a reference to the struct's targeted property. LLVMValueRef reference = LLVM.BuildStructGEP(context.Target, @struct, 0, this.Identifier); // Return the reference. return(reference); } // Ensure the variable exists in the local scope. else if (!context.SymbolTable.localScope.ContainsKey(this.Identifier)) { throw new Exception($"Reference to undefined variable named '{this.Identifier}'"); } // Retrieve the value. LLVMValueRef value = context.SymbolTable.localScope[this.Identifier]; // Return the retrieved value. return(value); }
public PayloadCacheScope(PipeContext context) { _context = context; CancellationToken = context.CancellationToken; _payloadCache = new PayloadCache(); }
public PayloadCacheScope(PipeContext context) { _parentCache = new PipeContextPayloadAdapter(context); CancellationToken = context.CancellationToken; _payloadCache = new PayloadCache(); }
public static void UpdatePayload(this PipeContext context, Scope scope) { context.GetOrAddPayload(() => scope); var container = scope.Container; context.AddOrUpdatePayload(() => container, existing => container); }
public IPipeElement <PipeContext, TInput, TReturn> StartWithActivity <TInput, TReturn>( TInput input, ISyncActivityStepProvider <TInput, TReturn> provider) { var context = new PipeContext(_serviceProvider); return(new StartElement <PipeContext, TInput, TReturn>(context, input, provider)); }
public static void UpdatePayload(this PipeContext context, IServiceScope scope) { context.GetOrAddPayload(() => scope); var serviceProvider = scope.ServiceProvider; context.AddOrUpdatePayload(() => serviceProvider, existing => serviceProvider); }
public override LLVMValueRef Emit(PipeContext <LLVMBuilderRef> context) { // Emit the value. LLVMValueRef valueRef = Resolvers.Literal(this.tokenType, this.value, this.type); // Return the emitted value. return(valueRef); }
public static PipeValue Test(PipeContext context) { PipeLambda testFn = context.TakeFunction() ?? context.TakeArgumentAsConstantFunction(); PipeLambda trueFn = context.TakeFunction() ?? context.TakeArgumentAsConstantFunction(); PipeLambda falseFn = context.TakeFunction() ?? context.TakeArgumentAsConstantFunction(); return(testFn.Invoke(context.Value) ? trueFn.Invoke(context.Value) : falseFn.Invoke(context.Value)); }
ILifetimeScope GetLifetimeScope(PipeContext context) { if (context.TryGetPayload <ILifetimeScope>(out var payload)) { return(payload); } return(_lifetimeScope ?? throw new MassTransitException("The lifetime scope was not in the payload, and a default lifetime scope was not specified.")); }
public StateMachineEventContextProxy(PipeContext context, StateMachine <TInstance> machine, TInstance instance, Event <TData> @event, TData data) : base(context) { _machine = machine; _instance = instance; _event = @event; _data = data; }
/// <summary> /// A pipe using the parent scope cancellationToken /// </summary> /// <param name="context"></param> /// <param name="payloads">Loads the payload cache with the specified objects</param> protected ScopePipeContext(PipeContext context, params object[] payloads) { _context = context; if (payloads != null && payloads.Length > 0) { _payloadCache = new ListPayloadCache(payloads); } }
public async Task <PipeContext <T> > RunAsync(T obj, CancellationToken token) { var context = new PipeContext <T>(obj, _cloner); context.AddSnapshot("original"); await _finalHandler(context, token).ConfigureAwait(false); return(context); }
public IPipeElement <PipeContext, TInput, TReturn> StartWithActivity <TInput, TReturn, TStepProvider>( TInput input) { var context = new PipeContext(_serviceProvider); var provider = _serviceProvider.GetRequiredService <TStepProvider>(); return(StartElement <PipeContext, TInput, TReturn> .Create(context, input, provider)); }
/// <summary> /// Get a payload from the pipe context /// </summary> /// <typeparam name="TPayload">The payload type</typeparam> /// <param name="context">The pipe context</param> /// <returns>The payload, or throws a PayloadNotFoundException if the payload is not present</returns> public static TPayload GetPayload <TPayload>(this PipeContext context) where TPayload : class { if (!context.TryGetPayload(out TPayload payload)) { throw new PayloadNotFoundException($"The payload was not found: {TypeCache<TPayload>.ShortName}"); } return(payload); }
internal static ITopicProducer <T> GetProducer <T>(this PipeContext context) where T : class { var factory = context.GetStateMachineActivityFactory(); ITopicProducer <T> producer = factory.GetService <ITopicProducer <T> >(context) ?? throw new ProduceException($"TopicProducer<{TypeMetadataCache<T>.ShortName} not found"); return(producer); }
public override async Task <bool> Process(PipeContext context) { if (context == null) { throw new System.ArgumentNullException("context"); } if (OnWillProcess != null && !OnWillProcess(context)) { return(true); } if (client == null) { var ipAddress = await Dns.GetHostAddressesAsync(Host); var ipv4Addr = ipAddress.FirstOrDefault((v) => v.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); client = GetClientByHost(HostType.Ftp); client.Host = ipv4Addr.ToString(); client.UserName = UserName; client.Password = Password; await client.Initialize(); } List <UploadGroupInfo> needToUpload = new List <UploadGroupInfo>(); needToUpload.Add(new UploadGroupInfo() { localPath = RemoteBuildPath, remotePath = RemoteLoadPath, files = Directory.GetFiles(RemoteBuildPath, "*.*", SearchOption.AllDirectories) }); bool success = true; try { await UploadGroups(client, needToUpload); } catch (System.Exception e) { success = false; Debug.LogException(e); } finally { await client.Release(); client = null; } return(success); }
public override LLVMValueRef Emit(PipeContext <LLVMBuilderRef> context) { // Create a new call expression. CallExpr call = new CallExpr(this.Identifier); // Emit the call. LLVMValueRef result = call.Emit(context); // Return the resulting call reference value. return(result); }
private async Task UpdateMongoDbSaga(PipeContext context, TSaga instance) { instance.Version++; var old = await _collection.FindOneAndReplaceAsync(x => x.CorrelationId == instance.CorrelationId && x.Version < instance.Version, instance, cancellationToken : context.CancellationToken).ConfigureAwait(false); if (old == null) { throw new MongoDbConcurrencyException("Unable to update saga. It may not have been found or may have been updated by another process."); } }