Beispiel #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);
 }
Beispiel #2
0
        public List <TheVisitorLogData> GetAllVisitors()
        {
            var tcs = new TaskCompletionSource <List <TheVisitorLogData> >();  //REVIEW: Alle Callbacks brauchen AL

            MyVisitorLogStore?.GetRecords((resp) => {
                tcs.SetResult(resp.MyRecords);
            }, true);
            return(tcs.Task.Result);
        }
        public void GetRecordsFromTheStorageMirrorTest(
            [Values(0, 500, 5000)] int maxCount,
            [Values(50, 5000)] int totalCandidates
            )
        {
            #region ASSEMBLE

            TheStorageMirror <TheStorageEngineTSM> .StoreResponse response = null;
            var random = new Random();
            var data   = Enumerable.Range(1, totalCandidates).OrderBy(i => random.Next(1, totalCandidates));
            ManualResetEventSlim gate = new ManualResetEventSlim();
            TheStorageMirror <TheStorageEngineTSM> mirror;
            List <TheStorageEngineTSM>             TSMs = new List <TheStorageEngineTSM>();

            // Build the collection of TSMs
            foreach (var payload in data)
            {
                TSMs.Add(new TheStorageEngineTSM()
                {
                    cdeMID     = Guid.NewGuid(),
                    TXTPattern = payload.ToString()
                });
            }

            // Spin up your mirror
            mirror = new TheStorageMirror <TheStorageEngineTSM>(TheCDEngines.MyIStorageService)
            {
                IsRAMStore               = true,
                CacheStoreInterval       = 1,
                IsStoreIntervalInSeconds = true,
                IsCachePersistent        = true,
                UseSafeSave              = true,
                AllowFireUpdates         = true,
            };
            if (maxCount > 0)
            {
                mirror.SetMaxStoreSize(maxCount);
            }
            mirror.RegisterEvent(eStoreEvents.StoreReady, e => { gate.Set(); });
            mirror.InitializeStore(true);

            // Wait for mirror to initialize...
            gate.Wait(30000);

            // Add your items
            Task.Factory.StartNew(() =>
            {
                mirror.AddItems(TSMs, payload =>
                {
                    response = payload;
                    gate.Set();
                });
            });

            //Wait for response
            gate.Reset();
            gate.Wait(30000);
            if ((response != null) && response.HasErrors)
            {
                Assert.Fail("Unable to add test collection items! Reason: {0}", response.ErrorMsg);
            }

            #endregion

            #region ACT

            // Attempt to retrieve your items
            Task.Factory.StartNew(() =>
            {
                mirror.GetRecords(payload =>
                {
                    response = payload;
                    gate.Set();
                },
                                  true);
            });

            // Wait for response
            gate.Reset();
            gate.Wait(30000);
            if ((response != null) && response.HasErrors)
            {
                Assert.Fail("Unable to retrieve items! Reason: {0}", response.ErrorMsg);
            }

            mirror?.Dispose();

            #endregion

            #region ASSERT

            var expectedCount = maxCount == 0 ? totalCandidates : Math.Min(maxCount, totalCandidates);

            Assert.AreEqual(expectedCount, response.MyRecords.Count, "Not all test records were not added successfully.");

            #endregion
        }