Пример #1
0
        public HttpResponseMessage CreateHost(CreateHostRequest request)
        {
            CreateHostResponse responseData = null;

            string newAPIKey = null;

            try
            {
                //Validate input
                if (request == null ||
                    string.IsNullOrEmpty(request.Name))
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, ResponseMessages.InvalidParam)));
                }

                //Perform transaction
                HostServices hostService = new HostServices();
                hostService.CreateHost(request, out newAPIKey);

                responseData        = new CreateHostResponse();
                responseData.APIKey = newAPIKey;

                //Send response
                return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
        /// <summary>
        /// Creates a resource that represents the infrastructure where a third-party provider
        /// is installed. The host is used when you create connections to an installed third-party
        /// provider type, such as GitHub Enterprise Server. You create one host for all connections
        /// to that provider.
        /// 
        ///  <note> 
        /// <para>
        /// A host created through the CLI or the SDK is in `PENDING` status by default. You can
        /// make its status `AVAILABLE` by setting up the host in the console.
        /// </para>
        ///  </note>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the CreateHost service method.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// 
        /// <returns>The response from the CreateHost service method, as returned by CodeStarconnections.</returns>
        /// <exception cref="Amazon.CodeStarconnections.Model.LimitExceededException">
        /// Exceeded the maximum limit for connections.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/codestar-connections-2019-12-01/CreateHost">REST API Reference for CreateHost Operation</seealso>
        public virtual Task<CreateHostResponse> CreateHostAsync(CreateHostRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();
            options.RequestMarshaller = CreateHostRequestMarshaller.Instance;
            options.ResponseUnmarshaller = CreateHostResponseUnmarshaller.Instance;

            return InvokeAsync<CreateHostResponse>(request, options, cancellationToken);
        }
        internal virtual CreateHostResponse CreateHost(CreateHostRequest request)
        {
            var options = new InvokeOptions();
            options.RequestMarshaller = CreateHostRequestMarshaller.Instance;
            options.ResponseUnmarshaller = CreateHostResponseUnmarshaller.Instance;

            return Invoke<CreateHostResponse>(request, options);
        }
Пример #4
0
        public async Task <HostResult> CreateAsync(string userId, CreateHostRequest request)
        {
            var fileLocation = _setting.ScriptLocation;
            var currentHost  = _db.Hosts.FirstOrDefault(c => c.HostAddress == request.HostAddress);

            if (currentHost == null)
            {
                var hashCode = Guid.NewGuid().ToString();
                var newHost  = new Host()
                {
                    HostAddress = request.HostAddress, UserId = userId, HostValidated = true, PageValidated = false, HashCode = hashCode, UserValidityId = 9, ProductValidityId = 9
                };
                await _db.Hosts.AddAsync(newHost);

                await _db.SaveChangesAsync();

                await _db.UsersHostAccess.AddAsync(new UsersHostAccess()
                {
                    UserId = userId, AdminAccess = true, HostId = newHost.Id
                });

                await _db.SaveChangesAsync();

                try
                {
                    if (!System.IO.Directory.Exists(System.IO.Path.Combine(fileLocation, request.HostAddress.RemoveSpecialCharacters())))
                    {
                        System.IO.Directory.CreateDirectory(System.IO.Path.Combine(fileLocation, request.HostAddress.RemoveSpecialCharacters()));
                        System.IO.File.Copy(System.IO.Path.Combine(fileLocation, "track.js"), System.IO.Path.Combine(fileLocation, request.HostAddress.RemoveSpecialCharacters(), "track.js"));
                    }
                }
                catch (Exception ex)
                {
                    await _errorLogger.LogError("DashboardHostManager=>" + ex.Message);
                }
                return(new HostResult()
                {
                    Id = newHost.Id, TrackerAddress = _setting.ScriptAPIUrlBase + newHost.HostAddress.RemoveSpecialCharacters() + "/track.js", HostAddress = newHost.HostAddress
                });
            }
            else
            {
                return new HostResult()
                       {
                           Id                    = currentHost.Id,
                           TrackerAddress        = "https://api.stickytracker.net/" + currentHost.HostAddress.RemoveSpecialCharacters() + "/track.js",
                           HostAddress           = currentHost.HostAddress,
                           AlreadyExists         = true,
                           SegmentCreationAccess = new SegmentCreationAccess()
                           {
                               Page         = currentHost.HostValidated && currentHost.PageValidated,
                               AddToCart    = currentHost.AddToCardValidated,
                               Buy          = currentHost.FinalizeValidated,
                               ProductVisit = currentHost.CategoryValidated
                           }
                       }
            };
        }
Пример #5
0
        /// <summary>
        /// Inserts a new host record in database.
        /// </summary>
        public void CreateHost(CreateHostRequest value, out string newAPIKey)
        {
            long newHostId = 0;

            //Generate address
            WalletServices walletServices = new WalletServices();
            string         hostAddress    = walletServices.GenerateWalletAddress();

            using (var context = new AnnoDBContext())
            {
                //Insert host to database
                var newHost = new Host()
                {
                    name          = value.Name,
                    address       = hostAddress,
                    record_status = RecordStatuses.Live,
                    created_date  = DateTime.UtcNow
                };
                context.Host.Add(newHost);
                context.SaveChanges();

                //Get the ID of the newly created host
                newHostId = newHost.host_id;

                //Generate new API key
                newAPIKey = Guid.NewGuid().ToString().Replace("-", "");

                //Insert into api_keys table
                context.ApiKey.Add(new ApiKey()
                {
                    host_id       = newHostId,
                    api_key       = newAPIKey,
                    record_status = RecordStatuses.Live,
                    created_date  = DateTime.UtcNow
                });
                context.SaveChanges();

                //Create host wallet
                WalletServices walletService = new WalletServices();
                walletService.SaveWallet(newHostId, WalletOwnerTypes.Host, hostAddress);
            }

            //Commit to blockchain
            ContractApi blockchainContract = new ContractApi();

            blockchainContract.CreateHost(hostAddress, value.Name);
        }
Пример #6
0
        public async Task <HostReponse> Create([FromBody] CreateHostRequest model)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                return new HostReponse()
                       {
                           Valid = false, Error = "No User Access"
                       }
            }
            ;
            var createdHost = (await _hostManager.CreateAsync(user.Email, model));

            return(new HostReponse()
            {
                Error = "",
                Valid = !createdHost.AlreadyExists,
                Result = new List <HostResult>()
                {
                    createdHost
                }
            });
        }
Пример #7
0
 public Task <ApiResponse> CreateAsync(CreateHostRequest request)
 => _client.PostAsync(Path, request);