Пример #1
0
        public static Expression Instantiate(this TypeName typeName, Expression[] arguments, Context ctx, Optional <ObjectIdentifier> tagHash)
        {
            var obj = ctx.TryGetUxConstructorFunction(typeName).MatchWith(
                some: ex => (Expression) new CallLambda(ex, arguments),
                none: () => (Expression) new Instantiate(typeName, arguments));

            if (!tagHash.HasValue)
            {
                return(obj);
            }

            return(ExpressionConverter.BytecodeFromSimpleLambda(() =>
                                                                ObjectTagRegistry.RegisterObjectTag(obj, tagHash.Value.ToString())));
        }
Пример #2
0
 public static Statement UpdateFile(string descriptor, byte[] data)
 {
     return(ExpressionConverter.BytecodeFromSimpleLambda(() =>
                                                         FileCache.Update(descriptor, data)));
 }
Пример #3
0
 public static Expression GetExpression(this BundleFileSource node, Context ctx)
 {
     return(ExpressionConverter.BytecodeFromSimpleLambda(() =>
                                                         FileCache.GetFileSource(node.GetDescriptor(ctx.ProjectDirectory))));
 }
Пример #4
0
        IObservable <CoalesceEntry> ReifyProject(IObservable <ProjectBytecode> bytecode, IObservable <BytecodeUpdated> bytecodeUpdated, CoalesceEntryCache cache, IObservable <IEnumerable <AbsoluteFilePath> > assets)
        {
            int idx             = 0;
            var bytecodeUpdates = bytecodeUpdated.Select(m => m.ToCoalesceEntry(BytecodeUpdated.MessageType + (++idx)))
                                  .Publish()
                                  .RefCount();

            var clearOldUpdates = bytecodeUpdates
                                  .Buffer(bytecode)
                                  .Select(
                oldUpdates =>
            {
                var cachedUpdates = new List <CoalesceEntry>();
                foreach (var oldUpdate in oldUpdates)
                {
                    cachedUpdates.Add(new CoalesceEntry()
                    {
                        BlobData    = Optional.None(),
                        CoalesceKey = oldUpdate.CoalesceKey
                    });
                }
                return(cachedUpdates);
            })
                                  .SelectMany(t => t);

            var reify = bytecode.WithLatestFromBuffered(assets, (bc, ass) =>
            {
                var waitForDependencies = Task.WaitAll(new []
                {
                    bc.Dependencies.Select(d => cache.HasEntry(d.ToString()))
                    .ToObservableEnumerable()
                    .FirstAsync()
                    .ToTask(),
                    ass.Select(d => cache.HasEntry(d.ToString()))
                    .ToObservableEnumerable()
                    .FirstAsync()
                    .ToTask()
                }, TimeSpan.FromSeconds(60));

                if (waitForDependencies == false)
                {
                    throw new TimeoutException("Failed to load all assets dependencies.");
                }

                try
                {
                    return(new BytecodeGenerated(
                               new ProjectBytecode(
                                   reify: new Lambda(
                                       Signature.Action(Variable.This),
                                       Enumerable.Empty <BindVariable>(),
                                       new[]
                    {
                        ExpressionConverter.BytecodeFromSimpleLambda(() => ObjectTagRegistry.Clear()),

                        new CallLambda(bc.Reify, new ReadVariable(Variable.This)),
                    }),
                                   metadata: bc.Metadata,
                                   dependencies: bc.Dependencies))
                           .ToCoalesceEntry(BytecodeGenerated.MessageType));
                }
                catch (Exception)
                {
                    return(new BytecodeUpdated(
                               new Lambda(
                                   Signature.Action(),
                                   Enumerable.Empty <BindVariable>(),
                                   Enumerable.Empty <Statement>()))
                           .ToCoalesceEntry("invalid-byte-code"));
                }
            })
                        .CatchAndRetry(TimeSpan.FromSeconds(15),
                                       e =>
            {
                _logMessages.OnNext("Failed to refresh because: " + e.Message);
            });

            return(Observable.Merge(clearOldUpdates, reify, bytecodeUpdates));
        }