public Response <RegistrationInfo> CreateRegistration(HostPool model, int expirationHours = 24, CancellationToken cancellationToken = default) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var properties = model.GetRequiredProperties(CRUDOperationsTypes.Update); foreach (var property in properties) { if (property.GetValue(model) == null) { throw new ArgumentNullException(property.Name); } } using var message = CreateCreateRegistrationRequest(model, expirationHours); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: case 201: { var value = SerializableResource <RegistrationInfo> .DeserializeAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(); return(Response.FromValue(value, message.Response)); }
public async Task <Response <List <RoleDefinition> > > GetRoleDefinitionsAsync(CancellationToken cancellationToken = default) { using var message = CreateGetRolePermissionsRequest(); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { List <RoleDefinition> value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); if (document.RootElement.ValueKind == JsonValueKind.Null) { value = null; } else { // value = ApplicationGroupList.DeserializeApplicationGroupList(document.RootElement); value = new List <RoleDefinition>(); foreach (var item in document.RootElement.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { value.Add(null); } else { value.Add(SerializableResource <RoleDefinition> .Deserialize(item.GetRawText())); } } } return(Response.FromValue(value, message.Response)); }
public virtual async Task <Response <TModel> > CreateAsync(TModel model, CancellationToken cancellationToken) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var properties = model.GetRequiredProperties(CRUDOperationsTypes.Create); foreach (var property in properties) { if (property.GetValue(model) == null) { throw new ArgumentNullException(property.Name); } } using var message = CreateCreateRequest(model); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: { var value = await SerializableResource <TModel> .DeserializeAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); return(Response.FromValue(value, message.Response)); }
public Response <List <StartMenuItem> > GetStartMemuApps(ApplicationGroup model, CancellationToken cancellationToken = default) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var properties = model.GetRequiredProperties(CRUDOperationsTypes.Get); foreach (var property in properties) { if (property.GetValue(model) == null) { throw new ArgumentNullException(property.Name); } } using var message = CreateStartMemuAppsRequest(model); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: { List <StartMenuItem> value = default; using var document = JsonDocument.Parse(message.Response.ContentStream); if (document.RootElement.ValueKind == JsonValueKind.Null) { value = null; } else { // value = ApplicationGroupList.DeserializeApplicationGroupList(document.RootElement); value = new List <StartMenuItem>(); foreach (var item in document.RootElement.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { value.Add(null); } else { value.Add(SerializableResource <StartMenuItem> .Deserialize(item.GetRawText())); } } } return(Response.FromValue(value, message.Response)); } default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } }
public static IContextualResourceModel CreateContextualResourceModel(string pathToTestResource) { var xElement = XML.MergeRemote.XmlResource.Fetch(pathToTestResource); var element = xElement.Element("Action"); var instanceActiveServer = ServerRepository.Instance.Source; var resource = new Resource(xElement); var serializableResource = new SerializableResource(); Mapper.AddMap <Resource, SerializableResource>(); Mapper.Map(resource, serializableResource, false, "Errors"); var hydrateResourceModel = ((ResourceRepository)instanceActiveServer.ResourceRepository).HydrateResourceModel(serializableResource, instanceActiveServer.ServerID.GetValueOrDefault(), true); Assert.IsNotNull(element); var contextualResourceModel = ResourceModelFactory.CreateResourceModel(instanceActiveServer); hydrateResourceModel.WorkflowXaml = new StringBuilder(element.ToString(SaveOptions.DisableFormatting)); contextualResourceModel.Update(hydrateResourceModel); return(contextualResourceModel); }
public virtual Response <TModel> Create(TModel model, CancellationToken cancellationToken = default) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var properties = model.GetRequiredProperties(CRUDOperationsTypes.Create); foreach (var property in properties) { if (property.GetValue(model) == null) { throw new ArgumentNullException(property.Name); } } using var message = CreateCreateRequest(model); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: case 201: { try { var value = SerializableResource <TModel> .DeserializeAsync(message.Response.ContentStream).GetAwaiter().GetResult(); return(Response.FromValue(value, message.Response)); } catch (Exception) { return(Response.FromValue(model, message.Response)); } } default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } }
public Response <List <RoleDefinition> > GetRoleDefinitions(CancellationToken cancellationToken = default) { using var message = CreateGetRolePermissionsRequest(); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: { List <RoleDefinition> value = default; using var document = JsonDocument.Parse(message.Response.ContentStream); if (document.RootElement.ValueKind == JsonValueKind.Null) { value = null; } else { // value = ApplicationGroupList.DeserializeApplicationGroupList(document.RootElement); value = new List <RoleDefinition>(); foreach (var item in document.RootElement.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { value.Add(null); } else { value.Add(SerializableResource <RoleDefinition> .Deserialize(item.GetRawText())); } } } return(Response.FromValue(value, message.Response)); } default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } }
public IResourceModel HydrateResourceModel(SerializableResource data, Guid serverId, bool forced = false, bool fetchXaml = false, bool prepairForDeployment = false) { if (!_server.Connection.IsConnected) { _server.Connection.Connect(_server.EnvironmentID); if (!_server.Connection.IsConnected) { ShowServerDisconnectedPopup(); return(null); } } Guid id = data.ResourceID; if (!IsInCache(id) || forced) { _cachedServices.Add(id); var isNewWorkflow = data.IsNewResource; var resource = ResourceModelFactory.CreateResourceModel(_server); resource.Inputs = data.Inputs; resource.Outputs = data.Outputs; if (data.IsSource) { resource.ResourceType = ResourceType.Source; } else if (data.IsService) { resource.ResourceType = ResourceType.WorkflowService; } else if (data.IsReservedService) { resource.ResourceType = ResourceType.Service; } else if (data.IsServer) { resource.ResourceType = ResourceType.Server; } else { resource.ResourceType = ResourceType.Unknown; } resource.ID = id; resource.ServerID = serverId; resource.IsValid = data.IsValid; resource.DataList = data.DataList?.Replace(GlobalConstants.SerializableResourceQuote, "\"").Replace(GlobalConstants.SerializableResourceSingleQuote, "'") ?? data.DataList; resource.ResourceName = data.ResourceName; resource.DisplayName = data.ResourceName; resource.VersionInfo = data.VersionInfo; resource.Category = data.ResourceCategory; resource.UserPermissions = data.Permissions; resource.Tags = string.Empty; resource.Comment = string.Empty; resource.ServerResourceType = data.ResourceType; resource.UnitTestTargetWorkflowService = string.Empty; resource.HelpLink = string.Empty; resource.IsNewWorkflow = isNewWorkflow; if (data.Errors != null) { foreach (var error in data.Errors) { resource.AddError(error); } } if (isNewWorkflow) { NewWorkflowNames.Instance.Add(resource.DisplayName); } return(resource); } return(null); }