public FakeSseResponse Any(FakeSseRequest sseRequest)
 {
     _serverEvents.NotifyChannel("test", "testMessage");
     return(new FakeSseResponse {
         TestProperty = sseRequest.TestProperty
     });
 }
        public object Any(SendMessage request)
        {
            if (string.IsNullOrWhiteSpace(request.Channel))
            {
                _serverEvents.NotifyAll(request.Message);
            }
            else
            {
                _serverEvents.NotifyChannel(request.Channel, request.Message);
            }

            return(new SendMessageResponse());
        }
Exemple #3
0
        public static void ProcessLongOperationStatus(LongOperationStatus longOperationStatus, IRedisClient redisClient, IServerEvents serverEvents)
        {
            var hashId     = string.Concat("LongOperationStatus:", longOperationStatus.ProcessKey.Split('!')[0], ":", longOperationStatus.TenantId);
            var setId      = string.Concat("LongOperationStatus:Keys:", longOperationStatus.ProcessKey.Split('!')[0], ":", longOperationStatus.TenantId);
            var processKey = string.Concat(longOperationStatus.UserId, "!", longOperationStatus.ProcessKey);

            redisClient.SetEntryInHash(hashId, processKey, longOperationStatus.ToJson());
            redisClient.AddItemToSortedSet(setId, processKey, longOperationStatus.Changed);
            redisClient.AddItemToSortedSet(string.Concat(setId, ":", longOperationStatus.UserId), processKey, longOperationStatus.Changed);

            var keys = redisClient.GetAllItemsFromSortedSet(setId);

            serverEvents.NotifyChannel(longOperationStatus.TenantId + ":" + longOperationStatus.ProcessKey.Split('!')[0], new LongOperationStatusCount {
                Tenant = keys.Count, User = keys.Count(x => x.StartsWith(longOperationStatus.UserId))
            });
        }
Exemple #4
0
        public object Any(HashGenerator request)
        {
            // Check if client id exists.
            if (request.Subscriber == null)
            {
                throw new HttpError(HttpStatusCode.BadRequest, $"The request is not valid - subscriber is empty.");
            }
            ;

            var url = request.Url;
            // Check if the url is valid.
            // Since we don't really "use" the uri object, just create one inline.
            var urlValidationResult = Uri.TryCreate(url, UriKind.Absolute, out var uriResult) &&
                                      (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

            if (!urlValidationResult)
            {
                throw new HttpError(HttpStatusCode.BadRequest, $"The url '{url}' is not valid.");
            }
            ;

            var mqServer = new RabbitMqServer("localhost");

            // dispatch a new thread for message queue processing

            new Thread(() =>
            {
                using (var mqClient = mqServer.CreateMessageQueueClient())
                {
                    mqClient.Publish(request);
                    var response = mqClient.Get <HashResponse>(QueueNames <HashResponse> .In);
                    mqClient.Ack(response);
                    // if there are any notification registered,
                    // push notification
                    _serverEvents.NotifyChannel("hash", response.Body);
                }
            }).Start();

            return(null);
        }
 public void Publish(INotification notification)
 {
     _serverEvents.NotifyChannel(notification.GetType().Name, notification);
 }
Exemple #6
0
 public static void NotifyChannel(this IServerEvents server, string channel, object message)
 {
     server.NotifyChannel(channel, Selector.Id(message.GetType()), message);
 }
Exemple #7
0
        static void Main(string[] args)
        {
            var skey   = AesUtils.CreateKey();
            var keyXml = skey.ToXml();
            var kUrl   = skey.ToBase64UrlSafe();

            JarsCore.Container = MEFBusinessLoader.Init();
            Logger.Info("MEF Loaded!");

            //add license
            string licPath = "~/ServiceStackLicense.txt".MapAbsolutePath();

            Logger.Info($"Registering ServiceStack Licence looking for:{licPath}");
            try
            {
                Licensing.RegisterLicenseFromFileIfExists(licPath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Press any key to close");
                Console.ReadLine();
                return;
            }
            //setup service
            var listeningOn = args.Length == 0 ? GetHostUrl() : args;
            //start setting up the service stack host
            JarsServiceAppHost appHost = new JarsServiceAppHost(AssemblyLoaderUtil.ServicesAssemblies.ToArray());

            appHost.OnConnect   = (evtSub, dictVal) => { Console.WriteLine($"OnConnect - Connection UserId:{evtSub.UserId} UserName: {evtSub.UserName} dictVals:{dictVal.Values}"); };
            appHost.OnSubscribe = (evtSub) => { Console.WriteLine($"OnSubscribe - sub:{evtSub.UserId}"); };
            appHost.OnPublish   = (sub, res, msg) => { if (!msg.Contains("cmd.onHeartbeat"))
                                                       {
                                                           Console.WriteLine($"Publish - DisplayName:{sub.DisplayName} Res.Status:{res.StatusCode} MsgLen:{msg.Length}");
                                                       }
            };
            appHost.OnUnsubscribe            = (evtSub) => { Console.WriteLine($"OnUnsubscribe - sub:{evtSub.UserId}"); };
            appHost.LimitToAuthenticatedUser = true;
            try
            {   //start the service
                appHost.Init().Start(listeningOn);
            }
            catch (Exception ex)
            {
                Logger.Info($"Error:{ex.Message}");
                Console.WriteLine("\r\n Press key to close app");
                Console.ReadLine();
                return;
            }

            string listeningOnVals = "";

            listeningOn.ToList().ForEach(s => listeningOnVals += $"ip: {s.ToString()}{Environment.NewLine}");

            Console.WriteLine($"AppHost Created at {DateTime.Now}, listening on: {Environment.NewLine}{listeningOnVals}");

            Console.WriteLine("write 'exit' to close, 'notify' to send notification to all subscribers, test to notify 'test' channel or sub-[chanel name] to notify that channel");

            //resolve the events plugin loaded in the configuration.
            IServerEvents se = appHost.TryResolve <IServerEvents>();

            int    i   = 0;
            string key = "start";

            while (key != "exit")
            {
                Console.Write("Subs: {0}", se.GetAllSubscriptionInfos().Count);
                key = Console.ReadLine();

                if (key == "notify")
                {
                    se.NotifyAll($"Notify All count({i})");
                }

                if (key == "test")
                {
                    se.NotifyChannel("test", $"Notify all in test channel : count({i})");
                }

                if (key.Contains("sub"))
                {
                    se.NotifyChannel(key.Substring(key.IndexOf("-")), $"Notify channel {key.Substring(key.IndexOf("-"))} : count({i})");
                }

                if (key.Contains("infos"))
                {
                    List <SubscriptionInfo> infs = se.GetAllSubscriptionInfos();

                    foreach (var si in infs)
                    {
                        Console.Write($"DisplayName:{si.DisplayName}, Auth:{si.IsAuthenticated}, SubId:{si.SubscriptionId}, UserId:{si.UserId}, UserName:{si.UserName}");
                        Console.WriteLine();
                    }
                }
                if (key.Contains("login"))
                {
                    ServerEventsClient   client = new ServerEventsClient("http://localhost:3337/", "test");
                    AuthenticateResponse aResp  = client.Authenticate(new Authenticate()
                    {
                        UserName = "******", Password = "******", RememberMe = true
                    });
                    Console.Write($"Auth DisplayName:{aResp.DisplayName}, BT:{aResp.BearerToken}, Un:{aResp.UserName}, UserId:{aResp.UserId}");
                }
                if (key.Contains("req"))
                {
                }
                i++;
            }
        }