public PSHybridConnectionAttributes(HybridConnection hybridConnection) { Id = hybridConnection.Id; Name = hybridConnection.Name; Type = hybridConnection.Type; CreatedAt = hybridConnection.CreatedAt; UpdatedAt = hybridConnection.UpdatedAt; ListenerCount = hybridConnection.ListenerCount; RequiresClientAuthorization = hybridConnection.RequiresClientAuthorization; UserMetadata = hybridConnection.UserMetadata; }
public Microsoft.ServiceBus.Channels.IConnection Connect(Uri uri, TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); Microsoft.ServiceBus.Channels.IConnection connection = this.relayedSocketInitiator.Connect(uri, timeoutHelper.RemainingTime()); this.SendInitiateMessage(connection, timeoutHelper.RemainingTime()); HybridConnectionInitiator.DirectSocketClient directSocketClient = new HybridConnectionInitiator.DirectSocketClient(this, this.directSocketInitiator, uri, timeoutHelper.RemainingTime()); HybridConnection hybridConnection = new HybridConnection(HybridConnectionRole.Initiator, connection, directSocketClient, this.bufferSize); directSocketClient.HybridConnection = hybridConnection; IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.StartDirectConnect), directSocketClient); return(hybridConnection); }
async Task <HybridConnection> IShieldInformationService.GetCustomerRelayConnectionAsync(Guid tenantId) { if (string.IsNullOrWhiteSpace(tenantId.ToString())) { throw new ArgumentException(nameof(tenantId)); } CustomerInformation customerInformation = await _customerManagementApiClient.GetCustomerInformationAsync(tenantId); if (customerInformation is null) { return(null); } HybridConnection customerRelayInformation = await _shieldApiClient.GetCustomerRelayAsync(customerInformation.TenantId); if (customerRelayInformation is null) { return(await _shieldApiClient.CreateCustomerRelayAsync(customerInformation.TenantId)); } else { return(customerRelayInformation); } }
public async Task <IActionResult> ShieldInformatiionControllerAsync( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "shieldInformation/controller/relay/{tenantId}")] HttpRequest req, string tenantId, ILogger log) { if (string.IsNullOrWhiteSpace(tenantId)) { throw new ArgumentNullException(nameof(tenantId)); } if (!Guid.TryParse(tenantId, out Guid guid)) { return(new BadRequestResult()); } HybridConnection hybridConnection = await _shieldInformationService.GetCustomerRelayConnectionAsync(guid); if (hybridConnection is null) { return(new BadRequestResult()); } else { return(new OkObjectResult(hybridConnection)); } }
private void EnqueueConnection(Guid connectionId, Microsoft.ServiceBus.Channels.IConnection connection, HybridConnectionListener.HybridConnectionSocketType socketType, Action dequeuedCallback) { HybridConnection hybridConnection; bool flag = false; try { lock (this.connectionTable) { if (this.connectionTable.TryGetValue(connectionId, out hybridConnection)) { hybridConnection.EnqueueConnection(connection); } else if (socketType != HybridConnectionListener.HybridConnectionSocketType.Direct) { hybridConnection = new HybridConnection(HybridConnectionRole.Listener, connection, null, this.bufferSize); hybridConnection.Closed += new EventHandler((object o, EventArgs e) => this.connectionTable.Remove(connectionId)); flag = true; this.connectionTable.Add(connectionId, hybridConnection); } else { connection.Abort(); return; } } if (flag) { this.connectionQueue.EnqueueAndDispatch(hybridConnection); } } finally { dequeuedCallback(); } }
private bool SendToRemoteDebugger(LocalWorkflowContext localContext, CodeActivityContext context) { if (!localContext.IsDebugContext) { localContext.Log("The context is genuine"); var initiatingUserId = localContext.GetInitiatingUserId(); var queryDebugSessions = BindingModelHelper.GetRetrieveAllQuery <DebugSession>(); queryDebugSessions.Criteria.AddCondition(DebugSessionDefinition.Columns.DebugeeId, ConditionOperator.Equal, initiatingUserId); queryDebugSessions.Criteria.AddCondition(DebugSessionDefinition.Columns.StateCode, ConditionOperator.Equal, DebugSessionState.Active.ToInt()); var debugSession = localContext.AdminOrganizationService.RetrieveAll <DebugSession>(queryDebugSessions).FirstOrDefault(); localContext.Log($"Debug session : {debugSession}"); if (debugSession != null) { if (debugSession.SessionEnd >= DateTime.Today) { var remoteContext = localContext.RemoteContext; remoteContext.TypeAssemblyQualifiedName = GetType().AssemblyQualifiedName; remoteContext.Id = Guid.NewGuid(); SetArgumentsInRemoteContext(context, remoteContext); var uri = new Uri($"{debugSession.RelayUrl}/{debugSession.HybridConnectionName}"); try { using (var hybridConnection = new HybridConnection(debugSession.SasKeyName, debugSession.SasConnectionKey, uri.AbsoluteUri)) { var message = new RemoteDebuggerMessage(RemoteDebuggerMessageType.Context, remoteContext, remoteContext.Id); RemoteDebuggerMessage response; while (true) { localContext.Log("Sending context to local machine : {0}", message); response = hybridConnection.SendMessage(message).GetAwaiter().GetResult(); localContext.Log("Received response : {0}", response); if (response.MessageType == RemoteDebuggerMessageType.Context || response.MessageType == RemoteDebuggerMessageType.Exception) { break; } var request = response.GetOrganizationRequest(); var service = response.UserId.HasValue ? localContext.GetService(response.UserId.Value) : localContext.AdminOrganizationService; var organizationResponse = service.Execute(request); message = new RemoteDebuggerMessage(RemoteDebuggerMessageType.Response, organizationResponse, remoteContext.Id); } if (response.MessageType == RemoteDebuggerMessageType.Exception) { throw response.GetException(); } var updatedContext = response.GetContext <RemoteDebugExecutionContext>(); localContext.UpdateContext(updatedContext); ExtractArgumentsFromRemoteContext(context, updatedContext, localContext.LogServiceMethod); } return(true); } catch (HttpRequestException e) { // Run the plugin as deploy if the remote debugger is not connected localContext.Log($"Error while sending context : {e}"); } } } } return(false); }
/// <summary> /// Creates or updates a service hybrid connection. This operation is /// idempotent. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Name of the Resource group within the Azure subscription. /// </param> /// <param name='namespaceName'> /// The namespace name /// </param> /// <param name='hybridConnectionName'> /// The hybrid connection name. /// </param> /// <param name='parameters'> /// Parameters supplied to create a hybrid connection. /// </param> public static HybridConnection CreateOrUpdate(this IHybridConnectionsOperations operations, string resourceGroupName, string namespaceName, string hybridConnectionName, HybridConnection parameters) { return(operations.CreateOrUpdateAsync(resourceGroupName, namespaceName, hybridConnectionName, parameters).GetAwaiter().GetResult()); }
/// <summary> /// Creates or updates a service hybrid connection. This operation is /// idempotent. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Name of the Resource group within the Azure subscription. /// </param> /// <param name='namespaceName'> /// The namespace name /// </param> /// <param name='hybridConnectionName'> /// The hybrid connection name. /// </param> /// <param name='parameters'> /// Parameters supplied to create a hybrid connection. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <HybridConnection> CreateOrUpdateAsync(this IHybridConnectionsOperations operations, string resourceGroupName, string namespaceName, string hybridConnectionName, HybridConnection parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, namespaceName, hybridConnectionName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
private bool SendToRemoteDebugger(LocalPluginContext localContext) { if (!localContext.IsDebugContext) { localContext.Log("The context is genuine"); localContext.Log($"UnSecuredConfig : {UnSecuredConfig}"); //if (!string.IsNullOrEmpty(UnSecuredConfig) && UnSecuredConfig.Contains("debugSessions")) //{ // var debuggerUnsecuredConfig = JsonConvert.DeserializeObject<DebuggerUnsecureConfig>(UnSecuredConfig); // localContext.Log($"Debug session ids : {string.Join(",", debuggerUnsecuredConfig.DebugSessionIds)}"); var initiatingUserId = localContext.GetInitiatingUserId(); localContext.Log($"Initiating user Id : {initiatingUserId}"); var queryDebugSessions = BindingModelHelper.GetRetrieveAllQuery <DebugSession>(); queryDebugSessions.Criteria.AddCondition(DebugSessionDefinition.Columns.DebugeeId, ConditionOperator.Equal, initiatingUserId); queryDebugSessions.Criteria.AddCondition(DebugSessionDefinition.Columns.StateCode, ConditionOperator.Equal, DebugSessionState.Active.ToInt()); //queryDebugSessions.Criteria.AddCondition(DebugSessionDefinition.Columns.Id, ConditionOperator.In, debuggerUnsecuredConfig.DebugSessionIds.Cast<object>().ToArray()); var debugSession = localContext.AdminOrganizationService.RetrieveAll <DebugSession>(queryDebugSessions).FirstOrDefault(); localContext.Log($"Debug session : {debugSession}"); if (debugSession != null) { if (debugSession.SessionEnd >= DateTime.Today) { var remoteContext = localContext.RemoteContext; remoteContext.Id = Guid.NewGuid(); remoteContext.TypeAssemblyQualifiedName = GetType().AssemblyQualifiedName; remoteContext.UnsecureConfig = UnSecuredConfig; remoteContext.SecureConfig = SecuredConfig; var uri = new Uri($"{debugSession.RelayUrl}/{debugSession.HybridConnectionName}"); try { using var hybridConnection = new HybridConnection(debugSession.SasKeyName, debugSession.SasConnectionKey, uri.AbsoluteUri); var message = new RemoteDebuggerMessage(RemoteDebuggerMessageType.Context, remoteContext, remoteContext.Id); RemoteDebuggerMessage response; while (true) { localContext.Log("Sending context to local machine : {0}", message); response = hybridConnection.SendMessage(message).GetAwaiter().GetResult(); localContext.Log("Received response : {0}", response); if (response.MessageType == RemoteDebuggerMessageType.Context || response.MessageType == RemoteDebuggerMessageType.Exception) { break; } var request = response.GetOrganizationRequest(); var service = response.UserId.HasValue ? localContext.GetService(response.UserId.Value) : localContext.AdminOrganizationService; var organizationResponse = service.Execute(request); message = new RemoteDebuggerMessage(RemoteDebuggerMessageType.Response, organizationResponse, remoteContext.Id); } if (response.MessageType == RemoteDebuggerMessageType.Exception) { throw response.GetException(); } var updatedContext = response.GetContext <RemoteDebugExecutionContext>(); localContext.UpdateContext(updatedContext); return(true); } catch (HttpRequestException) { // Run the plugin as deploy if the remote debugger is not connected } } } //} } return(false); }