예제 #1
0
        /*
         * // Another way to convert AutoRepairDTO list to AutoRepairWCF list
         * private List<AutoRepairShopInfo> TranslateAutoRepairShopDTOListToAutoRepairShopInfoList2(List<AutoRepairDTO> autoRepairShopDTOList)
         * {
         *  List<AutoRepairShopInfo> autoRepairShopInfoList = autoRepairShopDTOList.ConvertAll(x => new AutoRepairShopInfo
         *  {
         *      ID = x.ID,
         *      Name = x.Name,
         *      Address = x.Address,
         *      City = x.City,
         *      Phone = x.Phone,
         *      Url = x.Url,
         *      Geolocation = x.Geolocation.ToString()
         *      //RowVersion = product.RowVersion
         *  });
         *  return autoRepairShopInfoList;
         * }
         */

        /* */ // AutoRepairShopRequestObject - check for License Key or UserName and Password
        public AutoRepairShopInfo GetNearestAutoRepairRequest(AutoRepairShopRequest autoRepairShopRequest)
        {
            //AutoRepairDTO autoRepairDTO = null;
            // AutoRepairShopInfo autoRepairShopInfoObject = new AutoRepairShopInfo();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    AutoRepairDTO autoRepairDTO = null;
                    // AutoRepairShopRequestObject
                    autoRepairDTO = context.GetNearestAutoRepair(autoRepairShopRequest.Geolocation);

                    AutoRepairShopInfo autoRepairShopInfoObject = new AutoRepairShopInfo(autoRepairDTO);
                    //TranslateAutoRepairDTOToAutoRepairShopInfoObject(autoRepairDTO, autoRepairShopInfoObject);
                    //autoRepairShopInfoObject = context.GetNearestAutoRepair(autoRepairShopRequest.Geolocation);
                    return(autoRepairShopInfoObject);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException <AutoRepairFault>(
                          new AutoRepairFault
                {
                    ErrorMessage = ex.Message,
                    Source       = ex.Source,
                    StackTrace   = ex.StackTrace,
                    Target       = ex.TargetSite.ToString()
                },
                          new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
            }

            /*
             * if (autoRepairShopInfoObject == null)
             * {
             *  string msg = string.Format("No AutoRepairShop found for user location {0}", autoRepairShopRequest.Geolocation);
             *  throw new FaultException<AutoRepairFault>(new AutoRepairFault
             *  {
             *      ErrorMessage = msg,
             *      Source = null,
             *      StackTrace = null,
             *      Target = null
             *  },
             *      new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
             * }
             */
            //return autoRepairShopInfoObject;
        }
예제 #2
0
        public AutoRepairWCF GetNearestAutoRepair(string userLocation)
        {
            AutoRepairDTO autoRepairDTO = null;
            AutoRepairWCF autoRepairWCF = new AutoRepairWCF();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    autoRepairDTO = context.GetNearestAutoRepair(userLocation);
                    TranslateAutoRepairDTOToAutoRepairWCF(autoRepairDTO, autoRepairWCF);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException <AutoRepairFault>(
                          new AutoRepairFault
                {
                    ErrorMessage = ex.Message,
                    Source       = ex.Source,
                    StackTrace   = ex.StackTrace,
                    Target       = ex.TargetSite.ToString()
                },
                          new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));

                // throw new FaultException("Service fault exception: " +ex.Message);
            }

            if (autoRepairDTO == null)
            {
                string msg = string.Format("No AutoRepairShop found for user location {0}", userLocation);
                throw new FaultException <AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source       = null,
                    StackTrace   = null,
                    Target       = null
                },
                                                           new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }

            return(autoRepairWCF);
        }
예제 #3
0
        // Nearest 5 Auto Repair Shops
        public List <AutoRepairWCF> GetFiveNearestAutoRepairs(string userLocation)
        {
            List <AutoRepairDTO> autoRepairDTOList = new List <AutoRepairDTO>();
            List <AutoRepairWCF> autoRepairWCFList = new List <AutoRepairWCF>();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    autoRepairDTOList = context.GetFiveNearestAutoRepairs(userLocation);
                    TranslateAutoRepairShopDTOListToAuotoRepairWCFList(autoRepairDTOList, ref autoRepairWCFList);
                }
            }
            catch (Exception ex)
            {
                //Part 18 Throwing fault exceptions from a WCF service
                //throw new FaultException();
                throw new FaultException <AutoRepairFault>(
                          new AutoRepairFault
                {
                    ErrorMessage = ex.Message,
                    Source       = ex.Source,
                    StackTrace   = ex.StackTrace,
                    Target       = ex.TargetSite.ToString()
                },
                          new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
            }

            if (autoRepairDTOList == null)
            {
                string msg = string.Format("No Auto Repair Shop found.");
                throw new FaultException <AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source       = null,
                    StackTrace   = null,
                    Target       = null
                },
                                                           new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }

            return(autoRepairWCFList);
        }
예제 #4
0
        /*
         * // Controlling WCF message protection using ProtectionLevel parameter
         * // www.youtube.com/watch?v=ybY9dD24gtI&index=48&list=PL6n9fhu94yhVxEyaRMaMN_-qnDdNVGsL1
         * [OperationContract(Name = "GetAllAutoRepairs", ProtectionLevel=ProtectionLevel.None)]
         */
        // User has to be in Role to call the service operation
        // [PrincipalPermission(SecurityAction.Demand, Role = "member")]
        public List <AutoRepairWCF> GetAllAutoRepairs()
        {
            List <AutoRepairDTO> autoRepairDTOList = new List <AutoRepairDTO>();
            // List<AutoRepairWCF> autoRepairWCFList = new List<AutoRepairWCF>();
            List <AutoRepairWCF> autoRepairWCFList2 = new List <AutoRepairWCF>();

            try
            {
                using (AutoRepairShopRepositoryBLL context = new AutoRepairShopRepositoryBLL())
                {
                    autoRepairDTOList = context.GetAllAutoRepairs();
                    // TranslateAutoRepairShopDTOListToAuotoRepairWCFList(autoRepairDTOList, ref autoRepairWCFList);
                    autoRepairWCFList2 = TranslateAutoRepairShopDTOListToAuotoRepairWCFList2(autoRepairDTOList);
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                string sqlExceptionMessage = null;
                if (ex is SqlException)
                {
                    sqlExceptionMessage = "The underlying provider failed on Open. Cannot Open the Database.";

                    throw new FaultException <AutoRepairFault>(
                              new AutoRepairFault
                    {
                        ErrorMessage = sqlExceptionMessage,
                        Source       = ex.Source,
                        StackTrace   = ex.StackTrace,
                        Target       = ex.TargetSite.ToString()
                    },
                              new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
                }
                else
                {
                    throw new FaultException <AutoRepairFault>(
                              new AutoRepairFault
                    {
                        ErrorMessage = sqlExceptionMessage + "\n" + ex.Message,
                        Source       = ex.Source,
                        StackTrace   = ex.StackTrace,
                        Target       = ex.TargetSite.ToString()
                    },
                              new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + ex.Message)));
                }
            }

            if (autoRepairDTOList == null)
            {
                string msg = string.Format("No Auto Repair Shop found.");
                throw new FaultException <AutoRepairFault>(new AutoRepairFault
                {
                    ErrorMessage = msg,
                    Source       = null,
                    StackTrace   = null,
                    Target       = null
                },
                                                           new FaultReason(string.Format(CultureInfo.InvariantCulture, "{0}", "Service fault exception: " + msg)));
            }
            return(autoRepairWCFList2);
            //return autoRepairWCFList;
        }