Exemple #1
0
        /// <summary>
        /// Get's the latest and greatest from remote
        /// </summary>
        /// <param name="gitUser">
        /// The Git User.
        /// </param>
        /// <param name="gitPass">
        /// The Git Pass.
        /// </param>
        /// <returns>
        /// A boolean that signals success
        /// </returns>
        public bool Fetch(string gitUser, string gitPass)
        {
            log.Debug(() => "Fetch on remote repo");
            if (File.Exists(ExternalGitPath))
            {
                string GitOutput = ExecuteGitCommand("pull");
                bool   result    = Regex.IsMatch(GitOutput, "\\bfatal\\b", RegexOptions.IgnoreCase);
                if (result == true)
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    var signature = new Signature(
                        "pass4win",
                        "*****@*****.**",
                        new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
                    var fetchOptions = new FetchOptions
                    {
                        CredentialsProvider =
                            (url, user, cred) =>
                            new UsernamePasswordCredentials
                        {
                            Username = gitUser,
                            Password = gitPass
                        }
                    };
                    var mergeOptions = new MergeOptions();
                    var pullOptions  = new PullOptions {
                        FetchOptions = fetchOptions, MergeOptions = mergeOptions
                    };
                    Commands.Pull(gitRepo, signature, pullOptions);
                }
                catch (Exception message)
                {
                    log.DebugException(message.Message, message);
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Retrieves an authentication token based on the following waterfall: - if
        /// opts.authToken is set, use it to compute the auth header - if opts.skipAuth
        /// is true, return empty auth header - otherwise login and use the retrieved
        /// token to compute the auth header
        /// </summary>
        /// <param name="opts">           optional options </param>
        /// <param name="opts.authToken"> optional token to be used </param>
        /// <param name="opts.skipAuth">  optional flag to bypass authentication </param>
        /// <exception cref="TraceSdkException">   </exception>

        public async Task <string> GetAuthorizationHeader(FetchOptions opts)
        {
            if (opts != null)
            {
                if (opts.AuthToken != null)
                {
                    return(this.MakeAuthorizationHeader(opts.AuthToken));
                }
                if (opts.SkipAuth != null && opts.SkipAuth.Value)
                {
                    return(this.MakeAuthorizationHeader(null));
                }
            }

            await this.Login();

            return(this.MakeAuthorizationHeader(this.token));
        }
Exemple #3
0
 public void FetchAll()
 {
     using (var repo = new Repository(_LocalGitPath))
     {
         foreach (Remote remote in repo.Network.Remotes)
         {
             FetchOptions options = new FetchOptions
             {
                 CredentialsProvider = new CredentialsHandler((url, usernameFromUrl, types) => new UsernamePasswordCredentials()
                 {
                     Username = _UserName,
                     Password = _Password
                 })
             };
             repo.Network.Fetch(remote, options);
         }
     }
 }
Exemple #4
0
        public void CannotFetchWithMalformedCustomHeaders()
        {
            var scd = BuildSelfCleaningDirectory();

            const string url = "https://github.com/libgit2/TestGitRepository";

            string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

            const string knownHeader = "Hello world";
            var          options     = new FetchOptions {
                CustomHeaders = new String[] { knownHeader }
            };

            using (var repo = new Repository(clonedRepoPath))
            {
                Assert.Throws <LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
            }
        }
        public static FetchOptions ToFetchOptions(this AuthenticationInfo authenticationInfo)
        {
            var fetchOptions = new FetchOptions();

            if (authenticationInfo != null)
            {
                if (!string.IsNullOrEmpty(authenticationInfo.Username))
                {
                    fetchOptions.CredentialsProvider = (url, user, types) => new UsernamePasswordCredentials
                    {
                        Username = authenticationInfo.Username,
                        Password = authenticationInfo.Password
                    };
                }
            }

            return(fetchOptions);
        }
Exemple #6
0
        public void CanFetchWithCustomHeaders()
        {
            var scd = BuildSelfCleaningDirectory();

            const string url = "https://github.com/libgit2/TestGitRepository";

            string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

            const string knownHeader = "X-Hello: mygit-201";
            var          options     = new FetchOptions {
                CustomHeaders = new String[] { knownHeader }
            };

            using (var repo = new Repository(clonedRepoPath))
            {
                Commands.Fetch(repo, "origin", new string[0], options, null);
            }
        }
        /// <summary>
        /// Fetches the remote changes
        /// </summary>
        /// <param name="org">Unique identifier of the organisation responsible for the app.</param>
        /// <param name="repository">The name of the repository.</param>
        public void FetchRemoteChanges(string org, string repository)
        {
            string logMessage = string.Empty;

            using (var repo = new LibGit2Sharp.Repository(FindLocalRepoLocation(org, repository)))
            {
                FetchOptions fetchOptions = new FetchOptions();
                fetchOptions.CredentialsProvider = (_url, _user, _cred) =>
                                                   new UsernamePasswordCredentials {
                    Username = GetAppToken(), Password = string.Empty
                };

                foreach (Remote remote in repo.Network.Remotes)
                {
                    IEnumerable <string> refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                    Commands.Fetch(repo, remote.Name, refSpecs, fetchOptions, logMessage);
                }
            }
        }
Exemple #8
0
        public bool FetchAll()
        {
            if (_segments.Count == 0)
            {
                return(true);
            }

            var fetchOptions = new FetchOptions();
            var tasks        = new List <Task <bool> >();

            foreach (var segment in _segments.Values)
            {
                tasks.Add(segment.FetchSegment(fetchOptions));
            }

            Task.WaitAll(tasks.ToArray());

            return(tasks.All(t => t.Result == true));
        }
        void FetchCore(CommonRepository repository)
        {
            string logMessage = "";

            using (var repo = new Repository(repository.Path)) {
                FetchOptions options = new FetchOptions();
                options.CredentialsProvider = new CredentialsHandler((url, usernameFromUrl, types) =>
                                                                     new UsernamePasswordCredentials()
                {
                    Username = "******",
                    Password = "******"
                });
                foreach (Remote remote in repo.Network.Remotes)
                {
                    IEnumerable <string> refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                    Commands.Fetch(repo, remote.Name, refSpecs, options, logMessage);
                }
            }
        }
Exemple #10
0
        public async Task SynchronizeSplits(long targetChangeNumber)
        {
            try
            {
                if (targetChangeNumber <= _splitCache.GetChangeNumber())
                {
                    return;
                }

                var fetchOptions = new FetchOptions {
                    CacheControlHeaders = true
                };

                var result = await AttempSplitsSync(targetChangeNumber, fetchOptions, _onDemandFetchMaxRetries, _onDemandFetchRetryDelayMs, false);

                if (result.Success)
                {
                    await _segmentFetcher.FetchSegmentsIfNotExists(result.SegmentNames);

                    _log.Debug($"Refresh completed in {_onDemandFetchMaxRetries - result.RemainingAttempts} attempts.");

                    return;
                }

                fetchOptions.Till = targetChangeNumber;
                var withCDNBypassed = await AttempSplitsSync(targetChangeNumber, fetchOptions, OnDemandFetchBackoffMaxRetries, null, true);

                if (withCDNBypassed.Success)
                {
                    await _segmentFetcher.FetchSegmentsIfNotExists(withCDNBypassed.SegmentNames);

                    _log.Debug($"Refresh completed bypassing the CDN in {OnDemandFetchBackoffMaxRetries - withCDNBypassed.RemainingAttempts} attempts.");
                }
                else
                {
                    _log.Debug($"No changes fetched after {OnDemandFetchBackoffMaxRetries - withCDNBypassed.RemainingAttempts} attempts with CDN bypassed.");
                }
            }
            catch (Exception ex)
            {
                _log.Error($"Exception caught executing SynchronizeSplits. {targetChangeNumber}", ex);
            }
        }
        public GitClient(IGitHubCredentialProvider credentialProvider, IGitService gitService)
        {
            Guard.ArgumentNotNull(credentialProvider, nameof(credentialProvider));
            Guard.ArgumentNotNull(gitService, nameof(gitService));

            this.gitService = gitService;

            pushOptions = new PushOptions {
                CredentialsProvider = credentialProvider.HandleCredentials
            };
            fetchOptions = new FetchOptions {
                CredentialsProvider = credentialProvider.HandleCredentials
            };
            pullOptions = new PullOptions
            {
                FetchOptions = fetchOptions,
                MergeOptions = new MergeOptions(),
            };
        }
        /// <inheritdoc />
        public void Fetch(
            LibGit2Sharp.IRepository libGit2Repo,
            IEnumerable <string> refSpecs,
            Remote remote,
            FetchOptions fetchOptions,
            string logMessage)
        {
            if (libGit2Repo == null)
            {
                throw new ArgumentNullException(nameof(libGit2Repo));
            }

            if (remote == null)
            {
                throw new ArgumentNullException(nameof(remote));
            }

            Commands.Fetch((LibGit2Sharp.Repository)libGit2Repo, remote.Name, refSpecs, fetchOptions, logMessage);
        }
Exemple #13
0
        public IList <Folder> GetFolders(long?id, FolderFilter filter = null, FetchOptions options = null)
        {
            var crit = session.CreateCriteria <Folder>();

            SetupFilter(crit, filter);
            if (id.HasValue)
            {
                crit = crit.Add(Restrictions.Eq("ParentFolder.Id", id.Value));
            }
            else
            {
                crit = crit.Add(Restrictions.IsNull("ParentFolder"));
            }
            if (options != null)
            {
                SetFetchOptions(crit, options);
            }
            return(crit.List <Folder>());
        }
        public static void Pull(string repoPath, string username, string email, string password = null)
        {
            if (!Repository.IsValid(repoPath))
            {
                LogInfos(repoPath + "\nis not a valid repository.");
                return;
            }
            Repository            repo = new Repository(repoPath);
            RepositoryInformation info = repo.Info;

            try
            {
                PullOptions options = new PullOptions();
                if (password != null)
                {
                    FetchOptions fO = new FetchOptions();
                    fO.CredentialsProvider = new CredentialsHandler(
                        (url, user, types) => new UsernamePasswordCredentials
                    {
                        Username = username,
                        Password = password
                    });
                    options.FetchOptions = fO;
                }
                Commands.Pull(repo, new Signature(username, email, new DateTimeOffset(DateTime.Now)), options);
                LogInfos(info.Path + " succesful updated.");
            }
            catch (Exception e)
            {
                string text = "Update of " + info.Path + " failed.\n";
                if (e is LibGit2SharpException)
                {
                    LogInfos(text + "Check your internet connection.");
                }
                //else if (e is AuthenticationException)
                //    LogInfos(text + "Wrong username or password.");
                else
                {
                    LogInfos(text + "An unkown error occured.");
                }
            }
        }
        public void GetSpecificCustomAttributeFromClass()
        {
            Individual individual = new Individual()
            {
                FileAs = "Mr. Jorge Perez", FirstName = "jorge", LastName = "Perez", Address = new Address()
                {
                    ZipCode = "33333"
                }
            };

            foreach (var prop in individual.GetType().GetProperties())
            {
                System.Diagnostics.Debug.WriteLine("Attribues of {0}", prop.Name);
                var fetchOption = GetFetchOptionAttributes(prop);
                if (fetchOption != FetchOptions.AsBigInteger(FetchOptions.None))
                {
                    System.Diagnostics.Debug.WriteLine("Attribute name: {0}", fetchOption);
                }
            }
        }
Exemple #16
0
        public void Fetch(RuntimeParameters p_Parameters,
                          string p_RemoteName,
                          string p_HostingUrl)
        {
            FetchOptions options = new FetchOptions {
                CredentialsProvider = (url,
                                       usernameFromUrl,
                                       types) =>
                                      new UsernamePasswordCredentials {
                    Username = p_Parameters.Username, Password = p_Parameters.Password
                }
            };

            var remote = m_Repository.Network.Remotes[p_RemoteName];

            s_Logger.Debug($"Remote Url remote: {remote.Url}");
            var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);

            Commands.Fetch(m_Repository, remote.Name, refSpecs, options, "Fetching the latest changes.");
        }
Exemple #17
0
        public ActionResult Index(long?parent, FetchOptions fetchOptions)
        {
            Folder parentFolder = null;

            if (parent.HasValue)
            {
                parentFolder = folderRepository.Load(parent.Value);
            }
            var model = new FolderModel
            {
                Items = folderRepository.Find(new FolderFilter {
                    Parent = parentFolder
                }, fetchOptions),
                CurrentFolder = parentFolder,
                Parent        = parentFolder != null ? parentFolder.Parent : null
            };

            model.IsRootFolder = parent == null && model.Parent == null;
            return(View("List", model));
        }
Exemple #18
0
 public virtual void SetupFetchOptions(ICriteria crit, FetchOptions options)
 {
     if (options != null)
     {
         if (options.Start > 0)
         {
             crit.SetFirstResult(options.Start);
         }
         if (options.Count > 0)
         {
             crit.SetMaxResults(options.Count);
         }
         if (!string.IsNullOrEmpty(options.SortExpression))
         {
             crit.AddOrder(options.SortDirection == SortDirection.Ascending ?
                           Order.Asc(options.SortExpression) :
                           Order.Desc(options.SortExpression));
         }
     }
 }
Exemple #19
0
        /// <summary>
        /// Executes a GET query on a target service.
        /// </summary>
        /// <param name="service"> the service to target (account|trace|media) </param>
        /// <param name="route">   the route on the target service </param>
        /// <param name="parameters">  the query parameters </param>
        /// <param name="opts">    additional fetch options </param>
        /// <exception cref="TraceSdkException">
        /// @returns the response body object </exception>
        public async Task <HttpResponseMessage> GetAsync <T>(Service service, string route, IDictionary <string, string> parameters, FetchOptions opts)
        {
            //create default fetch options.
            if (opts == null)
            {
                opts = new FetchOptions();
            }

            string path    = this.endpoints.GetEndpoint(service) + '/' + route;
            var    builder = new UriBuilder(path);

            if (parameters != null)
            {
                builder.Query = string.Join("&", parameters.Select(x => $"{x.Key}={x.Value}"));
            }


            using (var client = new HttpClient(CreateHttpMessageHandler()))
            {
                client.DefaultRequestHeaders.Accept.Clear();

                client.DefaultRequestHeaders.Add("Accept", "application/json");
                client.DefaultRequestHeaders.Add("User-Agent", this.userAgent);
                client.DefaultRequestHeaders.Add("Authorization", await this.GetAuthorizationHeader(opts));

                HttpRequestMessage requestClient = new HttpRequestMessage(HttpMethod.Get, builder.Uri);

                int _retry = opts.Retry;

                // delegate to fetch wrapper
                var clientResponse = await FetchAsync <T>(requestClient, client, _retry);

                if (clientResponse.StatusCode != HttpStatusCode.OK)
                {
                    string res   = clientResponse.StatusCode + ":";
                    string error = clientResponse.Content.ReadAsStringAsync().Result;
                    throw new ApplicationException(res + error);
                }
                return(clientResponse);
            }
        }
Exemple #20
0
        /// <inheritdoc />
        public TRepository Fetch(UniqueId id, FetchOptions options = null)
        {
            if (options == null)
            {
                options = new FetchOptions();
            }

            var repository = this[id];

            using (_logger.BeginScope("Fetching repository '{Repository}'.", repository.Id))
            {
                return(repository.Execute(r =>
                {
                    var concrete = r as Repository ??
                                   throw new NotSupportedException($"Object of type {nameof(Repository)} expected.");
                    Commands.Fetch(concrete, r.Head.RemoteName, Array.Empty <string>(), options, null);

                    return _repositoryLoader.LoadFrom(this, repository.RepositoryDescription, r.Head.TrackedBranch.Tip.Id);
                }));
            }
        }
    /// <summary>
    /// Pulls the current changes from git.
    /// </summary>
    public void ResetToRemote()
    {
        using var repo = Repository;

        // Fetch All
        var options = new FetchOptions()
        {
            CredentialsProvider = GetCredentials
        };

        foreach (Remote remote in repo.Network.Remotes)
        {
            var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
            LibGit2Sharp.Commands.Fetch(repo, remote.Name, refSpecs, options, "");
        }

        // Reset
        var trackedBranch = repo.Head.TrackedBranch;

        repo.Reset(ResetMode.Hard, trackedBranch.Commits.OrderByDescending(x => x.Committer.When).First());
    }
        string IAssetService.FetchImageUrl(string source, FetchOptions options)
        {
            if (string.IsNullOrEmpty(source))
            {
                return(string.Empty);
            }

            options = options ?? FetchOptions.Default;

            var sb         = new StringBuilder(string.Format(FetchUrl, _cn.Api.Account.Cloud));
            var urlOptions = new List <string>();

            Optional(options.Crop).IfSome(c => urlOptions.Add($"c_{c}"));
            Optional(options.FetchFormat).IfSome(f => urlOptions.Add($"f_{f}"));
            Optional(options.Width).IfSome(w => urlOptions.Add($"w_{w}"));
            Optional(options.Height).IfSome(h => urlOptions.Add($"h_{h}"));

            return(sb.Append(urlOptions.Aggregate((a, b) => $"{a},{b}"))
                   .AppendFormat("/{0}", source)
                   .ToString());
        }
Exemple #23
0
        public async Task <string> FetchSegmentChanges(string name, long since, FetchOptions fetchOptions)
        {
            using (var clock = new Util.SplitStopwatch())
            {
                clock.Start();

                try
                {
                    var requestUri = GetRequestUri(name, since, fetchOptions.Till);
                    var response   = await ExecuteGet(requestUri, fetchOptions.CacheControlHeaders);

                    if ((int)response.statusCode >= (int)HttpStatusCode.OK && (int)response.statusCode < (int)HttpStatusCode.Ambiguous)
                    {
                        if (_log.IsDebugEnabled)
                        {
                            _log.Debug($"FetchSegmentChanges with name '{name}' took {clock.ElapsedMilliseconds} milliseconds using uri '{requestUri}'");
                        }

                        _telemetryRuntimeProducer.RecordSyncLatency(ResourceEnum.SegmentSync, Util.Metrics.Bucket(clock.ElapsedMilliseconds));
                        _telemetryRuntimeProducer.RecordSuccessfulSync(ResourceEnum.SegmentSync, CurrentTimeHelper.CurrentTimeMillis());

                        return(response.content);
                    }

                    _log.Error(response.statusCode == HttpStatusCode.Forbidden
                        ? "factory instantiation: you passed a browser type api_key, please grab an api key from the Split console that is of type sdk"
                        : $"Http status executing FetchSegmentChanges: {response.statusCode.ToString()} - {response.content}");

                    _telemetryRuntimeProducer.RecordSyncError(ResourceEnum.SegmentSync, (int)response.statusCode);

                    return(string.Empty);
                }
                catch (Exception e)
                {
                    _log.Error("Exception caught executing FetchSegmentChanges", e);

                    return(string.Empty);
                }
            }
        }
Exemple #24
0
        public static string Fetch(string repopath, string remotename = "", string username = "", string password = "")
        {
            if (!IsValid(repopath))
            {
                return("");
            }
            string logMessage = "";

            using var repo = new Repository(repopath);
            FetchOptions options = null;

            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
            {
                options = new FetchOptions
                {
                    CredentialsProvider = new CredentialsHandler((url, usernameFromUrl, types) =>
                                                                 new UsernamePasswordCredentials()
                    {
                        Username = "******",
                        Password = "******"
                    })
                };
            }
            if (string.IsNullOrWhiteSpace(remotename))
            {
                foreach (Remote remote in repo.Network.Remotes)
                {
                    IEnumerable <string> refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                    Commands.Fetch(repo, remote.Name, refSpecs, options, logMessage);
                }
            }
            else
            {
                var remote   = repo.Network.Remotes[remotename];
                var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                Commands.Fetch(repo, remote.Name, refSpecs, options, logMessage);
            }
            return(logMessage);
        }
        /// <inheritdoc />
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var tcs = new TaskCompletionSource <HttpResponseMessage>();

            cancellationToken.Register(() => tcs.TrySetCanceled());

            int id;

            lock (_idLock)
            {
                id = _nextRequestId++;
                _pendingRequests.Add(id, tcs);
            }

            var options = new FetchOptions();

            if (request.Properties.TryGetValue(FetchArgs, out var fetchArgs))
            {
                options.RequestInitOverrides = fetchArgs;
            }

            options.RequestInit = new RequestInit
            {
                Credentials = GetDefaultCredentialsString(),
                Headers     = GetHeadersAsStringArray(request),
                Method      = request.Method.Method
            };

            options.RequestUri = request.RequestUri.ToString();

            RegisteredFunction.InvokeUnmarshalled <int, byte[], string, object>(
                $"{typeof(BrowserHttpMessageHandler).FullName}.Send",
                id,
                request.Content == null ? null : await request.Content.ReadAsByteArrayAsync(),
                JsonUtil.Serialize(options));

            return(await tcs.Task);
        }
        public async Task <List <User> > Find(UserFilter userFilter, FetchOptions fetchOptions, Func <IQueryable <User>,
                                                                                                      IIncludableQueryable <User, object> > include = null, bool enableTracking = false)
        {
            var query = Context.Users.AsQueryable();

            if (!enableTracking)
            {
                query = query.AsNoTracking();
            }
            query = SetupFilter(userFilter, query);
            if (include != null)
            {
                query = include(query);
            }
            if (fetchOptions.SortExpression != null)
            {
                query = SetupFetchOptions(fetchOptions, query);
            }
            List <User> users = await query.ToListAsync();

            return(users);
        }
Exemple #27
0
        public static void BUYLCloneOrUpdateRepository()
        {
            if (!CheckForContentRepositoryDirectory())
            {
                //prg.ShowDialog();
                Directory.CreateDirectory(pathToLocalContentRepository);

                CloneOptions op = new CloneOptions();

                Repository.Clone(urlContentRepository, pathToLocalContentRepository, op);
                //prg.Close();
            }
            else
            {
                using (var repo = new Repository(pathToLocalContentRepository))
                {
                    Remote       remote = repo.Network.Remotes["origin"];
                    FetchOptions op     = new FetchOptions();
                    repo.Network.Fetch(remote);
                }
            }
        }
Exemple #28
0
        // PUT: api/fetch/5
        //public void Put(int id, [FromBody]string value)
        //{
        //}

        // DELETE: api/fetch/5
        //public void Delete(int id)
        //{
        //}

        public string command(string RepositoryName)
        {
            var configItem = WebApi.configuration.Where(x => x.repositoryName.Equals(RepositoryName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (configItem == null)
            {
                throw new Exception(string.Format("Repository {0} not found", RepositoryName));
            }

            deployTool.WebApi.logger.Debug("Command Start");

            string logMessage = "";


            using (var repo = new Repository(configItem.repositoryPath))
            {
                FetchOptions options = new FetchOptions();

                if (!string.IsNullOrEmpty(configItem.username))
                {
                    options.CredentialsProvider = new CredentialsHandler((url, usernameFromUrl, types) =>
                                                                         new UsernamePasswordCredentials()
                    {
                        Username = configItem.username,
                        Password = configItem.password
                    });
                }


                foreach (Remote remote in repo.Network.Remotes)
                {
                    IEnumerable <string> refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                    Commands.Fetch(repo, remote.Name, refSpecs, options, logMessage);
                }
            }
            deployTool.WebApi.logger.Debug("Command end");

            return(logMessage);
        }
Exemple #29
0
        public string GetStatusOfRemoteRepo(string repoPath, string account, string password)
        {
            string status = string.Empty;

            using (var repo = new Repository(repoPath))
            {
                FetchOptions options = new FetchOptions();
                options.CredentialsProvider = new CredentialsHandler((url, user_name_from_url, type) =>
                                                                     new UsernamePasswordCredentials()
                {
                    Username = account,
                    Password = password
                });

                foreach (Remote remote in repo.Network.Remotes)
                {
                    IEnumerable <string> refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                    Commands.Fetch(repo, remote.Name, refSpecs, options, status);
                }
            }
            return(status);
        }
Exemple #30
0
        /// <summary>
        /// Synchronize an already existing repository folder.
        /// </summary>
        /// <param name="caller">Required for log and progress origin</param>
        /// <param name="repofolder"></param>
        /// <param name="fetchops"></param>
        /// <param name="checkoutops"></param>
        /// <returns></returns>
        /// <remarks>
        /// OnCheckoutProgress and OnTransferProgress will be overriden to invoke <see cref="Logging.OnAnyProgress"/>.
        /// OnProgress, RepositoryOperationStarting and RepositoryOperationCompleted will be overriden to log
        /// in the uppm Serilog system.
        /// </remarks>
        public static Repository Synchronize(string repofolder, FetchOptions fetchops = null, CheckoutOptions checkoutops = null, ILogging caller = null)
        {
            var logger = caller?.Log ?? Logging.L;

            try
            {
                var repo = new Repository(repofolder);
                fetchops    = fetchops ?? new FetchOptions();
                checkoutops = checkoutops ?? new CheckoutOptions();

                fetchops.RepositoryOperationStarting  = RepoOperationStart(caller, "Fetching");
                fetchops.RepositoryOperationCompleted = RepoOperationEnd(caller, "Fetching");
                fetchops.OnTransferProgress           = progress =>
                {
                    caller?.InvokeAnyProgress(progress.TotalObjects, progress.ReceivedObjects, "Transferring");
                    return(true);
                };
                fetchops.OnProgress = output =>
                {
                    logger.Debug(output);
                    return(true);
                };
                checkoutops.OnCheckoutProgress = (path, steps, totalSteps) =>
                {
                    caller?.InvokeAnyProgress(totalSteps, steps, "Checking Out", path);
                };

                var remote   = repo.Network.Remotes["origin"];
                var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                Commands.Fetch(repo, remote.Name, refSpecs, fetchops, "");
                Commands.Checkout(repo, "master", checkoutops);
                return(repo);
            }
            catch (Exception e)
            {
                logger.Error(e, "Error opening or checking out locally available repository. ({RepoUrl})", repofolder);
                return(null);
            }
        }
Exemple #31
0
		/// <summary>
		/// Retrieves the mail message with the specified unique identifier (UID) using the specified
		/// fetch-option.
		/// </summary>
		/// <param name="uid">The unique identifier of the mail message to retrieve.</param>
		/// <param name="options">A value from the FetchOptions enumeration which allows
		/// for fetching selective parts of a mail message.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for this message on the
		/// server.</param>
		/// <param name="mailbox">The mailbox the message will be retrieved from. If this parameter is
		/// omitted, the value of the DefaultMailbox property is used to determine the mailbox to
		/// operate on.</param>
		/// <returns>An initialized instance of the MailMessage class representing the fetched mail
		/// message.</returns>
		/// <exception cref="BadServerResponseException">The mail message could not be fetched. The
		/// message property of the exception contains the error message returned by the
		/// server.</exception>
		/// <exception cref="ObjectDisposedException">The ImapClient object has been disposed.</exception>
		/// <exception cref="IOException">There was a failure writing to or reading from the
		/// network.</exception>
		/// <exception cref="NotAuthenticatedException">The method was called in non-authenticated
		/// state, i.e. before logging in.</exception>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each message which uniquely
		/// identifies the message within the respective mailbox. No two messages in a mailbox share
		/// the same UID.
		/// <para>If you need more fine-grained control over which parts of a mail message to fetch,
		/// consider using one of the overloaded GetMessage methods.
		/// </para>
		/// </remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessage-2"]/*'/>
		public MailMessage GetMessage(uint uid, FetchOptions options,
			bool seen = true, string mailbox = null) {
			AssertValid();
			switch (options) {
				case FetchOptions.HeadersOnly:
			        return GetMailHeaderB(uid, seen, mailbox).ToMailMessage();
					return MessageBuilder.FromHeader(GetMailHeader(uid, seen, mailbox));
				case FetchOptions.NoAttachments:
			        return GetMessageB(uid, p => p.Disposition.Type != ContentDispositionType.Attachment, seen, mailbox).ToMailMessage();
					return GetMessage(uid, p => { return p.Disposition.Type !=
						ContentDispositionType.Attachment; }, seen, mailbox);
				case FetchOptions.TextOnly:
			        return GetMessageB(uid, p => p.Type == ContentType.Text, seen, mailbox).ToMailMessage();
					return GetMessage(uid, p => { return p.Type == ContentType.Text; },
						seen, mailbox);
				default:
			        using (var stream = GetMessageDataB(uid, seen, mailbox)) {
			            return OpenPop.Mime.Message.Load(stream).ToMailMessage();
			        }
					return MessageBuilder.FromMIME822(GetMessageData(uid, seen, mailbox));
			}
		}
Exemple #32
0
	    public OpenPop.Mime.Message GetMessageB(uint uid, FetchOptions options, bool seen, string mailbox) {
            AssertValid();
            switch (options) {
                case FetchOptions.HeadersOnly:
                    return GetMailHeaderB(uid, seen, mailbox);
                case FetchOptions.NoAttachments:
                    return GetMessageB(uid, p => p.Disposition.Type != ContentDispositionType.Attachment, seen, mailbox);
                case FetchOptions.TextOnly:
                    return GetMessageB(uid, p => p.Type == ContentType.Text, seen, mailbox);
                default:
                    using (var stream = GetMessageDataB(uid, seen, mailbox)) {
                        return OpenPop.Mime.Message.Load(stream);
                    }
            }
        }
Exemple #33
0
		/// <summary>
		/// Retrieves a mail message from the POP3 server.
		/// </summary>
		/// <param name="number">The message number of the mail message to retrieve</param>
		/// <param name="options">A value from the FetchOptions enumeration which allows
		/// for fetching selective parts of a mail message.</param>
		/// <param name="delete">Set this to true to delete the message on the server
		/// after it has been retrieved.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail message could
		/// not be retrieved. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An initialized instance of the MailMessage class representing the
		/// fetched mail message</returns>
		/// <include file='Examples.xml' path='S22/Pop3/Pop3Client[@name="GetMessage"]/*'/>
		public MailMessage GetMessage(uint number, FetchOptions options = FetchOptions.Normal,
			bool delete = false) {
			if (!Authed)
				throw new NotAuthenticatedException();
			string command = options == FetchOptions.HeadersOnly ? ("TOP " + number + " 0") :
				("RETR " + number);
			StringBuilder builder = new StringBuilder();
			lock (sequenceLock) {
				string response = SendCommandGetResponse(command);
				if (!IsResponseOK(response))
					throw new BadServerResponseException(response);
				while ((response = GetResponse()) != ".")
					builder.AppendLine(response);
				if (delete)
					DeleteMessage(number);
			}
			return options == FetchOptions.HeadersOnly ?
				MessageBuilder.FromHeader(builder.ToString()) :
				MessageBuilder.FromMIME822(builder.ToString());
		}
Exemple #34
0
		/// <summary>
		/// Retrieves a set of mail messages. If no parameters are specified, all
		/// mail messages in the mailbox will be retrieved.
		/// </summary>
		/// <param name="numbers">An array of message numbers of the mail messages to
		/// retrieve. If this parameter is null, all mail messages will be retrieved.
		/// </param>
		/// <param name="options">A value from the FetchOptions enumeration which allows
		/// for fetching selective parts of a mail message.</param>
		/// <param name="delete">Set this to true to delete the messages on the server
		/// after they have been retrieved.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail messages could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An array of initialized instances of the MailMessage class representing
		/// the fetched mail messages</returns>
		/// <include file='Examples.xml' path='S22/Pop3/Pop3Client[@name="GetMessages"]/*'/>
		public MailMessage[] GetMessages(uint[] numbers = null, FetchOptions options =
			FetchOptions.Normal, bool delete = false) {
			List<MailMessage> list = new List<MailMessage>();
			if (numbers == null)
				numbers = GetMessageNumbers();
			foreach (uint n in numbers)
				list.Add(GetMessage(n, options, delete));
			return list.ToArray();
		}
        protected static MovieInfo FetchFilm(uint filmId, FetchOptions options = FetchOptions.None)
        {
            var movie = new MovieInfo();
            var filmInfo = new Kinopoisk.FilmPage(filmId);

            movie.AllGenres = filmInfo.GetGenreList().ToArray();
            movie.Budget = filmInfo.Budget;
            movie.MPAArating = filmInfo.MPAA;
            movie.Revenue = filmInfo.Revenue;
            movie.Runtime = filmInfo.Runtime;
            movie.Summary = Utils.UnHTML(filmInfo.Summary);
            movie.IMDBscore = filmInfo.IMDBScore;
            movie.Year = Utils.SafeYear(filmInfo.Year);
            movie.Local_Title = filmInfo.LocalTitle;
            movie.Original_Title = filmInfo.Title;

            // Added with plugin system version 2.1
            var countries = filmInfo.GetContries();
            if (countries.Count() > 0)
                movie.Country = string.Join(", ", countries);

            //public string Language = string.Empty;
            //public string ParentalRatingSummary = string.Empty;

            // Added with plugin system version 2.2
            movie.TagLine = filmInfo.TagLine;
            movie.FullMPAA = filmInfo.FullMPAA;
            movie.PosterURL = filmInfo.GetOnlyPoster();
            movie.BackdropURL = filmInfo.GetOnlyBackdrop();

            movie.Director = string.Join(", ", filmInfo.GetCrew().Where(p => p.Type == "director").Select(p=>p.LocalName).ToArray());
            movie.Writers = filmInfo.GetCrew().Where(p => p.Type == "writer").Select(p => p.LocalName).ToArray();
            movie.NumberOfVotes = filmInfo.Rating.ImdbRating.Votes.ToString();

            //public string FullCertifications = string.Empty;
            //public string Outline = string.Empty;
            //public string Plot = string.Empty;
            //public string Top250 = string.Empty;
            //public string Awards = string.Empty;
            //public string Website = string.Empty;
            //public string Trailer = string.Empty;

            if ((options & FetchOptions.FetchImages)==FetchOptions.FetchImages)
            {
                var link = filmInfo.GetOnlyBackdrop();
                if (link != null) movie.Backdrop = Utils.SerializeBitmap(Utils.LoadPictureFromURI(link));
                link = filmInfo.GetOnlyPoster();
                if (link != null) movie.Poster = Utils.SerializeBitmap(Utils.LoadPictureFromURI(link));
            }

            movie.AllCastAndCrew = ProcessCastAndCrew(filmInfo);

            //movie.IMDB_ID = Utils.ChopperBlank(sMoviePageContents, "<imdb>", "</imdb>");
            //movie.Studios  // not supported by tMDB API 2.0

            return movie;
        }
Exemple #36
0
		/// <summary>
		/// Retrieves a mail message by its unique identifier message attribute with the
		/// specified fetch option.
		/// </summary>
		/// <param name="uid">The unique identifier of the mail message to retrieve</param>
		/// <param name="options">A value from the FetchOptions enumeration which allows
		/// for fetching selective parts of a mail message.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for this message
		/// on the server.</param>
		/// <param name="mailbox">The mailbox the message will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail message could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An initialized instance of the MailMessage class representing the
		/// fetched mail message</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.
		/// <para>If you need more fine-grained control over which parts of a mail
		/// message to fetch, consider using one of the overloaded GetMessage methods.
		/// </para>
		/// </remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessage-2"]/*'/>
		public MailMessage GetMessage(uint uid, FetchOptions options,
			bool seen = true, string mailbox = null) {
			if (!Authed)
				throw new NotAuthenticatedException();
			lock (sequenceLock) {
				PauseIdling();
				SelectMailbox(mailbox);
				string header = GetMailHeader(uid, seen, mailbox);
				MailMessage message = MessageBuilder.FromHeader(header);
				if (options == FetchOptions.HeadersOnly) {
					ResumeIdling();
					return message;
				}
				/* Retrieve and parse the body structure of the mail message */
				string structure = GetBodystructure(uid, mailbox);
				try {
					Bodypart[] parts = Bodystructure.Parse(structure);
					foreach (Bodypart part in parts) {
						if (options != FetchOptions.Normal &&
							part.Disposition.Type == ContentDispositionType.Attachment)
							continue;
						if (options == FetchOptions.TextOnly && part.Type != ContentType.Text)
							continue;
						/* fetch the content */
						string content = GetBodypart(uid, part.PartNumber, seen, mailbox);

						message.AddBodypart(part, content);
					}
				} catch (FormatException) {
					throw new BadServerResponseException("Server returned erroneous " +
						"body structure:" + structure);
				}
				ResumeIdling();
				return message;
			}
		}
Exemple #37
0
		/// <summary>
		/// Retrieves the set of mail messages with the specified unique identifiers (UIDs) using the
		/// specified fetch-option.
		/// </summary>
		/// <param name="uids">An enumerable collection of unique identifiers of the mail messages to
		/// retrieve.</param>
		/// <param name="options">A value from the FetchOptions enumeration which allows for fetching
		/// selective parts of a mail message.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for the fetched messages on the
		/// server.</param>
		/// <param name="mailbox">The mailbox the messages will be retrieved from. If this parameter is
		/// omitted, the value of the DefaultMailbox property is used to determine the mailbox to
		/// operate on.</param>
		/// <returns>An enumerable collection of initialized instances of the MailMessage class
		/// representing the fetched mail messages.</returns>
		/// <exception cref="ArgumentNullException">The uids parameter is null.</exception>
		/// <exception cref="BadServerResponseException">The mail messages could not be fetched. The
		/// message property of the exception contains the error message returned by the
		/// server.</exception>
		/// <exception cref="ObjectDisposedException">The ImapClient object has been disposed.</exception>
		/// <exception cref="IOException">There was a failure writing to or reading from the
		/// network.</exception>
		/// <exception cref="NotAuthenticatedException">The method was called in non-authenticated
		/// state, i.e. before logging in.</exception>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each message which uniquely
		/// identifies the message within the respective mailbox. No two messages in a mailbox share
		/// the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessages-2"]/*'/>
		public IEnumerable<MailMessage> GetMessages(IEnumerable<uint> uids, FetchOptions options,
			bool seen = true, string mailbox = null) {
				uids.ThrowIfNull("uids");
				List<MailMessage> list = new List<MailMessage>();
				foreach (uint uid in uids)
					list.Add(GetMessage(uid, options, seen, mailbox));
				return list;
		}
Exemple #38
0
		/// <summary>
		/// Retrieves a set of mail messages by their unique identifier message attributes
		/// with the specified fetch option.
		/// </summary>
		/// <param name="uids">An array of unique identifiers of the mail messages to
		/// retrieve</param>
		/// <param name="options">A value from the FetchOptions enumeration which allows
		/// for fetching selective parts of a mail message.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for the fetched
		/// messages on the server.</param>
		/// <param name="mailbox">The mailbox the messages will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail messages could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An array of initialized instances of the MailMessage class representing
		/// the fetched mail messages</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessages-2"]/*'/>
		public MailMessage[] GetMessages(uint[] uids, FetchOptions options,
			bool seen = true, string mailbox = null) {
				List<MailMessage> list = new List<MailMessage>();
				foreach (uint uid in uids)
					list.Add(GetMessage(uid, options, seen, mailbox));
				return list.ToArray();
		}
Exemple #39
0
		/// <summary>
		/// Retrieves a mail message by its unique identifier message attribute with the
		/// specified fetch option.
		/// </summary>
		/// <param name="uid">The unique identifier of the mail message to retrieve</param>
		/// <param name="options">A value from the FetchOptions enumeration which allows
		/// for fetching selective parts of a mail message.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for this message
		/// on the server.</param>
		/// <param name="mailbox">The mailbox the message will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail message could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An initialized instance of the MailMessage class representing the
		/// fetched mail message</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.
		/// <para>If you need more fine-grained control over which parts of a mail
		/// message to fetch, consider using one of the overloaded GetMessage methods.
		/// </para>
		/// </remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessage-2"]/*'/>
		public MailMessage GetMessage(uint uid, FetchOptions options,
			bool seen = true, string mailbox = null) {
			switch (options) {
				case FetchOptions.HeadersOnly:
					return MessageBuilder.FromHeader(GetMailHeader(uid, seen, mailbox));
				case FetchOptions.NoAttachments:
					return GetMessage(uid, p => { return p.Disposition.Type !=
						ContentDispositionType.Attachment; }, seen, mailbox);
				case FetchOptions.TextOnly:
					return GetMessage(uid, p => { return p.Type == ContentType.Text; },
						seen, mailbox);
				default:
					return MessageBuilder.FromMIME822(GetMessageData(uid, seen, mailbox));
			}
		}
Exemple #40
0
		/// <summary>
		/// Retrieves a set of mail messages by their unique identifier message attributes
		/// with the specified fetch option.
		/// </summary>
		/// <param name="uids">An array of unique identifiers of the mail messages to
		/// retrieve</param>
		/// <param name="options">A value from the FetchOptions enumeration which allows
		/// for fetching selective parts of a mail message.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for the fetched
		/// messages on the server.</param>
		/// <param name="mailbox">The mailbox the messages will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail messages could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An array of initialized instances of the MailMessage class representing
		/// the fetched mail messages</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.</remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessages-2"]/*'/>
		public List<MessageInfo> GetMessages(long[] uids, FetchOptions options,
			bool seen = true, MessageReceived callback = null) {
            if (!Authed)
                throw new NotAuthenticatedException();
            lock (sequenceLock)
            {
                if (this.selectedMailbox == null)
                    throw new InvalidOperationException("No mailbox or folder currently selected.");

                List<MessageInfo> infos = GetMailHeader(uids, seen);

                if (options == FetchOptions.HeadersOnly)
                {
                    return infos;
                }
                /* Retrieve and parse the body structure of the mail message */
                Dictionary<long,string> structures = GetBodystructure(uids);
                try
                {
                    foreach (MessageInfo info in infos)
                    {
                        Bodypart[] parts = Bodystructure.Parse(structures[info.UID]);
                            
                        foreach (Bodypart part in parts)
                        {
                            if (options != FetchOptions.Normal &&
                                part.Disposition.Type == ContentDispositionType.Attachment)
                                continue;
                            if (options == FetchOptions.TextOnly && part.Type != ContentType.Text)
                                continue;
                            /* fetch the content */
                            string content = GetBodypart(info.UID, part.PartNumber, seen);

                            info.Envelope.AddBodypart(part, content);
                        }

                        if (callback != null)
                            callback.Invoke(info);
                    }
                }
                catch (FormatException)
                {
                    throw new BadServerResponseException("Server returned erroneous " +
                        "body structure.");
                }
           
                return infos;
            }
		}
Exemple #41
0
		/// <summary>
		/// Retrieves a mail message by its unique identifier message attribute with the
		/// specified fetch option.
		/// </summary>
		/// <param name="uid">The unique identifier of the mail message to retrieve</param>
		/// <param name="options">A value from the FetchOptions enumeration which allows
		/// for fetching selective parts of a mail message.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for this message
		/// on the server.</param>
		/// <param name="mailbox">The mailbox the message will be retrieved from. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to operate on.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail message could
		/// not be fetched. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>An initialized instance of the MailMessage class representing the
		/// fetched mail message</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.
		/// <para>If you need more fine-grained control over which parts of a mail
		/// message to fetch, consider using one of the overloaded GetMessage methods.
		/// </para>
		/// </remarks>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="GetMessage-2"]/*'/>
		public MessageInfo GetMessage(long uid, FetchOptions options,
			bool seen = true, string mailbox = null) {
			if (!Authed)
				throw new NotAuthenticatedException();
			lock (sequenceLock) {
                if (this.selectedMailbox == null)
                    throw new InvalidOperationException("No mailbox or folder currently selected.");

                MessageInfo info = GetMailHeader(uid, seen);
                if (options == FetchOptions.HeadersOnly)
                {
                    return info;
                }
				/* Retrieve and parse the body structure of the mail message */
				string structure = GetBodystructure(uid);
				try {
					Bodypart[] parts = Bodystructure.Parse(structure);
					foreach (Bodypart part in parts) {
						if (options != FetchOptions.Normal &&
							part.Disposition.Type == ContentDispositionType.Attachment)
							continue;
						if (options == FetchOptions.TextOnly && part.Type != ContentType.Text)
							continue;
						/* fetch the content */
						string content = GetBodypart(uid, part.PartNumber, seen);

						info.Envelope.AddBodypart(part, content);
					}
				} catch (FormatException) {
					throw new BadServerResponseException("Server returned erroneous " +
						"body structure:" + structure);
				}
				
				return info;
			}
		}