public M2mgoGetwayProjectDto RegisterProject(M2MgoCloudAgentConfiguration config, string serialId, UicProject project) { GatewayProjectGetModel gatewayProject = EnsureProject(config, project); GatewayGetModel gateway = EnsureGateway(config, serialId, gatewayProject); return(new M2mgoGetwayProjectDto(gateway, gatewayProject)); }
public string CreateGateway(M2MgoCloudAgentConfiguration config, string serialId, GatewayProjectGetModel project) { if (serialId == null) { throw new ArgumentNullException("serialId"); } if (project == null) { throw new ArgumentNullException("project"); } return(_userTokenWebApiWrapper.RetryWithTokenUpdate(config, () => { var request = (HttpWebRequest)WebRequest.Create(config.BaseUrl + "api/gateway" + "?gatewayTypeId=" + config.SgetGatewayTypeId.ToString("D") + "&domainId=" + project.Domain.ID + "&serial=" + serialId); request.Method = "PUT"; return _webApiRequestExecutor.ExecuteRequest(request, null, _userTokenWebApiWrapper.GetToken(), _logger); })); }
private GatewayGetModel EnsureGateway(M2MgoCloudAgentConfiguration config, string serialId, GatewayProjectGetModel project) { string result = _apiWrapper.AuthenticateGateway(config, serialId); if (result.IsNullOrEmpty()) { _apiWrapper.CreateGateway(config, serialId, project); result = _apiWrapper.AuthenticateGateway(config, serialId); if (result.IsNullOrEmpty()) { throw new Exception("Could not create Gateway!"); } } var gatewayId = _serializer.Deserialize <Guid>(result); string gatewayResult = _apiWrapper.GetGateway(config, gatewayId); var gatewayGetModel = _serializer.Deserialize <GatewayGetModel>(gatewayResult); if (gatewayGetModel.GatewayProjectIdentifier == null) { _apiWrapper.AddGatewayToProject(config, gatewayGetModel.Identifier.ID, project.ID); gatewayResult = _apiWrapper.GetGateway(config, gatewayId); gatewayGetModel = _serializer.Deserialize <GatewayGetModel>(gatewayResult); } return(gatewayGetModel); }
public M2mgoGetwayProjectDto(GatewayGetModel gateway, GatewayProjectGetModel gatewayProject) { Gateway = gateway; GatewayProject = gatewayProject; }