Пример #1
0
        /// <summary>
        /// Restores the state of all signals from a blob string created by signalStateToBlob
        /// </summary>
        /// <param name="rta">Runtime application to restore to</param>
        /// <param name="blob">blob</param>
        private static void restoreSignalStateFromBlob(NodeRuntimeApplication rta, string blob)
        {
            if (rta == null)
            {
                throw new ArgumentNullException("rta");
            }
            if (blob == null)
            {
                return;
            }
            var signalValues = EncodedSignalValue.ParseEncodedSignals(blob, rta.Signals);

            foreach (var signalTuple in signalValues)
            {
                NodeSignal signal = signalTuple.Item1;
                object     value  = signalTuple.Item2;
                try
                {
                    signal.Value = value;
                }
                catch
                {
                    // FIXME - tie into error reporting feature, to be developed
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Stores the state of all signals into a string that can be saved to a file.
        /// </summary>
        /// <param name="rta">Runtime application to store the state of</param>
        /// <returns>blob</returns>
        private static string signalStateToBlob(NodeRuntimeApplication rta)
        {
            if (rta == null)
            {
                throw new ArgumentNullException("rta");
            }
            var encodedSignals = from signal in rta.Signals select EncodedSignalValue.EncodeSignalValue(signal);

            return(string.Join(string.Empty, encodedSignals));
        }
Пример #3
0
 public void ReadSignalValues(IEnumerable <NodeSignal> signals)
 {
     if (Properties.Settings.Default.RunAsService)
     {
         var outPayload = new StringBuilder();
         foreach (var signal in signals)
         {
             outPayload.Append(signal.SignalId.ToString());
         }
         var response = sendReceiveTelegram <NodeTelegram>(m_TelegramReadSignals.SetPayload(FieldBase64.Encode(outPayload.ToString())));
         if (response != null)
         {
             foreach (var tpl in EncodedSignalValue.ParseEncodedSignals(response.Payload.Decode(), signals))
             {
                 var signal = tpl.Item1;
                 var value  = tpl.Item2;
                 m_runtimeService.Value.NotifyValueChanged(signal, value);
             }
         }
     }
     else
     {
         // uploading is instant
         var nRuntimeApplication = RuntimeApplicationUpload();
         if (nRuntimeApplication != null)
         {
             foreach (var sig in signals)
             {
                 var foundSig = nRuntimeApplication.FindSignal(sig.SignalId);
                 if (foundSig != null)
                 {
                     m_runtimeService.Value.NotifyValueChanged(foundSig, foundSig.Value);
                 }
             }
         }
     }
 }
Пример #4
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())));
        }