Example #1
0
        void IAssemblyObjectList.Remove(IAssemblyObject obj)
        {
            ExecutionInfo info = obj as ExecutionInfo;

            if (info != null)
            {
                info.Thread.Abort();
            }
        }
Example #2
0
        private object RunInternal(MethodOverloads methodOverloads, object[] rawParams)
        {
            // TODO: Security
            FileIOPermission phoenixLauncherFile = new FileIOPermission(FileIOPermissionAccess.AllAccess, System.IO.Path.Combine(Core.Directory, "PhoenixLauncher.xml"));

            phoenixLauncherFile.Deny();

            // First create ParameterData array
            ParameterData[] parameters = new ParameterData[rawParams.Length];
            for (int i = 0; i < rawParams.Length; i++)
            {
                parameters[i] = new ParameterData(rawParams[i]);
            }

            // Get valid overloads (array is never empty)
            Method[] methods = methodOverloads.FindOverloads(parameters);

            Exception exception = null;

            foreach (Method m in methods)
            {
                ExecutionInfo info = new ExecutionInfo(m);

                ExecutionAttribute[] execAttributes = (ExecutionAttribute[])m.MethodInfo.GetCustomAttributes(typeof(ExecutionAttribute), false);

                try {
                    // Call all Execution attributes
                    for (int i = 0; i < execAttributes.Length; i++)
                    {
                        execAttributes[i].Starting(m);
                    }

                    // Add execution to running list
                    lock (syncRoot) {
                        if (runningExecutions.Count >= Executions.MaxExecutions)
                        {
                            throw new RuntimeException("Executions limit exceeded.");
                        }

                        RuntimeCore.AddAssemblyObject(info, this);
                        runningExecutions.Add(info);

                        try {
                            // Raise Started event
                            executionStarted.Invoke(this, new ExecutionsChangedEventArgs(info));
                        }
                        catch (Exception e) {
                            Core.ShowMessageBoxAsync("Unhandled exception in Executions.ExecutionStarted event handler.\r\nMessage: " + e.Message, "Warning");
                        }
                    }

                    // Init thread-dependent classes
                    if (!threadInitialized)
                    {
                        ScriptErrorException.ThreadInit();
                        WorldData.World.ThreadInit();
                        Journal.ThreadInit();
                        threadInitialized = true;
                    }

                    // Invoke
                    try {
                        return(m.Invoke(parameters));
                    }
                    catch (System.Reflection.TargetInvocationException e) {
                        // Im interested only in exception thrown by code
                        throw e.InnerException;
                    }
                }
                catch (ParameterException e) {
                    exception = e;
                }
                catch (ExecutionBlockedException e) {
                    exception = e;
                }
                finally {
                    // Remove execution from running list
                    lock (syncRoot) {
                        runningExecutions.Remove(info);
                        RuntimeCore.RemoveAssemblyObject(info);

                        try {
                            // Raise Finished event
                            executionFinished.Invoke(this, new ExecutionsChangedEventArgs(info));
                        }
                        catch (Exception e) {
                            Core.ShowMessageBoxAsync("Unhandled exception in Executions.ExecutionFinished event handler.\r\nMessage: " + e.Message, "Warning");
                        }
                    }

                    // Call all Execution attributes
                    for (int i = 0; i < execAttributes.Length; i++)
                    {
                        execAttributes[i].Finished(m);
                    }
                }
            }

            if (exception != null)
            {
                throw exception;
            }
            else
            {
                throw new InternalErrorException();
            }
        }
Example #3
0
 public ExecutionsChangedEventArgs(ExecutionInfo ei)
 {
     executionInfo = ei;
 }