Beispiel #1
0
        private SharepointValidationResult ValidateLocationBySearch(string location)
        {
            SharepointValidationResult validationResult = null;

            Utils.WrapSharePointCsomCall(this.spSiteContextUrl, this.credentials, delegate(ClientContext context)
            {
                ResultTableCollection queryResults = SharepointValidator.CsomProvider.ExecuteSearch(context, location, false);
                validationResult = this.GetValidationResult(queryResults, context);
            });
            if (validationResult == null)
            {
                base.LogOneEntry(ExecutionLog.EventType.Error, "InvalidArgument: {0}", new object[]
                {
                    Strings.SpLocationValidationFailed(location)
                });
                validationResult = SharepointValidator.CreateFailedResult(Strings.SpLocationValidationFailed(location));
            }
            return(validationResult);
        }
Beispiel #2
0
        private SharepointValidationResult ValidateLocationByLoad(string location)
        {
            SharepointValidationResult validationResult = null;

            try
            {
                Uri uri = new Uri(location, UriKind.Absolute);
                if (this.spSiteContextUrl.IsBaseOf(uri))
                {
                    Utils.WrapSharePointCsomCall(uri, this.credentials, delegate(ClientContext context)
                    {
                        string siteUrl;
                        string text;
                        Guid siteId;
                        Guid webId;
                        SharepointValidator.CsomProvider.LoadWebInfo(context, out siteUrl, out text, out siteId, out webId);
                        if (string.IsNullOrWhiteSpace(text))
                        {
                            this.LogOneEntry(ExecutionLog.EventType.Error, "The site is invalid as it missing the title: {0}", new object[]
                            {
                                Strings.SpLocationValidationFailed(location)
                            });
                            validationResult = SharepointValidator.CreateFailedResult(Strings.SpLocationValidationFailed(location));
                            return;
                        }
                        SharepointSource sharepointSource = new SharepointSource(siteUrl, text, siteId, webId);
                        validationResult = new SharepointValidationResult
                        {
                            SharepointSource = sharepointSource,
                            IsValid          = true
                        };
                        if (this.spSiteContextUrl.Equals(sharepointSource.SiteUrl))
                        {
                            validationResult.IsTopLevelSiteCollection = true;
                            validationResult.ValidationText           = Strings.SpLocationHasMultipleSites(location);
                            this.LogOneEntry(ExecutionLog.EventType.Warning, "Found top level site collection. {0}", new object[]
                            {
                                validationResult.ValidationText
                            });
                        }
                    });
                }
                else
                {
                    base.LogOneEntry(ExecutionLog.EventType.Error, "InvalidArgument: {0}, the url does not start with the tenant root url {1}", new object[]
                    {
                        Strings.SpLocationValidationFailed(location),
                        this.spSiteContextUrl
                    });
                    validationResult = SharepointValidator.CreateFailedResult(Strings.SpLocationValidationFailed(location));
                }
            }
            catch (UriFormatException exception)
            {
                base.LogOneEntry(ExecutionLog.EventType.Error, exception, "InvalidArgument: {0}", new object[]
                {
                    Strings.SpLocationValidationFailed(location)
                });
                validationResult = SharepointValidator.CreateFailedResult(Strings.SpLocationValidationFailed(location));
            }
            catch (SpCsomCallException ex)
            {
                if (!(ex.InnerException is WebException) && !(ex.InnerException is ClientRequestException))
                {
                    throw;
                }
                base.LogOneEntry(ExecutionLog.EventType.Error, ex, "InvalidArgument: {0}", new object[]
                {
                    Strings.SpLocationValidationFailed(location)
                });
                validationResult = SharepointValidator.CreateFailedResult(Strings.SpLocationValidationFailed(location));
            }
            return(validationResult);
        }