コード例 #1
0
        /// <inheritdoc />
        public override async Task Start(IConfig config)
        {
            // config
            ConfigHelper c = config as ConfigHelper;

            // database
            BaseContext.Setup <UserContext>();
            await CheckUser(c.BrokerUser, c.BrokerPass, c.Secret);
            await CheckUser(c.AuthServiceUser, c.AuthServicePass, c.Secret);

            // get endpoint for local grpc host
            IPEndPoint grpcEndPoint = new IPEndPoint(IPAddress.Any, config.PortGrpc);//GetCloudAddress(config);

            // get endpoint which will be repoted to the network
            IPHostEntry entry        = Dns.GetHostEntry(Dns.GetHostName());
            var         host         = entry.AddressList.LastOrDefault(p => p.AddressFamily == AddressFamily.InterNetwork);
            var         upnpEndpoint = new IPEndPoint(host, CloudLocator.GetConfig().PortGrpc);

            // Start the server grpc endpoints
            CommonBaseHandler.Log(this.ToString(), "GRPC IP ADRESS: " + upnpEndpoint, NLog.LogLevel.Info);
            StartGrpcServer(grpcEndPoint, config.SrcDeviceId);

            // accept client connections
            (this.ActionWorker as ActionWorker).ReadyForConnections = true;
            Console.WriteLine("Auth server started -> ready for connections.");
        }
コード例 #2
0
        /// <inheritdoc />
        public override async Task <GrpcResponse> StreamDisconnected(string streamID)
        {
            await CommonSubscriptionHandler.UnregisterStream(streamID);

            CommonBaseHandler.Log(this.ToString(), string.Format("Client stream {0} disconnted.", streamID), LogLevel.Info);
            return(Ok());
        }
コード例 #3
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        /// <param name="srcDeviceId">The source device identifier.</param>
        /// <param name="communicationService">The communication service.</param>
        private void StartServer(string srcDeviceId, IServer <Command, FetchRequest, GrpcResponse> communicationService)
        {
            // Grpc server
            CommunicationServer server = new CommunicationServer(communicationService, srcDeviceId);

            // Grpc server actions
            server.OnAction             = async(cmd, streamId, token, header) => { return(await ActionWorker.ProcessCommand(srcDeviceId, cmd, streamId, token, header)); };
            server.OnStreaming          = async(cmd, stream, token, header) => { return(await ActionWorker.ProcessCommand(srcDeviceId, cmd, stream.Id, token, header)); };
            server.OnStreamOpened       = async(stream, token, header) => { return(await ActionWorker.StreamConnected(stream, token, header)); };
            server.OnClientDisconnected = async(id) => { await ActionWorker.StreamDisconnected(id); };
            server.OnLog += (sender, srcid, msg, level) =>
            {
                CommonBaseHandler.Log(sender.ToString(), msg, level);
            };
            server.Start();
        }
コード例 #4
0
        /// <inheritdoc />
        public override async Task <GrpcResponse> StreamConnected(IStream <Command> stream, string token, Metadata header)
        {
            if (await this.tokenObserver.IsValid(token) == null)
            {
                return(Unauthorized());
            }

            CommonSubscriptionHandler.RegisterStream(stream, stream.Id);
            CommonBaseHandler.Log(this.ToString(), string.Format("Client stream {0} is connected.", stream.Id), LogLevel.Info);

            // Send service metadata informations to client after successful connect
            foreach (var metaData in serviceMetaData.Values)
            {
                Command cmd = new Command {
                    Type = CommandType.Action, Topic = StaticCommandKeys.ServiceMetaData
                };
                cmd.Data.Add(Any.Pack(metaData));
                stream.AddToQueue(cmd);
            }

            return(Ok());
        }
コード例 #5
0
 /// <summary>
 /// Logs a message
 /// </summary>
 /// <param name="msg">The MSG.</param>
 /// <param name="level">The level.</param>
 protected virtual void Log(string msg, LogLevel level)
 {
     CommonBaseHandler.Log(this.GetType().ToString(), msg, level);
 }
コード例 #6
0
 /// <summary>
 /// Logs an exception
 /// </summary>
 /// <param name="code">The code.</param>
 /// <param name="ex">The ex.</param>
 protected virtual void Log(string code, Exception ex)
 {
     CommonBaseHandler.Log(this.GetType().ToString(), ex.ToText(code), LogLevel.Error);
 }
コード例 #7
0
 /// <inheritdoc />
 public override async Task <GrpcResponse> StreamDisconnected(string streamID)
 {
     CommonBaseHandler.Log(this.ToString(), string.Format("Client stream {0} disconnted.", streamID), LogLevel.Info);
     return(await Task.FromResult(Ok()));
 }
コード例 #8
0
 /// <inheritdoc />
 public override async Task <GrpcResponse> StreamConnected(IStream <Command> stream, string token, Metadata header)
 {
     CommonBaseHandler.Log(this.ToString(), string.Format("Client stream {0} is connected.", stream.Id), LogLevel.Info);
     return(await Task.FromResult(Ok()));
 }