Beispiel #1
0
        public T GetProperty <T>(string pPropName)
        {
            T ret = default(T);

            lock (Properties) {
                if (Properties.TryGetValue(pPropName, out PropertyDefnBase pbase))
                {
                    if (pbase.type == typeof(T))
                    {
                        PropertyDefn <T> defn = pbase as PropertyDefn <T>;
                        if (defn != null && defn.getter != null)
                        {
                            ret = defn.getter();
                        }
                    }
                    else
                    {
                        // The caller is asking for a different type than the native type.
                        // Get the value and try to do a conversion to the requested type.
                        // Probably wants to do a ToString().
                        try {
                            ret = ParamBlock.ConvertTo <T>(pbase.val);
                        }
                        catch (Exception e) {
                            BasilXContext.Instance.log.ErrorFormat("{0} GetProperty: exception fetching value for {1}: {2}",
                                                                   _logHeader, pPropName, e);
                            ret = default(T);
                        }
                    }
                }
            }
            return(ret);
        }
Beispiel #2
0
        // Set a parameter value
        public bool SetParameterValue(string pName, string pVal)
        {
            var ret = false;

            foreach (FieldInfo fi in this.GetType().GetFields())
            {
                foreach (Attribute attr in Attribute.GetCustomAttributes(fi))
                {
                    ConfigParam cp = attr as ConfigParam;
                    if (cp != null)
                    {
                        if (cp.name == pName)
                        {
                            fi.SetValue(this, ParamBlock.ConvertToObj(cp.valueType, pVal));
                            ret = true;
                            break;
                        }
                    }
                }
                if (ret)
                {
                    break;
                }
            }
            return(ret);
        }
Beispiel #3
0
        public void Start(string[] args)
        {
            // A single parameter of '--help' outputs the invocation parameters
            if (args.Length > 0 && args[0] == "--help")
            {
                System.Console.Write(Invocation());
                return;
            }

            // 'Params' initializes to default values.
            // Override default values with command line parameters.
            try {
                // Note that trailing parameters will be put into "Extras" parameter
                BasilTest.parms.MergeCommandLine(args, null, "Extras");
            }
            catch (Exception e) {
                BasilTest.log.ErrorFormat("ERROR: bad parameters: " + e.Message);
                BasilTest.log.ErrorFormat(Invocation());
                return;
            }

            if (BasilTest.parms.P <bool>("Verbose"))
            {
                BasilTest.log.SetVerbose(BasilTest.parms.P <bool>("Verbose"));
            }

            if (!BasilTest.parms.P <bool>("Quiet"))
            {
                System.Console.WriteLine("BasilTest v" + BasilTest.version
                                         + " built " + BasilTest.buildDate
                                         + " commit " + BasilTest.gitCommit
                                         );
            }

            InitializeHostnameForExternalAccess();

            // Create the parameter block for this type of layer
            ParamBlock ccParams = new ParamBlock(new Dictionary <string, object>()
            {
                { "ConnectionURL", BasilTest.parms.P <string>("ConnectionURL") },
                { "IsSecure", BasilTest.parms.P <bool>("IsSecure").ToString() },
                { "SecureConnectionURL", BasilTest.parms.P <string>("SecureConnectionURL") },
                { "Certificate", BasilTest.parms.P <string>("Certificate") },
                { "DisableNaglesAlgorithm", BasilTest.parms.P <bool>("DisableNablesAlgorithm").ToString() },
                { "ExternalAccessHostname", HostnameForExternalAccess }
            });
            var canceller         = new CancellationTokenSource();
            var TesterSpaceServer = new SpaceServerListener(ccParams, canceller, BasilTest.log,
                                                            (pCanceller, pConnection, pParams) => {
                return(new SpaceServerTester(pCanceller, pConnection));
            }
                                                            );

            while (!canceller.IsCancellationRequested)
            {
                Thread.Sleep(100);
            }
        }
Beispiel #4
0
    // 停封/解封玩家账号
    public OpRes blockPlayerAcc(string acc, bool block, GMUser user)
    {
        ParamBlock param = new ParamBlock();

        param.m_param   = acc;
        param.m_isBlock = block;
        OpRes res = user.doDyop(param, DyOpType.opTypeBlockAcc);

        return(res);
    }
Beispiel #5
0
        protected void onUnBlockAcc(object sender, EventArgs e)
        {
            GMUser user = (GMUser)Session["user"];

            ParamBlock param = new ParamBlock();

            param.m_param   = m_acc.Text;
            param.m_isBlock = false;
            OpRes res = user.doDyop(param, DyOpType.opTypeBlockAcc);

            m_res.InnerHtml = OpResMgr.getInstance().getResultString(res);
        }
Beispiel #6
0
        protected void onBlockAccount(object sender, EventArgs e)
        {
            ParamBlock p = new ParamBlock();

            p.m_isBlock = true;
            p.m_param   = m_acc.Text;
            GMUser  user = (GMUser)Session["user"];
            DyOpMgr mgr  = user.getSys <DyOpMgr>(SysType.sysTypeDyOp);
            OpRes   res  = mgr.doDyop(p, DyOpType.opTypeBlockAcc, user);

            m_res.InnerHtml = OpResMgr.getInstance().getResultString(res);
            genTable(m_result, user, mgr);
        }
Beispiel #7
0
        protected void onUnBlockAccount(object sender, EventArgs e)
        {
            GMUser     user = (GMUser)Session["user"];
            ParamBlock p    = new ParamBlock();

            p.m_isBlock = false;
            p.m_param   = m_accList;
            DyOpMgr mgr = user.getSys <DyOpMgr>(SysType.sysTypeDyOp);

            if (p.m_param != string.Empty)
            {
                OpRes res = mgr.doDyop(p, DyOpType.opTypeBlockAcc, user);
                m_res.InnerHtml = OpResMgr.getInstance().getResultString(res);
            }
            genTable(m_result, user, mgr);
        }
Beispiel #8
0
        // Store the value for the parameter.
        // If we accept the value as a good value for the parameter, return 1 else 0.
        // A 'good value' is one that does not start with '-' or is not after a boolean parameter.
        // Return the number of parameters to advance the parameter line. That means, return
        //    a zero of we didn't used the next parameter and a 1 if the next parameter
        //    was used as a value so don't consider it the next parameter.
        private int AddCommandLineParameter(string pParm, string val)
        {
            // System.Console.WriteLine(String.Format("AddCommandLineParameter: parm={0}, val={1}", pParm, val));
            int    ret  = 1; // start off assuming the next token is the value we're setting
            string parm = pParm.ToLower();

            // Strip leading hyphens
            while (parm[0] == '-')
            {
                parm = parm.Substring(1);
            }

            // If the boolean parameter starts with "no", turn it off rather than on.
            string positiveAssertion = "true";

            if (parm.Length > 2 && parm[0] == 'n' && parm[1] == 'o')
            {
                string maybeParm = parm.Substring(2);
                if (TryGetParameterInfo(parm, out ConfigParam bcp, out FieldInfo bfi))
                {
                    if (bcp.valueType == typeof(Boolean))
                    {
                        // The parameter without the 'no' exists and is a boolean
                        positiveAssertion = "false";
                        parm = maybeParm;
                    }
                }
            }

            // If the next token starts with a parameter mark, it's not really a value
            if (val == null)
            {
                ret = 0;    // the next token is not used here to set the value
            }
            else
            {
                if (val[0] == '-')
                {
                    val = null; // don't use the next token as a value
                    ret = 0;    // the next token is not used here to set the value
                }
            }

            if (TryGetParameterInfo(parm, out ConfigParam cp, out FieldInfo fi))
            {
                // If the parameter is a boolean type and the next value is not a parameter,
                //      don't try to take up the next value.
                // This handles boolean flags.
                // If there is a value next (val != null) and that value is not the
                //    values 'true' or 'false' or 't' or 'f', then ignore the next value
                //    as not belonging to this flag. THis allows (and the logic above)
                //    allows:
                //        "--flag --otherFlag ...",
                //        "--flag something ...",
                //        "--flag true --otherFlag ...",
                //        "--noflag --otherflag ...",
                //        etc
                if (cp.valueType == typeof(Boolean))
                {
                    if (val != null)
                    {
                        string valL = val.ToLower();
                        if (valL != "true" && valL != "t" && valL != "false" && valL != "f")
                        {
                            // The value is not associated with this boolean so ignore it
                            val = null; // don't use the val token
                            ret = 0;    // the next token is not used here to set the value
                        }
                    }
                    if (val == null)
                    {
                        // If the value is assumed, use the value based on the optional 'no'
                        val = positiveAssertion;
                    }
                }
                // Set the named parameter to the passed value
                fi.SetValue(this, ParamBlock.ConvertToObj(cp.valueType, val));
            }
 /// <summary>
 ///  Check to see if this action can happen now or has to be queued for later.
 /// </summary>
 /// <param name="rcontext"></param>
 /// <param name="cac"></param>
 /// <param name="p1"></param>
 /// <param name="p2"></param>
 /// <param name="p3"></param>
 /// <param name="p4"></param>
 /// <returns>true if the action was queued, false if the action should be done</returns>
 private bool QueueTilOnline(OMV.Simulator sim, CommActionCode cac, Object p1, Object p2, Object p3, Object p4)
 {
     bool ret = false;
     lock (m_waitTilOnline) {
     RegionContextBase rcontext = FindRegion(sim);
     if (rcontext != null && rcontext.State.isOnline) {
         // not queuing until later
         ret = false;
     }
     else {
         ParamBlock pb = new ParamBlock(sim, cac, p1, p2, p3, p4);
         m_waitTilOnline.Add(pb);
         // return that we queued the action
         ret = true;
     }
     }
     return ret;
 }
Beispiel #10
0
        // If run from the command line, create instance and call 'Start' with args.
        // If run programmatically, create instance and call 'Start' with parameters.
        public async Task Start(CancellationToken cancelToken, string[] args)
        {
            var parms  = new ConvoarParams();
            var logger = new BLoggerNLog(parms.LogFilename, parms.LogToConsole, parms.LogToFiles);

            // var logger = new LoggerLog4Net(),
            // var logger = new LoggerConsole(),

            Globals = new GlobalContext()
            {
                log   = logger,
                stats = new ConvoarStats(),
                parms = parms,
            };

            // A single parameter of '--help' outputs the invocation parameters
            if (args.Length > 0 && args[0] == "--help")
            {
                System.Console.Write(Invocation());
                return;
            }

            // 'ConvoarParams' initializes to default values.
            // Over ride default values with command line parameters.
            try {
                // Note that trailing parameters will be put into "InputOAR" parameter
                Globals.parms.MergeCommandLine(args, null, "InputOAR");
            }
            catch (Exception e) {
                Globals.log.Error("ERROR: bad parameters: " + e.Message);
                Globals.log.Error(Invocation());
                return;
            }

            if (Globals.parms.Verbose)
            {
                Globals.log.SetLogLevel(LogLevels.Debug);
            }

            if (!Globals.parms.Quiet)
            {
                System.Console.WriteLine("Convoar " + Globals.versionLong);
                System.Console.WriteLine("   using Herbal3d.CommonEntities " + org.herbal3d.cs.CommonEntities.VersionInfo.longVersion);
                System.Console.WriteLine("   using Herbal3d.CommonEntitiesConv " + org.herbal3d.cs.CommonEntitiesConv.VersionInfo.longVersion);
                System.Console.WriteLine("   using Herbal3d.CommonUtil " + org.herbal3d.cs.CommonUtil.VersionInfo.longVersion);
            }

            // Validate parameters
            if (String.IsNullOrEmpty(Globals.parms.InputOAR))
            {
                Globals.log.Error("An input OAR file must be specified");
                Globals.log.Error(Invocation());
                return;
            }
            if (String.IsNullOrEmpty(Globals.parms.OutputDir))
            {
                _outputDir = "./out";
                Globals.log.Debug("Output directory defaulting to {0}", _outputDir);
            }

            // Base asset storage system -- 'MemAssetService' is in-memory storage
            using (MemAssetService memAssetService = new MemAssetService()) {
                // 'assetManager' is the asset cache and fetching code -- where all the mesh,
                //    material, and instance information is stored for later processing.
                using (AssetManager assetManager = new AssetManager(memAssetService, Globals.log, Globals.parms.OutputDir)) {
                    try {
                        BScene bScene = await LoadOAR(memAssetService, assetManager);

                        Globals.contextName = bScene.name;

                        Globals.log.Debug("{0} Scene created. name={1}, instances={2}",
                                          _logHeader, bScene.name, bScene.instances.Count);
                        Globals.log.Debug("{0}    num assetFetcher.images={1}", _logHeader, assetManager.Assets.Images.Count);
                        Globals.log.Debug("{0}    num assetFetcher.materials={1}", _logHeader, assetManager.Assets.Materials.Count);
                        Globals.log.Debug("{0}    num assetFetcher.meshes={1}", _logHeader, assetManager.Assets.Meshes.Count);
                        Globals.log.Debug("{0}    num assetFetcher.renderables={1}", _logHeader, assetManager.Assets.Renderables.Count);

                        if (ConvOAR.Globals.parms.TerrainOnly)
                        {
                            ConvOAR.Globals.log.Debug("{0} Clearing out scene so there's only terrain (TerrainOnly)", _logHeader);
                            bScene.instances.Clear();
                            bScene.instances.Add(bScene.terrainInstance);
                        }

                        /*
                         * // Perform any optimizations on the scene and its instances
                         * if (Globals.parms.P<bool>("DoMeshSimplification")) {
                         *  // TODO:
                         * }
                         * if (Globals.parms.P<bool>("DoSceneOptimizations")) {
                         *  using (BSceneManipulation optimizer = new BSceneManipulation()) {
                         *      bScene = optimizer.OptimizeScene(bScene);
                         *      Globals.log.DebugFormat("{0} merged BScene. numInstances={1}", _logHeader, bScene.instances.Count);
                         *  }
                         * }
                         */
                        if (Globals.parms.MergeSharedMaterialMeshes)
                        {
                            // using (BSceneManipulation optimizer = new BSceneManipulation(Globals.log, Globals.parms)) {
                            var manipParams = new ParamBlock(new Dictionary <string, object> {
                                { "SeparateInstancedMeshes", false },
                                { "MergeSharedMaterialMeshes", false },
                                { "MeshShareThreshold", 5 }
                            });
                            using (BSceneManipulation optimizer = new BSceneManipulation(Globals.log, manipParams)) {
                                bScene = optimizer.RebuildSceneBasedOnSharedMeshes(bScene);
                                Globals.log.Debug("{0} merged meshes in scene. numInstances={1}", _logHeader, bScene.instances.Count);
                            }
                        }

                        // Output the transformed scene as Gltf version 2
                        GltfB gltf = new GltfB(bScene.name, Globals.log, new gltfParamsB()
                        {
                            inputOAR             = Globals.parms.InputOAR,
                            uriBase              = Globals.parms.URIBase,
                            verticesMaxForBuffer = Globals.parms.VerticesMaxForBuffer,
                            gltfCopyright        = Globals.parms.GltfCopyright,
                            addUniqueCodes       = Globals.parms.AddUniqueCodes,
                            doubleSided          = Globals.parms.DoubleSided,
                            textureMaxSize       = Globals.parms.TextureMaxSize,
                            logBuilding          = Globals.parms.LogBuilding,
                            logGltfBuilding      = Globals.parms.LogGltfBuilding,
                            versionLong          = Globals.versionLong
                        });

                        try {
                            gltf.LoadScene(bScene);

                            Globals.log.Debug("{0}   num Gltf.nodes={1}", _logHeader, gltf.nodes.Count);
                            Globals.log.Debug("{0}   num Gltf.meshes={1}", _logHeader, gltf.meshes.Count);
                            Globals.log.Debug("{0}   num Gltf.materials={1}", _logHeader, gltf.materials.Count);
                            Globals.log.Debug("{0}   num Gltf.images={1}", _logHeader, gltf.images.Count);
                            Globals.log.Debug("{0}   num Gltf.accessor={1}", _logHeader, gltf.accessors.Count);
                            Globals.log.Debug("{0}   num Gltf.buffers={1}", _logHeader, gltf.buffers.Count);
                            Globals.log.Debug("{0}   num Gltf.bufferViews={1}", _logHeader, gltf.bufferViews.Count);
                        }
                        catch (Exception e) {
                            Globals.log.Error("{0} Exception loading GltfScene: {1}", _logHeader, e);
                        }

                        try {
                            if (gltf.scenes.Count > 0)
                            {
                                string gltfFilename = gltf.GetFilename(gltf.IdentifyingString);
                                using (var outm = new MemoryStream()) {
                                    using (var outt = new StreamWriter(outm)) {
                                        gltf.ToJSON(outt);
                                    }
                                    await assetManager.AssetStorage.Store(gltfFilename, outm.ToArray());
                                }
                                gltf.WriteBinaryFiles(assetManager.AssetStorage);

                                if (Globals.parms.ExportTextures)
                                {
                                    gltf.WriteImages(assetManager.AssetStorage);
                                }
                            }
                            else
                            {
                                Globals.log.Error("{0} Not writing out GLTF because no scenes", _logHeader);
                            }
                        }
                        catch (Exception e) {
                            Globals.log.Error("{0} Exception writing GltfScene: {1}", _logHeader, e);
                        }

                        /*
                         * // Output all the instances in the scene as individual GLTF files
                         * if (Globals.parms.P<bool>("ExportIndividualGltf")) {
                         *  bScene.instances.ForEach(instance => {
                         *      string instanceName = instance.handle.ToString();
                         *      Gltf gltf = new Gltf(instanceName);
                         *      gltf.persist.baseDirectory = bScene.name;
                         *      // gltf.persist.baseDirectory = PersistRules.JoinFilePieces(bScene.name, instanceName);
                         *      GltfScene gltfScene = new GltfScene(gltf, instanceName);
                         *      gltf.defaultScene = gltfScene;
                         *
                         *      Displayable rootDisp = instance.Representation;
                         *      GltfNode rootNode = GltfNode.GltfNodeFactory(gltf, gltfScene, rootDisp, assetFetcher);
                         *      rootNode.translation = instance.Position;
                         *      rootNode.rotation = instance.Rotation;
                         *
                         *      gltf.BuildAccessorsAndBuffers();
                         *      gltf.UpdateGltfv2ReferenceIndexes();
                         *
                         *      // After the building, get rid of the default scene name as we're not outputting a scene
                         *      gltf.defaultScene = null;
                         *
                         *      PersistRules.ResolveAndCreateDir(gltf.persist.filename);
                         *
                         *      using (StreamWriter outt = File.CreateText(gltf.persist.filename)) {
                         *          gltf.ToJSON(outt);
                         *      }
                         *      gltf.WriteBinaryFiles();
                         *
                         *      if (Globals.parms.P<bool>("ExportTextures")) {
                         *          gltf.WriteImages();
                         *      }
                         *  });
                         * }
                         */
                    }
                    catch (Exception e) {
                        Globals.log.Error("{0} Global exception converting scene: {1}", _logHeader, e);
                        // A common error is not having all the DLLs for OpenSimulator. Print out what's missing.
                        if (e is ReflectionTypeLoadException refE)
                        {
                            foreach (var ee in refE.LoaderExceptions)
                            {
                                Globals.log.Error("{0} reference exception: {1}", _logHeader, ee);
                            }
                        }
                    }
                }
            }
        }