Exemplo n.º 1
0
 /// <summary>
 /// Log a new Visitor
 /// </summary>
 /// <param name="IP">IP address of the Visitor</param>
 /// <param name="pReferer">A cookie (i.e. URL Referer) of the visitor stored with the Log Entry</param>
 /// <returns></returns>
 public Guid LogVisitor(string IP, string pReferer)
 {
     if (mIsHostLogged)
     {
         TheVisitorLogData tLog    = new TheVisitorLogData();
         string            tFilter = "";
         lock (mVisitorListLock)
         {
             tLog.ip          = IP;
             tLog.LastVisit   = DateTimeOffset.Now;
             tLog.Referrer    = pReferer;
             tLog.Description = "VISITOR";
             tFilter          = "ip='" + IP + "'";
             if (mVisitorList.ContainsKey(tFilter) && DateTimeOffset.Now.Subtract(mVisitorList[tFilter].LastVisit).TotalMinutes < 10)
             {
                 return(Guid.Empty);
             }
             if (mVisitorList.ContainsKey(tFilter))
             {
                 mVisitorList[tFilter] = tLog;
             }
             else
             {
                 mVisitorList.TryAdd(tFilter, tLog);
             }
         }
         MyVisitorLogStore.GetRecords(tFilter, 1, GetIP, false);
         return(tLog.cdeMID);
     }
     return(Guid.Empty);
 }
Exemplo n.º 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);
             }
         }
     }
 }
Exemplo n.º 3
0
        private void sinkRegisterHost(IPAddress pIP, object pData)
        {
            TheVisitorLogData tData = pData as TheVisitorLogData;

            if (tData != null)
            {
                if (pIP == null)
                {
                    pIP = nsCDEngine.Discovery.TheNetworkInfo.GetIPAddress(false);
                }
                tData.ip = pIP.ToString();
                TheBaseAssets.MySYSLOG.WriteToLog(511, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("VisitorLog", "GetExternalIp returned: " + pIP.ToString(), eMsgLevel.l4_Message));
                TheREST.GetRESTAsync(new Uri($"http://api.ipstack.com/{pIP}?access_key={APIKey}"), 0, sinkProcessLocation, tData);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public bool Init()
        {
            if (mIsInitCalled)
            {
                return(false);
            }
            mIsInitCalled = true;

            MyBaseThing.RegisterEvent(eEngineEvents.IncomingMessage, HandleMessage);
            if (TheThing.GetSafePropertyString(MyBaseThing, "VisitorCount") == "")
            {
                VisitorCount = 0;
            }
            MyNodePrintsName = $"NodePrints{TheThing.GetSafeThingGuid(MyBaseThing, "NodePrints")}";
            TheBaseEngine.WaitForStorageReadiness(OnStorageReady, true);
            MyBaseThing.SetPublishThrottle(15000);
            TheCommCore.RegisterRelayEvents(null, null, sinkNewConnection);

            if (MyVisitorLog == null)
            {
                MyVisitorLog = new TheVisitorLog(MyBaseThing);
            }
            TheQueuedSenderRegistry.RegisterHealthTimer(GetSystemInfo);
            TheCDEngines.MyNMIService.RegisterEvent("NMI_MY_LOCATION", (sender2, para) =>
            {
                var t = para as TheNMILocationInfo;
                if (t != null)
                {
                    var NewEntry = new TheVisitorLogData {
                        cdeN = t.cdeN, latitude = t.Latitude, longitude = t.Longitude, ip = t.ClientInfo?.UserID.ToString(), LastVisit = DateTimeOffset.Now, Description = t.ClientInfo != null && t.ClientInfo.UserID != Guid.Empty ? TheUserManager.GetUserFullName(t.ClientInfo.UserID) : "Unknown user"
                    };
                    MyVisitorLog.LogVisitor(NewEntry);
                    myGoogleMap?.SetUXProperty(Guid.Empty, $"AddMarker={TheCommonUtils.SerializeObjectToJSONString(NewEntry)}");
                }
            });
            TheCommCore.MyHttpService.RegisterHttpInterceptorB4("/cdemeshinfo.aspx", sinkRequestMeshInfo);
            MyBaseEngine.ProcessInitialized();
            MyBaseEngine.SetEngineReadiness(true, null);
            MyBaseEngine.SetStatusLevel(1);
            mIsInitialized = true;
            return(true);
        }
Exemplo n.º 6
0
 private void StoreIsUp(StoreEventArgs ID)
 {
     if (!mIsHostLogged)
     {
         mIsHostLogged = true;
         TheVisitorLogData tLog = new TheVisitorLogData
         {
             LastVisit   = DateTimeOffset.Now,
             Description = TheBaseAssets.MyServiceHostInfo.MyStationName
         };
         IPAddress myaddr = nsCDEngine.Discovery.TheNetworkInfo.GetIPAddress(true);
         if (myaddr == null)
         {
             nsCDEngine.Discovery.TheNetworkInfo.GetExternalIp(sinkRegisterHost, tLog);
         }
         else
         {
             TheREST.GetRESTAsync(new Uri($"http://api.ipstack.com/{myaddr}?access_key={APIKey}"), 0, sinkProcessLocation, tLog);
         }
     }
 }
Exemplo n.º 7
0
 public bool LogVisitor(TheVisitorLogData pData)
 {
     MyVisitorLogStore?.AddAnItem(pData);
     return(MyVisitorLogStore != null);
 }