示例#1
0
        public string GenerateReadmeMdBrowserSampleCode(string emptyLine)
        {
            TSBuilder builder = new TSBuilder();

            builder.ConstQuotedStringVariable("subscriptionId", "<Subscription_Id>");
            builder.Text("const authManager = new msAuth.AuthManager(");
            builder.Object(tsObject =>
            {
                tsObject.QuotedStringProperty("clientId", "<client id for your Azure AD app>");
                tsObject.QuotedStringProperty("tenant", "<optional tenant for your organization>");
            });
            builder.Line(");");

            builder.Line($"authManager.finalizeLogin().then((res) => {{");
            builder.Indent(() =>
            {
                builder.If("!res.isLoggedIn", ifBlock =>
                {
                    ifBlock.LineComment("may cause redirects");
                    ifBlock.Line("authManager.login();");
                });

                builder.ConstVariable("client", $"new {BundleVarName}.{Name}(res.creds, subscriptionId)");
                builder.Line($"{GenerateSampleMethod(true)}.catch((err) => {{");
                builder.Indent(() =>
                {
                    builder.Line("console.log(\"An error occurred:\");");
                    builder.Line("console.error(err);");
                });
                builder.Line($"}});");
            });
            builder.Line($"}});");

            return(builder.ToString());
        }