public T GetService <T>(PipeContext context)
            where T : class
        {
            var container = context.GetPayload <Scope>();

            return(container.GetInstance <T>());
        }
Ejemplo n.º 2
0
        public T GetService <T>(PipeContext context)
            where T : class
        {
            var kernel = context.GetPayload <IKernel>();

            return(kernel.Resolve <T>());
        }
Ejemplo n.º 3
0
        /// <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
                       }
            };
        }
    }
Ejemplo n.º 4
0
        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,
                       }
            };
        }
    }
Ejemplo n.º 6
0
        public T GetService <T>(PipeContext context)
            where T : class
        {
            var lifetimeScope = context.GetPayload <ILifetimeScope>();

            return(ActivatorUtils.GetOrCreateInstance <T>(lifetimeScope));
        }
Ejemplo n.º 7
0
        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);
    }
Ejemplo n.º 9
0
        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);
    }
Ejemplo n.º 11
0
 public StateMachineEventContext(PipeContext context, StateMachine <TInstance> machine, TInstance instance, Event @event)
     : base(context)
 {
     _machine  = machine;
     _instance = instance;
     _event    = @event;
 }
Ejemplo n.º 12
0
        /// <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);
            }
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        public PayloadCacheScope(PipeContext context)
        {
            _context          = context;
            CancellationToken = context.CancellationToken;

            _payloadCache = new PayloadCache();
        }
Ejemplo n.º 15
0
        public PayloadCacheScope(PipeContext context)
        {
            _parentCache = new PipeContextPayloadAdapter(context);

            CancellationToken = context.CancellationToken;

            _payloadCache = new PayloadCache();
        }
Ejemplo n.º 16
0
        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));
        }
Ejemplo n.º 18
0
        public static void UpdatePayload(this PipeContext context, IServiceScope scope)
        {
            context.GetOrAddPayload(() => scope);

            var serviceProvider = scope.ServiceProvider;

            context.AddOrUpdatePayload(() => serviceProvider, existing => serviceProvider);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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));
        }
Ejemplo n.º 21
0
        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;
 }
Ejemplo n.º 23
0
        /// <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);
            }
        }
Ejemplo n.º 24
0
        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));
        }
Ejemplo n.º 26
0
        /// <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);
        }
Ejemplo n.º 27
0
        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);
        }
Ejemplo n.º 28
0
    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);
    }
Ejemplo n.º 29
0
        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.");
            }
        }