예제 #1
0
        public ApiResponse <Boolean> Test([FromRoute] Guid packageId, [FromBody] DataConnectionModel request)
        {
            // Create a default response object
            ApiResponse <Boolean> response = new ApiResponse <Boolean>();

            // Did we find a package?
            Package package = SessionHandler.PackageRepository.Get(packageId);

            if (package != null)
            {
                // Map the connection to something we can use
                DataConnection connection = mapper.Map <DataConnection>(request);

                // Create a new factory class and get the provider from the connection given
                IDataProvider provider = (new DataProviderFactory()).Get(package, connection, false);
                if (provider != null)
                {
                    // Can we connect?
                    response.Success = response.Success = provider.Test(connection);
                    provider         = null; // Kill the provider now
                }
            }

            // Send the response back
            return(response);
        }
            public static DataConnectionModel FromString(string connectionString)
            {
                var dic = connectionString.Split(';')
                          .Where(x => !string.IsNullOrEmpty(x))
                          .Select(x => x.Split('='))
                          .ToDictionary(x => x[0], x => x[1]);
                var re = new DataConnectionModel();

                ConnectionStringConstructor.Run(re, dic);
                return(re);
            }
예제 #3
0
        public async Task <IActionResult> Post([FromBody] DataConnectionModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await service.Create(model.ToEntity(this.User.GetUserId()));

            return(Created(Url.Link(RouteConstants.DataConnectionSelfRoute, new { id = result.Id }), result));
        }
        public void BuildFromString()
        {
            var model    = DataConnectionModel.FromString(ConnectionStringValue);
            var expected = new DataConnectionModel
            {
                Host     = "www.newbe.pro",
                Port     = 36524,
                Username = "******",
                Password = "******",
            };

            model.Should().BeEquivalentTo(expected);
        }
        public void JoinToString()
        {
            var model = new DataConnectionModel
            {
                Host     = "www.newbe.pro",
                Port     = 36524,
                Username = "******",
                Password = "******",
            };
            var connectionString = model.ToString();

            connectionString.Should().Be(ConnectionStringValue);
        }
예제 #6
0
        public async Task <IActionResult> Update([FromRoute] string id, [FromBody] DataConnectionModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var connection = await service.Find(id);

            if (connection.User != this.User.GetUserId())
            {
                return(Unauthorized());
            }

            var result = await service.Update(model.ToEntity(id, this.User.GetUserId()));

            return(Ok(result));
        }
        public void Populate_ConnectionModel()
        {
            // Arrange
            Guid credentialsId = Guid.NewGuid(); // Set the fixed id of the credentials

            // Create a new package to pick the credentials up from in the populate routine
            Package package = new Package()
            {
                CredentialsStore = new List <Credentials>()
                {
                    new Credentials()
                    {
                        Id = credentialsId, Name = "Dummy Credentials"
                    }
                }
            };

            // Create a new connection model without the populated fields
            DataConnectionModel model = new DataConnectionModel()
            {
                Credentials =
                    new KeyValuePair <Guid, string>
                        (credentialsId, String.Empty),
                ProviderType = (Int32)DataProviderType.SQLProvider
            };

            // Set up the mapper to map any needed objects
            AutoMapperProfile.Initialise();
            IMapper mapper = new Mapper(Mapper.Configuration);

            // Act
            model = ConnectionApiHelper.PopulateModel(mapper, package, model);

            // Assert
            Assert.True(model.Credentials.Value != String.Empty);
            Assert.True(model.ProviderData != null);
        }
예제 #8
0
        public ApiResponse <DataConnectionModel> Post([FromRoute] Guid packageId, [FromBody] DataConnectionModel request)
        {
            // Create the response object
            ApiResponse <DataConnectionModel> response = new ApiResponse <DataConnectionModel>();

            // Map the model to a domain object type
            DataConnection savedConnection = mapper.Map <DataConnection>(request);

            // Did the mapping work ok?
            if (savedConnection != null)
            {
                // Did we find a package?
                Package package = SessionHandler.PackageRepository.Get(packageId);
                if (package != null)
                {
                    // Get the repository to save the package for us
                    savedConnection = package.Save <DataConnection>(savedConnection);
                }

                // Saved ok?
                if (savedConnection != null)
                {
                    // Map the connection back to a model type and send it back to the user
                    response.Data = mapper.Map <DataConnectionModel>(savedConnection);

                    // Fill in the blanks
                    response.Data = ConnectionApiHelper.PopulateModel(mapper, package, response.Data);
                }

                // Nothing died .. Success
                response.Success = true;
            }

            // Send the response back
            return(response);
        }
예제 #9
0
        /// <summary>
        /// Makes sure that any additional items that cannot be automapped
        /// are attached to the model to be returned
        /// </summary>
        /// <param name="model">The model to be populated</param>
        /// <returns>The populated model</returns>
        public static DataConnectionModel PopulateModel(IMapper mapper, Package package, DataConnectionModel model)
        {
            // Post processing to fill in the missing titles
            // as this doesn't really fit well in Automapper due
            // to the source column type
            model.Credentials =
                mapper.Map <KeyValuePair <Guid, String> >
                    (package.Credentials(model.Credentials.Key));

            // Add the provider data which can't be automapped
            // As it connects to an enum
            model.ProviderData =
                mapper.Map <DataProviderModel>(
                    (new DataProviderFactory())
                    .Get((DataProviderType)model.ProviderType)
                    );

            return(model); // Send the model back (it's byref anyway but ..)
        }
예제 #10
0
        public ApiResponse <List <KeyValuePair <String, String> > > QueryObjects([FromRoute] Guid packageId, [FromBody] DataConnectionModel request)
        {
            // Create a default response object
            ApiResponse <List <KeyValuePair <String, String> > > response =
                new ApiResponse <List <KeyValuePair <String, String> > >()
            {
                Data = new List <KeyValuePair <String, String> >()
            };

            // Did we find a package?
            Package package = SessionHandler.PackageRepository.Get(packageId);

            if (package != null)
            {
                // Map the connection to something we can use
                DataConnection connection = mapper.Map <DataConnection>(request);

                // Create a new factory class and get the provider from the connection given
                IDataProvider provider = (new DataProviderFactory()).Get(package, connection, false);
                if (provider != null)
                {
                    response.Data    = provider.ObjectList();
                    response.Success = response.Success = true;
                    provider         = null; // Kill the provider now
                }
            }

            // Send the response back
            return(response);
        }