internal bool UpdateSessionLCID(Guid pSessionID, int pLCID)
 {
     lock (GetLock())                                      //LOCK-REVIEW: This is more a logic lock then read/write MySessionStates.MyRecordsLock)    //low impact
     {
         TheSessionState tSess = ValidateSEID(pSessionID); //Low Frequency
         if (tSess != null)
         {
             tSess.LCID = pLCID;
             MySessionStates.UpdateItem(tSess, null);
             return(true);
         }
     }
     return(false);
 }
Exemple #2
0
 private void GetIP(TheStorageMirror <TheVisitorLogData> .StoreResponse pRec)
 {
     lock (mVisitorList.MyLock)
     {
         TheVisitorLogData tLog = null;
         if (pRec == null || pRec.HasErrors || pRec.MyRecords.Count == 0)
         {
             if (pRec != null)
             {
                 mVisitorList.TryGetValue(pRec.SQLFilter, out tLog);
                 if (tLog != null)
                 {
                     TheREST.GetRESTAsync(new Uri($"http://api.ipstack.com/{tLog.ip}?access_key={APIKey}"), 0, sinkProcessLocation, tLog);
                     mVisitorList.RemoveNoCare(pRec.SQLFilter);
                 }
             }
         }
         else
         {
             tLog = pRec.MyRecords[0];
             tLog.Visits++;
             tLog.LastVisit = DateTimeOffset.Now;
             if (tLog.latitude == 0 && tLog.longitude == 0)
             {
                 TheREST.GetRESTAsync(new Uri($"http://api.ipstack.com/{tLog.ip}?access_key={APIKey}"), 0, sinkProcessLocation, tLog);
             }
             else
             {
                 MyVisitorLogStore.UpdateItem(MyLocation);
             }
         }
     }
 }
Exemple #3
0
        public override void HandleMessage(ICDEThing sender, object pIncoming)
        {
            TheProcessMessage pMsg = pIncoming as TheProcessMessage;

            if (pMsg == null || pMsg.Message == null)
            {
                return;
            }

            var cmd = TheCommonUtils.cdeSplit(pMsg.Message.TXT, ":", false, false);

            switch (cmd[0])
            {
            case nameof(MsgAddConnectionThing <TConnectionThingParam>):
                var addMsg = TheCommRequestResponse.ParseRequestMessageJSON <MsgAddConnectionThing <TConnectionThingParam> >(pMsg.Message);

                var responseMsg = new MsgAddConnectionThingResponse {
                    Error = "Unexpected"
                };
                if (addMsg != null)
                {
                    var thingToAdd = addMsg.ThingToAdd;

                    if (thingToAdd != null)
                    {
                        var currentThing = MyConnectionThings.MyMirrorCache.GetEntryByID(thingToAdd.cdeMID);
                        var newThing     = new TConnectionThing();
                        newThing.Initialize(thingToAdd);

                        if (currentThing == null)
                        {
                            MyConnectionThings.AddAnItem(newThing);
                            responseMsg.Error = null;
                        }
                        else
                        {
                            if (!newThing.IsEqual(currentThing))
                            {
                                UpdateConnectionThing(currentThing, newThing);
                                MyConnectionThings.UpdateItem(newThing);
                                Connect();
                            }
                            responseMsg.Error = null;
                        }
                    }
                    else
                    {
                        responseMsg.Error = "INVALIDARGS";
                    }
                }
                TheCommRequestResponse.PublishResponseMessageJson(pMsg.Message, responseMsg);
                break;

            default:
                base.HandleMessage(sender, pIncoming);
                break;
            }
        }
        void sinkServiceInfo(TSM pMsgMessage)
        {
            if (string.IsNullOrEmpty(pMsgMessage?.PLS))
            {
                return;
            }
            var MyInfo = TheCommonUtils.DeserializeJSONStringToObject <List <TheNodeTopics> >(pMsgMessage.PLS);

            int bk = 0;

            foreach (TheFootPrints tf in MyFootPrints.MyMirrorCache.TheValues)
            {
                tf.Counter = 0;
                tf.IsDirty = false;
            }
            if (MyInfo?.Count > 0)
            {
                foreach (var tIn in MyInfo)
                {
                    if (tIn.NodeType == cdeSenderType.CDE_JAVAJASON)
                    {
                        bk++;
                    }
                    else
                    {
                        foreach (TheFootPrints tf in MyFootPrints.MyMirrorCache.TheValues)
                        {
                            List <string> tFs = TheCommonUtils.CStringToList(tf.Footprint, ';');
                            if (IsListInList(tIn.Topics, tFs) && (tf.ExactCount == 0 || tf.ExactCount == tIn.Topics.Count))
                            {
                                tf.Counter++;
                                tf.IsDirty = true;
                            }
                        }
                    }
                }
                TheThing.SetSafePropertyNumber(MyBaseThing, "BrowserCount", bk);
            }
            foreach (TheFootPrints tf in MyFootPrints.MyMirrorCache.TheValues)
            {
                if (tf.IsDirty || tf.Counter == 0)
                {
                    MyFootPrints.UpdateItem(tf);
                    TheThing.SetSafePropertyNumber(MyBaseThing, $"{tf.NodeType}_Count", tf.Counter);
                }
            }
        }
Exemple #5
0
        internal void sinkProcessLocation(TheRequestData pLocationState)
        {
            if (pLocationState.ResponseBuffer == null)
            {
                return;
            }
            TheVisitorLogData tlog = pLocationState.CookieObject as TheVisitorLogData;

            if (tlog != null)
            {
                MyLocation = tlog;
            }
            if (MyLocation == null)
            {
                MyLocation = new TheVisitorLogData();
            }

            string pLocation = TheCommonUtils.CArray2UTF8String(pLocationState.ResponseBuffer);

            if (!string.IsNullOrEmpty(pLocation))
            {
                try
                {
                    TheVisitorLogData tIP = TheCommonUtils.DeserializeJSONStringToObject <TheVisitorLogData>(pLocation);
                    if (tIP != null)
                    {
                        MyLocation.ip          = tIP.ip;
                        MyLocation.latitude    = tIP.latitude;
                        MyLocation.longitude   = tIP.longitude;
                        MyLocation.region_code = tIP.region_code;
                        MyLocation.region_name = tIP.region_name;
                        MyLocation.zip         = tIP.zip;
                        MyBaseThing?.FireEvent("NewVisitorLogged", MyBaseThing, null, true);
                        //TheREST.GetRESTAsync(new Uri(string.Format("http://a4544535456.api.wxbug.net/getLiveWeatherRSS.aspx?ACode=a4544535456&lat={0}&long={1}&UnitType=1&OutputType=1", MyLocation.Latitude, MyLocation.Longitude)), 0, MyWeather.sinkProcessWeather, null);
                    }
                }
                catch (Exception ee)
                {
                    TheBaseAssets.MySYSLOG.WriteToLog(512, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("VisitorLog", "Error processing Location ", eMsgLevel.l1_Error, ee.ToString() + ":::" + pLocation));
                }
            }
            MyVisitorLogStore?.UpdateItem(MyLocation);
        }
Exemple #6
0
        //Helper to update storage list
        private void UpdateStorageList(string name, string status, int step, TheScript script, TheThing context, bool replay)
        {
            ScriptSnapshot existingSnapshot = null;

            // No longer adding a new entry on replay because the list is now used to disable script/steps etc.
            existingSnapshot = MyScriptTableStorage.MyMirrorCache.GetEntryByFunc(snapshot => snapshot.ScriptName == name && snapshot.ScriptStep == step);
            var stepName = step > 0 && step <= script?.Steps.Length ? script?.Steps[step - 1]?.GetName() ?? "" : "";

            if (existingSnapshot == null)
            {
                var newSnapshot = new ScriptSnapshot
                {
                    ScriptName    = name,
                    ScriptStatus  = status,
                    StepName      = stepName,
                    ScriptStep    = step,
                    ContextScript = script,
                    FileName      = script?.FileName,
                    ScriptRaw     = script?.ScriptRaw,
                    Context       = context,
                    LastUpdate    = DateTimeOffset.Now,
                };
                MyScriptTableStorage.AddAnItem(newSnapshot);
            }
            else
            {
                existingSnapshot.ScriptName    = name;
                existingSnapshot.ScriptStatus  = status;
                existingSnapshot.StepName      = stepName;
                existingSnapshot.ScriptStep    = step;
                existingSnapshot.ContextScript = script;
                existingSnapshot.FileName      = script?.FileName;
                existingSnapshot.ScriptRaw     = script?.ScriptRaw;
                existingSnapshot.Context       = context;
                existingSnapshot.LastUpdate    = DateTimeOffset.Now;
                MyScriptTableStorage.UpdateItem(existingSnapshot);
            }
        }