Exemplo n.º 1
0
        /*
        , byte[] coverData
        */
        public void StoreFile(BaseFile file)
        {
            byte[] coverData = null;
              try {
            coverData = Encode(file.MaybeGetCover());
              }
              catch (Exception) {
            // Ignore and store null.
              }

              _store.MaybeStoreFile(file, Encode(file), coverData);
        }
Exemplo n.º 2
0
 internal void UpdateFileCache(BaseFile aFile)
 {
     if (store != null) {
     store.MaybeStoreFile(aFile);
       }
 }
Exemplo n.º 3
0
 internal Cover GetCover(BaseFile file)
 {
     if (store != null) {
     return store.MaybeGetCover(file);
       }
       return null;
 }
Exemplo n.º 4
0
 void AddPending(BaseFile file)
 {
     lock (pendingFiles) {
       if (pendingFiles.Any(f => ((BaseFile)f.Target).Path == file.Path)) return;
       pendingFiles.Add(new WeakReference(file));
     }
 }
Exemplo n.º 5
0
 internal void UpdateFileCache(BaseFile aFile)
 {
     if (_storeWriter != null) {
     _storeWriter.StoreFile(aFile);
       }
 }
Exemplo n.º 6
0
 internal Cover GetCover(BaseFile file)
 {
     if (_storeReader != null) {
     return _storeReader.GetCover(file);
       }
       return null;
 }
Exemplo n.º 7
0
        internal void MaybeStoreFile(BaseFile file)
        {
            if (connection == null) {
            return;
              }
              if (!file.GetType().Attributes.HasFlag(TypeAttributes.Serializable)) {
            return;
              }
              try {
            using (var s = new MemoryStream()) {
              var ctx = new StreamingContext(StreamingContextStates.Persistence, null);
              var formatter = new BinaryFormatter(null, ctx) { TypeFormat = FormatterTypeStyle.TypesWhenNeeded, AssemblyFormat = FormatterAssemblyStyle.Simple };
              formatter.Serialize(s, file);

              lock (connection) {
            insertKey.Value = file.Item.FullName;
            insertSize.Value = file.Item.Length;
            insertTime.Value = file.Item.LastWriteTimeUtc.Ticks;
            insertData.Value = s.ToArray();

            var cover = file.MaybeGetCover();
            if (cover != null) {
              using (var c = new MemoryStream()) {
                formatter.Serialize(c, cover);
                insertCover.Value = c.ToArray();
              }
            }
            else {
              insertCover.Value = null;
            }

            try {
              insert.ExecuteNonQuery();
            }
            catch (DbException ex) {
              Error("Failed to put file cover into store", ex);
              return;
            }
              }
            }
              }
              catch (Exception ex) {
            Error("Failed to serialize an object of type " + file.GetType(), ex);
            throw;
              }
        }
Exemplo n.º 8
0
        internal Cover MaybeGetCover(BaseFile file)
        {
            if (connection == null) {
            return null;
              }

              var info = file.Item;
              byte[] data;
              lock (connection) {
            selectCoverKey.Value = info.FullName;
            selectCoverSize.Value = info.Length;
            selectCoverTime.Value = info.LastWriteTimeUtc.Ticks;
            try {
              data = selectCover.ExecuteScalar() as byte[];
            }
            catch (DbException ex) {
              Error("Failed to lookup file cover from store", ex);
              return null;
            }
              }
              if (data == null) {
            return null;
              }
              try {
            using (var s = new MemoryStream(data)) {
              var ctx = new StreamingContext(StreamingContextStates.Persistence, new DeserializeInfo(null, info, DlnaMime.JPEG));
              var formatter = new BinaryFormatter(null, ctx) { TypeFormat = FormatterTypeStyle.TypesWhenNeeded, AssemblyFormat = FormatterAssemblyStyle.Simple };
              var rv = formatter.Deserialize(s) as Cover;
              return rv;
            }
              }
              catch (SerializationException ex) {
            Debug("Failed to deserialize a cover", ex);
            return null;
              }
              catch (Exception ex) {
            Fatal("Failed to deserialize a cover", ex);
            throw;
              }
        }
Exemplo n.º 9
0
        internal bool HasCover(BaseFile file)
        {
            if (connection == null) {
            return false;
              }

              var info = file.Item;
              lock (connection) {
            selectCoverKey.Value = info.FullName;
            selectCoverSize.Value = info.Length;
            selectCoverTime.Value = info.LastWriteTimeUtc.Ticks;
            try {
              var data = selectCover.ExecuteScalar();
              return (data as byte[]) != null;
            }
            catch (DbException ex) {
              Error("Failed to lookup file cover existence from store", ex);
              return false;
            }
              }
        }