/// <summary> /// Initializes a new instance of the <see cref="ChainUrlFixer"/> class. /// </summary> public RedirectGenerator() { InitializeComponent(); RedirectTypeComboBox.DataSource = GetRedirectTypes(); CreateForEveryComboBox.SelectedIndex = 10; PostmanGenerator.Load(); }
/// <summary> /// Generates the postman collection. /// </summary> /// <param name="redirects">The redirects.</param> /// <param name="redirectType"></param> /// <returns>System.String.</returns> private string GeneratePostmanCollection(Redirect[] redirects, RedirectType redirectType) { var jsonItemList = new List <PostmanCollectionItemJsonData>(); var index = 0; var selectedSkipValue = CreateForEveryComboBox.SelectedIndex; foreach (var redirect in redirects) { if (selectedSkipValue == 10 || selectedSkipValue == index) { var oldUrl = redirect.OldUrl.Replace("\\", "/").Replace("\"", ""); var newUrl = redirect.NewUrl.Replace("\\", "/").Replace("\"", ""); var domainInfo = Helpers.GetDomainInfo(oldUrl); var hostSegments = domainInfo.Domain.Split('.'); var urlSegments = domainInfo.Path.Split('/'); newUrl = string.IsNullOrEmpty(newUrl) ? "/" : newUrl; if (!newUrl.StartsWith("http://") && !newUrl.StartsWith("https://")) { var targetSiteUrl = $"https://{domainInfo.Domain}"; newUrl = targetSiteUrl + newUrl; } jsonItemList.Add(new PostmanCollectionItemJsonData { Name = oldUrl, Guid = Guid.NewGuid().ToString("D"), StatusCode = redirectType.StatusCode, FullToUrl = newUrl, FullFromUrl = oldUrl, Protocol = domainInfo.HttpMode, Hosts = hostSegments, Paths = urlSegments }); } if (index == 9) { index = 0; } else { index++; } } var data = new PostmanCollectionJsonData { Name = CollectionNameTextBox.Text.Trim(), Guid = Guid.NewGuid().ToString("D"), Items = jsonItemList }; return(PostmanGenerator.GetCollectionJson(data)); }