public bool EventSchProcessQIS(ref QueueItemStruct QIS)
        {
            try
            {
                Exception      ex      = null;
                EnumeratorInfo Running = QIS.ID.Script.ExecuteEvent(QIS.State,
                                                                    QIS.functionName,
                                                                    QIS.param, QIS.CurrentlyAt, out ex);

                if (ex != null)
                {
                    //Check exceptions, some are ours to deal with, and others are to be logged
                    if (ex.Message.Contains("SelfDeleteException"))
                    {
                        if (QIS.ID.Part != null && QIS.ID.Part.ParentEntity != null)
                        {
                            IBackupModule backup =
                                QIS.ID.Part.ParentEntity.Scene.RequestModuleInterface <IBackupModule>();
                            if (backup != null)
                            {
                                backup.DeleteSceneObjects(
                                    new ISceneEntity[1] {
                                    QIS.ID.Part.ParentEntity
                                }, true, true);
                            }
                        }
                    }
                    else if (ex.Message.Contains("ScriptDeleteException"))
                    {
                        if (QIS.ID.Part != null && QIS.ID.Part.ParentEntity != null)
                        {
                            QIS.ID.Part.Inventory.RemoveInventoryItem(QIS.ID.ItemID);
                        }
                    }
                    //Log it for the user
                    else if (!(ex.Message.Contains("EventAbortException")) &&
                             !(ex.Message.Contains("MinEventDelayException")))
                    {
                        QIS.ID.DisplayUserNotification(ex.ToString(), "executing", false, true);
                    }
                    EventManager.EventComplete(QIS);
                    return(false);
                }
                else if (Running != null)
                {
                    //Did not finish so requeue it
                    QIS.CurrentlyAt = Running;
                    QIS.RunningNumber++;
                    return(true); //Do the return... otherwise we open the queue for this event back up
                }
            }
            catch (Exception ex)
            {
                //Error, tell the user
                QIS.ID.DisplayUserNotification(ex.ToString(), "executing", false, true);
            }
            //Tell the event manager about it so that the events will be removed from the queue
            EventManager.EventComplete(QIS);
            return(false);
        }
示例#2
0
        /// <summary>
        ///     This closes the script, removes it from any known spots, and disposes of itself.
        /// </summary>
        /// <param name="shouldbackup">Should we back up this script and fire state_exit?</param>
        public void CloseAndDispose(bool shouldbackup)
        {
            m_ScriptEngine.MaintenanceThread.RemoveFromEventSchQueue(this, true);

            if (Script != null)
            {
                //Fire the exit event for scripts that support it
                Exception      ex;
                EnumeratorInfo info = null;
                while ((info = Script.ExecuteEvent(State, "exit", new object[0], info, out ex))
                       != null)
                {
                }
            }
            m_ScriptEngine.MaintenanceThread.SetEventSchSetIgnoreNew(this, false);

            //Give the user back any controls we took
            ReleaseControls();

            // Tell script not to accept new requests
            //These are fine to set as the state wont be saved again
            if (shouldbackup)
            {
                Running  = false;
                Disabled = true;
            }

            // Remove from internal structure
            ScriptEngine.ScriptProtection.RemoveScript(this);
            //            if (!Silent) //Don't remove on a recompile because we'll make it under a different assembly
            //                ScriptEngine.ScriptProtection.RemovePreviouslyCompiled(Source);

            //Remove any errors that might be sitting around
            m_ScriptEngine.ScriptErrorReporter.RemoveError(ItemID);

            #region Clean out script parts

            //Only if this script changed target omega do we reset it
            if (TargetOmegaWasSet)
            {
                Part.AngularVelocity = Vector3.Zero;                  // Removed in SL
                Part.ScheduleUpdate(PrimUpdateFlags.AngularVelocity); // Send changes to client.
            }

            #endregion

            if (Script != null)
            {
                // Stop long command on script
                m_ScriptEngine.RemoveScriptFromPlugins(Part.UUID, ItemID);

                //Release the script and destroy it
                ILease lease = (ILease)RemotingServices.GetLifetimeService(Script as MarshalByRefObject);
                if (lease != null)
                {
                    lease.Unregister(Script.Sponsor);
                }

                Script.Close();
                Script = null;
            }

            if (InventoryItem != null)
            {
                MainConsole.Instance.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Closed Script " +
                                           InventoryItem.Name + " in " +
                                           Part.Name);
            }
            if (AppDomain == null)
            {
                return;
            }

            // Tell AppDomain that we have stopped script
            m_ScriptEngine.AppDomainManager.UnloadScriptAppDomain(AppDomain);
            AppDomain = null;
        }