/// <summary> /// Returns a channel message sink that delivers messages to the specified URL or channel data object. /// </summary> /// <param name="url">The url.</param> /// <param name="remoteChannelData">The information associated with the channel.</param> /// <param name="objectURI">The uri of the target.</param> /// <returns>A channel message sink that delivers messages to the specified URL or channel data object.</returns> public IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI) { objectURI = null; string channelUri = null; // if it's a well-known object if (url == null && remoteChannelData is IChannelDataStore) { url = ((IChannelDataStore)remoteChannelData).ChannelUris[0]; } if (url == null) { return(null); } // check whether we can service this url string[] channelPrefixes = this._possibleChannelPrefixes; int i = 0; for ( ; i < channelPrefixes.Length; i++) { if (url.StartsWith(channelPrefixes[i])) { break; } } // if the requested url wasn't recognized, it should be // directed to another channel if (i == channelPrefixes.Length) { return(null); } channelUri = GenuineUtility.Parse(url, out objectURI); // if the provided URI is not registered at common URI Storage, nothing will be able // to send anything there // if it's registered, it does not matter whose sink services the connection. if (!GenuineUtility.CheckUrlOnConnectivity(url) && UriStorage.GetTransportContext(channelUri) == null) { return(null); } if (channelUri == null) { return(null); } return(this._iClientChannelSinkProvider.CreateSink(this, url, remoteChannelData) as IMessageSink); }
public Startup(IConfiguration configuration) { Configuration = configuration; // This is where the mesh data folder is defined. /* If you want to use a storage location external to this applications * project folder, use symlinks or you will need to change UriStorage.cs * to not set UriKind.Relative when creating a new Uri(). */ this.storage = new UriStorage("mesh-data-folder/demosets.json"); Dependency.Storage = this.storage; }
// Disabling test for now. Needs updating post blob acl setting. // [TestMethod] public async Task Initialization() { string setsJson = Path.Combine(".", "data", "sets.json"); setsJson = Path.GetFullPath(setsJson); Uri setsJsonUri = new Uri(setsJson); UriStorage storage = new UriStorage(setsJsonUri.ToString()); storage.WaitLoad.WaitOne(); Assert.IsNotNull(storage.LastKnownGood); Assert.AreEqual(0, storage.LastKnownGood.Errors.Length); Assert.AreEqual(1, storage.LastKnownGood.Sets.Count); }
protected void Application_Start() { string dataPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, ".\\Data"); dataPath = Path.GetFullPath(dataPath); Trace.WriteLine(String.Format("Data path: {0}", dataPath)); //string connSecretsPath = Path.Combine(dataPath, "accountkey.txt"); //ISecretsProvider connProvider = new FileSecretsProvider(connSecretsPath); // .NET AppSettings provider ISecretsProvider connProvider = new AzureAppSettingsProvider(); string setRootUrl = ConfigurationManager.AppSettings["SetRootUrl"]; if (string.IsNullOrWhiteSpace(setRootUrl)) { throw new ConfigurationErrorsException("SetRootUrl not specified"); } if (connProvider.Exists) { this.storage = new AzureUriStorage(connProvider.Value, setRootUrl); } else { this.storage = new UriStorage(setRootUrl); } Dependency.Storage = this.storage; // wait reasonable amount of time for first load this.storage.WaitLoadCompleted.WaitOne(30000); GlobalConfiguration.Configuration.MapHttpAttributeRoutes(); GlobalConfiguration.Configuration.Formatters.Clear(); GlobalConfiguration.Configuration.Formatters.Add(new JsonMediaTypeFormatter()); GlobalConfiguration.Configuration.Formatters.Add(new BsonMediaTypeFormatter()); GlobalConfiguration.Configuration.EnsureInitialized(); }
/// <summary> /// Requests message processing from the current sink. /// </summary> /// <param name="msg">The message to process.</param> /// <param name="requestHeaders">The headers to add to the outgoing message heading to the server.</param> /// <param name="requestStream">The stream headed to the transport sink.</param> /// <param name="responseHeaders">When this method returns, contains an ITransportHeaders interface that holds the headers that the server returned. This parameter is passed uninitialized.</param> /// <param name="responseStream">When this method returns, contains a Stream coming back from the transport sink. This parameter is passed uninitialized.</param> public void ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, out ITransportHeaders responseHeaders, out Stream responseStream) { BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter; ITransportContext iTransportContext = this.ITransportContext; if (!GenuineUtility.CheckUrlOnConnectivity(this._recipientUri)) { // get the transport context from the Uri Storage iTransportContext = UriStorage.GetTransportContext(this._recipientUri); if (iTransportContext == null) { iTransportContext = this.ITransportContext; } } Message message = Message.CreateOutcomingMessage(iTransportContext, msg, requestHeaders, requestStream, true); try { message.Recipient = iTransportContext.KnownHosts[this._recipientUri]; // LOG: put down the log record if (binaryLogWriter != null && binaryLogWriter[LogCategory.MessageProcessing] > 0) { binaryLogWriter.WriteMessageCreatedEvent("GenuineTcpClientTransportSink.ProcessMessage", LogMessageType.MessageCreated, null, message, true, message.Recipient, this.ITransportContext.BinaryLogWriter[LogCategory.MessageProcessing] > 1 ? message.Stream : null, msg.Properties["__Uri"] as string, BinaryLogWriter.ParseInvocationMethod(msg.Properties["__MethodName"] as string, msg.Properties["__TypeName"] as string), GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, -1, -1, null, -1, null, "Synchronous .NET Remoting invocaiton is being initiated."); message.ITransportHeaders[Message.TransportHeadersInvocationTarget] = msg.Properties["__Uri"] as string; message.ITransportHeaders[Message.TransportHeadersMethodName] = BinaryLogWriter.ParseInvocationMethod(msg.Properties["__MethodName"] as string, msg.Properties["__TypeName"] as string); binaryLogWriter.WriteEvent(LogCategory.MessageProcessing, "GenuineTcpClientTransportSink.ProcessMessage", LogMessageType.MessageRequestInvoking, null, message, message.Recipient, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, GenuineUtility.TickCount, 0, 0, null, null, null, null, "The .NET Remoting synchronous invocation has been made."); } SyncSinkStackResponseProcessor syncSinkStackResponseProcessor = new SyncSinkStackResponseProcessor(iTransportContext, message); iTransportContext.IIncomingStreamHandler.RegisterResponseProcessor(message.MessageId, syncSinkStackResponseProcessor); message.CancelSending = syncSinkStackResponseProcessor.IsReceivedEvent; try { // send the message or initiate the sending iTransportContext.ConnectionManager.Send(message); } catch (Exception ex) { // if it's a response processor's problem, force its exception to be fired if (syncSinkStackResponseProcessor.DispatchedException != null) { throw OperationException.WrapException(syncSinkStackResponseProcessor.DispatchedException); } syncSinkStackResponseProcessor.DispatchException(ex); throw; } if (!GenuineUtility.WaitOne(syncSinkStackResponseProcessor.IsReceivedEvent, GenuineUtility.GetMillisecondsLeft(message.FinishTime))) { throw GenuineExceptions.Get_Send_ServerDidNotReply(); } if (syncSinkStackResponseProcessor.DispatchedException != null) { throw OperationException.WrapException(syncSinkStackResponseProcessor.DispatchedException); } // LOG: put down the log record if (binaryLogWriter != null && binaryLogWriter[LogCategory.MessageProcessing] > 0) { binaryLogWriter.WriteEvent(LogCategory.MessageProcessing, "GenuineTcpClientTransportSink.ProcessMessage", LogMessageType.MessageDispatched, null, syncSinkStackResponseProcessor.Response, syncSinkStackResponseProcessor.Response.Sender, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, GenuineUtility.TickCount, 0, message.SeqNo, null, null, null, null, "The .NET Remoting synchronous invocation has been completed."); } responseHeaders = syncSinkStackResponseProcessor.Response.ITransportHeaders; responseStream = syncSinkStackResponseProcessor.Response.Stream; } catch (Exception ex) { // LOG: put down the log record if (binaryLogWriter != null && binaryLogWriter[LogCategory.MessageProcessing] > 0) { binaryLogWriter.WriteEvent(LogCategory.MessageProcessing, "GenuineTcpClientTransportSink.ProcessMessage", LogMessageType.MessageDispatched, ex, message, message.Recipient, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, GenuineUtility.TickCount, 0, message.SeqNo, null, null, null, null, "The exception is dispatched to the caller context."); } throw; } }
/// <summary> /// Requests asynchronous processing of a method call on the current sink. /// </summary> /// <param name="sinkStack">A stack of channel sinks that called this sink.</param> /// <param name="msg">The message to process.</param> /// <param name="headers">The headers to add to the outgoing message heading to the server.</param> /// <param name="stream">The stream headed to the transport sink.</param> public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, Stream stream) { ITransportContext iTransportContext = this.ITransportContext; if (!GenuineUtility.CheckUrlOnConnectivity(this._recipientUri)) { // get the transport context from the Uri Storage iTransportContext = UriStorage.GetTransportContext(this._recipientUri); if (iTransportContext == null) { iTransportContext = this.ITransportContext; } } Message message = Message.CreateOutcomingMessage(iTransportContext, msg, headers, stream, false); message.Recipient = iTransportContext.KnownHosts[this._recipientUri]; IMethodMessage iMethodMessage = (IMethodMessage)msg; message.IsOneWay = RemotingServices.IsOneWay(iMethodMessage.MethodBase); // LOG: put down the log record BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter; if (binaryLogWriter != null && binaryLogWriter[LogCategory.MessageProcessing] > 0) { binaryLogWriter.WriteMessageCreatedEvent("GenuineTcpClientTransportSink.AsyncProcessRequest", LogMessageType.MessageCreated, null, message, true, message.Recipient, this.ITransportContext.BinaryLogWriter[LogCategory.MessageProcessing] > 1 ? message.Stream : null, msg.Properties["__Uri"] as string, BinaryLogWriter.ParseInvocationMethod(msg.Properties["__MethodName"] as string, msg.Properties["__TypeName"] as string), GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, -1, -1, null, -1, null, "Asynchronous .NET Remoting invocaiton is being initiated."); message.ITransportHeaders[Message.TransportHeadersInvocationTarget] = msg.Properties["__Uri"] as string; message.ITransportHeaders[Message.TransportHeadersMethodName] = BinaryLogWriter.ParseInvocationMethod(msg.Properties["__MethodName"] as string, msg.Properties["__TypeName"] as string); binaryLogWriter.WriteEvent(LogCategory.MessageProcessing, "GenuineTcpClientTransportSink.AsyncProcessRequest", LogMessageType.MessageRequestInvoking, null, message, message.Recipient, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, GenuineUtility.TickCount, 0, 0, null, null, null, null, "The .NET Remoting asynchronous invocation is being initiated."); } // register the response handler AsyncSinkStackResponseProcessor asyncSinkStackResponseProcessor = null; if (!message.IsOneWay) { asyncSinkStackResponseProcessor = new AsyncSinkStackResponseProcessor(iTransportContext, message, sinkStack); iTransportContext.IIncomingStreamHandler.RegisterResponseProcessor(message.MessageId, asyncSinkStackResponseProcessor); } try { // and try to send the message iTransportContext.ConnectionManager.Send(message); } catch (Exception ex) { asyncSinkStackResponseProcessor.DispatchException(ex); throw; } }