Exemplo n.º 1
0
        public LockSystemTest()
        {
            TimePeriodDefinition timePeriodDefinition = "20190211T080000Z/28800/DW(Mo+Tu+We+Th+Fr)/20190329T160000Z";
            AccessPolicy         accessPolicy         = new AccessPolicy("000002oe1g25o", new NumberOfLockings(12, 45), new[] { timePeriodDefinition });

            this.system = CreateEmptyLockSystem()
                          .AddLock(new Lock(TorWestId, "W1", null, "Tor West"))
                          .AddKey(new Key(KlausFenderId, "103-1", null, "Fender, Klaus"))
                          .AddAccessPolicy(accessPolicy);
        }
Exemplo n.º 2
0
        private LockSystem ListEvents(LockSystem lockSystem, string replyTo, int jobId, DateTime?since)
        {
            lockSystem.Events
            .Select(@event => String.Join(',', FormatEvent(@event)))
            .Append("LER,OK")
            .ToObservable()
            .Aggregate((accu, current) => accu + "\n" + current)
            .Select(s => new Statement(replyTo, jobId, s))
            .Subscribe(this.statementObserver);

            return(lockSystem);
        }
Exemplo n.º 3
0
        private LockSystem ListData(LockSystem lockSystem, string replyTo, int jobId)
        {
            lockSystem.Keys
            .Select(key => String.Join(',', FormatKey(key)))
            .Concat(lockSystem.Locks
                    .Select(@lock => String.Join(',', FormatLock(@lock))))
            .Append("LDR,OK")
            .ToObservable()
            .Aggregate((accu, current) => accu + "\n" + current)
            .Select(s => new Statement(replyTo, jobId, s))
            .Subscribe(this.statementObserver);

            return(lockSystem);
        }
Exemplo n.º 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .AddControllersWithViews()
            .AddNewtonsoftJson();
            services.AddRazorPages();


            services.AddSpaStaticFiles(spa => spa.RootPath = "ClientApp");
            // In production, the React files will be served from this directory
            // services.AddSpaStaticFiles(spa =>spa.RootPath = "build");

            services
            .AddSingleton <IDateTimeProvider>(new DateTimeProvider())
            .AddSingleton <Id>(sp => new Id(sp.GetService <IDateTimeProvider>()))
            .AddSingleton(sp => new AtomicValue <LockSystem>(LockSystem.Create(sp.GetService <Id>())))

            .AddSingleton <ISubject <Statement>, ReplaySubject <Statement> >()
            .AddSingleton <IObservable <Statement> >(sp => sp.GetService <ISubject <Statement> >().AsObservable())
            .AddSingleton <IObserver <Statement> >(sp => sp.GetService <ISubject <Statement> >())

            .AddSingleton <ISubject <Message>, ReplaySubject <Message> >()
            .AddSingleton <IObservable <Message> >(sp => sp.GetService <ISubject <Message> >().AsObservable())
            .AddSingleton <IObserver <Message> >(sp => sp.GetService <ISubject <Message> >())

            .AddSingleton <BrowserChannel>()
            .AddSingleton <MessageBusInteractor, MessageBusInteractor>()
            ;

            services.AddCors(options =>
            {
                options.AddPolicy(MyAllowSpecificOrigins, builder =>
                {
                    builder                    // .WithOrigins("http://localhost","http://127.0.0.1")
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowAnyOrigin()
                    //.AllowCredentials()
                    ;
                });
            });

            services
            .AddSignalR(options => { options.KeepAliveInterval = TimeSpan.FromSeconds(5); })
            .AddMessagePackProtocol();

            services
            .AddMqttService(this.configuration);
        }
Exemplo n.º 5
0
        public static void DisconnectClient(ClientStructure client, string reason = "")
        {
            if (!string.IsNullOrEmpty(reason))
            {
                LunaLog.Debug($"{client.PlayerName} sent Connection end message, reason: {reason}");
            }

            VesselUpdateRelaySystem.RemovePlayer(client);

            //Remove Clients from list
            if (ServerContext.Clients.ContainsKey(client.Endpoint))
            {
                ServerContext.Clients.TryRemove(client.Endpoint, out client);
                LunaLog.Debug($"Online Players: {ServerContext.PlayerCount}, connected: {ServerContext.Clients.Count}");
            }

            if (client.ConnectionStatus != ConnectionStatus.Disconnected)
            {
                client.ConnectionStatus = ConnectionStatus.Disconnected;
                LmpPluginHandler.FireOnClientDisconnect(client);
                if (client.Authenticated)
                {
                    ChatSystem.RemovePlayer(client.PlayerName);

                    var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <PlayerConnectionLeaveMsgData>();
                    msgData.PlayerName = client.PlayerName;

                    MessageQueuer.RelayMessage <PlayerConnectionSrvMsg>(client, msgData);
                    LockSystem.ReleasePlayerLocks(client);

                    if (!ServerContext.Clients.Any(c => c.Value.Subspace == client.Subspace))
                    {
                        WarpSystem.RemoveSubspace(client.Subspace);
                        VesselRelaySystem.RemoveSubspace(client.Subspace);
                    }
                }

                try
                {
                    client.Connection?.Disconnect(reason);
                }
                catch (Exception e)
                {
                    LunaLog.Debug($"Error closing client Connection: {e.Message}");
                }
                ServerContext.LastPlayerActivity = ServerContext.ServerClock.ElapsedMilliseconds;
            }
        }
Exemplo n.º 6
0
        public static void DisconnectClient(ClientStructure client, string reason = "")
        {
            if (!string.IsNullOrEmpty(reason))
            {
                LunaLog.Debug($"{client.PlayerName} sent Connection end message, reason: {reason}");
            }

            if (client.ConnectionStatus != ConnectionStatus.Disconnected)
            {
                client.ConnectionStatus = ConnectionStatus.Disconnected;
                LmpPluginHandler.FireOnClientDisconnect(client);
                if (client.Authenticated)
                {
                    var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <PlayerConnectionLeaveMsgData>();
                    msgData.PlayerName = client.PlayerName;

                    MessageQueuer.RelayMessage <PlayerConnectionSrvMsg>(client, msgData);
                    LockSystem.ReleasePlayerLocks(client);
                    WarpSystem.RemoveSubspace(client.Subspace);
                }

                try
                {
                    client.Connection?.Disconnect(reason);
                }
                catch (Exception e)
                {
                    LunaLog.Error($"Error closing client Connection: {e.Message}");
                }
            }

            //Remove Clients from list
            if (ServerContext.Clients.TryRemove(client.Endpoint, out ClientStructure removed))
            {
                LunaLog.Debug($"Online Players: {ServerContext.PlayerCount}, connected: {ServerContext.Clients.Count}");
            }
            else
            {
                LunaLog.Error($"Error removing client: {client.PlayerName} from list");
            }

            //As this is the last client that is connected to the server, run a safety backup once he disconnects
            if (ServerContext.Clients.Count == 0)
            {
                BackupSystem.RunBackup();
                GcSystem.PerformGCNow();
            }
        }
Exemplo n.º 7
0
        public void TestDefineLockAfterCreate()
        {
            const string lockName = "100";
            var          extData  = $"{lockName}, Meeting Room, Administration\0".ToBase64();
            var          system   = CreateEmptyLockSystem()
                                    .DefineStatement($"CL,APP,{lockName}");
            Func <string, string> getId = name => system.Locks.SingleOrDefault(@lock => @lock.Name == name)?.Id;

            system = system
                     .DefineStatement($"DL,{getId(lockName)},,,{extData}");

            Assert.Equal(1, system.Locks.Count());
            var lock_100 = system.Locks.First(x => x.Name == lockName);

            Assert.Equal("040000rbookls", lock_100.Id);
            Assert.Equal(lockName, lock_100.Name);
            Assert.Equal("APP", lock_100.AppId);
            Assert.Equal($"{lockName}, Meeting Room, Administration", lock_100.ExtData);
        }
Exemplo n.º 8
0
        public void TestDefineKeyAfterCreate()
        {
            const string keyName = "103-1";
            var          extData = $"{keyName}, Fender, Klaus\0".ToBase64();
            var          system  = CreateEmptyLockSystem()
                                   .DefineStatement($"CK,APP,{keyName}");
            Func <string, string> getId = name => system.Keys.SingleOrDefault(key => key.Name == name)?.Id;

            system = system
                     .DefineStatement($"DK,{getId(keyName)},,,{extData}");

            Assert.Equal(1, system.Keys.Count());
            var key_103_1 = system.Keys.First(x => x.Name == keyName);

            Assert.Equal("040000jbookls", key_103_1.Id);
            Assert.Equal(keyName, key_103_1.Name);
            Assert.Equal("APP", key_103_1.AppId);
            Assert.Equal($"{keyName}, Fender, Klaus", key_103_1.ExtData);
        }
Exemplo n.º 9
0
        public bool Check(string keyId, string lockId, DateTime dateTime)
        {
            dateTime = dateTime.ToUniversalTime();
            logger.LogInformation("key {Key} , Lock {Lock}, DateTime {DateTime}", keyId, lockId, dateTime);

            LockSystem system = lockSystem;

            Key  key   = system.QueryKey(keyId);
            Lock @lock = system.QueryLock(lockId);

            var @event = new Event(this.idGenerator.NewId(TableIds.Event, system.Events.Count() + 1),
                                   dateTime, key, @lock, system.HasAccess(key, @lock, dateTime));

            // statementObserver.OnNext(new Statement(TOPIC_RESPONSE, 4711,
            //  $"EK,{@event.Lock.Id},{@event.Key.Id},{@event.IsOpen}"));

            lockSystem.SetValue(x => x.AddEvent(@event));
            return(@event.EventType == EventType.Authorized_Access);
        }
Exemplo n.º 10
0
        public void TestDeltaLockNewSystem()
        {
            const string lockName = "100";
            const string keyName  = "103-1";

            var system_t0 = CreateEmptyLockSystem();
            var system_t1 = system_t0
                            .DefineStatement($"CL,APP,{lockName}")
                            .DefineStatement($"CK,APP,{keyName}");

            var newEntities = LockSystem.CreatedEntities(system_t0, system_t1);

            Assert.Equal(2, newEntities.Count());
            Assert.Equal(lockName, newEntities.OfType <Lock>().Single().Name);
            Assert.Equal(keyName, newEntities.OfType <Key>().Single().Name);

            var oldEntities = LockSystem.RemovedEntities(system_t1, system_t0);

            Assert.Equal(2, oldEntities.Count());
            Assert.Equal(lockName, oldEntities.OfType <Lock>().Single().Name);
            Assert.Equal(keyName, oldEntities.OfType <Key>().Single().Name);
        }
Exemplo n.º 11
0
    private void SetMenuOptions(int actorID, int itemID)
    {
        if (!MenuSystem.RemoveOptions(actorID, AllMenuOptions))
        {
            return;
        }

        if (ActionSystem.IsBusy(actorID))
        {
            return;
        }

        if (!ItemWithinRange(MenuSystem.DistanceToTarget(actorID)))
        {
            return;
        }

        if (LockSystem.IsLocked(itemID))
        {
            return;
        }

        MenuSystem.AddOption(actorID, IsOpen(itemID) ? RPGGameEvent.Menu_Close : RPGGameEvent.Menu_Open);
    }
Exemplo n.º 12
0
    private void OnMenuUseKey(GameEvent e)
    {
        var data = (MenuSystem.MenuOptionSelected)e.EventData;

        TimedActionStarted(data.ActorID, RPGGameEvent.Menu_UseKey, LockSystem.ActionTimeToUseKey(data.ItemID), true, data.ItemID);
    }
Exemplo n.º 13
0
        private void Receive(string replyTo, int jobId, string message)
        {
            this.logger.LogInformation($"Receive('{replyTo}', {jobId.ToHex()}, '{message.Shorten()}')");

            LockSystem systemBefore = lockSystem;
            LockSystem systemAfter  = message.Split("\n")
                                      .Where(x => !string.IsNullOrWhiteSpace(x))
                                      .Aggregate(systemBefore, (accu, current) =>
            {
                int index   = current.IndexOf(',');
                string head = index == -1 ? current : current.Substring(0, index);
                if (head.Equals("LE"))
                {
                    return(ListEvents(accu, replyTo, jobId, null));
                }
                else if (head.Equals("LD"))
                {
                    return(ListData(accu, replyTo, jobId));
                }
                else
                {
                    return(accu.DefineStatement(current));
                }
            });

            lockSystem.SetValue(x => systemAfter);

            if (systemBefore != systemAfter)
            {
                var statements = LockSystem.CreatedEntities(systemBefore, systemAfter).Select(entity =>
                {
                    switch (entity)
                    {
                    case Key key:
                        return(DefinedKey(key));

                    case Lock @lock:
                        return(DefinedLock(@lock));

                    case AccessPolicy accessPolicy:
                        return(DefinedAccessPolicy(accessPolicy));

                    case PolicyAssignment assignment:
                        return(DefinedAssignment(assignment));

                    default:
                        throw new ArgumentException(
                            message: "Missing 'DefinedXXX' operation for entity",
                            paramName: nameof(entity));
                    }
                }).Concat(LockSystem.RemovedEntities(systemBefore, systemAfter).Select(entity =>
                {
                    switch (entity)
                    {
                    case Key key:
                        return(RemovedKey(key));

                    case Lock @lock:
                        return(RemovedLock(@lock));

                    default:
                        throw new ArgumentException(
                            message: "Missing 'RemovedXXX' operation for entity",
                            paramName: nameof(entity));
                    }
                })).Concat(LockSystem.UpdatedEntities(systemBefore, systemAfter).Select(entity =>
                {
                    switch (entity)
                    {
                    case Key key:
                        return(UpdatedKey(key));

                    case Lock @lock:
                        return(UpdatedLock(@lock));

                    default:
                        throw new ArgumentException(
                            message: "Missing 'UpdatedXXX' operation for entity",
                            paramName: nameof(entity));
                    }
                }));

                if (!statements.IsEmpty())
                {
                    statements
                    .ToObservable()
                    .Aggregate((accu, current) => accu + "\n" + current)
                    .Select(s => new Statement(replyTo, jobId, s))
                    .Subscribe(this.statementObserver);
                }
            }
        }
Exemplo n.º 14
0
 private LockSystem CreateEmptyLockSystem() => LockSystem.Create(new Id("2020-01-23T16:14:35".FakeNow()));
Exemplo n.º 15
0
        public IEnumerable <PersonInfo> Persons()
        {
            logger.LogInformation("Persons called");

            LockSystem system = lockSystem;

            if (system.Keys.IsEmpty())
            {
                yield break;
            }
            else
            {
                Func <string, string> GetId =
                    x => system.Keys.SingleOrDefault(y => y.ExtData.Contains(x))?.Id;

                yield return(new PersonInfo {
                    keyId = GetId("900-1"),
                    value = "900-1", label = "Ahrens, Andrea", department = "Geschäftsführung", color = "OliveDrab"
                });

                yield return(new PersonInfo {
                    keyId = GetId("901-1"),
                    value = "901-1", label = "Barthauer, Thomas", department = "Geschäftsführung", color = "SandyBrown"
                });

                yield return(new PersonInfo {
                    keyId = GetId("103-1"),
                    value = "103-1", label = "Fendler, Klaus", department = "Buchhaltung"
                });

                yield return(new PersonInfo {
                    keyId = GetId("104-1"),
                    value = "104-1", label = "Kistler, Sabine", department = "Vertrieb"
                });

                yield return(new PersonInfo {
                    keyId = GetId("105-1"),
                    value = "105-1", label = "Kohl, Ulrich", department = "Vertrieb"
                });

                yield return(new PersonInfo {
                    keyId = GetId("200-1"),
                    value = "200-1", label = "Leinkamp, Sebastian", department = "Lager"
                });

                yield return(new PersonInfo {
                    keyId = GetId("201-1"),
                    value = "201-1", label = "Mertens, Martina", department = "Lager"
                });

                yield return(new PersonInfo {
                    keyId = GetId("202-1"),
                    value = "202-1", label = "Sidow, Janin", department = "Montage"
                });

                yield return(new PersonInfo {
                    keyId = GetId("203-1"),
                    value = "203-1", label = "Walter, Jens", department = "Montage"
                });

                yield return(new PersonInfo {
                    keyId = GetId("203-2"),
                    value = "203-2", label = "Winter, Sina", department = "Montage"
                });

                yield return(new PersonInfo {
                    keyId = GetId("203-3"),
                    value = "203-3", label = "Wondraschek, Volker", department = "Montage"
                });
            }
        }
Exemplo n.º 16
0
        public IEnumerable <GroupOrDoor> Doors()
        {
            logger.LogInformation("Doors called");

            LockSystem system = lockSystem;

            if (system.Locks.IsEmpty())
            {
                yield break;
            }
            else
            {
                Func <string, string> GetId = x => system.Locks.SingleOrDefault(y => y.ExtData.Contains(x))?.Id;

                yield return(new DoorInfo {
                    lockId = GetId("W1"),
                    value = "W1", label = "Tor West", building = "-.-", image = "tor_west", color = "LightSlateGray"
                });

                yield return(new GroupInfo {
                    type = "group", name = "Verwaltung", items = new [] {
                        new DoorInfo {
                            lockId = GetId("100"),
                            value = "100", label = "Konferenzraum", building = "Verwaltung", image = "konferenzraum", color = "Yellow"
                        },
                        new DoorInfo {
                            lockId = GetId("101"),
                            value = "101", label = "Büro Ahrens", building = "Verwaltung", image = "buero_ahrens", color = "Yellow"
                        },
                        new DoorInfo {
                            lockId = GetId("102"),
                            value = "102", label = "Büro Barthauer", building = "Verwaltung", image = "buero_barthauer", color = "Yellow"
                        },
                        new DoorInfo {
                            lockId = GetId("103"),
                            value = "103", label = "Buchhaltung", building = "Verwaltung", image = "buchhaltung", color = "Yellow"
                        },
                        new DoorInfo {
                            lockId = GetId("104"),
                            value = "104", label = "Büro Vertrieb 1", building = "Verwaltung", image = "buero_vertrieb1", color = "Yellow"
                        },
                        new DoorInfo {
                            lockId = GetId("105"),
                            value = "105", label = "Büro Vertrieb 2", building = "Verwaltung", image = "buero_vertrieb2", color = "Yellow"
                        },
                        new DoorInfo {
                            lockId = GetId("Z1"),
                            value = "Z1", label = "Eingang West", building = "Verwaltung", image = "eingang_west", color = "Yellow"
                        }
                    }
                });

                yield return(new GroupInfo {
                    type = "group", name = "Produktion", items = new [] {
                        new DoorInfo {
                            lockId = GetId("204"),
                            value = "204", label = "Werkhalle West", building = "Produktion", image = "werkhalle_west", color = "DeepSkyBlue"
                        },
                        new DoorInfo {
                            lockId = GetId("200"),
                            value = "200", label = "Metalllager", building = "Produktion", image = "metalllager", color = "DeepSkyBlue"
                        },
                        new DoorInfo {
                            lockId = GetId("202"),
                            value = "202", label = "Büro Montage", building = "Produktion", image = "buero_montage", color = "DeepSkyBlue"
                        },
                        new DoorInfo {
                            lockId = GetId("201"),
                            value = "201", label = "Warenlager", building = "Produktion", image = "warenlager", color = "DeepSkyBlue"
                        },
                        new DoorInfo {
                            lockId = GetId("205"),
                            value = "205", label = "Werkhalle Süd", building = "Produktion", image = "werkhalle_sued", color = "DeepSkyBlue"
                        }
                    }
                });
            }
        }