static void Main(string[] args)
        {
            ServicePointManager.Expect100Continue = false;
            var config = new MediaFireApiConfiguration
               (
                   appId: AppId,
                   apiKey: AppKey,
                   apiVersion: "1.5",
                   automaticallyRenewToken: true,
                   chunkTransferBufferSize: 1024
               );

            _agent = new MediaFireAgent(config);
            Main().Wait();
        }
Example #2
0
        public static async Task <MediaFireAgent> LoginAsync(string account, string code, string settingsPassPhrase)
        {
            if (string.IsNullOrEmpty(account))
            {
                throw new ArgumentNullException(nameof(account));
            }

            var agent = new MediaFireAgent(new MediaFireApiConfiguration(Secrets.API_KEY, Secrets.APP_ID, useHttpV1: true, automaticallyRenewToken: false));

            var synchronizationContext = default(SynchronizationContext);

            if (contextDirectory.TryGetValue(account, out synchronizationContext))
            {
                synchronizationContext.AttachContextHolder(agent.User);
            }
            else
            {
                var refreshToken = LoadRefreshToken(account, settingsPassPhrase);

                if (refreshToken != null)
                {
                    agent.User.SetAuthenticationContext(refreshToken);

                    refreshToken = await RefreshSessionTokenAsync(agent);
                }

                if (refreshToken == null)
                {
                    if (string.IsNullOrEmpty(code))
                    {
                        code = GetAuthCode(account);
                    }

                    var parts = code?.Split(new[] { ',' }, 2) ?? Array.Empty <string>();
                    if (parts.Length != 2)
                    {
                        throw new AuthenticationException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.ProvideAuthenticationData, account));
                    }

                    await agent.User.GetSessionToken(parts[0], parts[1], TokenVersion.V2);
                }

                contextDirectory.Add(account, synchronizationContext = new SynchronizationContext(agent.User, settingsPassPhrase));
            }

            return(agent);
        }
Example #3
0
    //
    //  The file to be uploaded
    //
    public uploadmediafire(string email, string password, string path, String appid, String appkey)

    {
        AppId    = appid;
        AppKey   = appkey;
        Email    = email;
        Password = password;
        FilePath = path;
        ServicePointManager.Expect100Continue = false;
        var config = new MediaFireApiConfiguration
                     (
            appId: AppId,
            apiKey: AppKey,
            apiVersion: "1.5",
            automaticallyRenewToken: true,
            chunkTransferBufferSize: 500000,
            useHttpV1: true    //On some platforms, the client will throw the error "The server committed a protocol violation. Section=ResponseStatusLine". In that cases set this property to true.

                     );

        _agent = new MediaFireAgent(config);
    }
        static void Main(string[] args)
        {
            var config = new MediaFireApiConfiguration
                (
                    appId: AppId,
                    apiKey: AppKey,
                    apiVersion: "1.4",
                    automaticallyRenewToken: true,
                    chunkTransferBufferSize:1024
                );

            var agent = new MediaFireAgent(config);

            Console.WriteLine("Signing in {0}...", Email);
            agent.User.GetSessionToken(Email, Password).Wait();

            Console.WriteLine("Getting root folder files and folders...", Email);

            var folderContent = agent.GetAsync<MediaFireGetContentResponse>(MediaFireApiFolderMethods.GetContent,
                new Dictionary<string, object>
                {
                    {MediaFireApiParameters.FolderKey, ""},
                    {MediaFireApiParameters.ContentType, MediaFireFolderContentType.Folders.ToApiParameter()}
                }).Result.FolderContent;

            var fileContent = agent.GetAsync<MediaFireGetContentResponse>(MediaFireApiFolderMethods.GetContent,
               new Dictionary<string, object>
                {
                    {MediaFireApiParameters.FolderKey, ""},
                    {MediaFireApiParameters.ContentType, MediaFireFolderContentType.Files.ToApiParameter()}
                }).Result.FolderContent;

            Console.WriteLine("Key | Name");
            foreach (var item in folderContent.Folders.Union<MediaFireItem>(fileContent.Files))
            {
                Console.WriteLine("{0} | {1}", item.Key, item.Name);
            }
        }
Example #5
0
 public MediaFireContext(MediaFireAgent agent)
 {
     Agent = agent;
 }