/// <inheritdoc/> public bool Push(IMemoryGroup memoryGroup) { if (new List <IMemoryGroup>(Layers) { memoryGroup }.CanLink()) { Layers.Add(memoryGroup); WritableLayer = memoryGroup as IWritableMemoryGroup; return(true); } else { return(false); } }
/// <inheritdoc/> protected override async Task <DataObject> RunScriptInternalAsync(IWritableMemoryGroup inputs, CapabilitiesCollection capabilities) { var thread = new Thread( ScriptInfo.GetUniqueId(), capabilities, new ThreadPointer(Commands.ToArray()), null); var output = await thread.RunThreadAsync(ParentObject, inputs); //// TODO: Make sure that this is the correct way to get the output of a script; handle flags such as no return and exception. if (thread.Pointer.Flags.HasFlag(CommandPointerFlags.Returned)) { return(output); } else { return(null); } }
/// <summary> /// Creates a linked memory group that is writable (items can be added) from an existing <see cref="LinkedMemoryGroup"/>. /// </summary> /// <param name="writeGroup">The <see cref="IWritableMemoryGroup"/> that will be used for adding new items to memory.</param> /// <param name="linkedMemory">The existing linked memory group.</param> public WritableLinkedMemoryGroup(IWritableMemoryGroup writeGroup, LinkedMemoryGroup linkedMemory) : base(new List <IMemoryGroup>(linkedMemory.LinkedGroups) { writeGroup }) { WriteGroup = writeGroup; }
/// <summary> /// Creates a linked memory group that is writable (items can be added) from a collection of existing memory groups. /// </summary> /// <param name="writeGroup">The <see cref="IWritableMemoryGroup"/> that will be used for adding new items to memory.</param> /// <param name="linkedGroups">A collection of <see cref="IMemoryGroup"/> to add to memory.</param> public WritableLinkedMemoryGroup(IWritableMemoryGroup writeGroup, IEnumerable <IMemoryGroup> linkedGroups) : base(new List <IMemoryGroup>(linkedGroups) { writeGroup }) { WriteGroup = writeGroup; }
/// <inheritdoc/> public void Pull() { Layers.Remove(Layers.Last()); ////Sets writable layer to the new top layer if it can be written to. WritableLayer = Layers.Last() as IWritableMemoryGroup; }
/// <summary> /// Creates a memory stack from an ordered collection of layers. /// </summary> /// <param name="layers">The layers of the memory stack, of type <see cref="IMemoryGroup"/>.</param> public MemoryStack(IEnumerable <IMemoryGroup> layers) { Layers = new List <IMemoryGroup>(layers); ////Sets writable layer to the new top layer if it can be written to. WritableLayer = Layers.Last() as IWritableMemoryGroup; }
/// <summary> /// Internal - runs the <see cref="Script"/> with the provided memory context and returns a <see cref="DataObject"/> result. /// </summary> /// <param name="inputs">An <see cref="IWritableMemoryGroup"/> containing the named <see cref="Script"/> inputs.</param> /// <param name="capabilities">The <see cref="CapabilitiesCollection"/> from the <see cref="ICommand"/> or other source that called the <see cref="Script"/>.</param> protected abstract Task <DataObject> RunScriptInternalAsync(IWritableMemoryGroup inputs, CapabilitiesCollection capabilities);
/// <summary> /// Calls and executes a given <see cref="Script"/> and returns the <see cref="DataObject"/> result. /// </summary> /// <param name="inputs">A collection of <see cref="DataObject"/>s which will be checked and stored in an <see cref="IWritableMemoryGroup"/> to be sent to the <see cref="Thread"/>'s <see cref="IMemoryStack"/>.</param> /// <param name="inheritedcapabilities">The <see cref="CapabilitiesCollection"/> from the <see cref="ICommand"/> or other source that called the <see cref="Script"/>.</param> public async Task <DataObject> CallScriptAsync(IEnumerable <DataObject> inputs, CapabilitiesCollection inheritedcapabilities) { IWritableMemoryGroup inputMemory = ScriptInfo.CreateMemoryFromInputs(inputs.ToArray()); return(await RunScriptInternalAsync(inputMemory, inheritedcapabilities)); }