Example #1
0
 public string SubmitSeat(AMS.Model.AMS_School school, string cardNo, string seatNum, string readingRoomNum)
 {
     SeatManage.IPocketBespeakBllService.IPocketBespeakBllService pocketBespeak = BespeakServiceConnProxy.BespeakServiceConnProxy.CreateChannelPocketBespeakBllService(school.ConnectionString);
     try
     {
         return(pocketBespeak.SubmitSeat(cardNo, seatNum, readingRoomNum));
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         ICommunicationObject ICommObjectService = pocketBespeak as ICommunicationObject;
         try
         {
             if (ICommObjectService.State == CommunicationState.Faulted)
             {
                 ICommObjectService.Abort();
             }
             else
             {
                 ICommObjectService.Close();
             }
         }
         catch
         {
             ICommObjectService.Abort();
         }
     }
 }
        /// <summary>
        /// 获取播放列表
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static SeatManage.ClassModel.AMS_PlayList GetPlayListByNum(string num)
        {
            IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
            bool error = false;

            try
            {
                return(seatService.GetPlayListByNum(num));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManageComm.WriteLog.Write("获取播放列表失败:" + ex.Message);
                return(null);
            }
            finally
            {
                ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Example #3
0
 public List <ClassModel.Seat> GetReadingRoomSeatList(AMS.Model.AMS_School school, string RoomId)
 {
     SeatManage.IPocketBespeakBllService.IPocketBespeakBllService pocketBespeak = BespeakServiceConnProxy.BespeakServiceConnProxy.CreateChannelPocketBespeakBllService(school.ConnectionString);
     try
     {
         return(pocketBespeak.GetReadingRoomSeatList(RoomId));
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         ICommunicationObject ICommObjectService = pocketBespeak as ICommunicationObject;
         try
         {
             if (ICommObjectService.State == CommunicationState.Faulted)
             {
                 ICommObjectService.Abort();
             }
             else
             {
                 ICommObjectService.Close();
             }
         }
         catch
         {
             ICommObjectService.Abort();
         }
     }
 }
Example #4
0
 private static void CloseCommunicationObject(Object obj, bool aborted, TimeSpan timeout)
 {
     if (obj != null)
     {
         ICommunicationObject co = obj as ICommunicationObject;
         if (co != null)
         {
             if (aborted)
             {
                 try
                 {
                     co.Abort();
                 }
                 catch (CommunicationException)
                 {
                 }
             }
             else
             {
                 co.Close(timeout);
             }
         }
         else if (obj is IDisposable)
         {
             ((IDisposable)obj).Dispose();
         }
     }
 }
 public void Dispose()
 {
     if (CommunicationObject == null)
     {
         return;
     }
     try {
         if (CommunicationObject.State != CommunicationState.Faulted)
         {
             CommunicationObject.Close();
         }
         else
         {
             CommunicationObject.Abort();
         }
     } catch (CommunicationException ce) {
         CommunicationObject.Abort();
     } catch (TimeoutException toe) {
         CommunicationObject.Abort();
     } catch (Exception e) {
         CommunicationObject.Abort();
         //Perhaps log this
     } finally {
         CommunicationObject = null;
     }
 }
Example #6
0
        /// <summary>
        /// 设置已读
        /// </summary>
        /// <param name="modelList"></param>
        /// <returns></returns>
        public static string SetReaderNoteRead(List <ReaderNoticeInfo> modelList)
        {
            IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
            bool error = false;

            try
            {
                return(seatService.SetReaderNoteRead(modelList));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManageComm.WriteLog.Write("获取通知记录失败:" + ex.Message);
                return("设置失败");
            }
            finally
            {
                ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Example #7
0
        /// <summary>
        /// 获取通知记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static List <ReaderNoticeInfo> GetReaderNoticeByCardNoStatus(string cardNo, EnumType.LogStatus logReadStatus)
        {
            IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
            bool error = false;

            try
            {
                return(seatService.GetReaderNoticeByCardNoStatus(cardNo, logReadStatus));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManageComm.WriteLog.Write("获取通知记录失败:" + ex.Message);
                return(new List <ReaderNoticeInfo>());
            }
            finally
            {
                ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
 /// <summary>
 /// 添加广告
 /// </summary>
 /// <param name="adInfo"></param>
 /// <returns></returns>
 public static string AddAdModel(SeatManage.ClassModel.AMS_Advertisement adInfo)
 {
     IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
     try
     {
         return(seatService.AddAdModel(adInfo));
     }
     catch (FaultException ex)
     {
         SeatManageComm.WriteLog.Write("添加广告失败:" + ex.Message);
         return(ex.Message);
     }
     finally
     {
         ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
         try
         {
             if (ICommObjectService.State == CommunicationState.Faulted)
             {
                 ICommObjectService.Abort();
             }
             else
             {
                 ICommObjectService.Close();
             }
         }
         catch
         {
             ICommObjectService.Abort();
         }
     }
 }
Example #9
0
        /// <summary>
        /// Safely closes a service client connection.
        /// </summary>
        /// <param name="myServiceClient">The client connection to close.</param>
        public static void CloseConnection(this ICommunicationObject myServiceClient)
        {
            if (myServiceClient.State != CommunicationState.Opened)
            {
                return;
            }

            try
            {
                myServiceClient.Close();
            }
            catch (CommunicationException ex)
            {
                Debug.Print(ex.ToString());
                myServiceClient.Abort();
            }
            catch (TimeoutException ex)
            {
                Debug.Print(ex.ToString());
                myServiceClient.Abort();
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
                myServiceClient.Abort();
                throw;
            }
        }
 /// <summary>
 /// 获取单个记录
 /// </summary>
 /// <param name="AdNum"></param>
 /// <param name="adType"></param>
 /// <returns></returns>
 public static SeatManage.ClassModel.AMS_AdvertUsage GetAdvertUsage(string AdNum, SeatManage.EnumType.AdType adType)
 {
     IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
     try
     {
         return(seatService.GetAdvertUsage(AdNum, adType));
     }
     catch (FaultException ex)
     {
         SeatManageComm.WriteLog.Write("获取广告状态失败:" + ex.Message);
         return(null);
     }
     finally
     {
         ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
         try
         {
             if (ICommObjectService.State == CommunicationState.Faulted)
             {
                 ICommObjectService.Abort();
             }
             else
             {
                 ICommObjectService.Close();
             }
         }
         catch
         {
             ICommObjectService.Abort();
         }
     }
 }
 /// <summary>
 /// 获取有效的广告列表
 /// </summary>
 /// <param name="isOverTime"></param>
 /// <param name="adType"></param>
 /// <returns></returns>
 public static List <SeatManage.ClassModel.AMS_Advertisement> GetAdList(bool?isOverTime, SeatManage.EnumType.AdType adType)
 {
     IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
     try
     {
         return(seatService.GetAdList(isOverTime, adType));
     }
     catch (FaultException ex)
     {
         SeatManageComm.WriteLog.Write("获取广告列表失败:" + ex.Message);
         return(new List <AMS_Advertisement>());
     }
     finally
     {
         ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
         try
         {
             if (ICommObjectService.State == CommunicationState.Faulted)
             {
                 ICommObjectService.Abort();
             }
             else
             {
                 ICommObjectService.Close();
             }
         }
         catch
         {
             ICommObjectService.Abort();
         }
     }
 }
 /// <summary>
 /// Stops a WCF client.
 /// </summary>
 /// <param name="client">The client to stop.</param>
 public static void StopWcfClient(ICommunicationObject client)
 {
     if (client != null)
     {
         try
         {
             client.Close();
         }
         catch (CommunicationException)
         {
             // ignore, it's expected to be in a faulted state in case the connection
             // isn't there anymore; theoretically we could only listen on a CommunicationObjectFaultedException,
             // but there might be other communication exceptions that could occur during closing the client
         }
         IDisposable events;
         if (_faultedEvents.TryRemove(client, out events))
         {
             events.Dispose();
         }
         IDisposable keepAlive;
         if (_keepAlives.TryRemove(client, out keepAlive))
         {
             keepAlive.Dispose();
         }
     }
 }
        /// <summary>
        /// 更新设备状态
        /// </summary>
        /// <param name="deviceNo"></param>
        /// <param name="stateUpdateTime"></param>
        /// <returns></returns>
        public static Model.Enum.HandleResult UpdateDeviceStatus(string deviceNo, DateTime stateUpdateTime)
        {
            AMS.IBllService.IAdvertManageBllService bllService = AMS.ServiceConnectChannel.AdvertManageBllServiceChannel.CreateServiceChannel();
            bool error = false;

            try
            {
                return(bllService.UpdateDeviceStatus(deviceNo, stateUpdateTime));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManage.SeatManageComm.WriteLog.Write(string.Format("更新设备状态遇到错误,异常来自:{0};信息:{1}", ex.Source, ex.Message));
                throw ex;
            }
            finally
            {
                ICommunicationObject ICommObjectService = bllService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
        /// <summary>
        /// 根据设备id查找设备
        /// </summary>
        /// <param name="No"></param>
        /// <returns></returns>
        public static Model.AMS_Device GetDevicebyID(int id)
        {
            AMS.IBllService.IAdvertManageBllService bllService = AMS.ServiceConnectChannel.AdvertManageBllServiceChannel.CreateServiceChannel();
            bool error = false;

            try
            {
                return(bllService.GetDevicebyID(id));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManage.SeatManageComm.WriteLog.Write(string.Format("根据id查看设备信息遇到错误,异常来自:{0};信息:{1}", ex.Source, ex.Message));
                throw ex;
            }
            finally
            {
                ICommunicationObject ICommObjectService = bllService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
        /// <summary>
        /// 获取包含Md5的信息
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static FileSliceInfo GetFilesSlice(string fileName, SeatManageSubsystem system)
        {
            IFileTransportService fileTransport = AMS.ServiceConnectChannel.AdvertManageBllServiceChannel.CreateChannelFileTransportService();

            try
            {
                return(fileTransport.GetFilesSliceInfo(fileName, system));
            }
            catch (Exception ex)
            {
                WriteLog.Write(string.Format("获取包含Md5的文件片段信息失败,异常信息:{0}", ex.Message));
                throw ex;
            }
            finally
            {
                ICommunicationObject ICommObjectService = fileTransport as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Example #16
0
        /// <summary>
        ///  Clean up and close proxy.
        /// </summary>
        public virtual void CloseProxy()
        {
            if (proxy != null)
            {
                proxy.Cleanup();
                ICommunicationObject channel = proxy as ICommunicationObject;
                if (channel != null)
                {
                    try
                    {
                        channel.Close();
                    }
                    catch (TimeoutException)
                    {
                        channel.Abort();
                    }
                    catch (CommunicationException)
                    {
                        channel.Abort();
                    }
                }

                proxy = null;
            }
        }
Example #17
0
        static void Main(string[] args)
        {
            TrustAllCertificates();

            Console.WriteLine("Enter a string to reverse, then press <ENTER>");
            string userInputString = Console.ReadLine();

            Console.WriteLine();

            string acsUsernameEndpoint = String.Format("https://{0}.{1}/v2/wstrust/13/username", SamplesConfiguration.ServiceNamespace, SamplesConfiguration.AcsHostUrl);

            ChannelFactory <IStringService> stringServiceFactory = CreateChannelFactory(acsUsernameEndpoint, ServiceAddress);
            IStringService       stringService = stringServiceFactory.CreateChannel();
            ICommunicationObject channel       = (ICommunicationObject)stringService;

            try
            {
                string outputString = stringService.Reverse(userInputString);

                Console.WriteLine("Service responded with: " + outputString);
                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to exit");
                Console.ReadLine();

                channel.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception thrown during execution: " + e.ToString());
                channel.Abort();
            }
        }
Example #18
0
        /// <summary>
        /// 根据学号获取读者最后一条等待记录。
        /// 如果房间号为空,则不根据房间号查询。
        /// </summary>
        /// <param name="cardNo">学号</param>
        /// <param name="roomNum">要查询的房间号</param>
        /// <returns></returns>
        public static WaitSeatLogInfo GetListWaitLogByCardNo(string cardNo, string roomNum)
        {
            IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
            bool error = false;

            try
            {
                return(seatService.GetListWaitLogByCardNo(cardNo, roomNum));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManageComm.WriteLog.Write("获取等待记录失败:" + ex.Message);
                return(null);
            }
            finally
            {
                ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Example #19
0
        /// <summary>
        /// 更新读者通知状态
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static EnumType.HandleResult UpdateReaderNotice(ReaderNoticeInfo model)
        {
            IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
            bool error = false;

            try
            {
                return(seatService.UpdateReaderNotice(model));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManageComm.WriteLog.Write("更新读者状态失败:" + ex.Message);
                return(EnumType.HandleResult.Failed);
            }
            finally
            {
                ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Example #20
0
        /// <summary>
        /// 添加等待记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int AddWaitSeatLog(WaitSeatLogInfo model)
        {
            IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
            bool error = false;

            try
            {
                return(seatService.AddWaitLog(model));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManageComm.WriteLog.Write("添加等待记录失败:" + ex.Message);
                return(-1);
            }
            finally
            {
                ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
        /// <summary>
        /// 根据学校编号获取设备列表
        /// </summary>
        /// <param name="schoolNum"></param>
        /// <param name="flag">表示是否获取更新的</param>
        /// <returns></returns>
        public static List <Model.AMS_Device> GeDeviceModelBySchoolNum(string schoolNum, bool flag)
        {
            AMS.IBllService.IAdvertManageBllService bllService = AMS.ServiceConnectChannel.AdvertManageBllServiceChannel.CreateServiceChannel();
            bool error = false;

            try
            {
                return(bllService.GeDeviceModelBySchoolNum(schoolNum, flag));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManage.SeatManageComm.WriteLog.Write(string.Format("根据学校编号获取设备列表遇到错误,异常来自:{0};信息:{1}", ex.Source, ex.Message));
                throw ex;
            }
            finally
            {
                ICommunicationObject ICommObjectService = bllService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Example #22
0
 public string SubmitStudyLog(AMS.Model.AMS_School school, ClassModel.StudyBookingLog logModel)
 {
     SeatManage.IPocketBespeakBllService.IPocketBespeakBllService pocketBespeak = BespeakServiceConnProxy.BespeakServiceConnProxy.CreateChannelPocketBespeakBllService(school.ConnectionString);
     try
     {
         return(pocketBespeak.SubmitStudyLog(logModel));
     }
     catch (Exception ex)
     {
         throw new RemoteServiceLinkFailed(ex.Message);
     }
     finally
     {
         ICommunicationObject ICommObjectService = pocketBespeak as ICommunicationObject;
         try
         {
             if (ICommObjectService.State == CommunicationState.Faulted)
             {
                 ICommObjectService.Abort();
             }
             else
             {
                 ICommObjectService.Close();
             }
         }
         catch
         {
             ICommObjectService.Abort();
         }
     }
 }
        public static void CloseProxy <I>(I instance) where I : class
        {
            ICommunicationObject proxy = instance as ICommunicationObject;

            Debug.Assert(proxy != null);
            proxy.Close();
        }
        /// <summary>
        /// 文件上传断点续传
        /// </summary>
        /// <param name="fileName">文件名称</param>
        /// <param name="fileByte">文件流</param>
        /// <param name="Length">文件大小</param>
        /// <param name="Offset">偏移量</param>
        /// <returns></returns>
        public static bool FileDelete(string file, SeatManageSubsystem system)
        {
            IFileTransportService fileTransport = WcfAccessProxy.ServiceProxy.CreateChannelFileTransportService();
            bool isError = false;

            try
            {
                return(fileTransport.DeleteFile(file, system));
            }
            catch (Exception ex)
            {
                isError = true;
                WriteLog.Write(string.Format("文件删除出错,异常信息:{0}", ex.Message));
                return(false);
            }
            finally
            {
                ICommunicationObject ICommObjectService = fileTransport as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
        /// <summary>
        ///删除播放列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static EnumType.HandleResult DeletePlaylist(SeatManage.ClassModel.AMS_PlayList model)
        {
            IWCFService.ISeatManageService seatService = WcfAccessProxy.ServiceProxy.CreateChannelSeatManageService();
            bool error = false;

            try
            {
                return(seatService.DeletePlaylist(model));
            }
            catch (Exception ex)
            {
                error = true;
                SeatManageComm.WriteLog.Write("删除播放列表失败:" + ex.Message);
                return(EnumType.HandleResult.Failed);
            }
            finally
            {
                ICommunicationObject ICommObjectService = seatService as ICommunicationObject;
                try
                {
                    if (ICommObjectService.State == CommunicationState.Faulted)
                    {
                        ICommObjectService.Abort();
                    }
                    else
                    {
                        ICommObjectService.Close();
                    }
                }
                catch
                {
                    ICommObjectService.Abort();
                }
            }
        }
Example #26
0
        public T2 PerformRemote <T, T2>(Func <T, T2> action)
        {
            var tType    = typeof(T);
            var endpoint = GetEndpointNameAddressPair(tType);

            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
            T arg = FactoryManager.CreateChannel <T>(endpoint.Key, endpoint.Value);
            ICommunicationObject obj2 = (ICommunicationObject)arg;
            bool succeeded            = false;

            try
            {
                if (obj2.State == CommunicationState.Faulted)
                {
                    throw new Exception("Error connecting to wcf.");
                }
                T2 res = action(arg);
                obj2.Close();
                succeeded = true;
                return(res);
            }
            catch (Exception ex)
            {
                ErrorHandler.LogException(ex);
                throw;
            }
            finally
            {
                if (!succeeded)
                {
                    obj2.Abort();
                }
            }
        }
Example #27
0
        public static void Using <T>(this T client, Action <T> work) where T : ShortcutCarouselService.IShortcutCarouselService
        {
            ICommunicationObject service = client as ICommunicationObject;

            if (service != null)
            {
                try
                {
                    work(client);
                    service.Close();
                }
                catch (CommunicationException)
                {
                    service.Abort();
                }
                catch (TimeoutException)
                {
                    service.Abort();
                }
                catch (Exception)
                {
                    service.Abort();
                    throw;
                }
            }
            else
            {
                work(client);
            }
        }
        public static void CloseCommunicationObject(ICommunicationObject communicationObject, TimeSpan timeout)
        {
            if (communicationObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("communicationObject");
            }

            bool flag = true;
            try
            {
                if (communicationObject.State == CommunicationState.Opened)
                {
                    communicationObject.Close(timeout);
                    flag = false;
                }
            }
            catch (CommunicationException communicatioException)
            {
                DiagnosticUtility.TraceHandledException(communicatioException, TraceEventType.Information);
            }
            catch (TimeoutException timeoutException)
            {
                DiagnosticUtility.TraceHandledException(timeoutException, TraceEventType.Information);
            }
            finally
            {
                if (flag)
                {
                    communicationObject.Abort();
                }
            }
        }
        /// <summary>Disposes the service client. </summary>
        /// <param name="service">The service client. </param>
        /// <param name="isDisposed">The reference to a value indicating whether the service is disposed. </param>
        public static void Dispose(ICommunicationObject service, ref bool isDisposed)
        {
            if (isDisposed)
                return;

            try
            {
                if (service.State == CommunicationState.Faulted)
                    service.Abort();
                else
                {
                    try
                    {
                        service.Close();
                    }
                    catch (Exception closeException)
                    {
                        try
                        {
                            service.Abort();
                        }
                        catch (Exception abortException)
                        {
                            throw new AggregateException(closeException, abortException);
                        }
                        throw;
                    }
                }
            }
            finally
            {
                isDisposed = true;
            }
        }
Example #30
0
 static void ActivateFirstInstance()
 {
    NetNamedPipeBinding binding = new NetNamedPipeBinding();
    IActivationMonitor monitor = ChannelFactory<IActivationMonitor>.CreateChannel(binding,new EndpointAddress(MonitorServiceAddress));
    monitor.ActivateApplication();
    ICommunicationObject proxy = monitor as ICommunicationObject;
    proxy.Close();
 }
Example #31
0
        public static void CloseConnection(ICommunicationObject serviceClient, string exceptionMessage = null, string currentMethod = null)
        {
            if (exceptionMessage == null && currentMethod == null)
            {
                //Attempt to close the WCF connection normally:
                #region Close the connection & handle any potential exceptions

                try
                {
                    serviceClient.Close();
                    //TODO: Log: error message for WCF connection closure
                }
                catch (CommunicationException e)
                {
                    var error = e.Message;
                    serviceClient.Abort();
                    //TODO: Log: error message for WCF connection closure
                }
                catch (TimeoutException e)
                {
                    var error = e.Message;
                    serviceClient.Abort();
                    //TODO: Log: error message for WCF connection closure
                }
                catch (Exception e)
                {
                    var error = e.Message;
                    serviceClient.Abort();
                    //TODO: Log: error message for WCF connection closure
                }

                #endregion
            }
            else
            {
                //An exception occured while using the WCF connection, abort and handle the exception:
                #region Abort connection and handle the exception

                serviceClient.Abort();


                string error  = exceptionMessage.ToString();
                string method = String.Empty;
                try
                {
                    method = currentMethod.ToString();
                }
                catch
                {
                }


                //TODO: Log: error message for WCF exception with error and method

                #endregion
            }
        }
Example #32
0
        /// <summary>
        /// 关闭Channel
        /// </summary>
        /// <param name="channel">channel</param>
        public static void DoClose(this ICommunicationObject channel)
        {
            if (channel == null)
            {
                return;
            }

            switch (channel.State)
            {
            case CommunicationState.Faulted:
                try
                {
                    //string msg = "WCFChannelHelper:CloseChannel Faulted 调用 channel.Abort";
                    //LogHelper.WriteDebug(msg);
                    channel.Abort();
                }
                catch (Exception ex)
                {
                    //LogHelper.WriteError(ex.Message, ex);
                }
                break;

            case CommunicationState.Closed:
            case CommunicationState.Closing:
                break;

            default:
                //Closing 指示通信对象正转换到 Closed 状态。 Closed 指示通信对象已关闭,且不再可用。
                try
                {
                    channel.Close();

                    //string msg = "WCFChannelHelper:CloseChannel";
                    //LogHelper.WriteDebug(msg);
                }
                catch (CommunicationException ex)
                {
                    //状态为 Faulted 的对象并没有关闭,可能仍在占用资源。应该使用 Abort 方法来关闭出错的对象。
                    // 如果对状态为 Faulted 的对象调用 Close,则会引发 CommunicationObjectFaultedException,这是因为没有正常关闭对象。
                    //string msg = "WCFChannelHelper.DoClose,调用channel.Abort " + ex.Message;
                    //LogHelper.WriteDebug(msg);
                    channel.Abort();
                }
                catch (TimeoutException ex)
                {
                    //string msg = "WCFChannelHelper.DoClose,调用channel.Abort " + ex.Message;
                    //LogHelper.WriteDebug(msg);
                    channel.Abort();
                }
                catch (Exception ex)
                {
                    //LogHelper.WriteError("DoClose:" + ex.Message, ex);
                    channel.Abort();
                }
                break;
            }
        }
Example #33
0
 public static void CloseClient(ICommunicationObject client)
 {
     if (client != null && client.State == CommunicationState.Faulted)
     {
         client.Abort();
     }
     else
     {
         client.Close();
     }
 }
Example #34
0
 private void CloseProxy(ICommunicationObject proxy)
 {
     if (proxy == null)
     {
         throw new ArgumentNullException();
     }
     if (proxy.State == CommunicationState.Faulted)
     {
         proxy.Abort();
     }
     else
     {
         proxy.Close();
     }
 }
Example #35
0
 private static void CloseClient(ICommunicationObject client)
 {
     if (client.State == CommunicationState.Opened)
     {
         try
         {
             client.Close();
         }
         catch (CommunicationException)
         {
             client.Abort();
         }
         catch (TimeoutException)
         {
             client.Abort();
         }
     }
 }
 public static void Close(ICommunicationObject co)
 {
     if (co == null)
     {
         return;
     }
     try
     {
         switch (co.State)
         {
             case CommunicationState.Closed:
             case CommunicationState.Closing:
                 break;
             case CommunicationState.Faulted:
                 co.Abort();
                 break;
             case CommunicationState.Created:
             case CommunicationState.Opened:
             case CommunicationState.Opening:
                 co.Close();
                 break;
             default:
                 co.Abort();
                 break;
         }
     }
     catch (Exception e)
     {
         s_Logger.Fatal(co, e);
         // ReSharper disable EmptyGeneralCatchClause
         try
         {
             co.Abort();
         }
         catch
         {
         }
         // ReSharper restore EmptyGeneralCatchClause
     }
 }
 /// <summary>
 /// </summary>
 /// <param name="channel">
 /// The channel.
 /// </param>
 private static void CloseChannel(ICommunicationObject channel)
 {
     try
     {
         channel.Close();
     }
     catch (Exception ex)
     {
         throw;
     }
     finally
     {
         channel.Abort();
     }
 }
Example #38
0
        private void CleanupCommunicationObject(ICommunicationObject communicationObject)
        {
            if (communicationObject != null)
            {
                communicationObject.Faulted -= CommunicationObject_Faulted;
                communicationObject.Closing -= CommunicationObject_Closing;

                if (communicationObject.State == CommunicationState.Faulted)
                {
                    communicationObject.Abort();
                }
                else
                {
                    communicationObject.Close();
                }
            }
        }
Example #39
0
        public void CloseOrAbortServiceChannel( ICommunicationObject communicationObject )
        {
            var isClosed = false;

            if (communicationObject == null || communicationObject.State == CommunicationState.Closed)
            {
                return;
            }

            try
            {
                if (communicationObject.State == CommunicationState.Faulted)
                {
                    return;
                }
                communicationObject.Close();
                isClosed = true;
            }
            catch (CommunicationException)
            {
                // Catch this expected exception so it is not propagated further.
                // Perhaps write this exception out to log file for gathering statistics...
            }
            catch (TimeoutException)
            {
                // Catch this expected exception so it is not propagated further.
                // Perhaps write this exception out to log file for gathering statistics...
            }
            finally
            {
                // If State was Faulted or any exception occurred while doing the Close(), then do an Abort()
                if (!isClosed)
                {
                    AbortServiceChannel(communicationObject);
                }
            }
        }
 private static void Close(ICommunicationObject client)
 {
     try
     {
         if (client.State != CommunicationState.Faulted)
         {
             client.Close();
         }
     }
     finally
     {
         if (client.State != CommunicationState.Closed)
         {
             client.Abort();
         }
     }
 }
 /// <summary>
 /// Tries to gracefully close communication object.
 /// </summary>        
 private static void TryCloseCommunicationObject(ICommunicationObject commObj)
 {
     if (commObj.State == CommunicationState.Faulted)
     {
         commObj.Abort();
     }
     else if (commObj.State != CommunicationState.Closed)
     {
         try
         {
             commObj.Close();
         }
         catch (CommunicationException)
         {
             commObj.Abort();
         }
     }
 }
 /// <summary>
 /// Closes the specified communication object, calling the
 /// <see cref="ICommunicationObject.Abort"/> method if it is in the faulted state.
 /// </summary>
 /// <param name="co">The communication object to close.</param>
 protected void SafeClose(ICommunicationObject co)
 {
     if (co == null)
         return;
     if (co.State == CommunicationState.Faulted)
         co.Abort();
     else
         co.Close();
 }
Example #43
0
 private void CloseProxy(ICommunicationObject proxy)
 {
     if (proxy != null)
     {
         if (proxy.State == CommunicationState.Faulted)
         {
             proxy.Abort();
         }
         else
         {
             proxy.Close();
         }
     }
 }