public Task <RemoteDebuggerMessage> SendMessageWithResponse(RemoteDebuggerMessage message) { SendMessage(message); RemoteDebuggerMessage response; while (!MessageReceiveCache.TryRemove(message.PluginExecutionId, out response)) { // Waiting for the response to come Thread.Sleep(50); } return(Task.FromResult(response)); }
public Task SendMessage(RemoteDebuggerMessage message) { if (CurrentResponseCache.TryGetValue(message.PluginExecutionId, out var currentResponse)) { var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)); try { currentResponse.OutputStream.Write(bytes, 0, bytes.Length); currentResponse.Close(); } catch (Exception) { // erreur ignorée } } return(Task.CompletedTask); }
public OrganizationResponse Execute(OrganizationRequest request) { var message = new RemoteDebuggerMessage(RemoteDebuggerMessageType.Request, request, Context.Id) { UserId = UserId }; var hybridResponse = _onRequestSent(message); var responseTemp = hybridResponse.GetOrganizationResponse(); var typeName = request.GetType().AssemblyQualifiedName.Replace("Request", "Response"); var type = Type.GetType(typeName); var response = (OrganizationResponse)Activator.CreateInstance(type); response.Results = responseTemp.Results; return(response); }
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); }
protected RemoteDebuggerMessage OnRequestSent(RemoteDebuggerMessage message) { return(RequestSent?.Invoke(message)); }
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); }