Esempio n. 1
0
        private void createInstance(InstanceType type)
        {
            InstanceLogger logger = null;

            try
            {
                var dialog = new CreateInstanceDialog(protocolPlugins.Values, type);
                dialog.ShowDialog();
                if (dialog.DialogResult == DialogResult.OK)
                {
                    var plugin = dialog.SelectedPlugin;
                    var name   = dialog.InstanceName;
                    var file   = dialog.LogFileName;
                    try
                    {
                        logger = new InstanceLogger(file, FileMode.Create);
                    }
                    // something went wrong with the path, save it as temp file
                    catch
                    {
                        logger = new InstanceLogger();
                    }
                    logger.WritePluginID(plugin.ID);
                    logger.WriteInstanceName(name);
                    var pack    = plugin.CreateInstance(logger, type);
                    var drivers = setupDrivers(pack.Controller);
                    ++itemID;
                    controllers.Add(itemID, new ControllerData(pack.Controller, true));
                    model.AddInstance(itemID, plugin.ID, name, type, pack.Controller.Instance.Settings);
                    foreach (var driver in drivers)
                    {
                        model.AddDriverToInstance(itemID, driver.Key, driver.Value);
                    }
                    bindInstanceEvents(pack.Controller.Instance);
                    view.AddInstance(itemID, name, pack.View, true);
                }
            }
            catch (SetupAbortedByUserException)
            {
                if (logger != null)
                {
                    logger.Close();
                }
            }
        }