﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:betag="http://dotnetblogengine.net/schemas/tags">
  <channel>
    <title>naspinski.net</title>
    <description>software development</description>
    <link>http://naspinski.net/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 3.3.5.0</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://naspinski.net/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
    <dc:creator>Stan Naspinski</dc:creator>
    <dc:title>naspinski.net</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <item>
      <title>Singleton Broadcaster in Angular2</title>
      <description>&lt;h2&gt;A simple way to subscribe and/or broadcast from anywhere in an app to anywhere else.&lt;/h2&gt;
&lt;p&gt;Basically, I needed a simple way to send out global messages not knowing what components would be loaded and didn't want to deal with injecting this anywhere in older components. &amp;nbsp;With a little messing around with some online guides (sorry I don't remember which ones) I came up with the following:&lt;/p&gt;
&lt;h6&gt;broadcast.service.ts&lt;/h6&gt;
&lt;pre class="brush:js;auto-links:false;toolbar:false" contenteditable="false"&gt;import { Injectable } from "@angular/core";
import { Subject } from "rxjs/Subject";

@Injectable()
export class BroadcastService {

    static instance: BroadcastService;
    static isCreating: Boolean = false;

    private broadcastMessageSource = new Subject&amp;lt;string&amp;gt;();
    broadcastMessage$ = this.broadcastMessageSource.asObservable();
    
    constructor() {
        if (!BroadcastService.isCreating) {
            throw new Error("You can't call new in Singleton instances");
        }
    }

    static getInstance() {
        if (BroadcastService.instance == null) {
            BroadcastService.isCreating = true;
            BroadcastService.instance = new BroadcastService();
            BroadcastService.isCreating = false;
        }
        return BroadcastService.instance;
    }

    broadcastMessage(modal: string) {
        this.broadcastMessageSource.next(modal);
    }
}&lt;/pre&gt;
&lt;p&gt;Then simply make sure to import it where you need it, and send out a broadcast:&lt;/p&gt;
&lt;pre class="brush:js;auto-links:false;toolbar:false" contenteditable="false"&gt;BroadcastService.getInstance().broadcastMessage('message-i-care-about');&lt;/pre&gt;
&lt;p&gt;Where you need to,&amp;nbsp; subscribe in the&amp;nbsp;constructor (or ngOnInit):&lt;/p&gt;
&lt;pre class="brush:js;auto-links:false;toolbar:false" contenteditable="false"&gt;BroadcastService.getInstance().broadcastMessage$.subscribe(this.receiveBroadcastMessage.bind(this));&lt;/pre&gt;
&lt;p&gt;And deal with the broadcast however you will:&lt;/p&gt;
&lt;pre class="brush:js;auto-links:false;toolbar:false" contenteditable="false"&gt;receiveBroadcastMessage(broadcast: string): void {
    console.log('broadcast received: ' + broadcast);

    // I generally run it through a switch to see if its something this component cares about
    switch (broadcast) { 
        case 'message-i-care-about': doSomething(); break;
    }
    // or just ignore it
}&lt;/pre&gt;
&lt;p&gt;There you go, just sent and received a global broadcast message.&lt;/p&gt;</description>
      <link>http://naspinski.net/post/2017/01/05/Singleton-Broadcaster-in-Angular2</link>
      <author>stan@naspinski.net</author>
      <comments>http://naspinski.net/post/2017/01/05/Singleton-Broadcaster-in-Angular2#comment</comments>
      <guid>http://naspinski.net/post.aspx?id=8bfa2921-c5ad-4336-be7c-abf093667ac2</guid>
      <pubDate>Thu, 5 Jan 2017 03:44:00 +0000</pubDate>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=8bfa2921-c5ad-4336-be7c-abf093667ac2</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=8bfa2921-c5ad-4336-be7c-abf093667ac2</trackback:ping>
      <wfw:comment>http://naspinski.net/post/2017/01/05/Singleton-Broadcaster-in-Angular2#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=8bfa2921-c5ad-4336-be7c-abf093667ac2</wfw:commentRss>
    </item>
    <item>
      <title>Azure Service Fabric ServiceProxy failing silently</title>
      <description>&lt;p&gt;Inside my service fabric, I was creating a ServiceProxy to call another part of the fabric which I had working in multiple other places in my code like this:&lt;/p&gt;
&lt;pre class="brush:csharp;auto-links:false;toolbar:false" contenteditable="false"&gt;var uri = new Uri("fabric:/MyNameSpace.MyClass");
var proxy = ServiceProxy.Create&amp;lt;ISomeInterface&amp;gt;(uri);
proxy.DoSomething(someString, someObjectCollection);&lt;/pre&gt;
&lt;p&gt;And it worked perfectly fine, next I tried with a different interface and it just silently failed, literally the&amp;nbsp;&lt;em&gt;exact&lt;/em&gt; same setup, but a new interface.&lt;/p&gt;
&lt;pre class="brush:csharp;auto-links:false;toolbar:false" contenteditable="false"&gt;public interface ISignalRelay : IService
{
    Task Broadcast(string group, string message, object details);
}&lt;/pre&gt;
&lt;p&gt;Then my code:&lt;/p&gt;
&lt;pre class="brush:csharp;auto-links:false;toolbar:false" contenteditable="false"&gt;var uri = new Uri("fabric:/MyNameSpace.MyClass");
var signalRelay = ServiceProxy.Create&amp;lt;ISignalRelay&amp;gt;(uri);
signalRelay.Broadcast(group, message, nonPrimitiveObject);&lt;/pre&gt;
&lt;p&gt;When stepping through the code, it would work fine until I hit&amp;nbsp;&lt;strong&gt;Broadcast()&lt;/strong&gt; and then just continue on, but that code was never hit. &amp;nbsp;From what I deduced, it was the ability of the proxy to deal with the base object class when it was passed something that was not a primitive type.&lt;/p&gt;
&lt;p&gt;I was able to work around this as I&amp;nbsp;was able to pass in a serialized string version of the object instead, but this is definitely a limitation of the way fabric works. &amp;nbsp;As an FYI, I tried generics, but you can not use the cross class fabric structure with generics (I forget the actual exception, but it's explicitly stated you cannot). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;If anyone has a way around this, or a better understanding, I would love to hear it. &amp;nbsp;Otherwise, I hope this saves someone from bashing their head on the desk all day like it did me.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
      <link>http://naspinski.net/post/2016/09/23/azure-service-fabric-serviceproxy-failing-silently</link>
      <author>stan@naspinski.net</author>
      <comments>http://naspinski.net/post/2016/09/23/azure-service-fabric-serviceproxy-failing-silently#comment</comments>
      <guid>http://naspinski.net/post.aspx?id=30f16f17-e139-4816-a403-2f7354c0ba3e</guid>
      <pubDate>Fri, 23 Sep 2016 11:29:00 +0000</pubDate>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=30f16f17-e139-4816-a403-2f7354c0ba3e</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=30f16f17-e139-4816-a403-2f7354c0ba3e</trackback:ping>
      <wfw:comment>http://naspinski.net/post/2016/09/23/azure-service-fabric-serviceproxy-failing-silently#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=30f16f17-e139-4816-a403-2f7354c0ba3e</wfw:commentRss>
    </item>
    <item>
      <title>Run a Controller action from inside another Controller as the current User</title>
      <description>&lt;h2&gt;manually creating a controller and running its action does not run as the logged in user&lt;/h2&gt;
&lt;div&gt;
    If you want to run an action of another controller from inside a separate controller, it will work fine *if* you do not need any current HttpContext values such as User, etc.  If you want to do that, you will need to force that context into the controller instance.  To do this, I added a simple method to my base Controller class:
&lt;/div&gt;
&lt;pre class="prettyprint"&gt;public T RunAsCurrentUser&lt;T&gt;(
    T controller, RouteData routeData = null) 
        where T : ControllerBase
{
    var newContext = new ControllerContext(
        new HttpContextWrapper(
            System.Web.HttpContext.Current), 
            routeData ?? new RouteData(), controller);
    controller.ControllerContext = newContext;
    return controller;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;div&gt;then to use it:&lt;/div&gt;
&lt;pre class="prettyprint"&gt;var someController = RunAsCurrentUser(
    new Some.NameSpace.SomeController());
var result = someController.SomeAction();&lt;/pre&gt;</description>
      <link>http://naspinski.net/post/2014/12/15/Run-a-Controller-action-from-inside-another-Controller-as-the-current-User</link>
      <author>stan@naspinski.net</author>
      <comments>http://naspinski.net/post/2014/12/15/Run-a-Controller-action-from-inside-another-Controller-as-the-current-User#comment</comments>
      <guid>http://naspinski.net/post.aspx?id=c646a4bb-dbfb-4fe3-8139-440fe2fe4e93</guid>
      <pubDate>Sun, 14 Dec 2014 22:15:00 +0000</pubDate>
      <betag:tag>asp.net mvc</betag:tag>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=c646a4bb-dbfb-4fe3-8139-440fe2fe4e93</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=c646a4bb-dbfb-4fe3-8139-440fe2fe4e93</trackback:ping>
      <wfw:comment>http://naspinski.net/post/2014/12/15/Run-a-Controller-action-from-inside-another-Controller-as-the-current-User#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=c646a4bb-dbfb-4fe3-8139-440fe2fe4e93</wfw:commentRss>
    </item>
  </channel>
</rss>