Beispiel #1
0
        /// <summary>
        /// Assumes the memento is the Node ID (FieldGuid)
        /// </summary>
        /// <param name="memento"></param>
        /// <returns></returns>
        public override IDocument CreateDocument(string memento)
        {
            if (memento == null)
            {
                throw new ArgumentNullException();
            }

            if (!m_docs.ContainsKey(memento))
            {
                ISolutionItem item = null;
                if (FieldGuid.CheckSyntax(memento))
                {
                    item = solutionPad.FindItemByNodeId(new Guid(memento)) as ISolutionItem;
                }

                if (item != null && item is PageItem)
                {
                    var pe = new PageEditor(item as PageItem); // adds itself to m_docs
                }
                else
                {
                    return(null);
                }
            }
            return(m_docs[memento]);
        }
Beispiel #2
0
        private FieldGuid sendTelegramWithGuidPayloadResponse(NodeTelegram telegram)
        {
            var response = sendReceiveTelegram <NodeTelegram>(telegram);

            if (response != null)
            {
                string payload = response.Payload.Decode();
                if (FieldGuid.CheckSyntax(payload))
                {
                    return(new FieldGuid(payload));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        private NodeTelegram readSignals(NodeTelegram request)
        {
            // incoming request should just be a bunch of Guids that represent signalIds
            var inPayload  = request.Payload.Decode();
            var outPayload = new StringBuilder();

            if (runtimeApplication != null)
            {
                for (int index = 0; index < inPayload.Length; index += m_guidLength)
                {
                    string oneGuidString = inPayload.Substring(index, m_guidLength);
                    if (FieldGuid.CheckSyntax(oneGuidString))
                    {
                        var signalId = new FieldGuid(oneGuidString);
                        var signal   = runtimeApplication.FindSignal(signalId);
                        if (signal != null)
                        {
                            outPayload.Append(EncodedSignalValue.EncodeSignalValue(signal));
                        }
                    }
                }
            }
            return(request.SetPayload(FieldBase64.Encode(outPayload.ToString())));
        }
        public static IEnumerable <Tuple <NodeSignal, object> > ParseEncodedSignals(string encoded, IEnumerable <NodeSignal> signals)
        {
            // parse it all into values
            var  dict  = new Dictionary <FieldGuid, object>();
            int  index = 0;
            bool found = true;

            while (found)
            {
                found = false;
                int commaPos1 = encoded.IndexOf(SEPARATOR, index);
                if (commaPos1 > 0) // signalId
                {
                    int commaPos2 = encoded.IndexOf(SEPARATOR, commaPos1 + 1);
                    if (commaPos2 > 0) // DataType
                    {
                        int commaPos3 = encoded.IndexOf(SEPARATOR, commaPos2 + 1);
                        if (commaPos3 > 0) // value length
                        {
                            string valueLengthString = encoded.Substring(commaPos2 + 1, commaPos3 - commaPos2 - 1);
                            int    valueLength;
                            if (int.TryParse(valueLengthString, out valueLength))
                            {
                                string valueString = encoded.Substring(commaPos3 + 1, valueLength);
                                if (valueString.Length == valueLength)
                                {
                                    string guidString = encoded.Substring(index, commaPos1 - index);
                                    if (FieldGuid.CheckSyntax(guidString))
                                    {
                                        var    signalId       = new FieldGuid(guidString);
                                        string dataTypeString = encoded.Substring(commaPos1 + 1, commaPos2 - commaPos1 - 1);
                                        FieldDataType.DataTypeEnum dataType;
                                        if (Enum.TryParse <FieldDataType.DataTypeEnum>(dataTypeString, out dataType))
                                        {
                                            if (FieldConstant.CheckSyntax(dataType + FieldConstant.SEPARATOR + valueString))
                                            {
                                                var constant = new FieldConstant(dataType + FieldConstant.SEPARATOR + valueString);
                                                found = true;
                                                index = commaPos3 + valueLength + 1 + END_OF_LINE.Length;
                                                dict.Add(signalId, constant.Value);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // match it up to the signals
            var retVal = new List <Tuple <NodeSignal, object> >();

            foreach (var signal in signals)
            {
                if (dict.ContainsKey(signal.SignalId))
                {
                    retVal.Add(new Tuple <NodeSignal, object>(signal, dict[signal.SignalId]));
                }
            }
            return(retVal);
        }