internal CompositeRoot CreateCompositeRoot(CompositeRootConfiguration configuration, EventHandler eventHandler, IEnumerable <Assembly> serviceAssemblies) { var compositeRoot = CompositeRoot.Create(configuration, eventHandler, serviceAssemblies); compositeRoot.ActiveCompositeRoots = this; compositeRoots.Add(configuration.Id.ToString(), compositeRoot); return(compositeRoot); }
public ActionResult <object> ReceiveRequest([FromForm] object _) { var requestBody = (string)null; var request = Request.QueryString.HasValue ? Request.QueryString.Value : string.Empty; IEnumerable <CompositeUploadedFile> uploadedFiles = null; IEnumerable <CompositeRootCommandRequest> commandRequests = null; var requestParts = request.Split('?'); requestBody = requestParts.Length >= 3 ? requestParts[2] : null; if (requestBody == null && Request.ContentLength.HasValue) { requestBody = Request.Body.GetRequest(Encoding.UTF8, Request.ContentType, string.Empty, CultureInfo.CurrentCulture, out uploadedFiles, out commandRequests); } var compositeRootHttpContext = GetContext(requestBody, uploadedFiles); var compositeRoot = CompositeRoot.Create(CompositeRootConfiguration); var compositeRootModelFieldName = compositeRoot.GetType().GetCustomAttribute <CompositeModelAttribute>()?.ModelFieldName; var compositeRootModelField = compositeRoot.GetType().GetField(compositeRootModelFieldName, BindingFlags.Instance | BindingFlags.NonPublic); var compositeRootModelFieldType = compositeRootModelField.FieldType; var loginResponseJson = string.Empty; if (request.ToLowerInvariant().StartsWith("?" + nameof(CompositeRootAuthenticator.LogOn).ToLowerInvariant())) { var loginResponse = compositeRoot.Authenticator.Execute(nameof(CompositeRootAuthenticator.LogOn) + "?" + requestBody, null, compositeRootHttpContext, string.Empty, string.Empty, uploadedFiles).ReturnValue as CompositeRootAuthenticatorResponse; SetCache(loginResponse.SessionToken, JsonConvert.SerializeObject(compositeRootModelField.GetValue(compositeRoot))); Response.ContentType = "application/json"; return(loginResponse); } else { var sessionToken = requestParts[1].Split('/')[0]; //var commandPath = Regex.Replace(request, @"^\?" + sessionToken + @"/?", string.Empty); var compositeRootModelJson = GetCache(sessionToken); compositeRootModelField.SetValue(compositeRoot, JsonConvert.DeserializeObject(compositeRootModelJson, compositeRootModelFieldType)); var commandResponses = compositeRoot.Execute(commandRequests, compositeRootHttpContext, string.Empty, sessionToken, uploadedFiles); SetCache(sessionToken, JsonConvert.SerializeObject(compositeRootModelField.GetValue(compositeRoot))); if (commandResponses.First().ReturnValue is byte[] binaryResponse) { Response.ContentType = compositeRootHttpContext.Response.ContentType; Response.ContentLength = compositeRootHttpContext.Response.ContentLength64; return(commandResponses.First().ReturnValue); } else { Response.ContentType = "application/json"; return((object)commandResponses); } } }
public CompositeRootSession CreateNewCompositeRootSession(string endPoint, string userName, string token) { var compositeRootConfiguration = Server.ServerConfiguration.ServerRootConfigurations.RootConfigurations.Values.Single(c => string.Compare(c.Endpoint, endPoint, true) == 0); CompositeRoot compositeRoot = null; if (compositeRootConfiguration.Mode == CompositeRootMode.SingleHost) { compositeRoot = Server.ActiveCompositeRoots.CompositeRoots.Values.Single(h => h.GetType() == compositeRootConfiguration.CompositeRootType); } else { compositeRoot = _serviceAssemblies != null? CompositeRoot.Create(compositeRootConfiguration, Server.CompositeRoot_EventAdded, _serviceAssemblies) : CompositeRoot.Create(compositeRootConfiguration, Server.CompositeRoot_EventAdded, _services); } return(CreateNewCompositeRootSession(endPoint, userName, token, compositeRootConfiguration.SessionExpiration, compositeRootConfiguration.Mode, compositeRoot)); }