Пример #1
0
        private bool SqlTrySelect(string chromatogramID, out Peak2DArray peaks)
        {
            SQLiteCommand cmd;

            if (!currentScope.TryGetCommand("SELECT_CHROMATOGRAM_PEAKS_CMD", out cmd))
            {
                cmd = currentScope.PrepareCommand("SELECT_CHROMATOGRAM_PEAKS_CMD", "SELECT PeakArray, PeakData FROM Chromatogram WHERE ChromatogramID = @chromatogramID");
            }
            else
            {
                cmd.Parameters.Clear();
            }

            cmd.Parameters.AddWithValue("@chromatogramID", chromatogramID);

            using (SQLiteDataReader reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    peaks = MzLiteJson.FromJson <Peak2DArray>(reader.GetString(0));
                    decoder.Decode(reader.GetStream(1), peaks);
                    return(true);
                }
                else
                {
                    peaks = null;
                    return(false);
                }
            }
        }
Пример #2
0
        public Stream GetRawTile(int x, int y, int zoom)
        {
            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(String.Format("Data Source={0};Version=3;", Path)))
                {
                    conn.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand()
                    {
                        Connection = conn, CommandText = String.Format("SELECT * FROM tiles WHERE tile_column = {0} and tile_row = {1} and zoom_level = {2}", x, y, zoom)
                    })
                    {
                        SQLiteDataReader reader = cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            var stream = reader.GetStream(reader.GetOrdinal("tile_data"));
                            return(stream);
                        }
                    }
                }
            }
            catch
            {
                throw new MemberAccessException("Could not load tile from Mbtiles");
            }

            return(null);
        }
Пример #3
0
 public static List <Section> TryGetBlobParse(this SQLiteDataReader reader, int i)
 {
     if (reader.IsDBNull(i))
     {
         return(null);
     }
     using (var stream = reader.GetStream(i))
     {
         return(BlobParser.Parse(stream));
     }
 }
Пример #4
0
 public static Bitmap MountSheet(int mount)
 {
     lock (outfiterLock) {
         string           mountName = outfiterMountNames[mount];
         SQLiteCommand    comm      = new SQLiteCommand(String.Format("SELECT image FROM MountImages WHERE name='{0}'", mountName), outfiterConn);
         SQLiteDataReader reader    = comm.ExecuteReader();
         while (reader.Read())
         {
             return(reader.IsDBNull(0) ? null : new Bitmap(Image.FromStream(reader.GetStream(0))));
         }
         return(null);
     }
 }
Пример #5
0
 public static Bitmap OutfitSheet(int outfit, Gender gender)
 {
     lock (outfiterLock) {
         string           outfitName = outfiterOutfitNames[outfit];
         bool             male       = gender == Gender.Male;
         SQLiteCommand    comm       = new SQLiteCommand(String.Format("SELECT image FROM OutfitImages WHERE name='{0}' AND male={1}", outfitName, male ? 1 : 0), outfiterConn);
         SQLiteDataReader reader     = comm.ExecuteReader();
         while (reader.Read())
         {
             return(reader.IsDBNull(0) ? null : new Bitmap(Image.FromStream(reader.GetStream(0))));
         }
         return(null);
     }
 }
Пример #6
0
        internal static BitmapSource GetBitmap(this SQLiteDataReader reader, int colIndex)
        {
            using (var stream = reader.GetStream(colIndex))
            {
                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.StreamSource = stream;
                bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                bitmap.EndInit();

                bitmap.Freeze();

                return(bitmap);
            }
        }
Пример #7
0
        private static string Decrypt(SQLiteDataReader reader, int column)
        {
            if (reader.IsDBNull(column))
            {
                return(null);
            }

            using var buffer = new MemoryStream();
            using (var stream = reader.GetStream(column))
            {
                stream.CopyTo(buffer);
            }

            return(InedoLib.UTF8Encoding.GetString(ProtectedData.Unprotect(buffer.ToArray(), null, RompConfig.UserMode ? DataProtectionScope.CurrentUser : DataProtectionScope.LocalMachine)));
        }
Пример #8
0
        /// <summary>
        /// Lire une image dans une colonne d'un enregistrement de la base
        /// </summary>
        /// <param name="reader">Le curseur en cours, positionné sur le bon enregistrement</param>
        /// <param name="colonne">Numero de la colonne</param>
        /// <returns></returns>
        public static Image readImage(SQLiteDataReader reader, int colonne)
        {
            try
            {
                Stream picData = reader.GetStream(colonne);
                if (picData == null)
                {
                    // Pas d'image
                    return(null);
                }

                return(new Bitmap(picData));
            }
            catch (Exception)
            {
                // Pas d'image
                return(null);
            }
        }
Пример #9
0
 private void SetValue(object instance, PropertyInfo propertyInfo, SQLiteDataReader reader)
 {
     ORMProperty[] props = (ORMProperty[])propertyInfo.GetCustomAttributes(typeof(ORMProperty), false);
     if (props.Length > 0)
     {
         if (propertyInfo.PropertyType == typeof(String))
         {
             propertyInfo.SetValue(instance, reader.GetString(reader.GetOrdinal(props[0].FieldName)));
         }
         else if (propertyInfo.PropertyType == typeof(Boolean))
         {
             propertyInfo.SetValue(instance, (Int64)reader[props[0].FieldName] > 0 ? true : false);
         }
         else if (propertyInfo.PropertyType == typeof(Int32))
         {
             propertyInfo.SetValue(instance, reader.GetInt32(reader.GetOrdinal(props[0].FieldName)));
         }
         else if (propertyInfo.PropertyType == typeof(Int64))
         {
             propertyInfo.SetValue(instance, reader.GetInt64(reader.GetOrdinal(props[0].FieldName)));
         }
         else if (propertyInfo.PropertyType == typeof(Decimal))
         {
             propertyInfo.SetValue(instance, reader.GetDecimal(reader.GetOrdinal(props[0].FieldName)));
         }
         else if (propertyInfo.PropertyType == typeof(Double))
         {
             propertyInfo.SetValue(instance, reader.GetDouble(reader.GetOrdinal(props[0].FieldName)));
         }
         else if (propertyInfo.PropertyType == typeof(DateTime))
         {
             if (reader[props[0].FieldName].GetType() != typeof(System.DBNull))
             {
                 propertyInfo.SetValue(instance, reader.GetDateTime(reader.GetOrdinal(props[0].FieldName)));
             }
             else
             {
                 propertyInfo.SetValue(instance, DateTime.MinValue);
             }
         }
         else if (propertyInfo.PropertyType.IsEnum)
         {
             string enumName = Enum.GetName(propertyInfo.PropertyType, reader[props[0].FieldName]);
             propertyInfo.SetValue(instance, Enum.Parse(propertyInfo.PropertyType, enumName));
         }
         else if (propertyInfo.PropertyType == typeof(Image))
         {
             if (reader[props[0].FieldName].GetType() != typeof(System.DBNull))
             {
                 propertyInfo.SetValue(instance, Image.FromStream(reader.GetStream(reader.GetOrdinal(props[0].FieldName))));
             }
         }
         else if (propertyInfo.PropertyType.BaseType == typeof(Stream))
         {
             // TODO: File PROPERTIES
             //if (reader[props[0].FieldName].GetType() != typeof(System.DBNull))
             //   propertyInfo.SetValue(instance, reader.GetStream(reader.GetOrdinal(props[0].FieldName)));
         }
         else if (this.IsOrmInstance(propertyInfo.PropertyType))
         {
             propertyInfo.SetValue(instance, this.GetORMInstance(propertyInfo.PropertyType,
                                                                 (long)reader[props[0].FieldName]));
         }
         else
         {
             throw new Exception("Data mapping error: Not supported data type conversion for type " + propertyInfo.PropertyType.FullName);
         }
     }
 }