Example #1
0
 void MarkDisabled()
 {
     SpeechButton.Checked = false;
     osLayer = null;
 }
Example #2
0
        /// <summary>
        /// Find the system-specific DLL for this platform
        /// </summary>
        private void LoadOSLayer()
        {
            string dirName = Application.StartupPath;

            if (!Directory.Exists(dirName))
            {
                throw new Exception("No startup directory found " + dirName);
            }

            // The filename depends on the platform.
            Version version      = System.Environment.OSVersion.Version;
            string  loadfilename = null;

            switch (System.Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32Windows:
                // XP and later have Speech Synthesis.
                // XP=5, Vista=6, W7=7
                if (version.Major >= 5)
                {
                    loadfilename = "RadSpeechWin";
                }
                break;

            case PlatformID.Unix:
                loadfilename = "RadSpeechLin";
                break;

            case PlatformID.MacOSX:
                loadfilename = "RadSpeechMac";
                break;
            }

            // If the name was not set, we do not support this platform
            if (loadfilename == null)
            {
                throw new Exception("Platform not supported for Speech");
            }

            loadfilename = Path.Combine(dirName, loadfilename + ".dll");
            try
            {
                Assembly assembly = Assembly.LoadFile(loadfilename);

                // Examine the types exposed by this DLL, looking for ours.
                foreach (Type type in assembly.GetTypes())
                {
                    if (typeof(IRadSpeech).IsAssignableFrom(type))
                    {
                        foreach (var ci in type.GetConstructors())
                        {
                            if (ci.GetParameters().Length > 0)
                            {
                                continue;
                            }
                            try
                            {
                                // This is the one.  Instantiate it.
                                osLayer = (IRadSpeech)ci.Invoke(new object[0]);
                                return;
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("ERROR in Speech OS Layer: " + ex.Message);
                            }
                        }
                    }
                }
            }
            catch (BadImageFormatException)
            {
                // non .NET .dlls
                throw new Exception("Speech OS Layer bad format " + loadfilename);
            }
            catch (ReflectionTypeLoadException ex)
            {
                // Out of date or dlls missing sub dependencies
                throw new Exception("ERROR loading Speech OS Layer " + loadfilename + ", " + ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("Exception loading Speech OS Layer " + loadfilename + ", " + ex.Message);
            }
        }
Example #3
0
        /// <summary>
        /// Find the system-specific DLL for this platform
        /// </summary>
        private void LoadOSLayer()
        {
            string dirName = Application.StartupPath;

            if (!Directory.Exists(dirName))
                throw new Exception("No startup directory found " + dirName);

            // The filename depends on the platform.
            System.Version version = System.Environment.OSVersion.Version;
            string loadfilename = null;
            switch (System.Environment.OSVersion.Platform)
            {
                case PlatformID.Win32NT:
                case PlatformID.Win32Windows:
                    // XP and later have Speech Synthesis.
                    // XP=5, Vista=6, W7=7
                    if (version.Major >= 5)
                        loadfilename = "RadSpeechWin";
                    break;
                case PlatformID.Unix:
                    loadfilename = "RadSpeechLin";
                    break;
                case PlatformID.MacOSX:
                    loadfilename = "RadSpeechMac";
                    break;
            }

            // If the name was not set, we do not support this platform
            if (loadfilename == null)
                throw new Exception("Platform not supported for Speech");

            loadfilename = Path.Combine(dirName, loadfilename + ".dll");
            try
            {
                Assembly assembly = Assembly.LoadFile(loadfilename);

                // Examine the types exposed by this DLL, looking for ours.
                foreach (Type type in assembly.GetTypes())
                {
                    if (typeof(IRadSpeech).IsAssignableFrom(type))
                    {
                        foreach (var ci in type.GetConstructors())
                        {
                            if (ci.GetParameters().Length > 0) continue;
                            try
                            {
                                // This is the one.  Instantiate it.
                                osLayer = (IRadSpeech)ci.Invoke(new object[0]);
                                return;
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("ERROR in Speech OS Layer: " + ex.Message);
                            }
                        }
                    }
                }
            }
            catch (BadImageFormatException)
            {
                // non .NET .dlls
                throw new Exception("Speech OS Layer bad format " + loadfilename);
            }
            catch (ReflectionTypeLoadException ex)
            {
                // Out of date or dlls missing sub dependencies
                throw new Exception("ERROR loading Speech OS Layer " + loadfilename + ", " + ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("Exception loading Speech OS Layer " + loadfilename + ", " + ex.Message);
            }
        }
Example #4
0
 void MarkDisabled()
 {
     SpeechButton.Checked = false;
     osLayer = null;
 }