Are there any updated samples that work with the newer .dlls?

  • 1
  • Question
  • Updated 7 months ago
Are there any updated samples that work with the newer .dlls?

I have run the samples and they connect perfectly but when trying to connect using the updated V4 .dll the code hangs on  (var oauthToken = await authService.PasswordGrantAsync(user.Username,
              user.Password, user.Subdomain, user.ControlPlane);) 

I am trying to create + send an encrypted email via the api as per the instructions in the link below.
https://community.sharefilesupport.com/citrixsharefile/topics/send-email-with-net-api-call-samples-e....

I have tried adding this code to the sample which connects, but the Encrypted email parts don't seem to exist.

Any pointers would be greatly appreciated.
Photo of Chris

Chris

  • 17 Posts
  • 2 Reply Likes

Posted 7 months ago

  • 1
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 52 Posts
  • 7 Reply Likes
Hi Chris,

The PasswordGrantAsync call should work just fine with the current version of the sdk (just tried it on my end). Can you post a more complete sample of the code you're running?
Photo of Chris

Chris

  • 17 Posts
  • 2 Reply Likes
Its hanging on "await oauthService.PasswordGrantAsync(user.Username,
              user.Password, user.Subdomain, user.ControlPlane)", I think it my have something to do with the WAIT() on RunSample, although this works in the samples with the older version.




static void Main(string[] args) {
            var user = new ShareFileUser {
                ControlPlane = "sharefile.com",
                Username = myEmail,
                Password = myPWD,
                Subdomain = mySubdomain
            };

            string oauthClientId = myID
            string oauthClientSecret = mySecret;

            if (string.IsNullOrEmpty(oauthClientId) || string.IsNullOrEmpty(oauthClientSecret)) {
                Console.WriteLine("You must provide oauthClientId and oauthClientSecret");
                return;
            }

            if (string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password) ||
                string.IsNullOrEmpty(user.Subdomain)) {
                Console.WriteLine("You must provide username, password and subdomain");
                return;
            }

            RunSample(user, oauthClientId, oauthClientSecret).Wait();

        }



        public static async Task RunSample(ShareFileUser user, string clientId, string clientSecret) {



            var sfClient = new ShareFileClient("https://secure.sf-api.com/sf/v3/");
            var oauthService = new OAuthService(sfClient, clientId, clientSecret);

            var oauthToken = await oauthService.PasswordGrantAsync(user.Username,
              user.Password, user.Subdomain, user.ControlPlane);

            sfClient.AddOAuthCredentials(oauthToken);
            sfClient.BaseUri = oauthToken.GetUri();


            //    // Authenticate with username/password
            //var sfClient = await PasswordAuthentication(user, clientId, clientSecret);

            //    // Create a Session
            await StartSession(sfClient);

            // Load Folder and Contents
            Folder defaultUserFolder = await LoadFolderAndChildren(sfClient);
            Console.WriteLine("Loaded - " + defaultUserFolder.Name);

            // Create a Folder
            var createdFolder = await CreateFolder(sfClient, defaultUserFolder);
            Console.WriteLine("Created a new folder - " + createdFolder.Name);

            // Upload a file
            var uploadedFileId = await Upload(sfClient, createdFolder);
            var itemUri = sfClient.Items.GetAlias(uploadedFileId);
            var uploadedFile = await sfClient.Items.Get(itemUri).ExecuteAsync();
            Console.WriteLine("Uploaded - " + uploadedFile.Name);

            // Download a file
            await Download(sfClient, uploadedFile);
            Console.WriteLine("Downloaded - " + uploadedFile.Name);

            // Share a file using a Link
            var share = await ShareViaLink(sfClient, uploadedFile);
            Console.WriteLine("Successfully created a share, it be be accessed using: " + share.Uri);

            // Share a file via ShareFile
            string recipientEmailAddress = "chris.matthews@taliscon.com";
            await ShareViaShareFileEmail(sfClient, uploadedFile, recipientEmailAddress);


        }
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 52 Posts
  • 7 Reply Likes
I tried running your sample, and the PasswordGrantAsync method returns almost instantly.
What version of the .Net framework are you using? (I've tried both 4.6.1 and 4.7 successfully).

If you want to share your subdomain/account id, I can try checking on our end if there are any issues.
You can do so by uploading a text file with the information here:
https://skrzypek.sharefile.com/r-r75d5a6b44024d72b
Photo of Chris

Chris

  • 17 Posts
  • 2 Reply Likes
I am using 4.5
I have got it working now, not really sure how though.

Thanks
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Chris,

One common reason we've seen this hang, as you've mentioned before, is adding a "Wait" or "Result" statement in front of the async call, as blocking on async code can often lead to deadlocks in applications. Try adding ConfigureAwait(false) to the async call, like this:
await oauthService.PasswordGrantAsync(user.Username,user.Password, user.Subdomain, 
user.ControlPlane).ConfigureAwait(false);
That should help with the issue, let us know how it goes

Eli
Photo of Chris

Chris

  • 17 Posts
  • 2 Reply Likes
I seem to have the issue when I create a new app, currently I am making a .dll so that our app can send encrypted emails via your api.

I have tried the ConfigureAwait(false) and it seems to works. 

Thanks
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 731 Posts
  • 102 Reply Likes
Awesome! Here's a good article that explains why this happens if you're curious 
https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
Photo of Chris

Chris

  • 17 Posts
  • 2 Reply Likes
Perfect, I was triggering the task from a button click!

Thanks