Exemple #1
0
        public override string ToSource()
        {
            StringBuilder source = new StringBuilder();

            var argumentList = new List <string>();

            foreach (var arg in Arguments)
            {
                argumentList.Add(PREFIX_REAL_ARG + arg.Name);
            }

            string argumentsStr = string.Join(",", argumentList.ToArray());

            source.AppendFormat("{0}.{1} += ({2}) => \n", GCommand.NamespaceName, GCommand.MethodName, argumentsStr);
            source.AppendLine("{");
            source.AppendLine("    Dispatcher.Invoke(() =>");
            source.AppendLine("    {");

            for (int i = 0; i < Arguments.Count; i++)
            {
                source.AppendFormat("object {0} = {1}{0};\n", Arguments[i].Name, PREFIX_REAL_ARG);
            }

            foreach (GStatement statement in Content)
            {
                source.AppendLine(ConvertAssistant.Indentation(statement.ToSource(), 2));
            }

            source.AppendLine("    });");
            source.AppendLine("};");

            return(source.ToString());
        }
Exemple #2
0
        public override string ToSource()
        {
            StringBuilder source = new StringBuilder();

            foreach (GDefine def in defineList)
            {
                source.AppendLine(def.ToSource());
            }

            source.AppendLine("\npublic delegate void LoadedHandler();");
            source.AppendLine("public event LoadedHandler Loaded;\n");

            source.AppendLine("public delegate void ClosingHandler();");
            source.AppendLine("public event ClosingHandler Closing;\n");

            source.AppendLine("public void Initialize()");
            source.AppendLine("{");

            foreach (GScope scope in scopeList)
            {
                source.AppendLine(ConvertAssistant.Indentation(scope.ToSource()));
            }

            source.AppendLine(ConvertAssistant.Indentation("if (Loaded != null) Loaded();").TrimEnd());
            source.AppendLine("}");

            foreach (GFunction func in functionList)
            {
                source.AppendLine(func.ToSource());
            }

            return(source.ToString());
        }
Exemple #3
0
        public override string ToSource()
        {
            StringBuilder builderCode = new StringBuilder();

            builderCode.AppendFormat
            (
                "if ({0}.ToBool())\n{{\n",
                Logic.ToSource()
            );

            foreach (GStatement statement in listStatement)
            {
                builderCode.AppendFormat
                (
                    "{0}",
                    ConvertAssistant.Indentation(statement.ToSource())
                );
            }
            ;

            builderCode.Append
            (
                "};"
            );

            return(builderCode.ToString());
        }
Exemple #4
0
        public override string ToSource()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("void {0}()\n{{\n", FunctionName);

            foreach (GStatement statement in Content)
            {
                builder.AppendLine(ConvertAssistant.Indentation(statement.ToSource()));
            }

            builder.AppendLine("};");

            return(builder.ToString());
        }
Exemple #5
0
        public override string ToSource()
        {
            StringBuilder builderCode = new StringBuilder();

            if (GNumber != null)
            {
                string varName = "_" + GetHashCode();
                builderCode.AppendFormat("for (int {0} = 0; {0} < {1}.ToNumber(); {0}++)\n{{\n", varName, GNumber.ToSource());
            }
            else
            {
                builderCode.AppendLine("while (true)\n{\n");
            }

            foreach (GStatement statement in listStatement)
            {
                builderCode.Append(ConvertAssistant.Indentation(statement.ToSource()));
            }
            ;

            builderCode.Append("};");

            return(builderCode.ToString());
        }
Exemple #6
0
        private string ConvertToFullSource(string source, bool isEmbedded = false, bool isCompressed = false)
        {
            StringBuilder result = new StringBuilder();

            result.AppendLine("using System;");
            result.AppendLine("using System.IO;");
            result.AppendLine("using System.Collections.Generic;");
            result.AppendLine("using System.Linq;");
            result.AppendLine("using System.Text;");
            result.AppendLine("using System.Threading.Tasks;");
            result.AppendLine("using System.Reflection;");
            result.AppendLine("using System.Windows;");
            result.AppendLine("using System.Windows.Markup;");
            result.AppendLine("using GSharp.Compressor;");
            result.AppendLine("using GSharp.Bootstrap.DataTypes;");
            result.AppendLine();
            result.AppendLine("[assembly: AssemblyTitle(\"Title\")]");
            result.AppendLine("[assembly: AssemblyProduct(\"Product\")]");
            result.AppendLine("[assembly: AssemblyCompany(\"Company\")]");
            result.AppendLine("[assembly: AssemblyCopyright(\"Copyright\")]");
            result.AppendLine("[assembly: AssemblyTrademark(\"Trademark\")]");
            result.AppendLine("[assembly: AssemblyVersion(\"1.0.0.0\")]");
            result.AppendLine("[assembly: AssemblyFileVersion(\"1.0.0.0\")]");
            result.AppendLine();
            result.AppendLine("namespace GSharp.Default");
            result.AppendLine("{");
            result.AppendLine("    public partial class App : Application");
            result.AppendLine("    {");
            result.AppendLine("        public static Window window;");
            if (isEmbedded && isCompressed)
            {
                result.AppendLine("        public static Assembly compressor;");
                result.AppendLine("        public static MethodInfo compressorMethod;");
            }
            result.AppendLine();
            result.AppendLine("        [STAThread]");
            result.AppendLine("        public static void Main()");
            result.AppendLine("        {");
            if (isEmbedded || isCompressed)
            {
                result.AppendLine("            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Resolve);");
                if (isEmbedded && isCompressed)
                {
                    result.AppendLine();
                    result.AppendLine("            var current = Assembly.GetExecutingAssembly();");
                    result.AppendLine(@"            var files = current.GetManifestResourceNames().Where(s => s.EndsWith(""GSharp.Compressor.dll""));");
                    result.AppendLine("            using (var stream = current.GetManifestResourceStream(files.First()))");
                    result.AppendLine("            {");
                    result.AppendLine("                var data = new byte[stream.Length];");
                    result.AppendLine("                stream.Read(data, 0, data.Length);");
                    result.AppendLine("                compressor = Assembly.Load(data);");
                    result.AppendLine(@"                compressorMethod = compressor.GetType(""GSharp.Compressor.GCompressor"").GetMethod(""Decompress"", new Type[] { typeof(Stream) });");
                    result.AppendLine("            }");
                    result.AppendLine();
                }
            }
            result.AppendLine("            App app = new App();");
            result.AppendLine("            app.InitializeComponent();");
            result.AppendLine("            app.Run();");
            result.AppendLine("        }");
            if (isEmbedded || isCompressed)
            {
                result.AppendLine();
                result.AppendLine("        public static Assembly Resolve(object sender, ResolveEventArgs args)");
                result.AppendLine("        {");
                result.AppendLine("            var current = Assembly.GetExecutingAssembly();");
                if (isCompressed)
                {
                    result.AppendLine(@"            var name = args.Name.Substring(0, args.Name.IndexOf(',')) + "".pak"";");
                }
                else
                {
                    result.AppendLine(@"            var name = args.Name.Substring(0, args.Name.IndexOf(',')) + "".dll"";");
                }

                if (isEmbedded)
                {
                    result.AppendLine("            var files = current.GetManifestResourceNames().Where(s => s.EndsWith(name));");
                    result.AppendLine();
                    result.AppendLine("            if (files.Count() > 0)");
                    result.AppendLine("            {");
                    result.AppendLine("                using (var stream = current.GetManifestResourceStream(files.First()))");
                    result.AppendLine("                {");
                    result.AppendLine("                    if (stream != null)");
                    result.AppendLine("                    {");
                    if (isCompressed)
                    {
                        result.AppendLine("                        var data = compressorMethod.Invoke(null, new object[] { stream }) as byte[];");
                        result.AppendLine("                        return Assembly.Load(data);");
                    }
                    else
                    {
                        result.AppendLine("                        var data = new byte[stream.Length];");
                        result.AppendLine("                        stream.Read(data, 0, data.Length);");
                        result.AppendLine("                        return Assembly.Load(data);");
                    }
                    result.AppendLine("                    }");
                    result.AppendLine("                }");
                    result.AppendLine("            }");
                }
                else
                {
                    result.AppendLine();
                    result.AppendLine("            var data = GCompressor.Decompress(AppDomain.CurrentDomain.BaseDirectory + name);");
                    result.AppendLine("            return Assembly.Load(data);");
                }
                if (isEmbedded)
                {
                    result.AppendLine();
                    result.AppendLine("            return null;");
                }
                result.AppendLine("        }");
            }
            if (XAML.Length > 0)
            {
                result.AppendLine();
                result.AppendLine("        public string Decode(string value)");
                result.AppendLine("        {");
                result.AppendLine("            if (value != null && value.Length > 0)");
                result.AppendLine("            {");
                result.AppendLine("                return Encoding.UTF8.GetString(Convert.FromBase64String(value));");
                result.AppendLine("            }");
                result.AppendLine("            else");
                result.AppendLine("            {");
                result.AppendLine("                return string.Empty;");
                result.AppendLine("            }");
                result.AppendLine("        }");
                result.AppendLine();
                result.AppendLine("        public T FindControl<T>(DependencyObject parent, string value)");
                result.AppendLine("        {");
                result.AppendLine("            return (T)(object)LogicalTreeHelper.FindLogicalNode(parent, value);");
                result.AppendLine("        }");
            }
            result.AppendLine();
            result.AppendLine("        public void InitializeComponent()");
            result.AppendLine("        {");
            result.AppendLine("                Dispatcher.UnhandledException += (dS, dE) =>");
            result.AppendLine("                {");
            result.AppendLine("                    dE.Handled = true;");
            result.AppendLine(@"                    if(MessageBox.Show(dE.Exception.Message + ""\n프로그램을 계속 진행 하시겠습니까?"", ""런타임 오류"", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.No)");
            result.AppendLine(@"                    {");
            result.AppendLine(@"                        Application.Current.Shutdown();");
            result.AppendLine(@"                    }");
            result.AppendLine("                };");
            result.AppendLine("                Dispatcher.UnhandledExceptionFilter += (dS, dE) =>");
            result.AppendLine("                {");
            result.AppendLine("                    dE.RequestCatch = true;");
            result.AppendLine("                };");
            if (XAML.Length > 0)
            {
                result.AppendLine($@"            window = (XamlReader.Parse(Decode(""{_XAML}"")) as Window);");
            }
            else
            {
                result.AppendLine("            window = new Window();");
                result.AppendLine("            window.Opacity = 0;");
                result.AppendLine("            window.WindowStyle = WindowStyle.None;");
                result.AppendLine("            window.AllowsTransparency = true;");
                result.AppendLine("            window.ShowInTaskbar = false;");
            }
            result.AppendLine("            window.Loaded += (s, e) => Initialize();");
            result.AppendLine("            window.Closing += (s, e) =>");
            result.AppendLine("            {");
            result.AppendLine("                if (Closing != null) Closing();");
            result.AppendLine("            };");
            result.AppendLine("            window.Show();");
            result.AppendLine("        }");
            result.AppendLine();
            result.Append(ConvertAssistant.Indentation(source, 2));
            result.AppendLine("    }");
            result.AppendLine("}");

            return(result.ToString());
        }