Example #1
0
        public static void Main(string[] args)
        {
            IPlatform platform;

            if (Globals.IsUnix)
            {
                platform = new UnixPlatform();
            }
            else
            {
                platform = new Win32Platform();
            }
            platform.Init();

            try {
                new Program(platform).Run();
            } catch (AggregateException ex) {
                var message = ex.Flatten().InnerException.ToString();
                Log.Error(message);
                throw;
            } catch (Exception ex) {
                var message = (ex.InnerException != null) ? ex.InnerException.ToString() : ex.ToString();
                Log.Error(message);
                throw;
            }
        }
Example #2
0
        private static void Main(string[] args)
        {
            /*
             * In this example we see the highly coupled implementation of a psuedo ThreadScheduler
             * for different platforms. The problem with this approach is for every variation of ThreadScheduler
             * every platform needs to implement their variations as well.
             */

            var winpts = new WindowsPTS();

            winpts.Schedule("Windows PT#1");
            var wincts = new WindowsCTS();

            wincts.Schedule("Windows CT#1");
            var nixpts = new UnixPTS();

            nixpts.Schedule("Unix PT#1");
            var nixcts = new UnixCTS();

            nixcts.Schedule("Unix CT#1");

            /*
             * The example below illustrates a better way of implementing this ThreadScheduler by using
             * the bridge pattern. We seperate variations of ThreadScheduler, and implemented a parameterized
             * ctor for each variation of ThreadScheduler (in base class) that requires the platform scheduler.
             * This way platform schedulers does not need to extends any scheduler variation.
             */

            var winplatform = new WindowsPlatform();
            var nixplatform = new UnixPlatform();

            var pts = new PreemptiveThreadScheduler(winplatform);
            var cts = new CooperativeScheduler(nixplatform);

            pts.Schedule("Windows Thread #1");
            cts.Schedule("Unix Thread #1");

            /*
             * Below is the course example of Bridge pattern in which we required to refactor a
             * psuedo renderer that is capable of rendering objects in various forms.
             */

            var vrenderer = new VectorRenderer();
            var rrenderer = new RasterRenderer();

            var square = new Square(vrenderer);

            WriteLine(square);
            square.Renderer = rrenderer;
            WriteLine(square);

            var triangle = new Triangle(vrenderer);

            WriteLine(triangle);
            triangle.Renderer = rrenderer;
            WriteLine(triangle);
        }
Example #3
0
        private static string GetCscPath()
        {
            string toolPath;

            switch (Platform.BuildPlatform.Target)
            {
            case TargetPlatform.Linux:
            case TargetPlatform.Mac:
            {
                // Use csc from Mono
                toolPath = UnixPlatform.Which("csc");
                if (toolPath != null)
                {
                    return(toolPath);
                }
                break;
            }

            case TargetPlatform.Windows:
            {
                if (CheckMsBuildPathFromRegistry("Microsoft\\VisualStudio\\SxS\\VS7", "15.0", "MSBuild\\15.0\\bin\\csc.exe", out toolPath))
                {
                    return(toolPath);
                }

                toolPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "MSBuild", "14.0", "bin", "csc.exe");
                if (File.Exists(toolPath))
                {
                    return(toolPath);
                }

                if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\14.0", "MSBuildToolsPath", "csc.exe", out toolPath))
                {
                    return(toolPath);
                }

                if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\12.0", "MSBuildToolsPath", "csc.exe", out toolPath))
                {
                    return(toolPath);
                }

                if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\4.0", "MSBuildToolsPath", "csc.exe", out toolPath))
                {
                    return(toolPath);
                }

                break;
            }
            }

            return(string.Empty);
        }
Example #4
0
        private static string GetMSBuildToolPath()
        {
            string toolPath;

            switch (Platform.BuildPlatform.Target)
            {
            case TargetPlatform.Linux:
            {
                // Use msbuild from Mono
                toolPath = UnixPlatform.Which("msbuild");
                if (toolPath != null)
                {
                    return(toolPath);
                }

                break;
            }

            case TargetPlatform.Windows:
            {
                var visualStudioInstances = VisualStudioInstance.GetInstances();
                foreach (var visualStudioInstance in visualStudioInstances)
                {
                    toolPath = Path.Combine(visualStudioInstance.Path, "MSBuild\\Current\\Bin\\MSBuild.exe");
                    if (File.Exists(toolPath))
                    {
                        return(toolPath);
                    }
                }

                if (CheckMsBuildPathFromRegistry("Microsoft\\VisualStudio\\SxS\\VS7", "15.0", "MSBuild\\15.0\\bin\\MSBuild.exe", out toolPath))
                {
                    return(toolPath);
                }

                toolPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "MSBuild", "14.0", "bin", "MSBuild.exe");
                if (File.Exists(toolPath))
                {
                    return(toolPath);
                }

                if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\14.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath))
                {
                    return(toolPath);
                }

                if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\12.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath))
                {
                    return(toolPath);
                }

                if (CheckMsBuildPathFromRegistry("Microsoft\\MSBuild\\ToolsVersions\\4.0", "MSBuildToolsPath", "MSBuild.exe", out toolPath))
                {
                    return(toolPath);
                }

                break;
            }
            }

            return(string.Empty);
        }