public static async void Run([TimerTrigger("*/1 * * * * * ")] TimerInfo myTimer, ILogger log,
                                     Binder binder)
        {
            // timer triggered every second (note: may be slowed down since this is an async method)
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            var Token_url = Environment.GetEnvironmentVariable("Token_url_service");

            // An implicit binding is used here to access the Token_service param from app settings
            TokenStoreInputBindingAttribute attribute = new TokenStoreInputBindingAttribute(Token_url, "tokenName", null); // Initialize TokenStoreBinding

            var outputToken = await binder.BindAsync <string>(attribute);

            if (!string.IsNullOrEmpty(outputToken))
            {
                using (var dbx = new DropboxClient(outputToken))
                {
                    var list = await dbx.Files.ListFolderAsync(string.Empty);

                    // show folders then files
                    foreach (var item in list.Entries.Where(i => i.IsFolder))
                    {
                        log.LogInformation($"Directory: {item.Name}");
                    }

                    foreach (var item in list.Entries.Where(i => i.IsFile))
                    {
                        log.LogInformation($"File: {item.Name}");
                    }
                }
            }
        }
Beispiel #2
0
    /// <summary>
    /// Main function for TokenStoreInputBinding logic. Returns an access token for specified service, or creates a token if it does not exist.
    /// </summary>
    private async Task <String> BuildItemFromAttribute(TokenStoreInputBindingAttribute attribute, ValueBindingContext arg2)
    {
        attribute.CheckValidity_URL();
        string tokenResourceUrl = attribute.tokenUrl; // for user scenario only specify path up to service, for msi scienario specify path up to token name

        // default token display name
        int pos = tokenResourceUrl.LastIndexOf("/") + 1;

        tokenDisplayName = tokenResourceUrl.Substring(pos, tokenResourceUrl.Length - pos);

        try
        {
            if (attribute.scenario.ToLower() == "user") // If Flag = "USER" or "user"
            {
                GetTokenName getTokenName = new GetTokenName(attribute);
                tokenResourceUrl = getTokenName.tokenResourceUrl;
                tokenDisplayName = getTokenName.tokenDisplayName;
            }

            // Shared logic for If scenario = "tokenName" or "user"
            if (attribute.scenario.ToLower() == "tokenname" || attribute.scenario.ToLower() == "user")
            {
                try
                {
                    // Use TokenStoreHelper to interact with your Token Store resource
                    TokenStoreHelper tokenStoreHelper = new TokenStoreHelper(tokenResourceUrl, tokenDisplayName, attribute);
                    return(await tokenStoreHelper.GetOrCreateToken());
                }
                catch (Exception exp)
                {
                    throw new SystemException($"{exp}");
                }
            }
            else // error, incorrect usage of scenario binding input
            {
                throw new ArgumentException("Incorrect usage of {scenario} binding input: Choose \"tokenName\" or \"user\" ");
            }
        }
        catch (Exception exp) // Overall catch statement
        {
            throw new SystemException($"{exp}");
        }
    }
Beispiel #3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log, Binder binder)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            // var Token_url = Environment.GetEnvironmentVariable("Token_url_name");
            var Token_url = "https://joetest.tokenstore.azure.net/services/dropbox/tokens/sampleToken";

            // An implicit binding is used here to access the Token_service param from app settings
            TokenStoreInputBindingAttribute attribute = new TokenStoreInputBindingAttribute(Token_url, "tokenName", "aad"); // Initialize TokenStoreBinding

            var outputToken = await binder.BindAsync <string>(attribute);

            log.LogInformation($"The output token is: {outputToken}");

            var filesList = new List <string>();

            if (!string.IsNullOrEmpty(outputToken))
            {
                using (var dbx = new DropboxClient(outputToken))
                {
                    var list = await dbx.Files.ListFolderAsync(string.Empty);

                    // show folders then files
                    foreach (var item in list.Entries.Where(i => i.IsFolder))
                    {
                        filesList.Add($"{item.Name}/");
                    }

                    foreach (var item in list.Entries.Where(i => i.IsFile))
                    {
                        filesList.Add($"{item.Name} \n");
                    }
                }
            }
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (var file in filesList)
            {
                sb.Append(file);
            }
            return((ActionResult) new OkObjectResult($"Files: \n {sb.ToString()}"));
        }