示例#1
0
        private static Logbook LoadLogbook(Store s, ulong seq)
        {
            // The record isn't authoritive. Don't bother checking.
            // if(!s.MasterInfo.LogbookSequence.Contains(seq)) return new Logbook(s.MasterInfo.MemberId, seq);
            var file = Path.Combine(_dataDir, LogbookFilename(s.MemberId, seq));

            if (File.Exists(file))
            {
                try {
                    using (Stream input = File.OpenRead(file)) {
                        //check header
                        byte[] buf = new byte[8];
                        input.ReadFully(buf);
                        if (buf.SequenceEqual(_logHeader))
                        {
                            //deserialize
                            using (DSReader rdr = new DSReader(input, true)) {
                                return(new Logbook(Premitives.StoragePremitive.Parse(rdr), new LinkedList <object>()));
                            }
                        }
                    }
                } catch (IOException) {
                    //Fall through.
                }
            }
            var newBook = new Logbook(s.MemberId, seq);

            s._dirtyLogbooks.Add(newBook);
            return(newBook);
        }
示例#2
0
        public List(DSReader input)
        {
            var fcount = input.Read7bUInt();

            for (uint i = 0; i < fcount; i++)
            {
                var v = Parse(input);
                data.Add((T)v);
            }
        }
示例#3
0
        public Compound(DSReader input)
        {
            var fcount = input.Read7bUInt();

            for (uint i = 0; i < fcount; i++)
            {
                var id    = input.Read7bUInt();
                var value = Parse(input);
                fields[id] = value;
            }
        }
示例#4
0
        public DsDictionary(DSReader input)
        {
            var fcount = input.Read7bUInt();

            for (uint i = 0; i < fcount; i++)
            {
                var k = Parse(input);
                var v = Parse(input);
                data.Add(new KeyValuePair <TKey, TValue>((TKey)k, (TValue)v));
            }
        }
示例#5
0
        internal static void SwitchMember(string memberId)
        {
            if (Current?.MemberId == memberId)
            {
                return;
            }
            Current?.SaveData();

            if (!_evRegistered)
            {
                _evRegistered = true;
                System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => System.Windows.Application.Current.Exit += (s, e) => Current?.SaveData()));
            }

            Store store;

            if (!_ds.ContainsKey(memberId) || !_ds[memberId].TryGetTarget(out store))
            {
                var masterTable = Path.Combine(_dataDir, MasterTableFilename(memberId));
                if (File.Exists(masterTable))
                {
                    try {
                        using (Stream input = File.OpenRead(masterTable)) {
                            byte[] buf = new byte[8];
                            input.ReadFully(buf);
                            if (buf.SequenceEqual(_masterHeader))
                            {
                                //deserialize
                                using (DSReader rdr = new DSReader(input, true)) {
                                    store = new Store(Premitives.StoragePremitive.Parse(rdr), new LinkedList <object>());
                                    goto register;
                                }
                            }
                        }
                    } catch (IOException) { }
                }
                store = new Store(memberId);

register:
                if (_onDataStoreCreate != null)
                {
                    _onDataStoreCreate(store);
                }
                _ds.Add(memberId, new WeakReference <Store>(store));
            }

            Current = store;
            if (_onDataStoreSwitch != null)
            {
                _onDataStoreSwitch(Current);
            }
        }
示例#6
0
        private static Type MapIdentifierToType(DSReader reader)
        {
            var type = (TypeIdentifier)reader.Read7bUInt();

            switch (type)
            {
            case TypeIdentifier.Blob:
                return(typeof(Blob));

            case TypeIdentifier.Compound:
                return(typeof(Compound));

            case TypeIdentifier.Decimal:
                return(typeof(DsDecimal));

            case TypeIdentifier.Dictionary:
                var kt = MapIdentifierToType(reader);
                var vt = MapIdentifierToType(reader);
                return(typeof(DsDictionary <,>).MakeGenericType(kt, vt));

            case TypeIdentifier.Double:
                return(typeof(DsDouble));

            case TypeIdentifier.Int:
                return(typeof(SignedInteger));

            case TypeIdentifier.List:
                return(typeof(DsList <>).MakeGenericType(MapIdentifierToType(reader)));

            case TypeIdentifier.String:
                return(typeof(DsString));

            case TypeIdentifier.UInt:
                return(typeof(UnsignedInteger));

            case TypeIdentifier.Undefined:
                return(typeof(StoragePremitive));

            default:
                throw new ArgumentException();
            }
        }
示例#7
0
 public DsDouble(DSReader input)
 {
     value = input.ReadDouble();
 }
示例#8
0
 public DsString(DSReader input)
 {
     value = input.ReadString();
 }
示例#9
0
 public Blob(DSReader input)
 {
     data = new byte[(int)input.Read7bUInt()];
     input.ReadFully(data);
 }
 public UnsignedInteger(DSReader input)
 {
     value = input.Read7bUInt();
 }
示例#11
0
 public SignedInteger(DSReader input)
 {
     value = input.Read7bInt();
 }
示例#12
0
 public Decimal(DSReader input)
 {
     value = input.ReadDecimal();
 }
示例#13
0
        private static Func <DSReader, StoragePremitive> MapIdentifierToConstructor(DSReader reader)
        {
            var type = (TypeIdentifier)reader.Read7bUInt();

            switch (type)
            {
            case TypeIdentifier.Blob:
                return(x => new Blob(x));

            case TypeIdentifier.Compound:
                return(x => new Compound(x));

            case TypeIdentifier.Decimal:
                return(x => new DsDecimal(x));

            case TypeIdentifier.Double:
                return(x => new DsDouble(x));

            case TypeIdentifier.Int:
                return(x => new SignedInteger(x));

            case TypeIdentifier.List:
                return(x => {
                    try {
                        return (StoragePremitive)typeof(DsList <>).MakeGenericType(MapIdentifierToType(x)).GetConstructor(new Type[] { typeof(DSReader) }).Invoke(new object[] { x });
                    } catch (System.Reflection.TargetInvocationException e) {
                        if (e.GetBaseException() is System.IO.IOException)
                        {
                            throw new System.IO.IOException("IO Error", e.GetBaseException());
                        }
                        else
                        {
                            throw;
                        }
                    }
                });

            case TypeIdentifier.String:
                return(x => new DsString(x));

            case TypeIdentifier.UInt:
                return(x => new UnsignedInteger(x));

            case TypeIdentifier.Null:
                return(x => null);

            case TypeIdentifier.Dictionary:
                return(x => {
                    try {
                        var kt = MapIdentifierToType(reader);
                        var vt = MapIdentifierToType(reader);
                        return (StoragePremitive)typeof(DsDictionary <,>).MakeGenericType(kt, vt).GetConstructor(new Type[] { typeof(DSReader) }).Invoke(new object[] { x });
                    } catch (System.Reflection.TargetInvocationException e) {
                        if (e.GetBaseException() is System.IO.IOException)
                        {
                            throw new System.IO.IOException("IO Error", e.GetBaseException());
                        }
                        else
                        {
                            throw;
                        }
                    }
                });

            default:
                throw new ArgumentException();
            }
        }
示例#14
0
 public static StoragePremitive Parse(DSReader input)
 {
     return(MapIdentifierToConstructor(input)(input));
 }