This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//FromAsync variant that can be used with APM across M<arshaling boundaries (you make your own TArgX overloads, please) | |
static class MarshalTask | |
{ | |
public static Task<TResult> FromAsync<TArg1, TArg2, TResult>(Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginFunc, Func<IAsyncResult, TResult> endFunc, TArg1 arg1, TArg2 arg2) | |
{ | |
var cp = new Completer<TResult>(endFunc); | |
var tcs = new TaskCompletionSource<TResult>(cp); | |
cp.TaskCompletionSource = tcs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NamespaceManager nsm = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString); | |
string name = nsm.Address.Host.Substring(0, nsm.Address.Host.IndexOf(".", System.StringComparison.Ordinal)); | |
var sendKey = SharedAccessAuthorizationRule.GenerateRandomKey(); | |
var listenKey = SharedAccessAuthorizationRule.GenerateRandomKey(); | |
var manageKey = SharedAccessAuthorizationRule.GenerateRandomKey(); | |
CreateSharedAccessRuleOnNamespaceRoot(name, "send", sendKey, AccessRights.Send, subscriptionId, publisherCertificate); | |
CreateSharedAccessRuleOnNamespaceRoot(name, "manage", manageKey, AccessRights.Manage|AccessRights.Send|AccessRights.Listen, subscriptionId, publisherCertificate); | |
CreateSharedAccessRuleOnNamespaceRoot(name, "listen", listenKey, AccessRights.Listen, subscriptionId, publisherCertificate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thought experiment: | |
Listened to eight .NET Rocks episodes yesterday while driving. One episode was about C# 6.0 with Bill Wagner | |
(http://www.dotnetrocks.com/default.aspx?showNum=1029), another about DDD with Steve Smith and Julie Lerman | |
(http://www.dotnetrocks.com/default.aspx?showNum=1023) where they specifically also discussed DDD's notion of | |
an anti-corruption layer, which aims to provide a neutral zone between different domains. The combination of | |
the two episodes gave me the following idea which I'll jot down here quickly. | |
Don't go "you dont do that in DDD, because .." since that's not the point. The point is efficiency and avoiding | |
data copies. Also, I'm not planning on doing anything further with it, so if anyone wants to take this somewhere, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wr = WebRequest.Create("http://localhost:39472/Provisioning.svc/setup"); | |
wr.Method = "POST"; | |
wr.Headers.Add("P-DeviceId", this.deviceId); | |
using (var wq = (HttpWebResponse)wr.GetResponse()) | |
{ | |
if (wq.StatusCode == HttpStatusCode.OK) | |
{ | |
settings.DeviceAccount = wq.Headers["P-DeviceAccount"]; | |
settings.DeviceKey = wq.Headers["P-DeviceKey"]; | |
settings.DeviceSubscriptionUri = new Uri(wq.Headers["P-DeviceSubscriptionUri"]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CorrelationSite.Controllers | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading; | |
using System.Web.Mvc; | |
using CorrelationSite.Models; | |
using Microsoft.ServiceBus.Messaging; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace BackgroundWorker | |
{ | |
using System.Threading; | |
using Microsoft.ServiceBus; | |
using Microsoft.ServiceBus.Messaging; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The scoping model in "catch" doesn't allow for async/await handling because | |
// catch needs to be able to rethrow without messaging up the stack frame, i.e. "throw;" | |
// There's obviously an alternate non-goto solution here with a result variable and a | |
// subsequent switch on that result, but if you code that up, the switch looks like | |
// a longer, uglier variant of the gotos. | |
static async Task LoopedReceive(Func<Task<BrokeredMessage>> receiveCallbackAsync, | |
Func<BrokeredMessage, Task<bool>> messageReceivedCallbackAsync, | |
CancellationToken token) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MartVue.Common | |
{ | |
using System; | |
using System.Runtime.Serialization; | |
using System.Threading.Tasks; | |
using Microsoft.ServiceBus.Messaging; | |
public static class RobustSendExtension | |
{ | |
static readonly TaskFactory TaskFactory = new TaskFactory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISomeExtension | |
{ | |
object Private { get; set; } | |
} | |
public static class SomeExtension | |
{ | |
class State | |
{ | |
public string data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Writing | |
{ | |
using System; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Threading; | |
class Program | |
{ | |
static void Main(string[] args) |
OlderNewer