Ejemplo n.º 1
0
        private static string BuildSourceLinkUrlForCloudEdition(Uri contentUri, string relativeUrl, string revisionId)
        {
            // change bitbucket.org to api.bitbucket.org
            UriBuilder apiUriBuilder = new UriBuilder(contentUri);

            apiUriBuilder.Host = $"api.{apiUriBuilder.Host}";

            string relativeApiUrl = UriUtilities.Combine(UriUtilities.Combine("2.0/repositories", relativeUrl), $"src/{revisionId}/*");

            return(UriUtilities.Combine(apiUriBuilder.Uri.ToString(), relativeApiUrl));
        }
Ejemplo n.º 2
0
        // Translates
        //   ssh://{account}@{domain}:{port}/{repositoryPath}/_ssh/{"_full"|"_optimized"}/{repositoryName}
        // to
        //   https://{domain}/{repositoryPath}/_git/{repositoryName}
        protected override string TranslateSshUrl(Uri uri)
        {
            if (!TeamFoundationUrlParser.TryParseOnPremSsh(uri, out var repositoryPath, out var repositoryName))
            {
                return(null);
            }

            return
                (UriUtilities.Combine(
                     UriUtilities.Combine("https://" + uri.Host, repositoryPath), "_git/" + repositoryName));
        }
Ejemplo n.º 3
0
 public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (this.Scopes != null)
     {
         foreach (var scope in this.Scopes)
         {
             if (UriUtilities.GetValidUri(scope) == null)
             {
                 yield return(new ValidationResult("Configuration contains scopes but they are not in a valid form", new string[] { nameof(this.Scopes) }));
             }
         }
     }
 }
Ejemplo n.º 4
0
        protected override string BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem?hostItem)
        {
            var trimLeadingSlash  = relativeUrl.TrimStart('/');
            var trimmedContentUrl = contentUri.ToString().TrimEnd('/', '\\');

            // p = project/path
            // a = action
            // hb = SHA/revision
            // f = repo file path
            var gitwebRawUrl = UriUtilities.Combine(trimmedContentUrl, $"?p={trimLeadingSlash}.git;a=blob_plain;hb={revisionId};f=*");

            return(gitwebRawUrl);
        }
Ejemplo n.º 5
0
        protected override string BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem hostItem)
        {
            if (!TeamFoundationUrlParser.TryParseHostedHttp(gitUri.Host, relativeUrl, out var projectPath, out var repositoryName))
            {
                Log.LogError(CommonResources.ValueOfWithIdentityIsInvalid, Names.SourceRoot.RepositoryUrlFullName, SourceRoot.ItemSpec, gitUri);
                return(null);
            }

            return
                (UriUtilities.Combine(
                     UriUtilities.Combine(contentUri.ToString(), projectPath), $"_apis/git/repositories/{repositoryName}/items") +
                 $"?api-version=1.0&versionType=commit&version={revisionId}&path=/*");
        }
Ejemplo n.º 6
0
        private DesignPackageInfo GetPackageInfoWithFirstAvailableMinorVersion(ClientContext context, string nameOfPackage, int majorVersion, int minorVersion)
        {
            var newVersionPackageInfo = GetPackageInfo(nameOfPackage, majorVersion, minorVersion);

            var nameInSolutionGallery = GetFileNameFromPackageInfo(newVersionPackageInfo);
            var serverRelativeUri     = UriUtilities.CombineServerRelativeUri(context.Site.ServerRelativeUrl, "/_catalogs/solutions/", nameInSolutionGallery);
            var fileInSolutionGallery = context.Web.GetFileByServerRelativeUrl(serverRelativeUri);

            context.Load(fileInSolutionGallery, f => f.Exists);
            context.ExecuteQuery();

            return(!fileInSolutionGallery.Exists ? newVersionPackageInfo : GetPackageInfoWithFirstAvailableMinorVersion(context, nameOfPackage, majorVersion, minorVersion + 1));
        }
        internal static string BuildSourceLinkUrlForEnterpriseEdition(
            Uri contentUri,
            string relativeBaseUrl,
            string projectName,
            string repositoryName,
            string commitSha,
            Version version)
        {
            var relativeUrl = (version >= s_versionWithNewUrlFormat) ?
                              $"projects/{projectName}/repos/{repositoryName}/raw/*?at={commitSha}" :
                              $"projects/{projectName}/repos/{repositoryName}/browse/*?at={commitSha}&raw";

            return(UriUtilities.Combine(contentUri.ToString(), UriUtilities.Combine(relativeBaseUrl, relativeUrl)));
        }
Ejemplo n.º 8
0
        public WorldRenderLayer(string fullName
                                , AbstractCamera camera
                                , GlobalLayerScaleType layerScaleType    = GlobalLayerScaleType.Dynamic
                                , UniformLayerScaleType uniformScaleType = UniformLayerScaleType.Stretch
                                , World world = null)
            : base(UriUtilities.GetLastPart(fullName), layerScaleType, uniformScaleType)
        {
            rp = ArtemisEngine.RenderPipeline; // for convenience

            Camera       = camera;
            camera.Layer = this;

            _world = world;
        }
Ejemplo n.º 9
0
        protected override string?BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem?hostItem)
        {
            var virtualDirectory = hostItem?.GetMetadata(VirtualDirectoryMetadataName) ?? "";

            if (!AzureDevOpsUrlParser.TryParseOnPremHttp(relativeUrl, virtualDirectory, out var projectPath, out var repositoryName))
            {
                Log.LogError(CommonResources.ValueOfWithIdentityIsInvalid, Names.SourceRoot.RepositoryUrlFullName, SourceRoot.ItemSpec, gitUri);
                return(null);
            }

            return
                (UriUtilities.Combine(
                     UriUtilities.Combine(contentUri.ToString(), projectPath), $"_apis/git/repositories/{repositoryName}/items") +
                 $"?api-version=1.0&versionType=commit&version={revisionId}&path=/*");
        }
Ejemplo n.º 10
0
        public static bool TryParseHostedSsh(Uri uri, out string account, out string repositoryPath, out string repositoryName)
        {
            Debug.Assert(uri != null);

            account = repositoryPath = repositoryName = null;

            // {"DefaultCollection"|""}/{repositoryPath}/"_ssh"/{"_full"|"_optimized"}/{repositoryName}
            if (!UriUtilities.TrySplitRelativeUrl(uri.GetPath(), out var parts) || parts.Length == 0)
            {
                return(false);
            }

            // Check for v3 url format
            if (parts[0] == "v3" &&
                parts.Length >= 3 &&
                TryParsePath(parts, 2, type: null, out repositoryPath, out repositoryName) &&
                repositoryPath != "")
            {
                // ssh://{user}@{domain}:{port}/v3/{account}/{repositoryPath}/{'_full'|'_optimized'|''}/{repositoryName}
                account = parts[1];
            }
            else
            {
                // ssh v1/v2 url formats
                // ssh://{account}@vs-ssh.visualstudio.com/

                account = uri.UserInfo;

                int index = 0;
                if (StringComparer.OrdinalIgnoreCase.Equals(parts[0], "DefaultCollection"))
                {
                    index++;
                }

                if (!TryParsePath(parts, index, "_ssh", out repositoryPath, out repositoryName))
                {
                    // Failed to parse path
                    return(false);
                }
            }

            if (account.Length == 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 11
0
        private void SetupView(ClientContext context, List list, ShView view)
        {
            var  viewCollection = list.Views;
            View setupView      = null;

            if (!string.IsNullOrEmpty(view.Title))
            {
                setupView = viewCollection.FirstOrDefault(v => v.Title == view.Title);
                if (setupView == null)
                {
                    setupView = viewCollection.Add(GetViewCreationInfoFromConfig(view));
                    context.ExecuteQuery();
                }
            }
            else if (!string.IsNullOrEmpty(view.Url))
            {
                context.Load(list, x => x.ParentWebUrl);
                context.Load(list, x => x.ParentWeb);
                context.ExecuteQuery();

                var serverRelativeUrl = UriUtilities.CombineServerRelativeUri(list.ParentWebUrl, view.Url);
                list.ParentWeb.CheckOutFile(serverRelativeUrl);
                setupView = viewCollection.FirstOrDefault(v => v.ServerRelativeUrl == serverRelativeUrl);
            }
            if (setupView != null)
            {
                if (view.ViewFields.Length > 0)
                {
                    setupView.ViewFields.RemoveAll();
                    foreach (var field in view.ViewFields)
                    {
                        setupView.ViewFields.Add(field);
                    }
                }
                setupView.JSLink    = view.JSLink;
                setupView.ViewQuery = view.Query;
                setupView.RowLimit  = view.RowLimit;

                setupView.Update();
                if (!string.IsNullOrEmpty(view.Url))
                {
                    list.ParentWeb.CheckInFile(setupView.ServerRelativeUrl, CheckinType.MajorCheckIn, "updated by sherpa");
                }
                context.ExecuteQuery();
            }
        }
Ejemplo n.º 12
0
        public static bool TryParseOnPremSsh(Uri uri, out string repositoryPath, out string repositoryName)
        {
            repositoryPath = repositoryName = null;

            if (!UriUtilities.TrySplitRelativeUrl(uri.GetPath(), out var parts))
            {
                return(false);
            }

            if (!TryParseRepositoryName(parts, out int teamNameIndex, "_ssh", out repositoryName))
            {
                return(false);
            }

            repositoryPath = string.Join("/", parts, 0, teamNameIndex + 1);
            return(true);
        }
Ejemplo n.º 13
0
        private string BuildSourceLinkUrlForEnterpriseEdition(Uri contentUri, string relativeUrl, string revisionId,
                                                              ITaskItem hostItem)
        {
            var bitbucketEnterpriseVersion = GetBitbucketEnterpriseVersion(hostItem);

            var splits         = relativeUrl.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var isSshRepoUri   = !(splits.Length == 3 && splits[0] == "scm");
            var projectName    = isSshRepoUri ? splits[0] : splits[1];
            var repositoryName = isSshRepoUri ? splits[1] : splits[2];

            var relativeUrlForBitbucketEnterprise =
                GetRelativeUrlForBitbucketEnterprise(projectName, repositoryName, revisionId,
                                                     bitbucketEnterpriseVersion);

            var result = UriUtilities.Combine(contentUri.ToString(), relativeUrlForBitbucketEnterprise);

            return(result);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Activates a design package based on package name
        /// Starting point: http://sharepoint.stackexchange.com/questions/90809/is-it-possible-to-activate-a-solution-using-client-code-in-sharepoint-online-201
        /// </summary>
        /// <param name="context"></param>
        /// <param name="filePathOrName">The filename of the package</param>
        /// <param name="siteRelativeUrlToLibrary">Site relative URL to the library of the package</param>
        public void ActivateDesignPackage(ClientContext context, string filePathOrName, string siteRelativeUrlToLibrary)
        {
            // if we pass in a full path, correct this
            var nameOfPackage = Path.GetFileNameWithoutExtension(filePathOrName);

            context.Load(context.Site);
            context.Load(context.Web);
            context.ExecuteQuery();

            var stagedFileUrl = UriUtilities.CombineServerRelativeUri(context.Site.ServerRelativeUrl, siteRelativeUrlToLibrary, nameOfPackage + ".wsp");
            var packageInfo   = GetPackageInfoWithLatestVersion(context, nameOfPackage, stagedFileUrl);

            Log.Info("Installing solution package " + GetFileNameFromPackageInfo(packageInfo));
            DesignPackage.Install(context, context.Site, packageInfo, stagedFileUrl);
            context.ExecuteQuery();

            DeleteFile(context, stagedFileUrl);
        }
        public AbstractRenderLayer(string fullName)
            : base(UriUtilities.GetLastPart(fullName))
        {
            tempFullName = fullName;
            Managed      = false;

            AllRenderables = new RenderableGroup(TOP_LEVEL);
            AddObservedNode(TOP_LEVEL, AllRenderables);

            LayerTarget = ArtemisEngine.RenderPipeline.CreateRenderTarget();

            // LayerTarget properties
            TargetFill                = Color.Transparent;
            TargetFormat              = SurfaceFormat.Color;
            TargetDepthFormat         = DepthFormat.None;
            PreferredMultiSampleCount = 0;
            TargetUsage               = RenderTargetUsage.DiscardContents;
            TargetIsMipMap            = false;
        }
Ejemplo n.º 16
0
        protected override string BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem hostItem)
        {
            var virtualDirectory = hostItem.GetMetadata(VirtualDirectoryMetadataName);

            if (string.IsNullOrEmpty(virtualDirectory))
            {
                Log.LogError(CommonResources.ItemOfItemGroupMustSpecifyMetadata, hostItem.ItemSpec, HostsItemGroupName, VirtualDirectoryMetadataName);
                return(null);
            }

            if (!TeamFoundationUrlParser.TryParseOnPremHttp(relativeUrl, virtualDirectory, out var projectPath, out var repositoryName))
            {
                Log.LogError(CommonResources.ValueOfWithIdentityIsInvalid, Names.SourceRoot.RepositoryUrlFullName, SourceRoot.ItemSpec, gitUri);
                return(null);
            }

            return
                (UriUtilities.Combine(
                     UriUtilities.Combine(contentUri.ToString(), projectPath), $"_apis/git/repositories/{repositoryName}/items") +
                 $"?api-version=1.0&versionType=commit&version={revisionId}&path=/*");
        }
Ejemplo n.º 17
0
        public Uri GetAuthorizationUrl(Uri redirectUri, string[] scopes)
        {
            string Scopes = string.Empty;

            if (scopes != null && scopes.Length != 0)
            {
                Scopes = string.Join(" ", scopes);
            }

            if (redirectUri == null)
            {
                throw new Exception("Required redirect uri.");
            }

            if (!UriUtilities.IsHttps(redirectUri))
            {
                throw new Exception("Redirect uri must be secure connection(https).");
            }

            return(new Uri(GetAuthorizationUrl(redirectUri.ToString(), Scopes)));
        }
Ejemplo n.º 18
0
        public AccessToken RequestAccessToken(string code, Uri redirectUri)
        {
            if (_AccessToken != null)
            {
                return(_AccessToken);
            }

            if (string.IsNullOrEmpty(code))
            {
                throw new Exception("Required authorization code.");
            }

            if (redirectUri == null)
            {
                throw new Exception("Required redirect uri.");
            }

            if (!UriUtilities.IsHttps(redirectUri))
            {
                throw new Exception("Redirect uri must be secure connection(https).");
            }

            return(GetAccessToken(code, redirectUri.ToString()));
        }
Ejemplo n.º 19
0
 public void UrlStartsWith(string url, string prefix, bool expected)
 {
     Assert.Equal(expected, UriUtilities.UrlStartsWith(url, prefix));
 }
Ejemplo n.º 20
0
 protected override string?BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem?hostItem)
 => UriUtilities.Combine(UriUtilities.Combine(contentUri.ToString(), relativeUrl), revisionId + "/*");
 /// <summary>
 /// Add an empty group with the given name to the layer.
 /// </summary>
 /// <param name="name"></param>
 public void AddGroup(string name)
 {
     AllRenderables.AddSubnode(name, new RenderableGroup(UriUtilities.GetLastPart(name)));
 }
 protected override Uri GetDefaultContentUriFromRepositoryUri(Uri repositoryUri)
 => new Uri(UriUtilities.Combine(repositoryUri.ToString(), "repo-default"), UriKind.Absolute);
Ejemplo n.º 23
0
        public static bool TryParseHostedHttp(string host, string relativeUrl, out string projectPath, out string repositoryName)
        {
            projectPath = repositoryName = null;

            if (!UriUtilities.TrySplitRelativeUrl(relativeUrl, out var parts) || parts.Length == 0)
            {
                return(false);
            }

            int    index = 0;
            string account;
            bool   isVisualStudioHost = IsVisualStudioHostedServer(host);

            if (isVisualStudioHost)
            {
                // account is stored in the domain, not in the path:
                account = null;

                // Trim optional "DefaultCollection" from path:
                if (StringComparer.OrdinalIgnoreCase.Equals(parts[index], "DefaultCollection"))
                {
                    index++;
                }
            }
            else
            {
                // Check this is not an 'enterprise' discovery page URL
                if (StringComparer.OrdinalIgnoreCase.Equals(parts[0], "e"))
                {
                    return(false);
                }

                // Account is first part of path:
                account = parts[index++];
            }

            if (index == parts.Length)
            {
                return(false);
            }

            if (!TryParsePath(parts, index, "_git", out var projectName, out var teamName, out repositoryName))
            {
                return(false);
            }

            if (isVisualStudioHost)
            {
                projectPath = projectName ?? repositoryName;
            }
            else
            {
                if (projectName == null || teamName != null)
                {
                    return(false);
                }

                projectPath = account + "/" + projectName;
            }

            return(true);
        }
Ejemplo n.º 24
0
        public void SetComposedLook(ClientContext context, ShWeb configWeb, Web web, ShComposedLook composedLook)
        {
            if (composedLook != null)
            {
                Log.Debug("Setting Composed Look for web " + configWeb.Name);
                var themeUrl      = string.Empty;
                var fontSchemeUrl = string.Empty;

                List themeList = web.GetCatalog(124);
                web.Context.Load(themeList);
                web.Context.ExecuteQuery();

                // We are assuming that the theme exists
                string camlString = @"
                <View>
                    <Query>                
                        <Where>
                            <Eq>
                                <FieldRef Name='Name' />
                                <Value Type='Text'>{0}</Value>
                            </Eq>
                        </Where>
                        </Query>
                </View>";
                camlString = string.Format(camlString, composedLook.Name);

                CamlQuery query = new CamlQuery();
                query.ViewXml = camlString;
                var themeItems = themeList.GetItems(query);
                web.Context.Load(themeItems);
                web.Context.ExecuteQuery();

                if (themeItems.Count == 0)
                {
                    if (!web.IsObjectPropertyInstantiated("ServerRelativeUrl"))
                    {
                        context.Load(web, w => w.ServerRelativeUrl);
                        context.ExecuteQuery();
                    }

                    var      itemInfo = new ListItemCreationInformation();
                    ListItem item     = themeList.AddItem(itemInfo);
                    item["Name"]  = composedLook.Name;
                    item["Title"] = composedLook.Title;
                    if (!string.IsNullOrEmpty(composedLook.ThemeUrl))
                    {
                        themeUrl         = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", Path.GetFileName(composedLook.ThemeUrl)));
                        item["ThemeUrl"] = themeUrl;
                    }
                    if (!string.IsNullOrEmpty(composedLook.FontSchemeUrl))
                    {
                        fontSchemeUrl         = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", Path.GetFileName(composedLook.FontSchemeUrl)));
                        item["FontSchemeUrl"] = fontSchemeUrl;
                    }
                    if (string.IsNullOrEmpty(composedLook.MasterPageUrl))
                    {
                        item["MasterPageUrl"] = Url.Combine(web.ServerRelativeUrl, "/_catalogs/masterpage/seattle.master");
                    }
                    else
                    {
                        item["MasterPageUrl"] = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/masterpage/{0}", Path.GetFileName(composedLook.MasterPageUrl)));
                    }
                    item["DisplayOrder"] = 11;
                    item.Update();
                    context.ExecuteQuery();
                }
                else
                {
                    ListItem item = themeItems[0];
                    var      themeUrlFieldValue      = item["ThemeUrl"] as FieldUrlValue;
                    var      fontSchemeUrlFieldValue = item["FontSchemeUrl"] as FieldUrlValue;
                    if (themeUrlFieldValue != null)
                    {
                        themeUrl = UriUtilities.GetRelativeUrl(themeUrlFieldValue.Url);
                    }
                    if (fontSchemeUrlFieldValue != null)
                    {
                        fontSchemeUrl = UriUtilities.GetRelativeUrl(fontSchemeUrlFieldValue.Url);
                    }
                }

                web.ApplyTheme(themeUrl, fontSchemeUrl, null, false);
                context.ExecuteQuery();
            }
        }
Ejemplo n.º 25
0
 public void TrySplitRelativeUrl(string url, string[]?parts)
 {
     if (!UriUtilities.TrySplitRelativeUrl(url, out string[]? actualParts))
 public AbstractOrderableRenderLayer(string fullName)
     : base(UriUtilities.GetLastPart(fullName))
 {
     GlobalTraversalOptions = TraversalOptions.Pre;
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UriContainer"/> class.
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="prefix">Default <see cref="ExchangerConstants.Prefix"/></param>
 /// <param name="contentType">Default <see cref="ExchangerConstants.ContentType"/></param>
 /// <param name="format">Default <see cref="ExchangerConstants.Format"/>.</param>
 public UriContainer(Uri uri, string prefix, string contentType, string format)
 {
     Format      = UriUtilities.ConcatUriParts(prefix, format);
     ContentType = contentType;
     Uri         = uri;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Get the value of a nested property with the given URI from an object.
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static object GetNestedPropertyValue(object obj, string name)
 {
     return(GetNestedPropertyValue(obj, UriUtilities.GetParts(name)));
 }
Ejemplo n.º 29
0
 private static string BuildSourceLinkUrlForCloudEdition(Uri contentUri, string relativeUrl, string revisionId)
 {
     return(UriUtilities.Combine(UriUtilities.Combine(contentUri.ToString(), relativeUrl),
                                 "raw/" + revisionId + "/*"));
 }