public void Execute(object parameter) { try { var dbservice = VEFModule.UnityContainer.Resolve(typeof(IDatabaseService), "") as IDatabaseService; IDALOptions options = dbservice.CurrentDB.DBOptions; options.Host = mpm.DBFilePath; //TODO use settings!! var ctx = ((IDAL.IDAL)dbservice.CurrentDB).GetDataContextOpt(false); IDAL.IDAL.TruncateDatabase(ctx); RekursivSaveToDB(mpm, ctx); // Type t = parameter as Type; //to create the objects i need the parameter data!!!! // mpm.Save(); //if (t.Name == "SceneDataModel") //{ // //KH 29.03 mpm.Items.Add(new SceneDataModel() { Parent = mpm, UnityContainer = mpm.UnityContainer, Name = "new scene", ContentID = "SceneID:##:" }); // // Type instance = (Type)Activator.CreateInstance(t); // // object obj = t.GetConstructor(new Type[] { }).Invoke(new object[] { }); // // mpm.Items.Add(obj as IItem); //} } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Adds a base item to the project-file manager /// </summary> /// <param name="theme">The item to add</param> /// <returns>true, if successful - false, otherwise</returns> public bool AddDBOption(IDALOptions db) { if (!DBOptions.Contains(db)) { DBOptions.Add(db); return(true); } return(false); }
public IDAL_DCTX GetDataContextOpt(Boolean checkUser = true) { IDAL_DCTX ctx = new IDAL_DCTX(); try { var _databaseService = VEFModule.UnityContainer.Resolve(typeof(IDatabaseService), "") as IDatabaseService; ////if (m_DBFound) ////{ ////} ////else //// ShowDBSetting(m_Container); // PS_COMID_DataContext crmDataContext = new PS_COMID_DataContext(); IDALOptions options = _databaseService.CurrentDB.DBOptions; if (options.DBType == DBType.MSSQL) { // //string connectionString = "metadata=res://*/MDB.MDB_PNDS.csdl|res://*/MDB.MDB_PNDS.ssdl|res://*/MDB.MDB_PNDS.msl;Server = " + options.Host + "; Database = PNDS; User Id = " + options.User + ";Password = "******"metadata=res://*/MDB.MDB_PNDS.csdl|res://*/MDB.MDB_PNDS.ssdl|res://*/MDB.MDB_PNDS.msl;provider=System.Data.SqlClient;provider connection string=\"data source=AP-HAAG\\SQLEX2008R203;initial catalog=PNDS;user id=PecuSoft;password=sesam1997oeffne;MultipleActiveResultSets=True;App=EntityFramework\""; string connectionString = "metadata=res://*/MDB.MDB_PNDS.csdl|res://*/MDB.MDB_PNDS.ssdl|res://*/MDB.MDB_PNDS.msl;provider=System.Data.SqlClient;provider connection string=\"data source=" + options.Host + ";initial catalog=PNDS;user id=" + options.User + ";password="******";MultipleActiveResultSets=True;App=EntityFramework\""; //string connectionString = "User Id=" + options.User + ";Password="******";Server=" + options.Host + ";Direct=True;Sid=" + options.ServiceName + ";Persist Security Info=True"; // string providerPrefix = ""; //if (!ConnectionDialog.Show(out connectionString, out providerPrefix)) //{ // stripLabel.Text = "Incorrect connection string"; // return; //} //Frame activating // Stream contextStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(String.Format("ComID.IDAL.MDB.CrmDataMapping{0}.lqml", providerPrefix)); // Devart.Data.Linq.Mapping.MappingSource mappingSource = Devart.Data.Linq.Mapping.XmlMappingSource.FromStream(contextStream); //PNDSEntities crmDataContext = new PNDSEntities(m_Container, connectionString);//, mappingSource); //crmDataContext.CTXID = _databaseService.GetNextCtxID(); //// crmDataContext.Connection.StateChange += new System.Data.StateChangeEventHandler(Connection_StateChange); //crmDataContext.Database.Connection.Open(); //// foreach (ListViewItem lvItem in lvFrames.Items) //// ((BaseControl)lvItem.Tag).OpenClick(); //if (checkUser && _databaseService.LoggedUser.UserID < 1) //{ // ShowLoginDialog(m_Container); // return null; //} //return crmDataContext; } else if (options.DBType == DBType.SQLite) { //System.Data.SQLite.SQLiteConnection.CreateFile("databaseFile.db3"); // Create the file which will be hosting our database //using (System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection("data source=\"F:\\Projekte\\coop\\XGame\\data\\dbData.s3db\"")) //{ // using (System.Data.SQLite.SQLiteCommand com = new System.Data.SQLite.SQLiteCommand(con)) // { // con.Open(); // Open the connection to the database // //com.CommandText = createTableQuery; // Set CommandText to our query that will create the table // //com.ExecuteNonQuery(); // Execute the query // //com.CommandText = "INSERT INTO MyTable (Key,Value) Values ('key one','value one')"; // Add the first entry into our database // //com.ExecuteNonQuery(); // Execute the query // //com.CommandText = "INSERT INTO MyTable (Key,Value) Values ('key two','value value')"; // Add another entry into our database // //com.ExecuteNonQuery(); // Execute the query // //com.CommandText = "Select * FROM MyTable"; // Select all rows from our database table // //using (System.Data.SQLite.SQLiteDataReader reader = com.ExecuteReader()) // //{ // // while (reader.Read()) // // { // // Console.WriteLine(reader["Key"] + " : " + reader["Value"]); // Display the value of the key and value column for every row // // } // //} // con.Close(); // Close the connection to the database // } //} //todo per settings! // string connectionString = "metadata=res://*/MDB.EDM_DBData.csdl|res://*/MDB.EDM_DBData.ssdl|res://*/MDB.EDM_DBData.msl;provider=System.Data.SQLite.EF6;provider connection string=\"data source=F:\\Projekte\\coop\\XGame\\data\\dbData.s3db\""; // string connectionString = "data source=F:\\Projekte\\coop\\XGame\\data\\dbData.s3db"; string connectionString = _databaseService.CurrentDB.DBOptions.Host; // string connectionString = "metadata=res://*/MDB.EDM_DBData.csdl|res://*/MDB.EDM_DBData.ssdl|res://*/MDB.EDM_DBData.msl;provider=System.Data.SQLite.EF6;provider connection string=\"data source=" + options.Host + "\""; //D:\\Projekte\\coop\\VEX\\Test\\dbData.s3db\""; // string connectionString = "metadata=res://*/MDB.MDB_PNDS.csdl|res://*/MDB.MDB_PNDS.ssdl|res://*/MDB.MDB_PNDS.msl;provider=System.Data.SqlClient;provider connection string=\"data source=" + options.Host + ";initial catalog=PNDS;user id=" + options.User + ";password="******";MultipleActiveResultSets=True;App=EntityFramework\""; dbDataEntities crmDataContext = new dbDataEntities(connectionString);//, mappingSource); crmDataContext.CTXID = _databaseService.GetNextCtxID(); // crmDataContext.Connection.StateChange += new System.Data.StateChangeEventHandler(Connection_StateChange); //------------- crmDataContext..Database..Connection.Open(); // foreach (ListViewItem lvItem in lvFrames.Items) // ((BaseControl)lvItem.Tag).OpenClick(); if (checkUser && _databaseService.LoggedUser.UserID < 1) { ShowLoginDialog(); return(null); } ctx.Context = crmDataContext; return(ctx); } else if (options.DBType == DBType.Oracle) { //string connectionString = "User Id=" + options.User + ";Password="******";Server=" + options.Host + ";Direct=True;Sid=" + options.ServiceName + ";Persist Security Info=True"; //// string providerPrefix = ""; ////if (!ConnectionDialog.Show(out connectionString, out providerPrefix)) ////{ //// stripLabel.Text = "Incorrect connection string"; //// return; ////} ////Frame activating //// Stream contextStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(String.Format("ComID.IDAL.MDB.CrmDataMapping{0}.lqml", providerPrefix)); //// Devart.Data.Linq.Mapping.MappingSource mappingSource = Devart.Data.Linq.Mapping.XmlMappingSource.FromStream(contextStream); //PNDSEntities crmDataContext = new PNDSEntities(m_Container, connectionString);//, mappingSource); //crmDataContext.CTXID = _databaseService.GetNextCtxID(); //// crmDataContext.Connection.StateChange += new System.Data.StateChangeEventHandler(Connection_StateChange); //crmDataContext.Database.Connection.Open(); //// foreach (ListViewItem lvItem in lvFrames.Items) //// ((BaseControl)lvItem.Tag).OpenClick(); //if (checkUser && _databaseService.LoggedUser.UserID < 1) //{ // ShowLoginDialog(m_Container); // return null; //} //return crmDataContext; } } catch (Exception ex) { var loggerService = VEFModule.UnityContainer.Resolve(typeof(ILoggerService), "") as ILoggerService; loggerService.Log("Datenbankverbindung fehlgeschlagen." + (ex.InnerException != null ? ex.InnerException.Message : ex.Message), LogCategory.Exception, LogPriority.High); // // workspace.NotificationRequest.Raise(new Notification { Content = "Datenbankverbindung fehlgeschlagen." + (ex.InnerException != null ? ex.InnerException.Message : ex.Message), Title = "Fehler" }); // stripLabel.Text = ex.Message; } return(ctx); }