Example #1
0
        internal DBSiteSettingsEx(
            string dbConnectionString,
            ILoggerFactory loggerFactory)
        {
            logFactory = loggerFactory;
            connectionString = dbConnectionString;

            // possibly will change this later to have SqlCeProviderFactory/DbProviderFactory injected
            AdoHelper = new SqlCeHelper(SqlCeProviderFactory.Instance);
        }
Example #2
0
        public DbSetup(
            cloudscribe.DbHelpers.SqlCe.SqlCeConnectionStringResolver connectionStringResolver,
            ILoggerFactory loggerFactory,
            IVersionProviderFactory versionProviderFactory)
        {
            if (connectionStringResolver == null) { throw new ArgumentNullException(nameof(connectionStringResolver)); }
            if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); }
            if (versionProviderFactory == null) { throw new ArgumentNullException(nameof(versionProviderFactory)); }

            versionProviders = versionProviderFactory;
            logFactory = loggerFactory;
            log = loggerFactory.CreateLogger(typeof(DbSetup).FullName);
            connectionString = connectionStringResolver.Resolve();
            sqlCeFilePath = connectionStringResolver.SqlCeFilePath;

            // possibly will change this later to have SqlCeProviderFactory/DbProviderFactory injected
            AdoHelper = new SqlCeHelper(SqlCeProviderFactory.Instance);

        }
        internal void Delete(Entity entity)
        {
            SqlStatement sql = new SqlStatement();

            // delete...
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from ");
            builder.Append(this.EntityType.NativeName);
            builder.Append(" where ");
            AppendSelectConstraint(builder, sql, entity);

            // run...
            sql.CommandText = builder.ToString();

            // run...
            SqlCeHelper db = new SqlCeHelper();
            db.EnsureTableExists(entity.EntityType);
            db.ExecuteNonQuery(sql);
        }
        internal void Update(Entity entity)
        {
            SqlStatement sql = new SqlStatement();

            // create...
            StringBuilder builder = new StringBuilder();
            builder.Append("update ");
            builder.Append(this.EntityType.NativeName);
            builder.Append(" set ");
            bool first = true;
            foreach (EntityField field in this.EntityType.Fields)
            {
                if (entity.IsModified(field))
                {
                    if (first)
                        first = false;
                    else
                        builder.Append(", ");
                    builder.Append(field.NativeName);
                    builder.Append("[email protected]");

                    // value...
                    object value = entity.GetValue(field);
                    builder.Append(sql.AddParameter(value).Name);
                }
            }
            builder.Append(" where ");
            this.AppendSelectConstraint(builder, sql, entity);

            // run...
            sql.CommandText = builder.ToString();

            // run...
            SqlCeHelper db = new SqlCeHelper();
            db.EnsureTableExists(entity.EntityType);
            db.ExecuteNonQuery(sql);
        }
        internal void Insert(Entity entity)
        {
            SqlStatement sql = new SqlStatement();

            // create...
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into ");
            builder.Append(this.EntityType.NativeName);
            builder.Append(" (");
            bool first = true;
            foreach (EntityField field in this.EntityType.Fields)
            {
                if (entity.IsModified(field))
                {
                    if (first)
                        first = false;
                    else
                        builder.Append(", ");
                    builder.Append(field.NativeName);
                }
            }
            builder.Append(") values (");
            first = true;
            foreach (EntityField field in this.EntityType.Fields)
            {
                if (entity.IsModified(field))
                {
                    if (first)
                        first = false;
                    else
                        builder.Append(", ");

                    // param...
                    object value = entity.GetValue(field);
                    SqlStatementParameter param = sql.AddParameter(value);
                    builder.Append("@");
                    builder.Append(param.Name);
                }
            }
            builder.Append(")");

            // run...
            sql.CommandText = builder.ToString();

            // run...
            SqlCeHelper db = new SqlCeHelper();
            db.EnsureTableExists(entity.EntityType);
            db.ExecuteNonQuery(sql);
        }
        internal static void DeleteAll()
        {
            SqlCeHelper db = new SqlCeHelper();

            // ensure...
            EntityType et = EntityType.GetEntityType(typeof(Bookmark));
            db.EnsureTableExists(et);

            // delete...
            db.ExecuteNonQuery(new SqlStatement("delete from " + et.NativeName));
        }
        private void GetLatest()
        {
            Debug.WriteLine("Getting latest...");

            BookmarksService service = new BookmarksService();
            service.GetAll((Action<List<Bookmark>>)delegate(List<Bookmark> bookmarks)
            {
                // ensure...
                SqlCeHelper db = new SqlCeHelper();
                db.EnsureTableExists(EntityType.GetEntityType(typeof(Bookmark)));

                // delete first...
                Bookmark.DeleteAll();

                // go through and save them...
                foreach (Bookmark fromServer in bookmarks)
                {
                    // we need to clone it as the ones that come from the server will have an id set.  we
                    // need to junk this id...
                    Bookmark newBookmark = new Bookmark();
                    newBookmark.Ordinal = fromServer.Ordinal;
                    newBookmark.Name = fromServer.Name;
                    newBookmark.Url = fromServer.Url;

                    // set the local only stuff...
                    newBookmark.IsLocalModified = false;
                    newBookmark.IsLocalDeleted = false;

                    // save...
                    newBookmark.SaveChanges();
                }

                // signal that we've finished...
                this.Callback();

            }, this.Failed);
        }
        private void TestConnection(bool showMessage)
        {
            try
            {
                if (createDb)
                {
                    if (!System.IO.File.Exists(dataSourceTextBox.Text))
                    {
                        var engineHelper = new SqlCeHelper();
                        engineHelper.CreateDatabase(_connectionString);
                    }
                }

                using (var repository = new DBRepository(_connectionString))
                {
                    if (showMessage)
                    {
                        System.Windows.MessageBox.Show("Connection OK!");
                    }
                    else
                    {
                        this.DialogResult = true;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(DataConnectionHelper.ShowErrors(ex));
            }
        }
        internal static string ShowErrors(Exception ex)
        {
#if V35
            ISqlCeHelper sqlCeHelper = new SqlCeHelper();
#else
            ISqlCeHelper sqlCeHelper = new SqlCeHelper4();
#endif
            Monitor.TrackException(ex);
            return sqlCeHelper.FormatError(ex);
        }