Пример #1
0
        internal void Save()
        {
            if (this.topics.Length > 1000 || this.agents.Length > 1000)
            {
                return;
            }
            long size = this.Size;

            if (size > 1048576L)
            {
                return;
            }
            MemoryMappedFile writableFile = this.GetWritableFile();

            if (writableFile == null)
            {
                return;
            }
            using (MapFileStream mapFileStream = writableFile.CreateView(0, (int)(size + 24L)))
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                byte[]          array           = new byte[24L];
                mapFileStream.Write(array, 0, array.Length);
                mapFileStream.Flush();
                binaryFormatter.Serialize(mapFileStream, this);
                AgentSubscription.Header header = new AgentSubscription.Header(size);
                array = header.GetBytes();
                mapFileStream.Seek(0L, SeekOrigin.Begin);
                mapFileStream.Write(array, 0, array.Length);
                mapFileStream.Flush();
            }
        }
Пример #2
0
        public static AgentSubscription Load(string name)
        {
            MemoryMappedFile readOnlyFile = AgentSubscription.GetReadOnlyFile(name);

            if (readOnlyFile == null)
            {
                return(null);
            }
            AgentSubscription result;

            try
            {
                int num  = 24;
                int num2 = 50;
                do
                {
                    Thread.Sleep(10);
                    result = null;
                    using (MapFileStream mapFileStream = readOnlyFile.CreateView(0, num))
                    {
                        byte[] array = new byte[24L];
                        int    num3  = mapFileStream.Read(array, 0, num);
                        if (num3 == num)
                        {
                            AgentSubscription.Header header = new AgentSubscription.Header(array);
                            if (header.Magic == 96101745125713L && header.PayloadSize > 0L && header.PayloadSize <= 1048576L)
                            {
                                using (MapFileStream mapFileStream2 = readOnlyFile.CreateView(0, num + (int)header.PayloadSize))
                                {
                                    mapFileStream2.Seek((long)num, SeekOrigin.Begin);
                                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                                    try
                                    {
                                        result = (AgentSubscription)binaryFormatter.Deserialize(mapFileStream2);
                                    }
                                    catch (SerializationException)
                                    {
                                        goto IL_137;
                                    }
                                }
                                mapFileStream.Seek(0L, SeekOrigin.Begin);
                                num3 = mapFileStream.Read(array, 0, num);
                                if (num3 == num)
                                {
                                    AgentSubscription.Header header2 = new AgentSubscription.Header(array);
                                    if (header.Magic == header2.Magic && header.PayloadSize == header2.PayloadSize && header.Ticks == header2.Ticks)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    IL_137 :;
                }while (num2-- > 0);
            }
            finally
            {
                readOnlyFile.Close();
            }
            return(result);
        }