Ejemplo n.º 1
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();

                        insertCover.Value = null;
                        try {
                            var cover = file.MaybeGetCover();
                            if (cover != null)
                            {
                                using (var c = new MemoryStream()) {
                                    formatter.Serialize(c, cover);
                                    insertCover.Value = c.ToArray();
                                }
                            }
                        }
                        catch (NotSupportedException) {
                            // Ignore and store 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;
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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;
              }
        }