Example #1
0
        /// <summary>
        /// Creates a ProviderPlugin connection on the current instance of the ProviderPluginManager.
        /// Therefor all required parameters (answers) are set.
        /// </summary>
        /// <param name="pluginInstanceSyneryIdentifier"></param>
        public void SetupProviderPluginDummyConnection(string pluginInstanceSyneryIdentifier = "Dummy", string[] connectionPath = null)
        {
            if (connectionPath == null)
            {
                // set default
                connectionPath = new string[] { "Connections", "DummyConnection" };
            }

            ProviderPluginConnectTask task = new ProviderPluginConnectTask();

            task.InstanceReferenceSyneryIdentifier = pluginInstanceSyneryIdentifier;
            task.ConnectionPath = connectionPath;
            task.Memory         = _SyneryMemory;

            // add the parameters needed by the provider plugin instance to create a connection
            task.Parameters.Add(new string[] { "Database", "Connection", "Server" }, "someServer");
            task.Parameters.Add(new string[] { "Database", "Connection", "Database" }, "someDb");
            task.Parameters.Add(new string[] { "Database", "Connection", "User" }, "SomeUser");
            task.Parameters.Add(new string[] { "Database", "Connection", "Password" }, "somePassword");
            task.Parameters.Add(new string[] { "Proffix", "Tables", "ShowAdditionalTables" }, true);
            task.Parameters.Add(new string[] { "Proffix", "Tables", "ShowSystemTables" }, true);

            _ProviderPluginManager.RunTask(task);
        }
        public void Run(SyneryParser.ProviderPluginStatementContext context)
        {
            ProviderPluginTask task;

            if (context.providerPluginConnectStatement() != null)
            {
                // interpret the statement and get the task for the ProviderPluginManager

                task = Controller.Interpret <SyneryParser.ProviderPluginConnectStatementContext, ProviderPluginConnectTask>(
                    context.providerPluginConnectStatement());
            }
            else if (context.providerPluginDataExchangeStatement() != null)
            {
                // interpret the statement and get the task for the ProviderPluginManager

                ProviderPluginDataExchangeTask dataExchangeTask = Controller.
                                                                  Interpret <SyneryParser.ProviderPluginDataExchangeStatementContext, ProviderPluginDataExchangeTask>(
                    context.providerPluginDataExchangeStatement());

                task = dataExchangeTask;
            }
            else
            {
                throw new SyneryInterpretationException(context, "Unknown statement in ProviderPluginStatementInterpreter. No interpreter found for the given context.");
            }

            // append the current state of the SyneryMemory to the task

            task.Memory = Memory;

            try
            {
                // execute the task

                Memory.ProviderPluginManager.RunTask(task);
            }
            catch (Exception ex)
            {
                // handle exception according to the task type

                ProviderPluginConnectTask      connectTask = task as ProviderPluginConnectTask;
                ProviderPluginDataExchangeTask dataTask    = task as ProviderPluginDataExchangeTask;

                // create a Synery exception that can be caught by the Synery developer

                if (connectTask != null)
                {
                    ProviderPluginConnectionExceptionRecord syneryException = new ProviderPluginConnectionExceptionRecord();
                    syneryException.Message        = ExceptionHelper.GetNestedExceptionMessages(ex);
                    syneryException.ConnectionPath = connectTask.SyneryConnectionPath;
                    syneryException.PluginInstanceReferenceIdentifier = connectTask.InstanceReferenceSyneryIdentifier;

                    Controller.HandleSyneryEvent(context, syneryException.GetAsSyneryValue());
                }
                else if (dataTask != null)
                {
                    ProviderPluginDataExchangeExceptionRecord syneryException = new ProviderPluginDataExchangeExceptionRecord();
                    syneryException.Message         = ExceptionHelper.GetNestedExceptionMessages(ex);
                    syneryException.DataCommandType = dataTask.Type.ToString().ToUpper();
                    syneryException.FullPath        = dataTask.FullSyneryPath;

                    Controller.HandleSyneryEvent(context, syneryException.GetAsSyneryValue());
                }
            }
        }