Пример #1
0
        public static HandleInfo Deserialize(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            BinaryReader br   = new BinaryReader(stream);
            HandleInfo   info = new HandleInfo();

            if (!MalockMessage.StreamIsReadable(stream, sizeof(bool)))
            {
                return(null);
            }
            info.Available = br.ReadBoolean();
            string s;

            if (!MalockMessage.TryFromStringInReadStream(br, out s))
            {
                return(null);
            }
            info.Key = s;
            if (!MalockMessage.TryFromStringInReadStream(br, out s))
            {
                return(null);
            }
            info.Identity = s;
            return(info);
        }
Пример #2
0
 public static bool Fill(IList <HandleInfo> s, Stream stream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (s == null)
     {
         throw new ArgumentNullException("s");
     }
     try
     {
         BinaryReader br    = new BinaryReader(stream);
         int          count = br.ReadInt32();
         for (int i = 0; i < count; i++)
         {
             HandleInfo info = HandleInfo.Deserialize(stream);
             s.Add(info);
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
        protected internal virtual bool TryGetAllInfo(int timeout, out IEnumerable <HandleInfo> infos, ref Exception exception)
        {
            IList <HandleInfo> out_infos     = emptryhandleinfos;
            Exception          out_exception = null;

            try
            {
                if (timeout <= 0 && timeout != -1)
                {
                    out_exception = EventWaitHandle.NewTimeoutException();
                    return(false);
                }
                using (ManualResetEvent events = new ManualResetEvent(false))
                {
                    bool success = false;
                    bool abort   = false;
                    if (!MalockMessage.TryInvokeAsync(this, MalockNodeMessage.New(null, this.Identity,
                                                                                  MalockNodeMessage.CLIENT_COMMAND_GETALLINFO, timeout), timeout,
                                                      (errno, message, stream) =>
                    {
                        if (errno == MalockMessage.Mappable.ERROR_NOERROR)
                        {
                            if (message.Command == MalockNodeMessage.CLIENT_COMMAND_GETALLINFO)
                            {
                                out_infos = new List <HandleInfo>();
                                success = HandleInfo.Fill(out_infos, stream);
                            }
                        }
                        else if (errno == MalockMessage.Mappable.ERROR_ABORTED)
                        {
                            abort = true;
                        }
                        else if (errno == MalockMessage.Mappable.ERROR_TIMEOUT)
                        {
                            out_exception = EventWaitHandle.NewTimeoutException();
                        }
                        events.Set();
                    }, ref out_exception) || out_exception != null)
                    {
                        return(false);
                    }
                    events.WaitOne();
                    if (abort)
                    {
                        out_exception = EventWaitHandle.NewAbortedException();
                        return(false);
                    }
                    return(success);
                }
            }
            finally
            {
                infos     = out_infos;
                exception = out_exception;
            }
        }
Пример #4
0
 protected internal virtual void GetAllInfoAsync(int timeout, Action <int, IEnumerable <HandleInfo> > state)
 {
     if (state == null)
     {
         throw new ArgumentNullException("callback");
     }
     if (timeout <= 0 && timeout != -1)
     {
         state(kERROR_TIMEOUT, emptryhandleinfos);
     }
     else
     {
         Exception exception = null;
         if (!MalockMessage.TryInvokeAsync(this,
                                           MalockNodeMessage.New(null, this.Identity, MalockNodeMessage.CLIENT_COMMAND_GETALLINFO, timeout), timeout,
                                           (errno, message, stream) =>
         {
             if (errno == MalockMessage.Mappable.ERROR_NOERROR)
             {
                 bool error = true;
                 if (message.Command == MalockNodeMessage.CLIENT_COMMAND_GETALLINFO)
                 {
                     IList <HandleInfo> results = new List <HandleInfo>();
                     if (HandleInfo.Fill(results, stream))
                     {
                         error = false;
                         state(kERROR_NOERROR, results);
                     }
                 }
                 if (error)
                 {
                     state(kERROR_ERRORNO, emptryhandleinfos);
                 }
             }
             else if (errno == MalockMessage.Mappable.ERROR_ABORTED)
             {
                 state(kERROR_ABORTED, emptryhandleinfos);
             }
             else if (errno == MalockMessage.Mappable.ERROR_TIMEOUT)
             {
                 state(kERROR_TIMEOUT, emptryhandleinfos);
             }
         }, ref exception))
         {
             state(kERROR_ABORTED, emptryhandleinfos);
         }
     }
 }