Ejemplo n.º 1
0
 public void SetData(AssociativeArray <double> array)
 {
     data.Fill(array);
 }
Ejemplo n.º 2
0
 public override void VisitAssociativeArray(AssociativeArray value)
 {
     snapshot.DestroyArray(parentIndex);
 }
Ejemplo n.º 3
0
 /// <inheritdoc />
 public override bool TryGetDescriptor(AssociativeArray arrayValue, out IArrayDescriptor descriptor)
 {
     return(arrayDescriptors.TryGetValue(arrayValue, out descriptor));
 }
Ejemplo n.º 4
0
        public override void VisitAssociativeArray(AssociativeArray value)
        {
            AssociativeArray arrayValue = worker.ProcessArrayValue(index, value);

            values.Add(arrayValue);
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public override void VisitAssociativeArray(AssociativeArray value)
 {
     arrayVisitor.SetLeftOperand(value);
     visitor = arrayVisitor;
 }
Ejemplo n.º 6
0
 /// <inheritdoc />
 public override void VisitAssociativeArray(AssociativeArray value)
 {
     result = TypeConversion.ToBoolean(snapshot, value);
 }
Ejemplo n.º 7
0
 /// <inheritdoc />
 public abstract void SetDescriptor(AssociativeArray arrayvalue, IArrayDescriptor descriptor);
Ejemplo n.º 8
0
        /// <summary>
        /// Sets the array descriptor which contains information about defined indexes in the specified array.
        /// </summary>
        /// <param name="arrayvalue">The arrayvalue.</param>
        /// <param name="descriptor">The descriptor.</param>
        internal void SetDescriptor(AssociativeArray arrayvalue, ArrayDescriptor descriptor)
        {
            lockedTest();

            ArrayDescriptors[arrayvalue] = descriptor;
        }
Ejemplo n.º 9
0
 /// <inheritdoc />
 public abstract bool TryGetArray(MemoryIndex index, out AssociativeArray arrayValue);
Ejemplo n.º 10
0
 /// <inheritdoc />
 public abstract bool TryGetCallArraySnapshot(AssociativeArray array, out IEnumerable <Snapshot> snapshots);
Ejemplo n.º 11
0
 /// <inheritdoc />
 public abstract IArrayDescriptor GetDescriptor(AssociativeArray arrayValue);
Ejemplo n.º 12
0
 /// <inheritdoc />
 public abstract bool TryGetDescriptor(AssociativeArray arrayValue, out IArrayDescriptor descriptor);
Ejemplo n.º 13
0
        /// <summary>
        /// Processes the merge operation.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="operationAccessor">The operation accessor.</param>
        /// <exception cref="System.Exception">
        /// Error merging structure in readonly mode - undefined index  + targetIndex
        /// or
        /// Error merging structure in readonly mode - target descriptor for  + targetIndex
        /// </exception>
        private void processMergeOperation(MergeOperation operation, TrackingMergeWorkerOperationAccessor operationAccessor)
        {
            MemoryIndex             targetIndex  = operation.TargetIndex;
            AssociativeArray        targetArray  = null;
            List <ContainerContext> sourceArrays = new List <ContainerContext>();
            bool arrayAlwaysDefined = !operation.IsUndefined;
            bool cotainsArray       = false;

            // Iterate sources
            foreach (MergeOperationContext operationContext in operation.Indexes)
            {
                // Retreive source context and definition
                MemoryIndex      sourceIndex      = operationContext.Index;
                SnapshotContext  context          = operationContext.SnapshotContext;
                IIndexDefinition sourceDefinition = context.SourceStructure.GetIndexDefinition(sourceIndex);

                // Provide custom operation for merge algorithm
                operationAccessor.addSource(operationContext, sourceDefinition);

                // Source array
                if (sourceDefinition.Array != null)
                {
                    // Becomes target array when not set
                    if (targetArray == null && sourceIndex.Equals(targetIndex))
                    {
                        targetArray = sourceDefinition.Array;
                    }
                    cotainsArray = true;

                    // Save source array to merge descriptors
                    IArrayDescriptor descriptor = context.SourceStructure.GetDescriptor(sourceDefinition.Array);
                    sourceArrays.Add(new ContainerContext(context, descriptor, operationContext.OperationType));

                    // Equeue all array indexes when whole subtree should be merged
                    if (operationContext.OperationType == MergeOperationType.WholeSubtree)
                    {
                        foreach (var index in descriptor.Indexes)
                        {
                            operation.TreeNode.GetOrCreateChild(index.Key);
                        }
                        operation.TreeNode.GetOrCreateAny();
                    }
                }
                else
                {
                    // Source do not contain array - at least one source is empty
                    arrayAlwaysDefined = false;
                }
            }

            IIndexDefinition targetDefinition;
            IArrayDescriptor targetArrayDescriptor = null;

            if (targetStructure.TryGetIndexDefinition(targetIndex, out targetDefinition))
            {
                // Index is set in target snapshot
                if (targetDefinition.Array != null)
                {
                    // Target contains array - continue merging
                    targetArray           = targetDefinition.Array;
                    targetArrayDescriptor = targetStructure.GetDescriptor(targetArray);
                }
            }
            else
            {
                // Index is not set in target snapshot - create it
                if (isStructureWriteable)
                {
                    writeableTargetStructure.NewIndex(targetIndex);
                }
                else
                {
                    throw new Exception("Error merging structure in readonly mode - undefined index " + targetIndex);
                }
            }

            // Provide custom operation for merge algorithm
            operationAccessor.provideCustomOperation(targetIndex);

            // Process next array
            if (cotainsArray)
            {
                if (targetArray == null)
                {
                    targetArray = targetSnapshot.CreateArray();
                }

                if (targetArrayDescriptor == null)
                {
                    // Target does not contain array - create and add new in target snapshot
                    if (isStructureWriteable)
                    {
                        targetArrayDescriptor = Factories.StructuralContainersFactories.ArrayDescriptorFactory.CreateArrayDescriptor(writeableTargetStructure, targetArray, targetIndex);
                        writeableTargetStructure.SetDescriptor(targetArray, targetArrayDescriptor);
                        writeableTargetStructure.NewIndex(targetArrayDescriptor.UnknownIndex);
                        writeableTargetStructure.SetArray(targetIndex, targetArray);
                    }
                    else
                    {
                        throw new Exception("Error merging structure in readonly mode - target descriptor for " + targetIndex);
                    }
                }

                // Create context and merge descriptors
                var arrayContext = new ArrayTargetContainerContext(writeableTargetStructure, targetArrayDescriptor);
                createAndEnqueueOperations(arrayContext, operation.TreeNode, sourceArrays, arrayAlwaysDefined);

                if (isStructureWriteable)
                {
                    // Ubdate current descriptor when changed
                    IArrayDescriptor currentDescriptor = arrayContext.getCurrentDescriptor();
                    if (currentDescriptor != targetArrayDescriptor)
                    {
                        writeableTargetStructure.SetDescriptor(targetArray, currentDescriptor);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private IEnumerable <Tuple <Snapshot, IArrayDescriptor> > getIArrayDescriptor(AssociativeArray array)
        {
            List <Tuple <Snapshot, IArrayDescriptor> > results = new List <Tuple <Snapshot, IArrayDescriptor> >();

            IArrayDescriptor       descriptor;
            IEnumerable <Snapshot> snapshots;

            if (targetSnapshot.Structure.Readonly.TryGetDescriptor(array, out descriptor))
            {
                results.Add(new Tuple <Snapshot, IArrayDescriptor>(targetSnapshot, descriptor));
            }
            else if (targetSnapshot.Structure.Readonly.TryGetCallArraySnapshot(array, out snapshots))
            {
                foreach (Snapshot snapshot in snapshots)
                {
                    IArrayDescriptor snapDescriptor = snapshot.Structure.Readonly.GetDescriptor(array);
                    results.Add(new Tuple <Snapshot, IArrayDescriptor>(snapshot, snapDescriptor));
                }
            }
            else
            {
                throw new Exception("Missing array descriptor");
            }

            return(results);
        }
Ejemplo n.º 15
0
 /// <inheritdoc />
 public abstract void AddCallArray(AssociativeArray array, Snapshot snapshot);
Ejemplo n.º 16
0
 /// <summary>
 /// Tries to get array descriptor which contains information about defined indexes in the specified array.
 /// </summary>
 /// <param name="arrayValue">The array value.</param>
 /// <param name="descriptor">The descriptor.</param>
 /// <returns>Array descriptor which contains information about defined indexes in the specified array.</returns>
 internal bool TryGetDescriptor(AssociativeArray arrayValue, out ArrayDescriptor descriptor)
 {
     return(ArrayDescriptors.TryGetValue(arrayValue, out descriptor));
 }
Ejemplo n.º 17
0
 /// <inheritdoc />
 public abstract void RemoveArray(MemoryIndex index, AssociativeArray arrayValue);
Ejemplo n.º 18
0
 public void Add(AssociativeArray <double> aa)
 {
     data.Add(aa);
     length = data.Count;
 }
Ejemplo n.º 19
0
 /// <inheritdoc />
 public override void VisitAssociativeArray(AssociativeArray value)
 {
     result         = TypeConversion.ToString(OutSet, value);
     abstractResult = null;
 }
Ejemplo n.º 20
0
 public override void VisitAssociativeArray(AssociativeArray value)
 {
     // Skip visiting array value - already processed
 }
Ejemplo n.º 21
0
 public override void VisitAssociativeArray(AssociativeArray value)
 {
     //Nothing to do, arrays are resolved in snapshot entries
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ArrayDescriptorBuilder"/> class.
 /// </summary>
 public ArrayDescriptorBuilder()
 {
     Indexes        = new Dictionary <string, MemoryIndex>();
     ArrayValue     = null;
     ParentVariable = null;
 }
Ejemplo n.º 23
0
 /// <inheritdoc />
 public void SetArrayValue(AssociativeArray arrayValue)
 {
     this.arrayValue = arrayValue;
 }
Ejemplo n.º 24
0
 /// <inheritdoc />
 public override void SetDescriptor(AssociativeArray arrayvalue, IArrayDescriptor descriptor)
 {
     arrayDescriptors[arrayvalue] = descriptor;
     changeTracker.ModifiedIndex(descriptor.ParentIndex);
 }
Ejemplo n.º 25
0
        public IArrayDescriptor CreateArrayDescriptor(IWriteableSnapshotStructure targetStructure, AssociativeArray createdArray, MemoryIndex memoryIndex)
        {
            LazyCopyArrayDescriptor descriptor = new LazyCopyArrayDescriptor(targetStructure);

            descriptor.SetArrayValue(createdArray);
            descriptor.SetParentIndex(memoryIndex);
            descriptor.SetUnknownIndex(memoryIndex.CreateUnknownIndex());
            return(descriptor);
        }
Ejemplo n.º 26
0
 /// <inheritdoc />
 public override void VisitAssociativeArray(AssociativeArray value)
 {
     result = "Array";
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazyCopyArrayDescriptor" /> class.
 /// </summary>
 /// <param name="associatedStrucutre">The associated strucutre.</param>
 /// <param name="parentIndex">Index of the parent.</param>
 /// <param name="arrayValue">The array value.</param>
 public LazyCopyArrayDescriptor(IWriteableSnapshotStructure associatedStrucutre, MemoryIndex parentIndex, AssociativeArray arrayValue)
 {
     this.associatedStrucutre = associatedStrucutre;
     this.parentIndex         = parentIndex;
     this.arrayValue          = arrayValue;
 }
Ejemplo n.º 28
0
        static void listener_RequestReceived(object sender, RequestEventArgs e)
        {
            IHttpClientContext context = (IHttpClientContext)sender;
            IHttpRequest request = e.Request;
            IHttpResponse response = request.CreateResponse(context);
            StreamWriter writer = new StreamWriter(response.Body);

            response.AddHeader("Content-type", "text/plain");
            response.AddHeader("Access-Control-Allow-Methods", "*");
            response.AddHeader("Access-Control-Allow-Origin", "*");

            string endpoint = (request.UriParts.Length > 0? request.UriParts[0] : "");
            int to = 0;
            int.TryParse((request.UriParts.Length > 1 ? request.UriParts[1] : ""), out to);
            string id = "";
            AsyncSerial toSerial = null;

            if (to != 0)
            {
                if (request.QueryString.Contains("baud") || request.QueryString.Contains("parity") || request.QueryString.Contains("dataBits") ||
                            request.QueryString.Contains("stopBits") || request.QueryString.Contains("newLine"))
                {
                    // TODO
                    toSerial = bus.Connect(to);
                }
                else
                {
                    toSerial = bus.Connect(to);
                }
            }

            switch (endpoint)
            {
                case "":
                    writer.Write("SerialServe is running! Check out the documentation on GitHub.");
                    writer.Flush();
                    response.Send();
                    break;
                case "list":
                    writer.Write("[" + string.Join(",", bus.Ports) + "]");
                    writer.Flush();
                    response.Send();
                    break;
                case "write":
                    try
                    {
                        toSerial.Write(request.QueryString["toWrite"].ToString());
                        writer.Write("{\"success\":true}");
                        writer.Flush();
                        response.Send();
                    }
                    catch
                    {
                        response.Status = System.Net.HttpStatusCode.BadRequest;
                        writer.Write("{\"error\":\"Could not write to the requested port.\"}");
                        writer.Flush();
                        response.Send();
                    }
                    break;
                case "enable":
                case "disable":
                    try
                    {
                        if (endpoint == "enable")
                        {
                            toSerial.DtsEnable();
                        }
                        else
                        {
                            toSerial.DtsDisable();
                        }
                        writer.Write("{\"success\":true}");
                        writer.Flush();
                        response.Send();
                    }
                    catch
                    {
                        response.Status = System.Net.HttpStatusCode.BadRequest;
                        writer.Write("{\"error\":\"Could not change the state of the requested port.\"}");
                        writer.Flush();
                        response.Send();
                    }
                    break;
                case "read":
                    if (!longpollConnections.ContainsKey(to))
                    {
                        longpollConnections[to] = new AssociativeArray<string, List<IHttpResponse>>();
                    }

                    if (!longpollConnections[to].ContainsKey(id))
                    {
                        longpollConnections[to][id] = new List<IHttpResponse>();
                    }

                    longpollConnections[to][id].Add(response);
                    break;
                default:
                    response.Status = System.Net.HttpStatusCode.NotFound;
                    writer.Write("Not found!");
                    writer.Flush();
                    response.Send();
                    break;
            }
        }
Ejemplo n.º 29
0
 public override void VisitAssociativeArray(AssociativeArray value)
 {
     ContainsArrayValue = true;
 }