コード例 #1
0
ファイル: ErrorsMiddleware.cs プロジェクト: wasphub/RElmah
        public ErrorsMiddleware(OwinMiddleware next, IErrorsInbox inbox, string prefix)
            : base(next)
        {
            Router.Build(builder => builder

                         .WithPrefix(prefix)

                         .ForRoute("post-error", route => route
                                   .Post(async(environment, keys, form) =>
            {
                var errorText = Encoding.UTF8.GetString(Convert.FromBase64String(form.Get("error")));
                var sourceId  = RetrieveSourceId(form);
                var errorId   = form.Get("errorId");
                var infoUrl   = form.Get("infoUrl");

                var payload = new ErrorPayload(sourceId, JsonConvert.DeserializeObject <Error>(errorText), errorId, infoUrl);

                await inbox.Post(payload);

                return(payload);
            })
                                   )
                         );
        }
コード例 #2
0
        public FrontendBackendNotifier(string endpoint, IErrorsInbox errorsInbox, IVisibilityPersistor visibilityPublisher)
        {
            var connection = new HubConnection(endpoint)
            {
                Credentials = CredentialCache.DefaultCredentials
            };

            _proxy = connection.CreateHubProxy("relmah-backend");

            _proxy.On <ErrorPayload>("error", p => errorsInbox.Post(p));

            _proxy.On <Delta <Cluster> >("cluster", p =>
            {
                switch (p.Type)
                {
                case DeltaType.Added:   visibilityPublisher.AddCluster(p.Target.Name, true);    break;

                case DeltaType.Removed: visibilityPublisher.RemoveCluster(p.Target.Name, true); break;
                }
            });

            _proxy.On <Delta <Source> >("source", p =>
            {
                switch (p.Type)
                {
                case DeltaType.Added:   visibilityPublisher.AddSource(p.Target.SourceId, p.Target.Description, true); break;

                case DeltaType.Removed: visibilityPublisher.RemoveSource(p.Target.SourceId, true); break;
                }
            });

            _proxy.On <Delta <User> >("user", p =>
            {
                switch (p.Type)
                {
                case DeltaType.Added:   visibilityPublisher.AddUser(p.Target.Name, true); break;

                case DeltaType.Removed: visibilityPublisher.RemoveUser(p.Target.Name, true); break;
                }
            });

            _proxy.On <Delta <Relationship <Cluster, Source> > >("clusterSource", p =>
            {
                switch (p.Type)
                {
                case DeltaType.Added:   visibilityPublisher.AddSourceToCluster(p.Target.Primary.Name, p.Target.Secondary.SourceId, true); break;

                case DeltaType.Removed: visibilityPublisher.RemoveSourceFromCluster(p.Target.Primary.Name, p.Target.Secondary.SourceId, true); break;
                }
            });

            _proxy.On <Delta <Relationship <Cluster, User> > >("clusterUser", p =>
            {
                switch (p.Type)
                {
                case DeltaType.Added:   visibilityPublisher.AddUserToCluster(p.Target.Primary.Name, p.Target.Secondary.Name, true); break;

                case DeltaType.Removed: visibilityPublisher.RemoveUserFromCluster(p.Target.Primary.Name, p.Target.Secondary.Name, true); break;
                }
            });

            connection.Start().Wait();
        }