Example #1
0
        public IEnumerable <SnippetData> All()
        {
            using (var connection = GetOpenConnection()) {
                SqlCeCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT * FROM Snippets";

                SqlCeDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    long   length        = reader.GetBytes(1, 0, null, 0, 0);
                    byte[] assemblyBytes = new byte[length];
                    reader.GetBytes(1, 0, assemblyBytes, 0, assemblyBytes.Length);

                    yield return(new SnippetData()
                    {
                        Id = Guid.Parse(reader.GetString(0)),
                        AssemblyBytes = assemblyBytes,
                        SnippetSource = reader.GetString(2),
                        UsingDirectives = reader.GetString(3),
                        SnippetHealth = (SnippetHealth)reader.GetInt32(4),
                        CompilerVersion = reader.IsDBNull(5) ? String.Empty : reader.GetString(5),
                        SnippetClasses = reader.IsDBNull(6) ? String.Empty : reader.GetString(6)
                    });
                }
            }
        }
Example #2
0
        public SnippetData Get(Guid id)
        {
            using (var connection = GetOpenConnection()) {
                SqlCeCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT * FROM Snippets WHERE Id = ?";

                cmd.Parameters.Add(new SqlCeParameter("Id", SqlDbType.NVarChar));
                cmd.Parameters["Id"].Value = id.ToString();

                SqlCeDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    long   length        = reader.GetBytes(1, 0, null, 0, 0);
                    byte[] assemblyBytes = new byte[length];
                    reader.GetBytes(1, 0, assemblyBytes, 0, assemblyBytes.Length);

                    return(new SnippetData()
                    {
                        Id = id,
                        AssemblyBytes = assemblyBytes,
                        SnippetSource = reader.GetString(2),
                        UsingDirectives = reader.GetString(3),
                        SnippetHealth = (SnippetHealth)reader.GetInt32(4),
                        CompilerVersion = reader.IsDBNull(5) ? String.Empty : reader.GetString(5),
                        SnippetClasses = reader.IsDBNull(6) ? String.Empty : reader.GetString(6)
                    });
                }
            }
            return(null);
        }
        public void LoadDB()
        {
            using (conn = new SqlCeConnection(stringCon))
            {
                conn.Open();
                using (cmd = new SqlCeCommand(@"SELECT * FROM FaceList", conn))
                {
                    SqlCeDataReader re = cmd.ExecuteReader();
                    while (re.Read())
                    {
                        TFaceRecord fr = new TFaceRecord();
                        fr.ImageFileName = re.GetString(0);
                        fr.subjectName   = re.GetString(1);

                        fr.FacePosition       = new FSDK.TFacePosition();
                        fr.FacePosition.xc    = re.GetInt32(2);
                        fr.FacePosition.yc    = re.GetInt32(3);
                        fr.FacePosition.w     = re.GetInt32(4);
                        fr.FacePosition.angle = re.GetFloat(5);

                        fr.FacialFeatures      = new FSDK.TPoint[2];
                        fr.FacialFeatures[0]   = new FSDK.TPoint();
                        fr.FacialFeatures[0].x = re.GetInt32(6);
                        fr.FacialFeatures[0].y = re.GetInt32(7);

                        fr.FacialFeatures[1]   = new FSDK.TPoint();
                        fr.FacialFeatures[1].x = re.GetInt32(8);
                        fr.FacialFeatures[1].y = re.GetInt32(9);

                        fr.Template = new byte[FSDK.TemplateSize];
                        re.GetBytes(10, 0, fr.Template, 0, FSDK.TemplateSize);

                        Image img      = Image.FromStream(new System.IO.MemoryStream(re.GetSqlBinary(11).Value));
                        Image img_face = Image.FromStream(new System.IO.MemoryStream(re.GetSqlBinary(12).Value));
                        fr.image     = new FSDK.CImage(img);
                        fr.faceImage = new FSDK.CImage(img_face);



                        dbList.Add(fr);

                        img.Dispose();
                        img_face.Dispose();
                    }
                }
                conn.Close();
            }
        }
 public static void testValues4(String hashName, SqlCeDataReader sqlData, String string0, String string1, String bytes, String base64)
 {
     byte[] byteResult   = null;
     byte[] byteExpected = null;
     Assert.AreEqual(string0, sqlData.GetString(0), String.Format("StringData <> {0}", string0));
     if (String.IsNullOrEmpty(string1))
     {
         Assert.IsTrue(sqlData.IsDBNull(1), "2nd Column is NOT null");
     }
     else
     {
         Assert.AreEqual(string1, sqlData.GetString(1), String.Format("AccountName <> {0}", string1));
     }
     byteResult = new byte[4];
     sqlData.GetBytes(5, 0, byteResult, 0, 4);
     byteExpected = StaticTestUtilities.GetStringToBytes(bytes);
     StaticTestUtilities.testByteValues(byteExpected, byteResult, String.Format("{0} Hash as Binary", hashName));
     Assert.AreEqual(String.Format("0x{0}", bytes), sqlData.GetString(6).ToLower(), String.Format("{0} Hash as Hex String", hashName));
     Assert.AreEqual(base64, sqlData.GetString(7), String.Format("{0} as Base 64", hashName));
 }
Example #5
0
        public Model.Memory.Config GetConfig()
        {
            SqlCeCommand command = Connection.CreateCommand();

            command.CommandText = "SELECT TOP(1) * FROM [config]";
            SqlCeDataReader reader = command.ExecuteReader();

            reader.Read();

            byte[] token = new byte[21];
            reader.GetBytes(reader.GetOrdinal("token"), 0, token, 0, 21);

            return(new Model.Memory.Config()
            {
                Address = reader.GetString(reader.GetOrdinal("address")),
                Port = reader.GetInt32(reader.GetOrdinal("port")),
                Protocol = reader.GetInt32(reader.GetOrdinal("protocol")),
                Token = token,
                Login = reader.GetString(reader.GetOrdinal("login")),
                Password = reader.GetString(reader.GetOrdinal("password")),
                ServerId = reader.GetInt32(reader.GetOrdinal("server")),
                Name = reader.GetString(reader.GetOrdinal("name"))
            });
        }
Example #6
0
        private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
        {
            HttpContext context = HttpContext.Current;

            string[] names  = null;
            string   values = null;

            byte[] buf   = null;
            string sName = null;

            if (context != null)
            {
                sName = (context.Request.IsAuthenticated ? context.User.Identity.Name : context.Request.AnonymousID);
            }

            using (SqlCeConnection conn = new SqlCeConnection(connectionString))
            {
                Guid userId;

                using (SqlCeCommand cmd = new SqlCeCommand("SELECT ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName", conn))
                {
                    conn.Open();

                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(CreateInputParam("@ApplicationId", SqlDbType.UniqueIdentifier, SqlCeMembershipUtils.GetApplicationId(conn.ConnectionString, ApplicationName)));
                    cmd.Parameters.Add(CreateInputParam("@UserName", SqlDbType.NVarChar, userName));
                    cmd.CommandText = "SELECT UserId FROM aspnet_Users WHERE ApplicationId = @ApplicationId AND LoweredUserName = LOWER(@UserName)";

                    object o = cmd.ExecuteScalar();
                    if (o != null && o is Guid)
                    {
                        userId = (Guid)o;
                    }
                    else
                    {
                        return;
                    }

                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(CreateInputParam("@UserId", SqlDbType.UniqueIdentifier, userId));
                    cmd.CommandText = "SELECT PropertyNames, PropertyValuesString, PropertyValuesBinary FROM aspnet_Profile WHERE UserId = @UserId";

                    using (SqlCeDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(CreateInputParam("@CurrentTimeUtc", SqlDbType.DateTime, DateTime.UtcNow));
                        cmd.Parameters.Add(CreateInputParam("@UserId", SqlDbType.UniqueIdentifier, userId));
                        cmd.CommandText = "UPDATE aspnet_Users SET LastActivityDate = @CurrentTimeUtc WHERE UserId = @UserId";

                        cmd.ExecuteNonQuery();

                        if (reader.Read())
                        {
                            names  = reader.GetString(0).Split(':');
                            values = reader.GetString(1);

                            int size = (int)reader.GetBytes(2, 0, null, 0, 0);

                            buf = new byte[size];
                            reader.GetBytes(2, 0, buf, 0, size);
                        }
                        ParseDataFromDB(names, values, buf, svc);
                    }
                }
            }
        }
Example #7
0
        public List <TFaceRecord> LoadSubject(string conString)
        {
            InitializeSDK();
            SubjectImageList = new ImageList();

            List <TFaceRecord> SubjectList = new List <TFaceRecord>();

            try
            {
                using (conn = new SqlCeConnection(conString))
                {
                    conn.Open();

                    using (cmd = new SqlCeCommand(@"Select * From FaceList", conn))
                    {
                        SqlCeDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            TFaceRecord fr = new TFaceRecord();
                            fr.ImageFileName = reader.GetString(0);
                            fr.suspectName   = reader.GetString(1);

                            fr.FacePosition       = new FSDK.TFacePosition();
                            fr.FacePosition.xc    = reader.GetInt32(2);
                            fr.FacePosition.yc    = reader.GetInt32(3);
                            fr.FacePosition.w     = reader.GetInt32(4);
                            fr.FacePosition.angle = reader.GetFloat(5);

                            fr.FacialFeatures      = new FSDK.TPoint[2];
                            fr.FacialFeatures[0]   = new FSDK.TPoint();
                            fr.FacialFeatures[0].x = reader.GetInt32(6);
                            fr.FacialFeatures[0].y = reader.GetInt32(7);

                            fr.FacialFeatures[1]   = new FSDK.TPoint();
                            fr.FacialFeatures[1].x = reader.GetInt32(8);
                            fr.FacialFeatures[1].y = reader.GetInt32(9);

                            fr.Template = new byte[FSDK.TemplateSize];
                            reader.GetBytes(10, 0, fr.Template, 0, FSDK.TemplateSize);

                            Image img      = Image.FromStream(new System.IO.MemoryStream(reader.GetSqlBinary(11).Value));
                            Image img_face = Image.FromStream(new System.IO.MemoryStream(reader.GetSqlBinary(12).Value));
                            fr.image     = new FSDK.CImage(img);
                            fr.faceImage = new FSDK.CImage(img_face);

                            SubjectList.Add(fr);
                            SubjectImageList.Images.Add(fr.faceImage.ToCLRImage());

                            img.Dispose();
                            img_face.Dispose();
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception on loading database");
            }

            return(SubjectList);
        }