当前位置: 首页>>代码示例>>C#>>正文


C# IScript.GetStateEventFlags方法代码示例

本文整理汇总了C#中IScript.GetStateEventFlags方法的典型用法代码示例。如果您正苦于以下问题:C# IScript.GetStateEventFlags方法的具体用法?C# IScript.GetStateEventFlags怎么用?C# IScript.GetStateEventFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IScript的用法示例。


在下文中一共展示了IScript.GetStateEventFlags方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        /// <summary>
        /// Load the script from an assembly into an AppDomain.
        /// </summary>
        /// <param name='dom'></param>
        /// <param name='assembly'></param>
        /// <param name='dataPath'>
        /// Path for all script associated data (state, etc.).  In a multi-region set up
        /// with all scripts loading into the same AppDomain this may not be the same place as the DLL itself.
        /// </param>
        /// <param name='stateSource'></param>
        /// <returns>false if load failed, true if suceeded</returns>
        public bool Load(
            IScript script, EventWaitHandle coopSleepHandle, string assemblyPath, 
            string dataPath, StateSource stateSource, bool coopTermination)
        {
            m_Script = script;
            m_coopSleepHandle = coopSleepHandle;
            m_assemblyPath = assemblyPath;
            m_dataPath = dataPath;
            m_stateSource = stateSource;
            m_coopTermination = coopTermination;

            if (m_coopTermination)
                CoopWaitHandle = coopSleepHandle;
            else
                CoopWaitHandle = null;

            ApiManager am = new ApiManager();

            foreach (string api in am.GetApis())
            {
                m_Apis[api] = am.CreateApi(api);
                m_Apis[api].Initialize(Engine, Part, ScriptTask);
            }

            try
            {
                foreach (KeyValuePair<string,IScriptApi> kv in m_Apis)
                {
                    m_Script.InitApi(kv.Key, kv.Value);
                }

                //                // m_log.Debug("[Script] Script instance created");

                Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State));
            }
            catch (Exception e)
            {
                m_log.ErrorFormat(
                    "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}.  Error initializing script instance.  Exception {6}{7}",
                    ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, e.Message, e.StackTrace);

                return false;
            }

            // For attachments, XEngine saves the state into a .state file when XEngine.SetXMLState() is called.           
            string savedState = Path.Combine(m_dataPath, ItemID.ToString() + ".state");

            if (File.Exists(savedState))
            {
                //                m_log.DebugFormat(
                //                    "[SCRIPT INSTANCE]: Found state for script {0} for {1} ({2}) at {3} in {4}", 
                //                    ItemID, savedState, Part.Name, Part.ParentGroup.Name, Part.ParentGroup.Scene.Name);

                string xml = String.Empty;

                try
                {
                    FileInfo fi = new FileInfo(savedState);
                    int size = (int)fi.Length;
                    if (size < 512000)
                    {
                        using (FileStream fs = File.Open(savedState,
                                                         FileMode.Open, FileAccess.Read, FileShare.None))
                        {
                            Byte[] data = new Byte[size];
                            fs.Read(data, 0, size);

                            xml = Encoding.UTF8.GetString(data);

                            ScriptSerializer.Deserialize(xml, this);

                            AsyncCommandManager.CreateFromData(Engine,
                                                               LocalID, ItemID, ObjectID,
                                                               PluginData);

                            //                            m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName);

                            Part.SetScriptEvents(ItemID,
                                                 (int)m_Script.GetStateEventFlags(State));

                            if (!Running)
                                m_startOnInit = false;

                            Running = false;

                            // we get new rez events on sim restart, too
                            // but if there is state, then we fire the change
                            // event

//.........这里部分代码省略.........
开发者ID:Gitlab11,项目名称:opensim,代码行数:101,代码来源:ScriptInstance.cs

示例2: Start


//.........这里部分代码省略.........
                            (DateTime.Now.ToUniversalTime() - StartTime).TotalSeconds);

            //Create the app domain if needed.
            try
            {
                Script = m_ScriptEngine.AppDomainManager.LoadScript(AssemblyName, "Script.ScriptClass", out AppDomain);
                m_ScriptEngine.Compiler.FinishCompile(this, Script);
                //Add now so that we don't add it too early and give it the possibility to fail
                ScriptEngine.ScriptProtection.AddPreviouslyCompiled(Source, this);
            }
            catch (FileNotFoundException) // Not valid!!!
            {
                MainConsole.Instance.Error("[" + m_ScriptEngine.ScriptEngineName +
                            "]: File not found in app domain creation. Corrupt state save! " + AssemblyName);
                ScriptEngine.ScriptProtection.RemovePreviouslyCompiled(Source);
                return Start(startInfo); // Lets restart the script if this happens
            }
            catch (Exception ex)
            {
                DisplayUserNotification(ex.ToString(), "app domain creation", reupload, true);
                //It might have failed, but we still need to add it so that we can reuse this script data class later
                ScriptEngine.ScriptProtection.AddNewScript(this);
                return false;
            }
            Source = null; //Don't keep it in memory, we don't need it anymore
            Compiled = true; //We compiled successfully

            //ILease lease = (ILease)RemotingServices.GetLifetimeService(Script as MarshalByRefObject);
            //if (lease != null) //Its null if it is all running in the same app domain
            //    lease.Register(Script.Sponsor);

            //If its a reupload, an avatar is waiting for the script errors
            if (reupload)
                m_ScriptEngine.ScriptErrorReporter.AddError(ItemID, new ArrayList(new[] { "SUCCESSFULL" }));

            if (useDebug)
                MainConsole.Instance.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Stage 2 compile: " +
                            (DateTime.Now.ToUniversalTime() - StartTime).TotalSeconds);

            SetApis();

            //Now do the full state save finding now that we have an app domain.
            if (LastStateSave != null)
            {
                string assy = AssemblyName;
                // don't restore the assembly name, the one we have is right (if re-compiled or not)
                m_ScriptEngine.StateSave.Deserialize(this, LastStateSave);
                AssemblyName = assy;
                if (this.State == "" && DefaultState != this.State)
                //Sometimes, "" is a valid state for other script languages
                {
                    MainConsole.Instance.Warn("BROKEN STATE SAVE!!! - " + this.Part.Name + " @ " + this.Part.AbsolutePosition);
                    this.State = DefaultState;
                    m_ScriptEngine.StateSave.SaveStateTo(this, true);
                }
                else
                {
                    // we get new rez events on sim restart, too
                    // but if there is state, then we fire the change
                    // event
                    StartedFromSavedState = true;
                }

                // ItemID changes sometimes (not sure why, but observed it)
                // If so we want to clear out the old save state,
                // which would otherwise have hung around in the object forever
                if (LastStateSave.ItemID != ItemID)
                {
                    m_ScriptEngine.StateSave.DeleteFrom(Part, LastStateSave.ItemID);
                    m_ScriptEngine.StateSave.SaveStateTo(this, true);
                }
            }
            else
            {
                //Make a new state save now
                m_ScriptEngine.StateSave.SaveStateTo(this, true);
            }

            //Set the event flags
            Part.SetScriptEvents(ItemID, Script.GetStateEventFlags(State));

            // Add it to our script memstruct so it can be found by other scripts
            ScriptEngine.ScriptProtection.AddNewScript(this);

            //All done, compiled successfully
            Loading = false;

            if (MainConsole.Instance.IsDebugEnabled)
            {
                TimeSpan time = (DateTime.Now.ToUniversalTime() - StartTime);

                MainConsole.Instance.Debug("[" + m_ScriptEngine.ScriptEngineName +
                            "]: Started Script " + InventoryItem.Name +
                            " in object " + Part.Name + "@" + Part.ParentEntity.RootChild.AbsolutePosition +
                            (presence != null ? " by " + presence.Name : "") +
                            " in region " + Part.ParentEntity.Scene.RegionInfo.RegionName +
                            " in " + time.TotalSeconds + " seconds.");
            }
            return true;
        }
开发者ID:rjspence,项目名称:YourSim,代码行数:101,代码来源:ScriptData.cs

示例3: Start


//.........这里部分代码省略.........
                                }
                                DisplayUserNotification(error, "compiling", reupload, false);
                                return;
                            }
                        }

                        #endregion

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        DisplayUserNotification(ex.Message, "compiling", reupload, true);
                        return;
                    }
                }
            }

            bool useDebug = false;
            if (useDebug)
                m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Stage 1 compile: " + (DateTime.Now.ToUniversalTime() - StartTime).TotalSeconds);

            //Create the app domain if needed.
            try
            {
                Script = m_ScriptEngine.AppDomainManager.LoadScript(AssemblyName, "Script.ScriptClass", out AppDomain);
                ScriptEngine.ScriptProtection.AddPreviouslyCompiled(Source, this);
            }
            catch (System.IO.FileNotFoundException) // Not valid!!!
            {
                m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: File not found in app domain creation. Corrupt state save! " + AssemblyName);
                ScriptEngine.ScriptProtection.RemovePreviouslyCompiled(Source);
                ScriptFrontend.DeleteStateSave(AssemblyName);
                Start(reupload); // Lets restart the script if this happens
                return;
            }
            catch (Exception ex)
            {
                DisplayUserNotification(ex.Message, "app domain creation", reupload, true);
                return;
            }

            ILease lease = (ILease)RemotingServices.GetLifetimeService(Script as MarshalByRefObject);
            if (lease != null)
                lease.Register(Script.Sponsor);

            //If its a reupload, an avatar is waiting for the script errors
            if (reupload)
                m_ScriptEngine.ScriptErrorReporter.AddError(ItemID, new ArrayList(new string[] { "SUCCESSFULL" }));

            if (useDebug)
                m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Stage 2 compile: " + (DateTime.Now.ToUniversalTime() - StartTime).TotalSeconds);

            SetApis();

            //Set the event flags
            part.SetScriptEvents(ItemID, Script.GetStateEventFlags(State));

            //Now do the full state save finding now that we have an app domain.
            if (LastStateSave != null)
            {
                ScriptDataSQLSerializer.Deserialize(this, m_ScriptEngine, LastStateSave);

                m_ScriptEngine.CreateFromData(part.UUID, ItemID, part.UUID,
                    PluginData);

                // we get new rez events on sim restart, too
                // but if there is state, then we fire the change
                // event
                StartedFromSavedState = true;
            }
            else
            {

                //Make a new state save now
                m_ScriptEngine.MaintenanceThread.AddToStateSaverQueue(this, true);
            }

            // Add it to our script memstruct so it can be found by other scripts
            ScriptEngine.ScriptProtection.AddNewScript(this);

            //All done, compiled successfully
            Loading = false;

            TimeSpan time = (DateTime.Now.ToUniversalTime() - StartTime);

            if (presence != null)
                MainConsole.Instance.Output("[" + m_ScriptEngine.ScriptEngineName +
                    "]: Started Script " + InventoryItem.Name +
                    " in object " + part.Name +
                    " by " + presence.Name +
                    " in region " + part.ParentGroup.Scene.RegionInfo.RegionName +
                    " in " + time.TotalSeconds + " seconds.", "None");
            else
                MainConsole.Instance.Output("[" + m_ScriptEngine.ScriptEngineName +
                    "]: Started Script " + InventoryItem.Name +
                    " in object " + part.Name +
                    " in region " + part.ParentGroup.Scene.RegionInfo.RegionName +
                    " in " + time.TotalSeconds + " seconds.", "None");
        }
开发者ID:shangcheng,项目名称:Aurora,代码行数:101,代码来源:ScriptData.cs

示例4: ScriptInstance

        public ScriptInstance(IScriptEngine engine, SceneObjectPart part,
                UUID itemID, UUID assetID, string assembly,
                AppDomain dom, string primName, string scriptName,
                int startParam, bool postOnRez, StateSource stateSource,
                int maxScriptQueue)
        {
            m_Engine = engine;

            m_LocalID = part.LocalId;
            m_ObjectID = part.UUID;
            m_ItemID = itemID;
            m_AssetID = assetID;
            m_PrimName = primName;
            m_ScriptName = scriptName;
            m_Assembly = assembly;
            m_StartParam = startParam;
            m_MaxScriptQueue = maxScriptQueue;
            m_stateSource = stateSource;
            m_postOnRez = postOnRez;
            m_AttachedAvatar = part.AttachedAvatar;
            m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;

            if (part != null)
            {
                lock (part.TaskInventory)
                {
                    if (part.TaskInventory.ContainsKey(m_ItemID))
                    {
                        m_thisScriptTask = part.TaskInventory[m_ItemID];
                    }
                }
            }

            ApiManager am = new ApiManager();

            foreach (string api in am.GetApis())
            {
                m_Apis[api] = am.CreateApi(api);
                m_Apis[api].Initialize(engine, part, m_LocalID, itemID);
            }

            try
            {
                m_Script = (IScript)dom.CreateInstanceAndUnwrap(
                    Path.GetFileNameWithoutExtension(assembly),
                    "SecondLife.Script");

                // Add a sponsor to the script
//                ISponsor scriptSponsor = new ScriptSponsor();
//                ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as MarshalByRefObject);
//                lease.Register(scriptSponsor);
                //m_ScriptSponsor = scriptSponsor;

            }
            catch (Exception)
            {
                // m_log.ErrorFormat("[Script] Error loading assembly {0}\n"+e.ToString(), assembly);
            }

            try
            {
                foreach (KeyValuePair<string,IScriptApi> kv in m_Apis)
                {
                    m_Script.InitApi(kv.Key, kv.Value);
                }

//                // m_log.Debug("[Script] Script instance created");

                part.SetScriptEvents(m_ItemID,
                                     (int)m_Script.GetStateEventFlags(State));
            }
            catch (Exception)
            {
                // m_log.Error("[Script] Error loading script instance\n"+e.ToString());
                return;
            }

            m_SaveState = true;

            string savedState = Path.Combine(Path.GetDirectoryName(assembly),
                    m_ItemID.ToString() + ".state");
            if (File.Exists(savedState))
            {
                string xml = String.Empty;

                try
                {
                    FileInfo fi = new FileInfo(savedState);
                    int size=(int)fi.Length;
                    if (size < 512000)
                    {
                        using (FileStream fs = File.Open(savedState,
                                                         FileMode.Open, FileAccess.Read, FileShare.None))
                        {
                            System.Text.ASCIIEncoding enc =
                                new System.Text.ASCIIEncoding();

                            Byte[] data = new Byte[size];
                            fs.Read(data, 0, size);

//.........这里部分代码省略.........
开发者ID:Ideia-Boa,项目名称:opensim,代码行数:101,代码来源:ScriptInstance.cs

示例5: Start


//.........这里部分代码省略.........
                            if (compilewarnings != null && compilewarnings.Length != 0)
                            {
                                string error = string.Empty;
                                foreach(string compileerror in compileerrors)
                                {
                                    error += compileerror;
                                }
                                DisplayUserNotification(error, "compiling", reupload, false);
                                return;
                            }
                        }

                        #endregion

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        //LEAVE IT AS ToString() SO THAT WE GET THE STACK TRACE TOO
                        DisplayUserNotification(ex.ToString(), "(exception) compiling", reupload, true);
                        return;
                    }
                }
            }

            bool useDebug = false;
            if (useDebug)
                m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Stage 1 compile: " + (DateTime.Now.ToUniversalTime() - StartTime).TotalSeconds);

            //Create the app domain if needed.
            try
            {
                Script = m_ScriptEngine.AppDomainManager.LoadScript(AssemblyName, "Script.ScriptClass", out AppDomain);
                m_ScriptEngine.Compiler.FinishCompile (this, Script);
                //Add now so that we don't add it too early and give it the possibility to fail
                ScriptEngine.ScriptProtection.AddPreviouslyCompiled(Source, this);
            }
            catch (System.IO.FileNotFoundException) // Not valid!!!
            {
                m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: File not found in app domain creation. Corrupt state save! " + AssemblyName);
                ScriptEngine.ScriptProtection.RemovePreviouslyCompiled(Source);
                Start(reupload); // Lets restart the script if this happens
                return;
            }
            catch (Exception ex)
            {
                DisplayUserNotification(ex.ToString(), "app domain creation", reupload, true);
                return;
            }

            ILease lease = (ILease)RemotingServices.GetLifetimeService(Script as MarshalByRefObject);
            if (lease != null) //Its null if it is all running in the same app domain
                lease.Register(Script.Sponsor);

            //If its a reupload, an avatar is waiting for the script errors
            if (reupload)
                m_ScriptEngine.ScriptErrorReporter.AddError(ItemID, new ArrayList(new string[] { "SUCCESSFULL" }));

            if (useDebug)
                m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Stage 2 compile: " + (DateTime.Now.ToUniversalTime() - StartTime).TotalSeconds);

            SetApis();

            //Set the event flags
            Part.SetScriptEvents(ItemID, Script.GetStateEventFlags(State));

            //Now do the full state save finding now that we have an app domain.
            if (LastStateSave != null)
            {
                m_ScriptEngine.StateSave.Deserialize(this, LastStateSave);

                m_ScriptEngine.CreateFromData(Part.UUID, ItemID, Part.UUID,
                    PluginData);

                // we get new rez events on sim restart, too
                // but if there is state, then we fire the change
                // event
                StartedFromSavedState = true;
            }
            else
            {
                //Make a new state save now
                m_ScriptEngine.StateSave.SaveStateTo (this);
            }

            // Add it to our script memstruct so it can be found by other scripts
            ScriptEngine.ScriptProtection.AddNewScript(this);

            //All done, compiled successfully
            Loading = false;

            TimeSpan time = (DateTime.Now.ToUniversalTime() - StartTime);

            m_log.Debug("[" + m_ScriptEngine.ScriptEngineName +
                    "]: Started Script " + InventoryItem.Name +
                    " in object " + Part.Name + "@" + Part.ParentEntity.RootChild.AbsolutePosition +
                    (presence != null ? " by " + presence.Name : "") + 
                    " in region " + Part.ParentEntity.Scene.RegionInfo.RegionName +
                    " in " + time.TotalSeconds + " seconds.");
        }
开发者ID:kow,项目名称:Aurora-Sim,代码行数:101,代码来源:ScriptData.cs


注:本文中的IScript.GetStateEventFlags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。