Exemplo n.º 1
0
 private Mega(Transport t)
 {
     transport = t;
     transport.Proxy = WebRequest.GetSystemWebProxy();
     transport.ServerRequest += (s, e) => { if (ServerRequest != null) { ServerRequest(s, e); } };
     downloader = new MegaDownloader(transport);
     uploader = new MegaUploader(transport);
 }
Exemplo n.º 2
0
        private static IMegaRequest ThreadInit(MegaUser user, Action<Mega> OnSuccess, Action<int> OnError)
        {
            var initTransport = new Transport();
            var mega = new Mega(initTransport);

            // mandatory anonymous registration
            if (user == null || (user.Email == null && user.Id == null))
            {
                user = new MegaUser();
                var req = new MRequestCreateAnon<MResponseCreateAnon>(user);
                int? error = null;
                req.Success += (s, args) => user.Id = args.UserId;
                req.Error += (s, e) => error = e.Error;
                initTransport.EnqueueRequest(req);
                req.ResetEvent.WaitOne();
                if (error != null)
                {
                    OnError((int)error);
                    // just to have the ResetEvent for async compatibility
                    return new EmptyRequest();
                }
            }

            // set the credentials
            mega.User = user;

            // the login itself
            var sidRequest = new MRequestGetSid<MResponseGetSid>(mega.User);
            sidRequest.Success += (s, args) =>
            {
                mega.User.Sid = args.SessionId;
                mega.User.SetMasterKey(args.MasterKey.Value);

                var getUserRequest = new MRequestGetUser<MResponseGetUser>(mega.User);
                getUserRequest.Success += (s2, args2) =>
                {
                    mega.User.Status = args2.UserStatus;
                    mega.User.Email = args2.Email;
                    mega.User.Id = args2.UserId;
                    OnSuccess(mega);
                };
                getUserRequest.Error += (s2, e) =>
                {
                    OnError(e.Error);
                    sidRequest.ResetEvent.Set();
                };
                initTransport.EnqueueRequest(getUserRequest);
                getUserRequest.ResetEvent.WaitOne();
            };
            sidRequest.Error += (s, a) => OnError(a.Error);

            initTransport.EnqueueRequest(sidRequest);
            return sidRequest;
        }
Exemplo n.º 3
0
 public MegaDownloader(Transport transport, string tempFolder = null, int maxConnections = 4, int maxThreads = 4)
     : base(transport, tempFolder, maxConnections, maxThreads) { }