Exemplo n.º 1
0
        public void DLLRegisterServer(int regMode)
        {
            //register dll
            //same as:
            //post build event: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe $(TargetPath) /codebase

            RegistrationServices regAsm = new RegistrationServices();
            bool bResult = regAsm.RegisterAssembly(
                ComponentConfig.typeToRegister.Assembly,
                AssemblyRegistrationFlags.SetCodeBase);

            GME.Util.MgaRegistrar reg = new GME.Util.MgaRegistrar();
            if ((int)GME.MGA.Core.GMEInterfaceVersion_enum.GMEInterfaceVersion_Current != (int)((GME.MGA.Core.IGMEVersionInfo)reg).version)
            {
                throw new Exception("MgaInterfaceVersion mismatch: this assembly is using " +
                                    (int)GME.MGA.Core.GMEInterfaceVersion_enum.GMEInterfaceVersion_Current +
                                    " but the GME interface version is " + (int)((GME.MGA.Core.IGMEVersionInfo)reg).version +
                                    "\n\nPlease install a compatible GME version or update the interop dlls.");
            }
            reg.RegisterComponent(
                regAsm.GetProgIdForType(ComponentConfig.typeToRegister),
                GME.MGA.componenttype_enum.COMPONENTTYPE_INTERPRETER,
                ComponentConfig.componentName,
                regacc_translate(regMode));

            reg.set_ComponentExtraInfo(regacc_translate(regMode), regAsm.GetProgIdForType(ComponentConfig.typeToRegister), "Icon", ComponentConfig.iconId);

            if (!ComponentConfig.paradigmName.Equals("*"))
            {
                reg.Associate(regAsm.GetProgIdForType(ComponentConfig.typeToRegister), ComponentConfig.paradigmName, (GME.Util.regaccessmode_enum)regMode);
            }
        }
Exemplo n.º 2
0
        public void DaServerTest()
        {
            DaServer _daServer = new DaServer();

            Assert.IsNotNull(_daServer);
            Assert.IsTrue(File.Exists("CommServer_Main.log"), $"Cannot find the file in {Environment.CurrentDirectory}");
            Assert.IsFalse(Environment.Is64BitProcess);
            RegistrationServices _registrationServices = new RegistrationServices();
            //GetProgIdForType
            string _progId = _registrationServices.GetProgIdForType(typeof(DaServer));

            Assert.AreEqual <string>("CAS.CommServer.DA.Server.NETServer.DaServer", _progId);
            //GetRegistrableTypesInAssembly
            Type[] _typesToRegister = _registrationServices.GetRegistrableTypesInAssembly(typeof(DaServer).Assembly);
            Assert.IsNotNull(_typesToRegister);
            Assert.AreEqual <int>(1, _typesToRegister.Length);
            Assert.AreEqual <string>("CAS.CommServer.DA.Server.NETServer.DaServer", _typesToRegister[0].FullName);
            //TypeRepresentsComType
            Assert.IsFalse(_registrationServices.TypeRepresentsComType(typeof(DaServer)));
            Assert.IsFalse(_registrationServices.TypeRepresentsComType(typeof(IOPCCommon)));
            Assert.IsFalse(_registrationServices.TypeRepresentsComType(typeof(IOPCCommon)));
            Assert.IsFalse(_registrationServices.TypeRepresentsComType(typeof(IOPCWrappedServer)));
            //TypeRequiresRegistration
            Assert.IsTrue(_registrationServices.TypeRequiresRegistration(typeof(DaServer)));
            object[] _attributes = typeof(DaServer).GetCustomAttributes(typeof(GuidAttribute), false);
            Assert.AreEqual <int>(1, _attributes.Length);
            Assert.AreEqual <string>("BE77A3C7-D2B7-44E7-B943-B978C1C87E5A", ((GuidAttribute)_attributes[0]).Value.ToUpper());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes the entries needed to register a class type to the registry file.
        /// </summary>
        /// <param name="type">Type to write.</param>
        /// <param name="codebase">Optional codebase, if it needs to be written.</param>
        /// <param name="rootKeyName">Name of root key where to add types.</param>
        /// <param name="writer"><see cref="RegistryFileWriter"/> used to write to the
        /// registry file.</param>
        private void WriteClassInRegistryFile(Type type, string codebase,
                                              string rootKeyName, RegistryFileWriter writer)
        {
            Debug.Assert(type != null);
            Debug.Assert(!String.IsNullOrEmpty(rootKeyName));
            Debug.Assert(writer != null);

            // For class types, we add ProgID entries AND CLSID entries.
            string clsid  = type.GUID.ToString("B").ToUpper(CultureInfo.InvariantCulture);
            string progId = regServices.GetProgIdForType(type);
            string keyPath;

            // First ProgID if class has one. Link it to CLSID.
            if (!String.IsNullOrEmpty(progId))
            {
                keyPath = String.Format(@"{0}\{1}", rootKeyName, progId);
                using (RegistryKeyWriter keyWriter = writer.AddKey(keyPath)) {
                    keyWriter.AddDefaultValue(type.FullName);
                }
                keyPath += @"\CLSID";
                using (RegistryKeyWriter keyWriter = writer.AddKey(keyPath)) {
                    keyWriter.AddDefaultValue(clsid);
                }
            }

            // Now CLSID. First write class name in root CLSID key.
            keyPath = String.Format(@"{0}\CLSID\{1}", rootKeyName, clsid);
            using (RegistryKeyWriter keyWriter = writer.AddKey(keyPath)) {
                keyWriter.AddDefaultValue(type.FullName);
            }

            // Now write all infos in InprocServer32.
            keyPath += @"\InprocServer32";
            using (RegistryKeyWriter keyWriter = writer.AddKey(keyPath)) {
                keyWriter.AddDefaultValue("mscoree.dll");
                keyWriter.AddValue("ThreadingModel", "Both");
                keyWriter.AddValue("Class", type.FullName);
                keyWriter.AddValue("Assembly", assembly.FullName);
                keyWriter.AddValue("RuntimeVersion", assembly.ImageRuntimeVersion);
                if (codebase != null)
                {
                    keyWriter.AddValue("CodeBase", codebase);
                }
            }

            // Also write versioned key.
            keyPath += String.Format(@"\{0}", assembly.GetName().Version);
            using (RegistryKeyWriter keyWriter = writer.AddKey(keyPath)) {
                keyWriter.AddValue("Class", type.FullName);
                keyWriter.AddValue("Assembly", assembly.FullName);
                keyWriter.AddValue("RuntimeVersion", assembly.ImageRuntimeVersion);
                if (codebase != null)
                {
                    keyWriter.AddValue("CodeBase", codebase);
                }
            }

            // If class has a ProgID, link the CLSID to it.
            if (!String.IsNullOrEmpty(progId))
            {
                keyPath = String.Format(@"{0}\CLSID\{1}\ProgId", rootKeyName, clsid);
                using (RegistryKeyWriter keyWriter = writer.AddKey(keyPath)) {
                    keyWriter.AddDefaultValue(progId);
                }
            }

            // Finally, add implemented categories.
            keyPath = String.Format(@"{0}\CLSID\{1}\Implemented Categories\{2}", rootKeyName, clsid,
                                    regServices.GetManagedCategoryGuid().ToString("B").ToUpper(CultureInfo.InvariantCulture));
            writer.AddEmptyKey(keyPath);
        }