/// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Events.PermissionDeniedEvent"/> class.
        /// </summary>
        /// <param name="e">thrown permission denied exception</param>
        public PermissionDeniedEvent(CmisPermissionDeniedException e) : base(e)
        {
            if (e.Data != null && e.Data.Contains(HttpHeaderRetryAfter))
            {
                string[] values = e.Data[HttpHeaderRetryAfter] as string[];
                if (values == null)
                {
                    return;
                }

                List <DateTime> dates = new List <DateTime>();
                foreach (var value in values)
                {
                    try {
                        long seconds = Convert.ToInt64(value);
                        dates.Add(DateTime.UtcNow + TimeSpan.FromSeconds(seconds));
                    } catch (FormatException) {
                        DateTime parsed;
                        if (DateTime.TryParse(value, out parsed))
                        {
                            dates.Add(parsed);
                        }
                    }
                }

                dates.Sort();
                this.IsBlockedUntil = dates.Count > 0 ? dates[0] : (DateTime?)null;
            }
        }
示例#2
0
        /// <summary>
        /// Try to find the CMIS server associated to any URL.
        /// Users can provide the URL of the web interface, and we have to return the CMIS URL
        /// Returns the list of repositories as well.
        /// </summary>
        static public Tuple<CmisServer, Exception> GetRepositoriesFuzzy(Uri url, string user, string password)
        {
            Dictionary<string, string> repositories = null;
            Exception firstException = null;

            // Try the given URL, maybe user directly entered the CMIS AtomPub endpoint URL.
            try
            {
                repositories = GetRepositories(url, user, password);
            }
            catch (DotCMIS.Exceptions.CmisRuntimeException e)
            {
                if (e.Message == "ConnectFailure")
                    return new Tuple<CmisServer, Exception>(new CmisServer(url, null), new CmisServerNotFoundException(e.Message, e));
                firstException = e;

            }
            catch (Exception e)
            {
                // Save first Exception and try other possibilities.
                firstException = e;
            }
            if (repositories != null)
            {
                // Found!
                return new Tuple<CmisServer, Exception>(new CmisServer(url, repositories), null);
            }

            // Extract protocol and server name or IP address
            string prefix = url.GetLeftPart(UriPartial.Authority);

            // See https://github.com/nicolas-raoul/CmisSync/wiki/What-address for the list of ECM products prefixes
            // Please send us requests to support more CMIS servers: https://github.com/nicolas-raoul/CmisSync/issues
            string[] suffixes = {
                "/cmis/atom",
                "/alfresco/cmisatom",
                "/alfresco/service/cmis",
                "/cmis/resources/",
                "/emc-cmis-ea/resources/",
                "/emc-cmis-weblogic/resources/",
                "/emc-cmis-wls/resources/",
                "/emc-cmis-was61/resources/",
                "/emc-cmis-wls1030/resources/",
                "/xcmis/rest/cmisatom",
                "/files/basic/cmis/my/servicedoc",
                "/p8cmis/resources/Service",
                "/_vti_bin/cmis/rest?getRepositories",
                "/Nemaki/atom/bedroom",
                "/nuxeo/atom/cmis"
            };
            string bestUrl = null;
            // Try all suffixes
            for (int i=0; i < suffixes.Length; i++)
            {
                string fuzzyUrl = prefix + suffixes[i];
                Logger.Info("Sync | Trying with " + fuzzyUrl);
                try
                {
                    repositories = GetRepositories(new Uri(fuzzyUrl), user, password);
                }
                catch (DotCMIS.Exceptions.CmisPermissionDeniedException e)
                {
                    firstException = new CmisPermissionDeniedException(e.Message, e);
                    bestUrl = fuzzyUrl;
                }
                catch (Exception e)
                {
                    // Do nothing, try other possibilities.
                    Logger.Info(e.Message);
                }
                if (repositories != null)
                {
                    // Found!
                    return new Tuple<CmisServer, Exception>( new CmisServer(new Uri(fuzzyUrl), repositories), null);
                }
            }

            // Not found. Return also the first exception to inform the user correctly
            return new Tuple<CmisServer,Exception>(new CmisServer(bestUrl==null?url:new Uri(bestUrl), null), firstException);
        }