Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var user = new SampleUser
            {
                ControlPlane = "sharefile.com",
                Username     = "",
                Password     = "",
                Subdomain    = ""
            };

            string oauthClientId     = "";
            string oauthClientSecret = "";

            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();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var user = new SampleUser
            {
                ControlPlane = "sharefile.com",
                Username = "",
                Password = "",
                Subdomain = ""
            };

            string oauthClientId = "";
            string oauthClientSecret = "";

            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();
        }
Ejemplo n.º 3
0
        public static async Task RunSample(SampleUser user, string clientId, string clientSecret)
        {
            // Authenticate with username/password
            var sfClient = await PasswordAuthentication(user, clientId, clientSecret);

            // Create a Session
            await StartSession(sfClient);

            // Load Folder and Contents
            var 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 = "[EnterEmailAddress]";

            await ShareViaShareFileEmail(sfClient, uploadedFile, recipientEmailAddress);

            Console.ReadKey();
        }
Ejemplo n.º 4
0
        public static async Task <ShareFileClient> PasswordAuthentication(SampleUser user, string clientId, string clientSecret)
        {
            // Initialize ShareFileClient.
            var configuration = Configuration.Default();

            configuration.Logger = new DefaultLoggingProvider();

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

            // Perform a password grant request.  Will give us an OAuthToken
            var oauthToken = await oauthService.PasswordGrantAsync(user.Username, user.Password, user.Subdomain, user.ControlPlane);

            // Add credentials and update sfClient with new BaseUri
            sfClient.AddOAuthCredentials(oauthToken);
            sfClient.BaseUri = oauthToken.GetUri();

            return(sfClient);
        }
Ejemplo n.º 5
0
        public static async Task RunSample(SampleUser user, string clientId, string clientSecret)
        {
            // Authenticate with username/password
            var sfClient = await PasswordAuthentication(user, clientId, clientSecret);

            // Create a Session
            await StartSession(sfClient);

            // Load Folder and Contents
            var 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 = "[EnterEmailAddress]";
            await ShareViaShareFileEmail(sfClient, uploadedFile, recipientEmailAddress);

            Console.ReadKey();
        }
Ejemplo n.º 6
0
        public static async Task<ShareFileClient> PasswordAuthentication(SampleUser user, string clientId, string clientSecret)
        {
            // Initialize ShareFileClient.
            var configuration = Configuration.Default();
            configuration.Logger = new DefaultLoggingProvider();

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

            // Perform a password grant request.  Will give us an OAuthToken
            var oauthToken = await oauthService.PasswordGrantAsync(user.Username, user.Password, user.Subdomain, user.ControlPlane);

            // Add credentials and update sfClient with new BaseUri
            sfClient.AddOAuthCredentials(oauthToken);
            sfClient.BaseUri = oauthToken.GetUri();

            return sfClient;
        }