예제 #1
0
        IEnumerable <JSonOpcArrayElement> GetJSONArray(TheThingStore thingEvent)
        {
            // TODO Replace with linkid some identifier that represents the activated instance/customer, and make this more efficient (avoid or cache thing registry lookup)
            string linkid;
            var    tThing = TheThingRegistry.GetThingByMID("*", TheCommonUtils.CGuid(thingEvent.cdeMID), true);

            if (tThing != null && !String.IsNullOrEmpty(tThing.FriendlyName))
            {
                linkid = tThing.FriendlyName;
            }
            else
            {
                if (thingEvent.PB.ContainsKey("Address"))
                {
                    linkid = TheCommonUtils.CStr(thingEvent.PB["Address"]);
                }
                else
                {
                    if (tThing != null)
                    {
                        linkid = tThing.Address;
                    }
                    else
                    {
                        linkid = TheCommonUtils.cdeGuidToString(thingEvent.cdeMID);
                    }
                }
            }

            var jsonArray = new List <JSonOpcArrayElement>();

            jsonArray.AddRange(thingEvent.PB.Select(propKV => GetJSONArrayElement(linkid, propKV.Key, thingEvent.cdeCTIM, propKV.Value)));
            return(jsonArray.OrderBy(ev => ev.sourcetimestamp));
        }
예제 #2
0
        IEnumerable<Measurement> GetMeasurements(TheThingStore thingEvent)
        {
            var jsonArray = new List<Measurement>();
            jsonArray.AddRange(thingEvent.PB
                .Where(prop => !reservedProps.Contains(prop.Key))
                .Select(propKV => GetMeasurement(propKV.Key, thingEvent.cdeCTIM, propKV.Value)));

            return jsonArray.OrderBy(ev => ev.ts);
        }
예제 #3
0
        IEnumerable<object> GetEvents(TheThingStore thingEvent, IEnumerable<Measurement> measurements, int maxEventDataSize)
        {
            string eventPayloadJson = SerializeJSonArray(thingEvent, measurements);
            //string eventPayloadJson = TheCommonUtils.SerializeObjectToJSONString<List<JSonArrayElement>>(jsonArray as List<JSonArrayElement>);
            if (eventPayloadJson.Length > maxEventDataSize)
            {
                //Console.WriteLine("Splitting array");
                var firstHalf = measurements.Count() / 2;
                return GetEvents(thingEvent, measurements.Take(firstHalf), maxEventDataSize)
                    .Concat(GetEvents(thingEvent, measurements.Skip(firstHalf), maxEventDataSize));
            }

            return new List<object> { eventPayloadJson };
        }
예제 #4
0
 public string GetPartitionKeyValue(TheThingStore thingEvent)
 {
     if (PartitionKey == null || PartitionKey == PartitionKeyChoices[0])
     {
         return(null);
     }
     if (PartitionKey == PartitionKeyChoices[1])
     {
         return(GetThing()?.GetBaseThing()?.Address);
     }
     if (PartitionKey == PartitionKeyChoices[2])
     {
         return(ThingMID);
     }
     return("0");
 }
예제 #5
0
        internal void CheckOnHealthTimer(long tTimerVal)
        {
            if (mDisableCollection)
            {
                return;
            }
            if ((tTimerVal % HealthUpdateCycle) != 0)
            {
                return;
            }
            if (TheCommonUtils.cdeIsLocked(lockCheckTimer))
            {
                return;
            }
            lock (lockCheckTimer)
            {
                if (!AreCounterInit)
                {
                    return;
                }
                TheBaseAssets.MySYSLOG.WriteToLog(8005, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("jcHealth", "Enter CheckOnHealthTimer", eMsgLevel.l7_HostDebugMessage));
                TheDiagnostics.SetThreadName("C-MyComputer-HealthTimer", true);
                if (!IsEnergyRegistered)
                {
                    TheThing tThing = TheThingRegistry.GetBaseEngineAsThing("CDMyEnergy.TheCDMyEnergyEngine");
                    if (tThing != null)
                    {
                        IsEnergyRegistered = true;
                        tThing.RegisterEvent(eEngineEvents.MessageProcessed, sinkEnergyFound);
                    }
                }
                SendHealthInfo(Guid.Empty);

                if (MyServiceHealthDataStore != null)
                {
                    TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("jcHealth", "Storing HealthInfo", eMsgLevel.l7_HostDebugMessage, MyHealthData.cdeUptime.ToString()));
                    if (!MyServiceHealthDataStore.IsReady)
                    {
                        MyServiceHealthDataStore.InitializeStore(false);
                        TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("jcHealth", "Storing HealthInfo- Initializing store", eMsgLevel.l4_Message));
                    }
                    MyServiceHealthDataStore.AddAnItem(TheThingStore.CloneFromTheThing(MyHealthData, true));
                }

                TheBaseAssets.MySYSLOG.WriteToLog(8006, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("jcHealth", "Leave CheckOnHealthTimer", eMsgLevel.l7_HostDebugMessage));
            }
        }
예제 #6
0
        string SerializeJSonArray(TheThingStore thingEvent, IEnumerable<Measurement> measurements)
        {
            if (!(measurements is List<Measurement>))
            {
                measurements = new List<Measurement>(measurements);
            }

            var payload = new MeasurementPayload();

            object deviceId;
            if (thingEvent.PB.TryGetValue("deviceID", out deviceId))
            {
                payload.device.deviceID = TheCommonUtils.CStr(deviceId);
            }
            else
            {
                payload.device.deviceID = TheCommonUtils.cdeGuidToString(thingEvent.cdeMID);
            }
            payload.measurements.AddRange(measurements);

            string eventPayloadJson = TheCommonUtils.SerializeObjectToJSONString(payload);
            //eventPayloadJson = eventPayloadJson.Replace("\"contentspec\"", "\"content-spec\""); // Hack to avoid newtonsoft dependency for now: attribute ignored by cdeEngine internal serializer
            return eventPayloadJson;
        }