Exemplo n.º 1
0
        public MainActivityFile(string appName, string assemblyName) : base("MainActivity.cs")
        {
            SGFile file = new SGFile("MainActivity.cs")
            {
                UsingStatements =
                {
                    new CGUsingStatement("System"),
                    new CGUsingStatement("Android.App"),
                    new CGUsingStatement("Android.Content.PM"),
                    new CGUsingStatement("Android.Runtime"),
                    new CGUsingStatement("Android.Views"),
                    new CGUsingStatement("Android.Widget"),
                    new CGUsingStatement("Android.OS")
                },
                Namespaces =
                {
                    new CGNamespace(assemblyName)
                    {
                        Classes =
                        {
                            new CGClass("MainActivity",                                              "global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity")
                            {
                                ClassAttributes =
                                {
                                    $"[Activity(Label = \"{appName}\", Icon = \"@drawable/icon\", Theme = \"@style/MainTheme\", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]"
                                },
                                ClassMethods =
                                {
                                    new CGMethod(new CGMethodSignature(AccessibilityLevel.Protected, "OnCreate",                                         "void",          false, true)
                                    {
                                        Arguments =
                                        {
                                            new CGMethodArgument("Bundle",                           "bundle")
                                        }
                                    })
                                    {
                                        MethodText = String.Concat(
                                            "TabLayoutResource = Resource.Layout.Tabbar;",           Environment.NewLine,
                                            "ToolbarResource = Resource.Layout.Toolbar;",            Environment.NewLine,
                                            Environment.NewLine,
                                            "base.OnCreate(bundle);",                                Environment.NewLine,
                                            Environment.NewLine,
                                            "global::Xamarin.Forms.Forms.Init(this, bundle);",       Environment.NewLine,
                                            "LoadApplication(new App());"
                                            )
                                    }
                                }
                            }
                        }
                    }
                }
            };

            this.FileContents = file.ToString();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileTemplate"/> class.
 /// </summary>
 /// <param name="file">The file.</param>
 public FileTemplate(SGFile file)
 {
     TemplateText = file.ToString();
 }
        public DefaultMainPageXamlFile(string assemblyName) : base("MainPage")
        {
            XNamespace @namespace     = "http://xamarin.com/schemas/2014/forms";
            XNamespace xNamespace     = "http://schemas.microsoft.com/winfx/2009/xaml";
            XNamespace localNamespace = $"clr-namespace:{assemblyName}";

            XElement rootNode = new XElement(@namespace + "ContentPage",
                                             //new XAttribute(@namespace+"xmlns", "http://xamarin.com/schemas/2014/forms"),
                                             //new XAttribute(xNamespace+"xmlns", "http://schemas.microsoft.com/winfx/2009/xaml"),
                                             //new XAttribute(localNamespace+"xmlns", $"clr-namespace:{assemblyName}"),
                                             new XAttribute(xNamespace + "Class", $"{assemblyName}.MainPage"),
                                             new XElement(@namespace + "Label",
                                                          new XAttribute("Text", "Welcome to Xamarin Forms!"),
                                                          new XAttribute("VerticalOptions", "Center"),
                                                          new XAttribute("HorizontalOptions", "Center")
                                                          )
                                             );

            using (var memoryStream = new MemoryStream())
            {
                rootNode.Save(memoryStream);

                memoryStream.Position = 0;
                using (var streamReader = new StreamReader(memoryStream))
                {
                    XamlFileContents = streamReader.ReadToEnd();
                }
            }

            SGFile file = new SGFile("MainPage.xaml.cs")
            {
                UsingStatements =
                {
                    new CGUsingStatement("System"),
                    new CGUsingStatement("System.Collections.Generic"),
                    new CGUsingStatement("System.Linq"),
                    new CGUsingStatement("System.Text"),
                    new CGUsingStatement("System.Threading.Tasks"),
                    new CGUsingStatement("Xamarin.Forms")
                },
                Namespaces =
                {
                    new CGNamespace(assemblyName)
                    {
                        Classes =
                        {
                            new CGClass("MainPage", "ContentPage", false, false, true)
                            {
                                ClassConstructors =
                                {
                                    new CGClassConstructor("MainPage")
                                    {
                                        ConstructorText =
                                        {
                                            "InitializeComponent();"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            XamlCsFileContents = file.ToString();
        }
Exemplo n.º 4
0
        public DefaultAppXamlFile(string namespaceName) : base("App")
        {
            XNamespace @namespace = "http://xamarin.com/schemas/2014/forms";
            XNamespace xNamespace = "http://schemas.microsoft.com/winfx/2009/xaml";

            XElement rootNode = new XElement(@namespace + "Application",
                                             //new XAttribute("xmlns", "http://xamarin.com/schemas/2014/forms"),
                                             //new XAttribute("xmlns", "http://schemas.microsoft.com/winfx/2009/xaml"),
                                             new XAttribute(xNamespace + "Class", $"{namespaceName}.App"),
                                             new XElement(@namespace + "Application.Resources"
                                                          )
                                             );

            using (var memoryStream = new MemoryStream())
            {
                rootNode.Save(memoryStream);

                memoryStream.Position = 0;
                using (var streamReader = new StreamReader(memoryStream))
                {
                    XamlFileContents = streamReader.ReadToEnd();
                }
            }

            SGFile file = new SGFile("App.xaml.cs")
            {
                AssemblyReferences =
                {
                    new SGAssemblyReference("System"),
                    new SGAssemblyReference("Xamarin.Forms"),
                    new SGAssemblyReference("Xamarin.Forms.Xaml")
                },
                Namespaces =
                {
                    new SGNamespace(namespaceName)
                    {
                        Attributes =
                        {
                            new SGAttribute("XamlCompilation", "XamlCompilationOptions.Compile").WithNamespace("assembly")
                        },
                        Classes =
                        {
                            new SGClass("App",                                     SGAccessibilityLevel.Public,    false,            false, true)
                            {
                                Constructors =
                                {
                                    new SGClassConstructor("App",                  SGAccessibilityLevel.Public)
                                    {
                                        Lines =
                                        {
                                            "InitializeComponent();",
                                            "",
                                            "MainPage = new MainPage();"
                                        }
                                    }
                                },
                                Methods =
                                {
                                    new SGMethod(new SGMethodSignature("OnStart",  SGAccessibilityLevel.Protected,  isOverride: true, returnType: "void"))
                                    {
                                        Lines ={ "// Handle when your app starts"         }
                                    },
                                    new SGMethod(new SGMethodSignature("OnSleep",  SGAccessibilityLevel.Protected,  isOverride: true, returnType: "void"))
                                    {
                                        Lines ={ "// Handle when your app sleeps"         }
                                    },
                                    new SGMethod(new SGMethodSignature("OnResume", SGAccessibilityLevel.Protected,  isOverride: true, returnType: "void"))
                                    {
                                        Lines ={ "// Handle when your app resumes"        }
                                    }
                                }
                            }.WithBaseClass("Application")
                        }
                    }
                }
            };

            XamlCsFileContents = file.ToString();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectFile"/> class.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="shouldCompile">if set to <c>true</c> [should compile].</param>
 /// <param name="isContent">if set to <c>true</c> [is content].</param>
 public ProjectFile(SGFile file, bool shouldCompile, bool isContent) :
     this(String.Concat(file.FileName, ".", file.FileExtension), shouldCompile, isContent, file.ToString())
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectFile"/> class.
 /// </summary>
 /// <param name="file">The file.</param>
 public ProjectFile(SGFile file) :
     this(String.Concat(file.FileName, ".", file.FileExtension), true, false, file.ToString())
 {
 }
        public DefaultMainPageXamlFile(string namespaceName) : base("MainPage")
        {
            XNamespace @namespace     = "http://xamarin.com/schemas/2014/forms";
            XNamespace xNamespace     = "http://schemas.microsoft.com/winfx/2009/xaml";
            XNamespace localNamespace = $"clr-namespace:{namespaceName}";

            XElement rootNode = new XElement(@namespace + "ContentPage",
                                             //new XAttribute(@namespace+"xmlns", "http://xamarin.com/schemas/2014/forms"),
                                             //new XAttribute(xNamespace+"xmlns", "http://schemas.microsoft.com/winfx/2009/xaml"),
                                             //new XAttribute(localNamespace+"xmlns", $"clr-namespace:{assemblyName}"),
                                             new XAttribute(xNamespace + "Class", $"{namespaceName}.MainPage"),
                                             new XElement(@namespace + "StackLayout",
                                                          new XComment("Place new controls here"),
                                                          new XElement(@namespace + "Label",
                                                                       new XAttribute("Text", "Welcome to Xamarin Forms!"),
                                                                       new XAttribute("VerticalOptions", "Center"),
                                                                       new XAttribute("HorizontalOptions", "CenterAndExpand")
                                                                       )
                                                          )
                                             );

            using (var memoryStream = new MemoryStream())
            {
                rootNode.Save(memoryStream);

                memoryStream.Position = 0;
                using (var streamReader = new StreamReader(memoryStream))
                {
                    XamlFileContents = streamReader.ReadToEnd();
                }
            }

            SGFile file = new SGFile("App.xaml.cs")
            {
                AssemblyReferences =
                {
                    new SGAssemblyReference("System"),
                    new SGAssemblyReference("System.Collections.Generic"),
                    new SGAssemblyReference("System.Linq"),
                    new SGAssemblyReference("System.Text"),
                    new SGAssemblyReference("System.Threading.Tasks"),
                    new SGAssemblyReference("Xamarin.Forms")
                },
                Namespaces =
                {
                    new SGNamespace(namespaceName)
                    {
                        Classes =
                        {
                            new SGClass("MainPage",                    SGAccessibilityLevel.Public, isPartial: true)
                            {
                                Constructors =
                                {
                                    new SGClassConstructor("MainPage", SGAccessibilityLevel.Public)
                                    {
                                        Lines ={ "InitializeComponent();"             }
                                    }
                                }
                            }.WithBaseClass("ContentPage")
                        }
                    }
                }
            };

            XamlCsFileContents = file.ToString();
        }
Exemplo n.º 8
0
        public DefaultAppXamlFile(string assemblyName) : base("App")
        {
            XNamespace @namespace = "http://xamarin.com/schemas/2014/forms";
            XNamespace xNamespace = "http://schemas.microsoft.com/winfx/2009/xaml";

            XElement rootNode = new XElement(@namespace + "Application",
                                             //new XAttribute("xmlns", "http://xamarin.com/schemas/2014/forms"),
                                             //new XAttribute("xmlns", "http://schemas.microsoft.com/winfx/2009/xaml"),
                                             new XAttribute(xNamespace + "Class", $"{assemblyName}.App"),
                                             new XElement(@namespace + "Application.Resources"
                                                          )
                                             );

            using (var memoryStream = new MemoryStream())
            {
                rootNode.Save(memoryStream);

                memoryStream.Position = 0;
                using (var streamReader = new StreamReader(memoryStream))
                {
                    string contents = streamReader.ReadToEnd();
                    XamlFileContents = contents;
                }
            }

            SGFile file = new SGFile("App.xaml.cs")
            {
                UsingStatements =
                {
                    new CGUsingStatement("System"),
                    new CGUsingStatement("System.Collections.Generic"),
                    new CGUsingStatement("System.Linq"),
                    new CGUsingStatement("System.Text"),
                    new CGUsingStatement("Xamarin.Forms")
                },
                Namespaces =
                {
                    new CGNamespace(assemblyName)
                    {
                        Classes =
                        {
                            new CGClass("App",                                                       "Application", false,  false, true)
                            {
                                ClassConstructors =
                                {
                                    new CGClassConstructor("App")
                                    {
                                        ConstructorText =
                                        {
                                            "InitializeComponent();",
                                            Environment.NewLine,
                                            $"MainPage = new {assemblyName}.MainPage();"
                                        }
                                    }
                                },
                                ClassMethods =
                                {
                                    new CGMethod(new CGMethodSignature(AccessibilityLevel.Protected, "OnStart",  "void",     false, true))
                                    {
                                        MethodText = "// Handle when your app starts"
                                    },
                                    new CGMethod(new CGMethodSignature(AccessibilityLevel.Protected, "OnSleep",  "void",     false, true))
                                    {
                                        MethodText = "// Handle when your app sleeps"
                                    },
                                    new CGMethod(new CGMethodSignature(AccessibilityLevel.Protected, "OnResume", "void",     false, true))
                                    {
                                        MethodText = "// Handle when your app resumes"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            XamlCsFileContents = file.ToString();
        }
Exemplo n.º 9
0
        public AppDelegateFile(string assemblyName) : base("AppDelegate.cs", true, false)
        {
            SGFile file = new SGFile("AppDelegate.cs")
            {
                AssemblyReferences =
                {
                    new SGAssemblyReference("System"),
                    new SGAssemblyReference("System.Collections.Generic"),
                    new SGAssemblyReference("System.Linq"),
                    new SGAssemblyReference("Foundation"),
                    new SGAssemblyReference("UIKit")
                },
                Namespaces =
                {
                    new SGNamespace(assemblyName)
                    {
                        Classes =
                        {
                            new SGClass("AppDelegate",                                                                                 SGAccessibilityLevel.Public, false, false, true)
                            {
                                BaseClass     = "global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate",
                                ClassComments =
                                {
                                    "The UIApplicationDelegate for the application. This class is responsible for launching the",
                                    "User Interface of the application, as well as listening (and optionally responding) to",
                                    "application events from iOS."
                                },
                                Attributes =
                                {
                                    new SGAttribute("[Register(\"AppDelegate\")]")
                                },
                                Methods =
                                {
                                    new SGMethod(new SGMethodSignature("FinishedLaunching",                                            SGAccessibilityLevel.Public,                                                     false, false, true, "bool")
                                    {
                                        Arguments =
                                        {
                                            new SGArgument("UIApplication", "app"),
                                            new SGArgument("NSDictionary",  "options")
                                        }
                                    })
                                    {
                                        MethodComments =
                                        {
                                            "",
                                            "This method is invoked when the application has loaded and is ready to run. In this",
                                            "method you should instantiate the window, load the UI into it and then make the window",
                                            "visible.",
                                            "",
                                            "You have 17 seconds to return from this method, or iOS will terminate your application.",
                                            ""
                                        },
                                        MethodText = String.Concat(
                                            "global::Xamarin.Forms.Forms.Init();",                                                     Environment.NewLine,
                                            "LoadApplication(new App());",                                                             Environment.NewLine,
                                            Environment.NewLine,
                                            "return base.FinishedLaunching(app, options);"
                                            )
                                    }
                                }
                            }
                        }
                    }
                }
            };

            this.FileContents = file.ToString();
        }