Beispiel #1
0
        public async void CreateAProject_NullLocationCheck_ReturnBadRequestException()
        {
            var errMessage            = "Bad Request";
            LocationResource location = null;
            var summary = new ProjectSummary {
                Title            = "",
                Location         = location,
                ProjectStartDate = new System.DateTime(),
                ProjectEndDate   = new System.DateTime(),
                ProjectNumber    = "test"
            };
            var manager = new ProjectManager {
                UserID    = "1",
                FirstName = "",
                LastName  = ""
            };
            var profile = new ProjectProfile {
                ProjectSummary = summary,
                ProjectManager = manager,
                UsersSummary   = Enumerable.Empty <UserSummary>(),
                Openings       = Enumerable.Empty <OpeningPositionsSummary>()
            };

            var result = (await _controller.CreateAProject(profile)) as ObjectResult;

            Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
            Assert.IsType <BadRequestException>(result.Value);
            var response = result.Value as BadRequestException;

            Assert.Equal(errMessage, response.status);
        }
        public async void UpdateUser_TryBlock_InvalidUser_ReturnInternalServerException()
        {
            Setup_LocationsRepo_GetALocation_Default(new Location());
            Setup_UsersRepo_UpdateAUser_Default("-1");
            var errMessage = "Internal Server Error";
            var location   = new LocationResource {
                LocationID = 1,
                City       = "city",
                Province   = "province"
            };
            var summary = new UserSummary {
                UserID             = "1",
                Location           = location,
                FirstName          = "first",
                LastName           = "last",
                Utilization        = 0,
                ResourceDiscipline = null,
                IsConfirmed        = false
            };
            var user = new UserProfile {
                UserSummary     = summary,
                CurrentProjects = Enumerable.Empty <ProjectSummary>(),
                Availability    = Enumerable.Empty <OutOfOfficeResource>(),
                Disciplines     = Enumerable.Empty <ResourceDisciplineResource>(),
                Positions       = Enumerable.Empty <PositionSummary>()
            };

            var result = (await _controller.UpdateUser(user, "1")) as ObjectResult;

            Assert.Equal(StatusCodes.Status500InternalServerError, result.StatusCode);
            var response = result.Value as InternalServerException;

            Assert.Equal(errMessage, response.status);
        }
Beispiel #3
0
        public async Task <IActionResult> PostAsync([FromRoute] string username, [FromBody] LocationResource location)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                return(BadRequest("No username supplied."));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var userLocation = _mapper.Map <LocationResource, UserLocation>(location);

            userLocation.Username = username;

            var response = await _userLocationService.AddUserLocationAsync(userLocation);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            var userLocationResource = new UserLocationResource()
            {
                Username  = response.UserLocation.Username,
                Locations = new List <LocationResource>()
                {
                    _mapper.Map <UserLocation, LocationResource>(response.UserLocation)
                }
            };

            return(Ok(userLocationResource));
        }
Beispiel #4
0
        /// <summary>
        /// Creates Address based on EA location. If the data is not there, default to customer data.
        /// </summary>
        /// <param name="magentoRegion"></param>
        /// <param name="eaLocation"></param>
        /// <param name="customer"></param>
        public AddressResource(RegionResource magentoRegion, LocationResource eaLocation, CustomerResource customer)
        {
            var customerAddress = customer.addresses.First();

            region     = magentoRegion.name;
            regionId   = int.Parse(magentoRegion.id);
            regionCode = magentoRegion.code;
            countryId  = eaLocation.Address.CountryCode;

            street = new List <string>();
            if (eaLocation.Address.AddressLine1 != null)
            {
                street.Add(eaLocation.Address.AddressLine1);
            }
            if (eaLocation.Address.AddressLine2 != null)
            {
                street.Add(eaLocation.Address.AddressLine2);
            }

            if (!street.Any())
            {
                street = customerAddress.street;
            }

            telephone = eaLocation.StorePhoneNumbers.FirstOrDefault()?.Number ?? customerAddress.telephone;
            postcode  = eaLocation.Address.Zip ?? customerAddress.postcode;
            city      = eaLocation.Address.City;
            firstname = customer.firstname;
            lastname  = customer.lastname;
            email     = customer.email;
        }
Beispiel #5
0
        public IActionResult UpdateLocation([FromBody] LocationResource LocationResource)
        {
            var location   = mapper.Map <LocationResource, Location>(LocationResource);
            var locationdb = db.Locations.Where(l => l.Id.Equals(location.Id)).SingleOrDefault();

            locationdb.Name = location.Name;
            db.SaveChanges();
            return(Ok(mapper.Map <Location, LocationResource>(location)));
        }
Beispiel #6
0
        public async Task <Location> GetLocationIdByCityProvince(LocationResource location)
        {
            var sql = @"
                Select * from Locations
                where City = @City and Province = @Province;";

            using var connection = new SqlConnection(connectionString);
            connection.Open();
            return(await connection.QueryFirstOrDefaultAsync <Location>(sql, new { City = location.City, Province = location.Province }));
        }
        protected async override Task <bool> GetDataAsync()
        {
            var resource = new LocationResource(Context);

            _results = await resource.GetLocationsAsync(startIndex : StartIndex, pageSize : PageSize, sortBy : SortBy, filter : Filter);

            TotalCount = _results.TotalCount;
            PageCount  = _results.PageCount;
            PageSize   = _results.PageSize;
            return(_results.Items != null && _results.Items.Count > 0);
        }
Beispiel #8
0
        public IActionResult CreateLocation([FromBody] LocationResource LocationResource)
        {
            var location = mapper.Map <LocationResource, Location>(LocationResource);

            try {
                db.Locations.Add(location);
                db.SaveChanges();
                return(Ok(mapper.Map <Location, LocationResource>(location)));
            } catch {
                return(StatusCode(501));
            }
        }
Beispiel #9
0
 public Location ParseLocation(LocationResource location)
 {
     return(new Location
     {
         LocationId = location.LocationId,
         Name = location.Name,
         Address = location.Address,
         StoreProducts = ParseInventory(location.StoreProducts),
         //add parse inventory
         //order history
     });
 }
Beispiel #10
0
        public IHttpActionResult GetLocationById(int idLocation)
        {
            Location         l    = usercntxt.Locations.Find(idLocation);
            LocationResource lres = new LocationResource
            {
                Id           = l.LocationId,
                Latitude     = l.Latitude,
                Longitude    = l.Longitude,
                LocationName = l.LocationName
            };

            return(Ok(lres));
        }
 public IActionResult AddLocation(LocationResource location)
 {
     try
     {
         _locationService.AddLocation(_mapper.ParseLocation(location));
         _locationService.SaveChanges();
         return(CreatedAtAction("AddLocation", location));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Beispiel #12
0
        // //POST
        public async Task <int> CreateALocation(LocationResource location)
        {
            var sql = @"
                insert into Locations
                    (City, Province)
                values
                    (@City, @Province);
                select cast(scope_identity() as int);
            ;";

            using var connection = new SqlConnection(connectionString);
            connection.Open();
            location.LocationID = await connection.QuerySingleAsync <int>(sql, new { City = location.City, Province = location.Province });

            return(location.LocationID);
        }
Beispiel #13
0
        public async void CreateALocation_CatchBlock_ReturnsBadRequestException()
        {
            string errMessage          = "Bad Request";
            var    badRequestException = new CustomException <BadRequestException>(new BadRequestException(errMessage));

            Setup_LocationsRepo_CreateALocation_ThrowsException(badRequestException);

            var location = new LocationResource();
            var result   = (await _controller.CreateALocation(location)) as ObjectResult;

            Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
            Assert.IsType <BadRequestException>(result.Value);
            var response = result.Value as BadRequestException;

            Assert.Equal(errMessage, response.status);
        }
Beispiel #14
0
        public IEnumerable <LocationResource> GetLocations()
        {
            List <LocationResource> locationResList = new List <LocationResource>();

            foreach (Location l in usercntxt.Locations.ToList())
            {
                LocationResource lres = new LocationResource
                {
                    Id           = l.LocationId,
                    Latitude     = l.Latitude,
                    Longitude    = l.Longitude,
                    LocationName = l.LocationName
                };
                locationResList.Add(lres);
            }
            return(locationResList);
        }
Beispiel #15
0
        public async void CreateALocation_CatchBlock_ReturnsSqlException()
        {
            string errMessage   = "Internal Server Error";
            var    sqlException = new SqlExceptionBuilder().WithErrorNumber(50000).WithErrorMessage(errMessage).Build();

            Setup_LocationsRepo_CreateALocation_ThrowsException(sqlException);

            var location = new LocationResource
            {
                Province = "A Province",
                City     = "A City"
            };
            var result = (await _controller.CreateALocation(location)) as ObjectResult;

            Assert.Equal(StatusCodes.Status500InternalServerError, result.StatusCode);
            var response = result.Value as InternalServerException;

            Assert.Equal(errMessage, response.status);
        }
Beispiel #16
0
        public async void CreateAProvince_TryBlock_ReturnValidId()
        {
            var location = new LocationResource
            {
                LocationID = 0,
                Province   = "test",
                City       = ""
            };

            Setup_LocationsRepo_CreateAProvince_Default(location.Province);

            var result = (await _controller.CreateAProvince(location)) as ObjectResult;

            Verify_LocationsRepo_CreateALocation(Times.Never);
            Verify_LocationsRepo_CreateAProvince(Times.Once);
            Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
            Assert.IsType <CreatedResponse <string> >(result.Value);
            var response = result.Value as CreatedResponse <string>;

            Assert.IsType <string>(response.payload);
        }
Beispiel #17
0
        public async void CreateALocation_TryBlock_ReturnValidId()
        {
            var location = new LocationResource
            {
                Province = "A Province",
                City     = "A City"
            };
            var returnVal = 1;

            Setup_LocationsRepo_CreateALocation_Default(returnVal);

            var result = (await _controller.CreateALocation(location)) as ObjectResult;

            Verify_LocationsRepo_CreateALocation(Times.Once);
            Verify_LocationsRepo_CreateAProvince(Times.Never);
            Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
            Assert.IsType <CreatedResponse <int> >(result.Value);
            var response = result.Value as CreatedResponse <int>;

            Assert.IsType <int>(response.payload);
        }
        public async void UpdateUser_CatchBlock_ReturnInternalServerException()
        {
            var errMessage   = "Internal Server Error";
            var sqlException = new SqlExceptionBuilder().WithErrorNumber(50000).WithErrorMessage(errMessage).Build();

            Setup_AllRepo_UpdateUser(It.IsAny <ResourceDiscipline>(), Enumerable.Empty <ResourceDiscipline>(),
                                     new OutOfOffice(), Enumerable.Empty <OutOfOffice>(), new ResourceSkill(), Enumerable.Empty <ResourceSkill>());
            Setup_LocationsRepo_GetALocation_Default(new Location());
            Setup_UsersRepo_UpdateAUser_ThrowsException(sqlException);

            var location = new LocationResource {
                LocationID = 1,
                City       = "city",
                Province   = "province"
            };
            var summary = new UserSummary {
                UserID             = "NoneEmpty",
                Location           = location,
                FirstName          = "first",
                LastName           = "last",
                Utilization        = 0,
                ResourceDiscipline = null,
                IsConfirmed        = false
            };
            var user = new UserProfile {
                UserSummary     = summary,
                CurrentProjects = Enumerable.Empty <ProjectSummary>(),
                Availability    = Enumerable.Empty <OutOfOfficeResource>(),
                Disciplines     = Enumerable.Empty <ResourceDisciplineResource>(),
                Positions       = Enumerable.Empty <PositionSummary>()
            };

            var result = (await _controller.UpdateUser(user, "NoneEmpty")) as ObjectResult;

            Assert.Equal(StatusCodes.Status500InternalServerError, result.StatusCode);
            var response = result.Value as InternalServerException;

            Assert.Equal(errMessage, response.status);
        }
Beispiel #19
0
        public async void CreateAProject_CatchBlockProjectErr_ReturnsBadRequestException()
        {
            string errMessage          = "Bad Request";
            var    badRequestException = new CustomException <BadRequestException>(new BadRequestException(errMessage));

            Setup_LocationsRepo_GetALocation_Default(new Location());
            Setup_ProjectsRepo_CreateAProject_ThrowsException(badRequestException);
            var location = new LocationResource {
                LocationID = 1,
                Province   = "",
                City       = ""
            };
            var summary = new ProjectSummary {
                Title            = "",
                Location         = location,
                ProjectStartDate = new System.DateTime(),
                ProjectEndDate   = new System.DateTime(),
                ProjectNumber    = "test"
            };
            var manager = new ProjectManager {
                UserID    = "1",
                FirstName = "",
                LastName  = ""
            };
            var profile = new ProjectProfile {
                ProjectSummary = summary,
                ProjectManager = manager,
                UsersSummary   = Enumerable.Empty <UserSummary>(),
                Openings       = Enumerable.Empty <OpeningPositionsSummary>()
            };

            var result = (await _controller.CreateAProject(profile)) as ObjectResult;

            Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
            Assert.IsType <BadRequestException>(result.Value);
            var response = result.Value as BadRequestException;

            Assert.Equal(errMessage, response.status);
        }
Beispiel #20
0
        public async void CreateAProject_CatchBlockProjectErr_ReturnsSqlException()
        {
            var errMessage   = "Internal Server Error";
            var sqlException = new SqlExceptionBuilder().WithErrorNumber(50000).WithErrorMessage(errMessage).Build();

            Setup_LocationsRepo_GetALocation_Default(new Location());
            Setup_ProjectsRepo_CreateAProject_ThrowsException(sqlException);
            var location = new LocationResource {
                LocationID = 1,
                Province   = "",
                City       = ""
            };
            var summary = new ProjectSummary {
                Title            = "",
                Location         = location,
                ProjectStartDate = new System.DateTime(),
                ProjectEndDate   = new System.DateTime(),
                ProjectNumber    = "test"
            };
            var manager = new ProjectManager {
                UserID    = "1",
                FirstName = "",
                LastName  = ""
            };
            var profile = new ProjectProfile {
                ProjectSummary = summary,
                ProjectManager = manager,
                UsersSummary   = Enumerable.Empty <UserSummary>(),
                Openings       = Enumerable.Empty <OpeningPositionsSummary>()
            };

            var result = (await _controller.CreateAProject(profile)) as ObjectResult;

            Assert.Equal(StatusCodes.Status500InternalServerError, result.StatusCode);
            var response = result.Value as InternalServerException;

            Assert.Equal(errMessage, response.status);
        }
Beispiel #21
0
        public async Task <IActionResult> CreateAProvince([FromBody] LocationResource location)
        {
            if (location == null)
            {
                var error = new BadRequestException("The given request body is null / Request Body cannot be read");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            if (String.IsNullOrEmpty(location.Province))
            {
                var error = new BadRequestException("Province cannot be null or empty");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            try
            {
                var createdProvinceName = await locationsRepository.CreateAProvince(location.Province);

                var response = new CreatedResponse <string>(createdProvinceName, $"Successfully created province '{createdProvinceName}'");
                // Log.Information("@{a}", response);
                return(StatusCode(StatusCodes.Status201Created, response));
            }
            catch (Exception err)
            {
                var errMessage = $"Source: {err.Source}\n  Message: {err.Message}\n  StackTrace: {err.StackTrace}\n";
                if (err is SqlException)
                {
                    var error = new InternalServerException(errMessage);
                    return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException()));
                }
                else
                {
                    // Log.Information("second bad request");
                    var error = new BadRequestException(errMessage);
                    return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                }
            }
        }
        public async void UpdateUser_TryBlock_ReturnValidUserID()
        {
            Setup_AllRepo_UpdateUser(new ResourceDiscipline(), Enumerable.Empty <ResourceDiscipline>(),
                                     new OutOfOffice(), Enumerable.Empty <OutOfOffice>(), new ResourceSkill(), Enumerable.Empty <ResourceSkill>());
            Setup_LocationsRepo_GetALocation_Default(new Location());
            Setup_UsersRepo_UpdateAUser_Default("1");

            var location = new LocationResource {
                LocationID = 1,
                City       = "city",
                Province   = "province"
            };
            var summary = new UserSummary {
                UserID             = "1",
                Location           = location,
                FirstName          = "first",
                LastName           = "last",
                Utilization        = 0,
                ResourceDiscipline = null,
                IsConfirmed        = false
            };
            var user = new UserProfile {
                UserSummary     = summary,
                CurrentProjects = Enumerable.Empty <ProjectSummary>(),
                Availability    = Enumerable.Empty <OutOfOfficeResource>(),
                Disciplines     = Enumerable.Empty <ResourceDisciplineResource>(),
                Positions       = Enumerable.Empty <PositionSummary>()
            };

            var result = (await _controller.UpdateUser(user, "1")) as ObjectResult;

            Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
            Assert.IsType <OkResponse <string> >(result.Value);
            var response = result.Value as OkResponse <string>;

            Assert.IsType <string>(response.payload);
        }
        public async void UpdateUser_CatchBlock_ReturnBadRequestException()
        {
            string errMessage          = "Bad Request";
            var    badRequestException = new CustomException <BadRequestException>(new BadRequestException(errMessage));

            Setup_UsersRepo_UpdateAUser_ThrowsException(badRequestException);

            var location = new LocationResource {
                LocationID = 1,
                City       = "city",
                Province   = "province"
            };
            var summary = new UserSummary {
                UserID             = null,
                Location           = location,
                FirstName          = "first",
                LastName           = "last",
                Utilization        = 0,
                ResourceDiscipline = null,
                IsConfirmed        = false
            };
            var user = new UserProfile {
                UserSummary     = summary,
                CurrentProjects = Enumerable.Empty <ProjectSummary>(),
                Availability    = Enumerable.Empty <OutOfOfficeResource>(),
                Disciplines     = Enumerable.Empty <ResourceDisciplineResource>(),
                Positions       = Enumerable.Empty <PositionSummary>()
            };

            var result = (await _controller.UpdateUser(user, "")) as ObjectResult;

            Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
            Assert.IsType <BadRequestException>(result.Value);
            var response = result.Value as BadRequestException;

            Assert.Equal(errMessage, response.status);
        }
Beispiel #24
0
        public async void CreateAProject_TryBlock_ValidCreation()
        {
            Setup_LocationsRepo_GetALocation_Default(new Location());
            Setup_ProjectsRepo_CreateAProject_Default("1");
            var location = new LocationResource {
                LocationID = 1,
                Province   = "",
                City       = ""
            };
            var summary = new ProjectSummary {
                Title            = "",
                Location         = location,
                ProjectStartDate = new System.DateTime(),
                ProjectEndDate   = new System.DateTime(),
                ProjectNumber    = "test"
            };
            var manager = new ProjectManager {
                UserID    = "1",
                FirstName = "",
                LastName  = ""
            };
            var profile = new ProjectProfile {
                ProjectSummary = summary,
                ProjectManager = manager,
                UsersSummary   = Enumerable.Empty <UserSummary>(),
                Openings       = Enumerable.Empty <OpeningPositionsSummary>()
            };

            var result = (await _controller.CreateAProject(profile)) as ObjectResult;

            Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
            Assert.IsType <CreatedResponse <string> >(result.Value);
            var response = result.Value as CreatedResponse <string>;

            Assert.IsType <string>(response.payload);
        }
Beispiel #25
0
        public async Task <IActionResult> CreateALocation([FromBody] LocationResource location)
        {
            if (location == null)
            {
                var error = new BadRequestException("The given request body is null / Request Body cannot be read");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            if (String.IsNullOrEmpty(location.Province) || String.IsNullOrEmpty(location.City))
            {
                var error = new BadRequestException("Province and City cannot be null or empty");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            try
            {
                var createdLocationID = await locationsRepository.CreateALocation(location);

                var response = new CreatedResponse <int>(createdLocationID, $"Successfully created location '{createdLocationID}'");
                return(StatusCode(StatusCodes.Status201Created, response));
            }
            catch (Exception err)
            {
                var errMessage = $"Source: {err.Source}\n  Message: {err.Message}\n  StackTrace: {err.StackTrace}\n";
                if (err is SqlException)
                {
                    var error = new InternalServerException(errMessage);
                    return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException()));
                }
                else
                {
                    var error = new BadRequestException(errMessage);
                    return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                }
            }
        }
 public IList<Locations> Locations(Locations locaton)
 {
     LocationResource objLocationResource = new LocationResource();
     return objLocationResource.LocationList(locaton);
 }
 //
 public IList<Locations> GetCountryList(Locations locations)
 {
     LocationResource objLocations = new LocationResource();
     return objLocations.LocationList(locations);
 }
 public IList<Locations> GetCountryState(object[] param)
 {
     LocationResource objLocations = new LocationResource();
     return objLocations.GetCountryState(param);
 }
Beispiel #29
0
        public void LoadResources()
        {
            if (Directory.Exists(RESOURCES_CACHE))
            {
                foreach (string directory in Directory.GetDirectories(RESOURCES_CACHE))
                {
                    string id = Path.GetFileName(directory);
                    int    objectID;
                    if (int.TryParse(id, out objectID))
                    {
                        LWM2MResources resources = null;
                        switch (objectID)
                        {
                        case 0:
                            resources = _SecurityResources;
                            break;

                        case 1:
                            resources = _ServerResources;
                            break;

                        case 3:
                            resources = new DeviceResources();
                            break;

                        case 4:
                            resources = new ConnectivityMonitoringResources();
                            break;

                        case 5:
                            resources = new FirmwareUpdateResources();
                            break;

                        case 6:
                            resources = new LocationResources();
                            break;

                        case 7:
                            resources = new ConnectivityStatisticsResources();
                            break;

                        case 15:
                            resources = new DeviceCapabilityResources();
                            break;

                        case 20000:
                            resources = new FlowObjectResources();
                            break;

                        case 20001:
                            resources = new FlowAccessResources();
                            break;

                        case 20005:
                            resources = new FlowCommandResources();
                            EventHandler <ChildCreatedEventArgs> handler = (s, e) =>
                            {
                                FlowCommandResource flowCommandResource = e.Resource as FlowCommandResource;
                                if (flowCommandResource != null)
                                {
                                    flowCommandResource.Updated += new EventHandler(FlowCommand_Updated);
                                    FlowCommand_Updated(flowCommandResource, null);
                                }
                            };
                            resources.ChildCreated += handler;
                            break;

                        default:
                            break;
                        }
                        if (resources != null)
                        {
                            foreach (string fileName in Directory.GetFiles(directory, "*.tlv"))
                            {
                                LWM2MResource resource = null;
                                switch (objectID)
                                {
                                case 0:
                                    resource = new SecurityResource(Path.GetFileNameWithoutExtension(fileName));
                                    break;

                                case 1:
                                    resource = new ServerResource(Path.GetFileNameWithoutExtension(fileName));
                                    break;

                                case 3:
                                    resource = new DeviceResource();
                                    break;

                                case 4:
                                    resource = new ConnectivityMonitoringResource();
                                    break;

                                case 5:
                                    resource = new FirmwareUpdateResource();
                                    break;

                                case 6:
                                    resource = new LocationResource();
                                    break;

                                case 7:
                                    resource = new ConnectivityStatisticsResource();
                                    break;

                                case 15:
                                    resource = new DeviceCapabilityResource(Path.GetFileNameWithoutExtension(fileName));
                                    break;

                                case 20000:
                                    resource          = new FlowObjectResource();
                                    resource.Updated += new EventHandler(FlowObject_Updated);
                                    break;

                                case 20001:
                                    resource = new FlowAccessResource();
                                    break;

                                case 20005:
                                    resource          = new FlowCommandResource(Path.GetFileNameWithoutExtension(fileName));
                                    resource.Updated += new EventHandler(FlowCommand_Updated);
                                    break;

                                default:
                                    break;
                                }
                                if (resource != null)
                                {
                                    using (Stream stream = File.OpenRead(fileName))
                                    {
                                        TlvReader reader = new TlvReader(stream);
                                        if (resource.Deserialise(reader))
                                        {
                                            resources.Add(resource);
                                        }
                                    }

                                    if (objectID == 0)
                                    {
                                        SecurityResource securityResource = resource as SecurityResource;
                                        if (securityResource.SecurityMode == TSecurityMode.PreSharedKey)
                                        {
                                            UsePSK(System.Text.Encoding.UTF8.GetString(securityResource.ClientPublicKey), StringUtils.HexString(securityResource.SecretKey));
                                        }
                                    }
                                    else if (objectID == 20000)
                                    {
                                        FlowObjectResource flowObjectResource = resource as FlowObjectResource;
                                        if (flowObjectResource != null)
                                        {
                                            flowObjectResource.TenantHash = null;
                                        }
                                    }
                                }
                            }
                            this.AddResources(resources);
                        }
                    }
                }
            }
            else
            {
                LoadDefaultResources();
            }
        }
 public int GetstateIdByName(object[] objValue)
 {
     LocationResource objLocationResource = new LocationResource();
     return objLocationResource.GetstateIdByName(objValue);
 }
 public int GetCountryIdByName(string countryName)
 {
     LocationResource objLocationResource = new LocationResource();
     return objLocationResource.GetCountryIdByName(countryName);
 }
 public IList<Locations> GetStateList(Locations locations)
 {
     LocationResource objResource = new LocationResource();
     return objResource.LocationList(locations);
 }
Beispiel #33
0
        /// <summary>
        /// Sets the shipping and billing information on a Magento cart.
        /// Shipping address used is based on the EA location unless the data needed is not available. In this case, data is pulled from the customer.
        /// Shipping method used will be the one set in App.config. If that shipping method cannot be used for the cart specified, an exception will occur.
        /// </summary>
        /// <param name="cartId">Identifier for cart to set information on.</param>
        /// <param name="magentoRegion">Region information for address</param>
        /// <param name="eaLocation">Location information for address</param>
        /// <param name="customer">Customer for address information</param>
        public void SetShippingAndBillingInformationForCart(int cartId, RegionResource magentoRegion, LocationResource eaLocation, CustomerResource customer)
        {
            AddressResource shippingAddress;

            if (magentoRegion != null)
            {
                shippingAddress = new AddressResource(magentoRegion, eaLocation, customer);
            }
            else
            {
                shippingAddress = new AddressResource(customer);
            }

            //Verfiy that shipping code matches App.config file
            var shippingInformation = new CartSetShippingInformationResource(ConfigReader.MagentoShippingCode, shippingAddress);

            _magentoCartController.SetShippingInformation(cartId, shippingInformation);

            if (_magentoCartController.GetShippingMethods(cartId).FirstOrDefault(x => x.method_code == ConfigReader.MagentoShippingCode) == null)
            {
                throw new Exception(string.Format("Unable to add shipping information to cart {0}. Ensure that shipping code {1} is valid for this cart.",
                                                  cartId, ConfigReader.MagentoShippingCode));
            }
        }