Exemple #1
0
        /// <summary>
        /// Starts the Manager
        /// </summary>
        public void Start()
        {
            if (Started || _Starting)
            {
                return;
            }

            try
            {
                _Starting = true;

                if (Config == null)
                {
                    ReadConfig();
                }

                //See if there is any remoting end poit.
                //There can be only one remoting end point.
                //See if there are any WCF end point. Thre can be more WCF end points.
                EndPointConfiguration remotingEpc = null;
                bool areAnyWcfEps = false;

                foreach (string key in Config.EndPoints.Keys)
                {
                    EndPointConfiguration epc = Config.EndPoints[key];
                    if (epc.RemotingMechanism == RemotingMechanism.TcpBinary)
                    {
                        if (remotingEpc != null)
                        {
                            throw new DoubleRemotingEndPointException("Cannot set two EndPoint where Rempting Mechanism is set to TcpBinary");
                        }

                        remotingEpc = epc;
                    }
                    else
                    {
                        areAnyWcfEps = true;
                    }
                }

                if (remotingEpc != null)
                {
                    StartTcpBinary(remotingEpc);
                }

                if (areAnyWcfEps)
                {
                    StartWCF();
                }


                logger.Debug("Configuring storage...");
                ManagerStorageFactory.CreateManagerStorage(Config);
                if (!ManagerStorageFactory.ManagerStorage().VerifyConnection())
                {
                    throw new Exception("Error connecting to manager storage. Please check manager log file for details.");
                }

                logger.Debug("Configuring internal shared class...");
                InternalShared common = InternalShared.GetInstance(Config);

                logger.Debug("Starting dispatcher thread");
                dispatcher.Start();

                logger.Info("Starting watchdog thread");
                watchdog.Start();

                //start a seperate thread to init-known executors, since this may take a while.
                _InitExecutorsThread      = new Thread(new ThreadStart(InitExecutors));
                _InitExecutorsThread.Name = "InitExecutorsThread";
                _InitExecutorsThread.Start();

                Config.Serialize();

                Started = true;

                try
                {
                    if (ManagerStartEvent != null)
                    {
                        ManagerStartEvent(this, new EventArgs());
                    }
                }
                catch { }
            }
            catch (Exception ex)
            {
                Stop();
                logger.Error("Error Starting Manager Container", ex);
                throw ex;
            }
            finally
            {
                _Starting = false;
            }
        }
Exemple #2
0
        private void btInstall_Click(object sender, EventArgs e)
        {
            //instead of the old method, just use the ManagerStorageSetup members now.
            Alchemi.Manager.Configuration config = null;

            try
            {
                // serialize configuration
                Log("[ Creating Configuration File ] ... ");

                config            = new Alchemi.Manager.Configuration(InstallLocation);
                config.DbServer   = txServer.Text;
                config.DbUsername = txUsername.Text;
                config.DbPassword = txAdminPwd.Text;
                config.DbName     = "master";             //we need this to initially create the alchemi database.
                config.Slz();
                Log("[ Done ].");

                //for now just use RunSQL method.
                ManagerStorageFactory.CreateManagerStorage(config);
                IManagerStorage store = ManagerStorageFactory.ManagerStorage();

                // (re)create database
                Log("[ Setting up storage ] ... ");

                string scriptPath = Path.Combine(scriptLocation, "Alchemi_database.sql");

                while (!File.Exists(scriptPath))
                {
                    MessageBox.Show("Alchemi SQL files not found in folder: " + scriptLocation + ". Please select the folder where the sql scripts are located!", "Locate Script Files", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    DialogResult result = dirBox.ShowDialog(this);
                    if (result == DialogResult.Cancel)
                    {
                        break;
                    }
                    scriptLocation = dirBox.SelectedPath;
                    scriptPath     = Path.Combine(scriptLocation, "Alchemi_database.sql");
                }

                if (!File.Exists(scriptPath))
                {
                    return;                     //cannot continue.
                }

                // create structure
                Log("[ Creating Database Structure ] ... ");

                //load it from sql files for now. later make use of resources.
                using (FileStream fs = File.OpenRead(scriptPath))
                {
                    StreamReader sr  = new StreamReader(fs);
                    String       sql = sr.ReadToEnd();
                    sr.Close();
                    fs.Close();
                    store.RunSql(sql);
                }
                Log("[ Done ].");

                Log("[ Creating tables ] ... ");
                scriptPath = Path.Combine(scriptLocation, "Alchemi_structure.sql");
                //load it from sql files for now. later make use of resources.
                using (FileStream fs = File.OpenRead(scriptPath))
                {
                    StreamReader sr  = new StreamReader(fs);
                    String       sql = sr.ReadToEnd();
                    sr.Close();
                    fs.Close();
                    store.RunSql(sql);
                }
                Log("[ Done ].");

                Log("[ Inserting initialization data ] ... ");
                scriptPath = Path.Combine(scriptLocation, "Alchemi_data.sql");
                //load it from sql files for now. later make use of resources.
                using (FileStream fs = File.OpenRead(scriptPath))
                {
                    StreamReader sr  = new StreamReader(fs);
                    String       sql = sr.ReadToEnd();
                    sr.Close();
                    fs.Close();
                    store.RunSql(sql);
                }

                Log("[ Done ].");

                // serialize configuration
                Log("[ Updating Configuration File ] ... ");
                config.DbServer   = txServer.Text;
                config.DbUsername = txUsername.Text;
                config.DbPassword = txAdminPwd.Text;
                config.DbName     = "Alchemi";
                config.Slz();
                Log("[ Done ].");

                Log("Wrote configuration file to " + InstallLocation);
                Log("[ Installation Complete! ]");

                btInstall.Enabled = false;
                btFinish.Enabled  = true;
            }
            catch (Exception ex)
            {
                Log("[ Error ]");
                Log(ex.Message);
                return;
            }
        }
Exemple #3
0
        /// <summary>
        /// Thread doing the actual installation
        /// </summary>
        private void WorkerThread()
        {
            ShowProgress("Installer thread starting...",
                         0);

            ShowProgress(String.Format("Database type: {0}", _parent.managerConfiguration.DbType),
                         0);

            try
            {
                /// Create a storage object with the initial catalogue left to the default one.
                /// This is usually master for SQL Server or nothing for mySQL
                IManagerStorage storage = ManagerStorageFactory.CreateManagerStorage(_parent.managerConfiguration, false);

                // this storage object is also a storage setup object so it is safe to cast
                IManagerStorageSetup setup = (IManagerStorageSetup)storage;

                ShowProgress("Creating the database.",
                             1);

                if (_parent.managerConfiguration.DbType == ManagerStorageEnum.db4o)
                {
                    setup.CreateStorage(_parent.managerConfiguration.DbFilePath);
                }
                else
                {
                    setup.CreateStorage(_parent.managerConfiguration.DbName);
                }

                ShowProgress("Database created.",
                             20);
            }
            catch (Exception ex1)
            {
                ShowProgress("Unable to create the database. Error message:" + ex1.Message,
                             100);
#if DEBUG
                ShowProgress("Debug information:",
                             100);
                ShowProgress(ex1.ToString(),
                             100);
#endif
                return;
            }

            try
            {
                IManagerStorage storage = ManagerStorageFactory.CreateManagerStorage(_parent.managerConfiguration);

                // this storage object is also a storage setup object so it is safe to cast
                IManagerStorageSetup setup = (IManagerStorageSetup)storage;

                ShowProgress("Creating the database structure.",
                             40);

                // create storage structures
                setup.SetUpStorage();

                ShowProgress("Database structure created.",
                             60);

                ShowProgress("Creating default users, groups and permissions.",
                             80);

                // insert the default values
                setup.InitializeStorageData();

                ShowProgress("All default objects created.",
                             90);
            }
            catch (Exception ex2)
            {
                ShowProgress("Unable to initialize the database data. Error message:" + ex2.Message,
                             100);
#if DEBUG
                ShowProgress("Debug information:",
                             100);
                ShowProgress(ex2.ToString(),
                             100);
#endif
                return;
            }

            ShowProgress("Done!",
                         100);
        }