Пример #1
0
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                GorgonApplication.Run(Initialize(), Idle);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                GorgonExample.UnloadResources();

                foreach (GorgonTexture2D texture in _textures)
                {
                    texture?.Dispose();
                }

                _renderer?.Dispose();
                _depthBuffer?.Dispose();
                _screen?.Dispose();
                _graphics?.Dispose();
                _assemblyCache?.Dispose();
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the <see cref="E:FormClosing" /> event.
        /// </summary>
        /// <param name="e">The <see cref="FormClosingEventArgs"/> instance containing the event data.</param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            // Always dispose your devices when the window is shutting down.
            // Failure to do so can lead to unpredictable results.
            if (_joystickList != null)
            {
                foreach (IGorgonGamingDevice joystick in _joystickList)
                {
                    joystick.Dispose();
                }
            }

            if (_drivers != null)
            {
                foreach (IGorgonGamingDeviceDriver driver in _drivers)
                {
                    driver.Dispose();
                }
            }

            _input?.UnregisterDevice(_mouse);
            _input?.Dispose();

            _assemblyCache?.Dispose();
        }
Пример #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data.</param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            GorgonExample.UnloadResources();

            _pluginCache?.Dispose();
            _texture?.Dispose();
            _swap?.Dispose();
            _graphics?.Dispose();
            _image?.Dispose();
        }
Пример #4
0
        public static async Task Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Application.DoEvents();

                // This is necessary to get winforms to play nice with our background thread prior to running the application.
                WindowsFormsSynchronizationContext.AutoInstall = false;
                SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());

                FormMain window = GorgonExample.Initialize(new DX.Size2(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height), "Space Scene",
                                                           async(sender, _) => await InitializeAsync(sender as FormMain));

                GorgonApplication.Run(window);
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
            }
            finally
            {
                // Always perform your clean up.
                if (_keyboard != null)
                {
                    _keyboard.KeyUp -= Keyboard_KeyUp;
                }

                _helpFont?.Dispose();
                _fontFactory?.Dispose();

                GorgonExample.UnloadResources();

                if (_keyboard != null)
                {
                    _input?.UnregisterDevice(_keyboard);
                }
                _input?.Dispose();
                _sceneRenderer?.Dispose();
                _resources?.Dispose();
                _renderer?.Dispose();
                _mainRtv?.Dispose();
                _screen?.Dispose();
                _graphics?.Dispose();
                _assemblyCache?.Dispose();
            }
        }
Пример #5
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event.</summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data. </param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            _blurredImage[1]?.Dispose();
            _blurredTarget[1]?.Dispose();
            _blurredImage[0]?.Dispose();
            _blurredTarget[0]?.Dispose();
            _blurEffect?.Dispose();
            _helpFont?.Dispose();
            _textFont?.Dispose();
            _renderer?.Dispose();
            _screen?.Dispose();
            _graphics?.Dispose();
            _assemblyCache?.Dispose();
        }
Пример #6
0
        /// <summary>Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.ApplicationContext" /> and optionally releases the managed resources.</summary>
        /// <param name="disposing">
        /// <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources. </param>
        protected override void Dispose(bool disposing)
        {
            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;

            ToolPlugInService    toolPlugIns    = Interlocked.Exchange(ref _toolPlugIns, null);
            ContentPlugInService contentPlugIns = Interlocked.Exchange(ref _contentPlugIns, null);
            GraphicsContext      context        = Interlocked.Exchange(ref _graphicsContext, null);
            GorgonMefPlugInCache pluginCache    = Interlocked.Exchange(ref _pluginCache, null);
            FormMain             mainForm       = Interlocked.Exchange(ref _mainForm, null);
            FormSplash           splash         = Interlocked.Exchange(ref _splash, null);

            toolPlugIns?.Dispose();
            contentPlugIns?.Dispose();
            context?.Dispose();
            pluginCache?.Dispose();
            mainForm?.Dispose();
            splash?.Dispose();

            base.Dispose(disposing);
        }
Пример #7
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data.</param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (_controllers != null)
            {
                foreach (IGorgonGamingDevice controller in _controllers)
                {
                    controller.Dispose();
                }
            }

            _assemblies?.Dispose();

            if (_surface == null)
            {
                return;
            }

            _surface.Dispose();
            _surface = null;
        }
Пример #8
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static void Main()
        {
            _log = new GorgonLog("FileSystemProviders", "Tape_Worm");
            _log.LogStart();

            // Create a plugin assembly cache to hold our plugin assemblies.
            _pluginAssemblies = new GorgonMefPlugInCache(_log);
            // Create the plugin service.
            _pluginService = new GorgonMefPlugInService(_pluginAssemblies);

            try
            {
                Console.WriteLine("Gorgon is capable of mounting virtual file systems for file access.  A virtual");
                Console.WriteLine("file system root can be a folder on a hard drive, a zip file, or any data store");
                Console.WriteLine("(assuming there's a provider for it).\n");
                Console.WriteLine("In Gorgon, the types of data that can be mounted as a virtual file system are");
                Console.WriteLine("managed by objects called providers. By default, the file system has a folder");
                Console.WriteLine("provider.  This allows a folder to be mounted as the root of a virtual file\nsystem.\n");
                Console.WriteLine("This example will show how to load extra providers that can be used in a file\nsystem.\n");

                Console.ForegroundColor = ConsoleColor.White;

                // Get our file system providers.
                Console.WriteLine("Found {0} external file system plug ins.\n", LoadFileSystemProviders());

                // Loop through each provider and print some info.
                for (int i = 0; i < _providers.Count; ++i)
                {
                    // Print some info about the file system provider.
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("{0}. {1}", i + 1, _providers[i].Name);

                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine("    Description: {0}", _providers[i].Description);

                    // Gather the preferred extensions.
                    // File system providers that use a file (like a Zip file) as its root
                    // have a list of file extensions that are preferred.  For example, the
                    // Zip provider, expects to find *.zip files.  These are merely here
                    // for the convenience of the developer and are formatted like a common
                    // dialog file mask so they can be easily dropped into that control.
                    // In this case, we're going to just strip out the relevant part and
                    // concatenate each preferred extension description into a single string.
                    //
                    // Note that a provider may have multiple preferred extensions.
                    string[] extensionList = (from preferred in _providers[i].PreferredExtensions
                                              select $"*.{preferred.Extension}").ToArray();

                    if (extensionList.Length > 0)
                    {
                        Console.WriteLine("    Preferred Extensions: {0}", string.Join(", ", extensionList));
                    }
                }

                Console.ResetColor();
                Console.WriteLine("\nPress any key to close.");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                ex.Catch(_ =>
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", _.Message, _.StackTrace);
                },
                         _log);
                Console.ResetColor();
#if DEBUG
                Console.ReadKey();
#endif
            }
            finally
            {
                // Always call dispose so we can unload our temporary application domain.
                _pluginAssemblies.Dispose();

                _log.LogEnd();
            }
        }
Пример #9
0
        private static void Main()
        {
            try
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.White;
                Console.Title           = "Gorgon Example - Input Services.";

                Console.WriteLine("In this example we will perform the first step in accessing Gorgon's gaming");
                Console.WriteLine("device driver API. These drivers will allow access to any gaming device (e.g. a ");
                Console.WriteLine("joystick, game pad, etc...) that is supported by its underlying native provider.");
                Console.WriteLine("These drivers are loaded as plug ins and can be used to mix and match various");
                Console.WriteLine("types of gaming devices.");
                Console.WriteLine();
                Console.WriteLine("Only connected gaming device drivers will be reported by this example.");
                Console.WriteLine();
                Console.WriteLine("It is important to note that this example does not create any of these devices ");
                Console.WriteLine("since some providers (e.g. Direct Input) require a window handle to operate.");

                Console.WriteLine();
                Console.WriteLine("Loading gaming device drivers...");

                // Load our input factory plugins.
                IReadOnlyList <IGorgonGamingDeviceDriver> inputPlugIns = GetGamingDeviceDrivers();

                // No plugins?  No luck.
                if (inputPlugIns.Count == 0)
                {
                    Console.ResetColor();
                    Console.WriteLine("Could not find any gaming device driver plug ins.");
                    return;
                }

                // Display the plugin information.
                Console.WriteLine();
                Console.WriteLine("{0} gaming device driver plug ins found:", inputPlugIns.Count);
                foreach (IGorgonGamingDeviceDriver plugIn in inputPlugIns)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;

                    // Enumerate the devices available on the system.
                    try
                    {
                        IReadOnlyList <IGorgonGamingDeviceInfo> devices = plugIn.EnumerateGamingDevices(true);

                        Console.WriteLine($"{plugIn.Description} ({devices.Count} device(s))");
                        Console.ForegroundColor = ConsoleColor.Gray;
                        for (int i = 0; i < devices.Count; ++i)
                        {
                            Console.WriteLine($"\t{i + 1}. {devices[i].Description}");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Cannot enumerate devices from {0}. Error:\n{1}", plugIn.Description, ex.Message.Ellipses(Console.WindowWidth - 4));
                    }
                }

                Console.ResetColor();

                Console.WriteLine();
                Console.WriteLine("Press any key...");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                ex.Catch(_ =>
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", _.Message, _.StackTrace);
                });
                Console.ResetColor();
                Console.ReadKey();
            }
            finally
            {
                _pluginCache?.Dispose();
            }
        }
Пример #10
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static void Main()
        {
            _log = new GorgonLog("ZipFileSystem", "Tape_Worm");
            _log.LogStart();

            // Create the plugin assembly cache.
            _pluginAssemblies = new GorgonMefPlugInCache(_log);
            // Create the plugin service.
            _pluginService = new GorgonMefPlugInService(_pluginAssemblies);

            try
            {
                Console.WindowHeight = 28;
                Console.BufferHeight = Console.WindowHeight;

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("This example will mount a zip file as the root of a virtual file system.  The");
                Console.WriteLine("virtual file system is capable of mounting various types of data such as a zip,");
                Console.WriteLine("a file system folder, etc... as the root or a sub directory.  You can even");
                Console.WriteLine("mount a zip file as the root, and a physical file system directory as a virtual");
                Console.WriteLine("sub directory in the same virtual file system and access them as a single");
                Console.WriteLine("unified file system.");

                // Unlike the folder file system example, we need to load
                // a provider to handle zip files before trying to mount
                // one.
                if (!LoadZipProviderPlugIn())
                {
                    return;
                }

                // Set the following zip file as root on the virtual file system.
                //
                // If we wanted to, we could mount a zip file as a sub directory of
                // the root of the virtual file system.  For example, mounting the
                // directory D:\Dir\zipFile.zip with Mount(@"D:\Dir", "/VFSDir"); would mount
                // the contents of the D:\Dir\zipFile.zip directory under /VFSDir.
                //
                // It's also important to point out that the old Gorgon "file system"
                // would load files from the system into memory when mounting a
                // directory.  While this version only loads directory and file
                // information when mounting.  This is considerably more efficient.
                string physicalPath = GetResourcePath(@"FileSystem.zip");
                _fileSystem.Mount(physicalPath);

                Console.Write("\nMounted: ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write("'{0}'", physicalPath.Ellipses(Console.WindowWidth - 20, true));
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(" as ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("'/'\n");
                Console.ForegroundColor = ConsoleColor.White;

                // Get a count of all sub directories and files under the root directory.
                IGorgonVirtualDirectory[] directoryList = _fileSystem.FindDirectories("*").ToArray();

                // Display directories.
                Console.WriteLine("Virtual file system contents:");

                for (int i = -1; i < directoryList.Length; i++)
                {
                    IGorgonVirtualDirectory directory = _fileSystem.RootDirectory;

                    // Go into the sub directories under root.
                    if (i > -1)
                    {
                        directory = directoryList[i];
                    }

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("{0}", directory.FullPath);

                    Console.ForegroundColor = ConsoleColor.Yellow;

                    foreach (IGorgonVirtualFile file in directory.Files)
                    {
                        Console.Write("   {0}", file.Name);
                        // Align the size to the same place.
                        Console.CursorLeft = 65;
                        Console.WriteLine("{0}", file.Size.FormatMemory());
                    }
                }

                Console.ResetColor();
                Console.WriteLine("\nPress any key to close.");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                ex.Catch(_ =>
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", _.Message, _.StackTrace);

                    Console.ResetColor();
#if DEBUG
                    Console.ReadKey();
#endif
                });
            }
            finally
            {
                // Always dispose the cache to clean up the temporary app domain it creates.
                _pluginAssemblies.Dispose();
                _log.LogEnd();
            }
        }
Пример #11
0
        private static void Main(string[] args)
        {
            _log = new GorgonLog("Example 004", "Tape_Worm", typeof(Program).Assembly.GetName().Version);

            // Set up the assembly cache.
            // We'll need the assemblies loaded into this object in order to load our plugin types.
            var pluginCache = new GorgonMefPlugInCache(_log);

            // Create our plugin service.
            // This takes the cache of assemblies we just created.
            IGorgonPlugInService pluginService = new GorgonMefPlugInService(pluginCache);

            try
            {
                Console.Title           = "Gorgon Example #4 - PlugIns.";
                Console.ForegroundColor = ConsoleColor.White;

                Console.WriteLine("This is an example to show how to create and use custom plugins.");
                Console.WriteLine("The plugin interface in Gorgon is quite flexible and gives the developer");
                Console.WriteLine("the ability to allow extensions to their own applications.\n");

                Console.ResetColor();

                pluginCache.LoadPlugInAssemblies(Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]).FormatDirectory(Path.DirectorySeparatorChar), "Example004.*PlugIn.dll");
                Console.WriteLine("{0} plugin assemblies found.", pluginCache.PlugInAssemblies.Count);

                if (pluginCache.PlugInAssemblies.Count == 0)
                {
                    return;
                }

                // Our text writer plugin interfaces.
                IList <TextColorWriter> writers = new List <TextColorWriter>();

                // Create our plugin instances, we'll limit to 9 entries just for giggles.
                TextColorPlugIn[] plugins = (from pluginName in pluginService.GetPlugInNames()
                                             let plugin = pluginService.GetPlugIn <TextColorPlugIn>(pluginName)
                                                          where plugin != null
                                                          select plugin).ToArray();

                // Display a list of the available plugins.
                Console.WriteLine("\n{0} Plug-ins loaded:\n", plugins.Length);
                for (int i = 0; i < plugins.Length; i++)
                {
                    // Here's where we make use of our description.
                    Console.WriteLine("{0}. {1} ({2})", i + 1, plugins[i].Description, plugins[i].GetType().FullName);

                    // Create the text writer interface and add it to the list.
                    writers.Add(plugins[i].CreateWriter());
                }

                Console.Write("0. Quit\n\nSelect a plugin:  ");

                // Loop until we quit.
                while (true)
                {
                    if (!Console.KeyAvailable)
                    {
                        continue;
                    }

                    Console.ResetColor();

                    // Remember our cursor coordinates.
                    int cursorX = Console.CursorLeft; // Cursor position.
                    int cursorY = Console.CursorTop;

                    ConsoleKeyInfo keyValue = Console.ReadKey(false);

                    if (char.IsNumber(keyValue.KeyChar))
                    {
                        if (keyValue.KeyChar == '0')
                        {
                            break;
                        }

                        // Move to the next line and clear the previous line of text.
                        Console.WriteLine();
                        Console.Write(new string(' ', Console.BufferWidth - 1));
                        Console.CursorLeft = 0;

                        // Call our text color writer to print the text in the plugin color.
                        int writerIndex = keyValue.KeyChar - '0';
                        writers[writerIndex - 1].WriteString($"You pressed #{writerIndex}.");
                    }

                    Console.CursorTop  = cursorY;
                    Console.CursorLeft = cursorX;
                }
            }
            catch (Exception ex)
            {
                ex.Catch(_ =>
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", ex.Message, ex.StackTrace);
                },
                         _log);
                Console.ResetColor();
#if DEBUG
                Console.ReadKey(true);
#endif
            }
            finally
            {
                // Always call dispose so we can unload our temporary application domain.
                //pluginAssemblies.Dispose();
                pluginCache.Dispose();

                _log.LogEnd();
            }
        }