public static CodeGenerator Create(ISqlCeDatabase database, string language, string target = null)
        {
            if (String.Compare(language, "C#", StringComparison.OrdinalIgnoreCase) == 0 ||
                String.Compare(language, "CSharp", StringComparison.OrdinalIgnoreCase) == 0 ||
                String.Compare(language, "CS", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (!string.IsNullOrEmpty(target) && target == "Mango")
                {
                    return(new CSharpMangoLinqToSqlCodeGenerator(database));
                }
                if (!string.IsNullOrEmpty(target) && target == "LinqToSql")
                {
                    return(new CSharpMangoSqlMetalCodeGenerator(database));
                }

                return(new CSharpCodeGenerator(database));
            }

            if (String.Compare(language, "VB.NET", StringComparison.OrdinalIgnoreCase) == 0 ||
                String.Compare(language, "Visual Basic", StringComparison.OrdinalIgnoreCase) == 0 ||
                String.Compare(language, "VisualBasic", StringComparison.OrdinalIgnoreCase) == 0 ||
                String.Compare(language, "VB", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (!string.IsNullOrEmpty(target) && target == "Mango")
                {
                    throw new NotSupportedException("Visual Basic Code Generation for Windows Phone \"Mango\" is not supported");
                }

                return(new VisualBasicCodeGenerator(database));
            }

            return(Create(database));
        }
Esempio n. 2
0
        /*
         *      public void RenameObject(object treeViewItem)
         *      {
         *          var window = new RenameObjectWindow();
         *
         *          if (treeViewItem is Table)
         *              window.ViewModel = new RenameObjectViewModel(database, treeViewItem as Table);
         *          else if (treeViewItem is Column)
         *              window.ViewModel = new RenameObjectViewModel(database, treeViewItem as Column);
         *
         *          if (window.ViewModel != null)
         *              window.ShowDialog();
         *      }
         */

        private void CreateNewDatabase()
        {
            var window       = new CreateDatabaseWindow();
            var dialogResult = window.ShowDialog();

            if (!dialogResult.GetValueOrDefault())
            {
                return;
            }

            var viewModel = window.DataContext as CreateDatabaseViewModel;

            if (viewModel == null)
            {
                return;
            }

            Text = "SQL Compact Query Analyzer";
            Tree = null;
            ResetTableData();
            ResultsContainer.Clear();
            ResultSetMessages = ResultSetErrors = ResultSetXml.Text = Query.Text = string.Empty;
            RaisePropertyChanged("Tree");
            RaisePropertyChanged("Query");
            RaisePropertyChanged("ResultSetXml");
            CurrentMainTabIndex = 0;
            lastSelectedTable   = null;
            database            = null;

            dataSource = viewModel.Filename;
            password   = viewModel.Password;
            AnalyzeDatabase();
        }
 public RepositoryPatternGenerator(ISqlCeDatabase database, DataAccessLayerGeneratorOptions options, bool supportSqlCeTransactions = true, bool usesLinqToSql = false)
     : base(database)
 {
     this.options = options;
     this.supportSqlCeTransactions = supportSqlCeTransactions;
     this.usesLinqToSql            = usesLinqToSql;
 }
Esempio n. 4
0
 protected CodeGenerator(ISqlCeDatabase database)
 {
     Database  = database;
     CodeFiles = new Dictionary <string, StringBuilder>();
     Code      = new StringBuilder();
     Code.AppendLine();
 }
Esempio n. 5
0
        private void AnalyzeDatabase()
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    if (!File.Exists(dataSource))
                    {
                        throw new InvalidOperationException("Unable to find " + dataSource);
                    }

                    Text = "SQL Compact Query Analyzer" + " - " + dataSource;

                    var fileInfo         = new FileInfo(dataSource);
                    fileInfo.Attributes &= ~FileAttributes.ReadOnly;

                    database = SqlCeDatabaseFactory.Create(GetConnectionString());
                    while (!database.VerifyConnectionStringPassword())
                    {
                        bool?result           = null;
                        PasswordWindow window = null;
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            window = new PasswordWindow();
                            result = window.ShowDialog();
                        });
                        if (result != true)
                        {
                            return;
                        }
                        password = window.Password;
                        database.ConnectionString = GetConnectionString(4091);
                    }

                    AnalyzingTablesIsBusy = true;

                    var stopwatch = Stopwatch.StartNew();

                    database.AnalyzeDatabase();

                    ResultSetMessages = "Analyzed database in " + stopwatch.Elapsed;
                    stopwatch.Stop();

                    Application.Current.Dispatcher.Invoke((Action)PopulateTables);

                    AddRecentFile(dataSource);
                }
                catch (Exception e)
                {
                    ResultSetErrors        = e.ToString();
                    CurrentResultsTabIndex = 3;
                }
                finally
                {
                    AnalyzingTablesIsBusy = false;
                }
            });
        }
Esempio n. 6
0
        public CodeDomCodeGenerator(ISqlCeDatabase tableDetails, CodeDomProvider provider)
            : base(tableDetails)
        {
            this.provider = provider;

            compileUnit   = new CodeCompileUnit();
            codeNamespace = new CodeNamespace(Database.DefaultNamespace);
            compileUnit.Namespaces.Add(codeNamespace);
        }
Esempio n. 7
0
        public static string GenerateSchemaAndDataScript(this Table table, ISqlCeDatabase database)
        {
            var builder = new StringBuilder();

            builder.AppendLine(GenerateSchemaScript(table));
            builder.AppendLine(Environment.NewLine);
            builder.AppendLine(Environment.NewLine);
            builder.AppendLine(GenerateDataScript(table, database));

            return(builder.ToString());
        }
Esempio n. 8
0
        public static string GenerateDataScript(this Table table, ISqlCeDatabase database)
        {
            var data = database.GetTableData(table) as DataTable;

            if (data == null || data.Rows.Count == 0)
            {
                return(string.Empty);
            }

            var builder = new StringBuilder();

            foreach (DataRow row in data.Rows)
            {
                builder.AppendLine();
                builder.AppendFormat("INSERT INTO {0}", table.Name);

                builder.Append(" (");
                foreach (var column in table.Columns.Where(column => column.Value.ManagedType != typeof(byte[])))
                {
                    builder.AppendFormat("{0},", column.Value.Name);
                }
                builder.Remove(builder.Length - 1, 1);

                builder.Append(") VALUES (");
                foreach (var column in table.Columns.Where(column => column.Value.ManagedType != typeof(byte[])))
                {
                    var value = row[column.Value.Ordinal - 1];
                    if (value == null)
                    {
                        builder.Append("NULL,");
                        continue;
                    }

                    if (column.Value.ManagedType == typeof(string) || column.Value.ManagedType == typeof(DateTime))
                    {
                        builder.AppendFormat("'{0}',", value.ToString().Replace("'", "''"));
                    }
                    else
                    {
                        builder.Append(value + ",");
                    }
                }
                builder.Remove(builder.Length - 1, 1);
                builder.Append(");");
            }

            builder.AppendLine();
            return(builder.ToString());
        }
Esempio n. 9
0
 private void ResetFields()
 {
     Tree = null;
     ResetTableData();
     ResultsContainer.Clear();
     ResultSetMessages = ResultSetErrors = ResultSetXml.Text = Query.Text = string.Empty;
     RaisePropertyChanged("Tree");
     RaisePropertyChanged("Query");
     RaisePropertyChanged("ResultSetXml");
     CurrentMainTabIndex = 0;
     lastSelectedTable   = null;
     dataSource          = null;
     database            = null;
     password            = null;
 }
Esempio n. 10
0
        public static string GenerateDataScript(this IEnumerable <Table> tables, ISqlCeDatabase database)
        {
            var builder = new StringBuilder();

            foreach (var table in tables)
            {
                var script = GenerateDataScript(table, database);
                if (!string.IsNullOrEmpty(script))
                {
                    builder.Append(script);
                }
            }

            return(builder.ToString());
        }
Esempio n. 11
0
        public void Connect(string path)
        {
            dataSource = path;
            if (!File.Exists(dataSource))
            {
                throw new InvalidOperationException("Unable to find Windows Live Photo Gallery database file:" + dataSource);
            }

            var       connstr   = string.Format("Data Source={0}; Password={1};", path, "");
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            database = SqlCeDatabaseFactory.Create(connstr);
            stopwatch.Stop();
            if (stopwatch.ElapsedMilliseconds > 200)
            {
                Logger.Info("Connect Compact SQL CE " + stopwatch.ElapsedMilliseconds.ToString());
            }
        }
        public static CodeGenerator Create(ISqlCeDatabase database, string testfx, string target = null)
        {
            if (!string.IsNullOrEmpty(target) && target == "Mango")
            {
                throw new NotSupportedException("Unit Test Framework not supported"); //return new CSharpMangoFakeDataAccessLayerCodeGenerator(database);
            }
            switch (testfx.ToLower())
            {
            case "mstest":
                return(new MSTestUnitTestCodeGenerator(database));

            case "nunit":
                return(new NUnitTestCodeGenerator(database));

            case "xunit":
                return(new XUnitTestCodeGenerator(database));
            }

            throw new NotSupportedException("Unit Test Framework not supported");
        }
        public void CreateDatabase()
        {
            ISqlCeDatabase database = null;

            switch (SelectedIndex)
            {
            case 0:
                database = SqlCeDatabaseFactory.Create(SupportedVersions.SqlCe31);
                break;

            case 1:
                database = SqlCeDatabaseFactory.Create(SupportedVersions.SqlCe35);
                break;

            case 2:
                database = SqlCeDatabaseFactory.Create(SupportedVersions.SqlCe40);
                break;
            }

            if (database != null)
            {
                database.CreateDatabase(Filename, Password, MaxDatabaseSize);
            }
        }
Esempio n. 14
0
 public VisualBasicCodeGenerator(ISqlCeDatabase database)
     : base(database)
 {
 }
 public UnitTestCodeGeneratorFactory(ISqlCeDatabase database)
 {
     this.database = database;
 }
Esempio n. 16
0
 public CSharpMangoFakeDataAccessLayerCodeGenerator(ISqlCeDatabase tableDetails)
     : base(tableDetails)
 {
 }
 public static CodeGenerator Create <T>(ISqlCeDatabase database) where T : CodeGenerator
 {
     return(Activator.CreateInstance(typeof(T), database) as T);
 }
Esempio n. 18
0
        public static string GenerateSchemaAndDataScript(this IEnumerable <Table> tables, ISqlCeDatabase database)
        {
            var builder = new StringBuilder();

            foreach (var table in tables)
            {
                builder.AppendLine(GenerateSchemaScript(table));
            }

            builder.AppendLine(Environment.NewLine);
            builder.AppendLine(Environment.NewLine);

            foreach (var table in tables)
            {
                builder.AppendLine(GenerateDataScript(table, database));
            }

            return(builder.ToString());
        }
 public static CodeGenerator Create(ISqlCeDatabase database)
 {
     return(new CSharpCodeGenerator(database));
 }
 public RenameObjectViewModel(ISqlCeDatabase database, Table table)
     : this(database, table.Name)
 {
     objectToRename = table;
 }
 public RenameObjectViewModel(ISqlCeDatabase database, Column column)
     : this(database, column.Name)
 {
     objectToRename = column;
 }
 private RenameObjectViewModel(ISqlCeDatabase database, string objectName)
 {
     this.database = database;
     Name          = objectName;
 }
 public MSTestUnitTestCodeGenerator(ISqlCeDatabase tableDetails)
     : base(tableDetails)
 {
 }
Esempio n. 24
0
 public CSharpCodeDomCodeGenerator(ISqlCeDatabase database)
     : base(database, new CSharpCodeProvider())
 {
 }
Esempio n. 25
0
 public VisualBasicCodeDomCodeGenerator(ISqlCeDatabase database)
     : base(database, new VBCodeProvider())
 {
 }
 public static CodeGenerator Create(ISqlCeDatabase database)
 {
     return(new MSTestUnitTestCodeGenerator(database));
 }
 public CSharpMangoLinqToSqlCodeGenerator(ISqlCeDatabase tableDetails)
     : base(tableDetails)
 {
 }
 protected CSharpUnitTestCodeGenerator(ISqlCeDatabase tableDetails)
     : base(tableDetails)
 {
 }
Esempio n. 29
0
 public CSharpCodeGenerator(ISqlCeDatabase tableDetails)
     : base(tableDetails)
 {
 }
 public CSharpMangoSqlMetalCodeGenerator(ISqlCeDatabase database)
     : base(database)
 {
 }