/// <summary>
        /// DoCheckForReplay method implementation
        /// </summary>
        public bool DoCheckForReplay(NamedPipeReplayRecord requestor)
        {
            try
            {
                if (OnDecrypt == null)
                {
                    OnDecrypt += PipeClientOnDecrypt;
                }
                if (OnEncrypt == null)
                {
                    OnEncrypt += PipeClientOnEncrypt;
                }

                Task <bool> task = null;

                NamedPipeClientStream ClientStream = new NamedPipeClientStream(_servers[0], "adfsmfaconfig", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation);
                task = Task <bool> .Factory.StartNew(() =>
                {
                    try
                    {
                        ClientStream.Connect();
                        PipeStreamData ss = new PipeStreamData(ClientStream);
                        ss.WriteString(OnEncrypt(Proofkey));
                        if (OnDecrypt(ss.ReadString()) == Proofkey)
                        {
                            NamedPipeNotificationReplayRecord xdata = new NamedPipeNotificationReplayRecord(requestor);
                            ss.WriteData(ObjectToByteArray(xdata));
                            return(ByteArrayToObject <bool>(ss.ReadData()));
                        }
                    }
                    catch (IOException e)
                    {
                        LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8888);
                        ClientStream.Close();
                    }
                    finally
                    {
                        ClientStream.Close();
                    }
                    return(false);
                });

                task.Wait();
                return(task.Result);
            }
            catch (Exception e)
            {
                LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8888);
                return(false);
            }
        }
        /// <summary>
        /// DoCheckForRemoteReplay method implementation
        /// </summary>
        public bool DoCheckForRemoteReplay(NamedPipeNotificationReplayRecord record)
        {
            try
            {
                if (_servers.Count > 0)
                {
                    if (OnDecrypt == null)
                    {
                        OnDecrypt += PipeClientOnDecrypt;
                    }
                    if (OnEncrypt == null)
                    {
                        OnEncrypt += PipeClientOnEncrypt;
                    }

                    record.MustDispatch = false;

                    Task <bool>[] tasks = new Task <bool> [_servers.Count];
                    for (int i = 0; i <= _servers.Count - 1; i++)
                    {
                        string servername = _servers[i];
                        tasks[i] = Task <bool> .Factory.StartNew((svr) =>
                        {
                            NamedPipeClientStream ClientStream = new NamedPipeClientStream(svr.ToString(), "adfsmfaconfig", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation);
                            try
                            {
                                ClientStream.Connect();
                                PipeStreamData ss = new PipeStreamData(ClientStream);
                                ss.WriteString(OnEncrypt(Proofkey));
                                if (OnDecrypt(ss.ReadString()) == Proofkey)
                                {
                                    ss.WriteData(ObjectToByteArray(record));
                                    return(ByteArrayToObject <bool>(ss.ReadData()));
                                }
                            }
                            catch (IOException e)
                            {
                                LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8888);
                                ClientStream.Close();
                            }
                            finally
                            {
                                ClientStream.Close();
                            }
                            return(false);
                        }, servername);
                    }
                    Task.WaitAll(tasks);
                    foreach (Task <bool> ts in tasks)
                    {
                        if (!ts.Result)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                LogForSlots.WriteEntry("PipeClient Error : " + e.Message, EventLogEntryType.Error, 8888);
                return(false);
            }
        }
        /// <summary>
        /// PipeServerConfigThread method implmentation
        /// </summary>
        private void PipeServerConfigThread(object data)
        {
            int threadId = Thread.CurrentThread.ManagedThreadId;

            try
            {
                while (!MustExit)
                {
                    ConfigPipeServer.WaitForConnection();
                    try
                    {
                        PipeStreamData ss = new PipeStreamData(ConfigPipeServer);
                        if (OnDecrypt(ss.ReadString()) == this.Proofkey)
                        {
                            ss.WriteString(this.OnEncrypt(Proofkey));
                            object obj = ByteArrayToObject <object>(ss.ReadData());

                            if (obj is NamedPipeReloadConfigRecord)
                            {
                                NamedPipeReloadConfigRecord encrypted = (NamedPipeReloadConfigRecord)obj;
                                bool b = false;
                                if (OnReloadConfiguration != null)
                                {
                                    b = OnReloadConfiguration(encrypted.Requestor, OnDecrypt(encrypted.Message));
                                    ss.WriteData(ObjectToByteArray <bool>(b));
                                }
                            }
                            else if (obj is NamedPipeServerConfigRecord)
                            {
                                NamedPipeServerConfigRecord encrypted = (NamedPipeServerConfigRecord)obj;
                                NamedPipeRegistryRecord     reg;
                                if (OnRequestServerConfiguration != null)
                                {
                                    reg = OnRequestServerConfiguration(encrypted.Requestor);
                                    ss.WriteData(ObjectToByteArray <NamedPipeRegistryRecord>(reg));
                                }
                            }
                            else if (obj is NamedPipeNotificationReplayRecord)
                            {
                                NamedPipeNotificationReplayRecord encrypted = (NamedPipeNotificationReplayRecord)obj;
                                bool b = false;
                                if (OnCheckForReplay != null)
                                {
                                    b = OnCheckForReplay(encrypted);
                                    if ((b) && (encrypted.MustDispatch))
                                    {
                                        bool c = false;
                                        if (OnCheckForRemoteReplay != null)
                                        {
                                            c = OnCheckForRemoteReplay(encrypted);
                                            ss.WriteData(ObjectToByteArray <bool>(c));
                                        }
                                        else
                                        {
                                            ss.WriteData(ObjectToByteArray <bool>(b));
                                        }
                                    }
                                    else if ((b) && (!encrypted.MustDispatch))
                                    {
                                        ss.WriteData(ObjectToByteArray <bool>(true));
                                    }
                                    else
                                    {
                                        ss.WriteData(ObjectToByteArray <bool>(false));
                                    }
                                }
                            }
                        }
                    }
                    catch (IOException e)
                    {
                        LogForSlots.WriteEntry("PipeServer Error : " + e.Message, EventLogEntryType.Error, 8888);
                        ConfigPipeServer.Close();
                    }
                    finally
                    {
                        ConfigPipeServer.WaitForPipeDrain();
                        ConfigPipeServer.Disconnect();
                    }
                }
            }
            finally
            {
                ConfigPipeServer.Close();
            }
        }