public void GetAccountByIdTest() { var accountObject = _clientObject.GetAccountById(_configData.AccountId); Assert.IsNotNull(accountObject); Assert.AreEqual(accountObject.Id, _configData.AccountId.ToString()); }
public void GetAccountById_InvalidCredential() { var invalidCredential = new GcConnectClient("abc", _configData.Email); var accountObject = invalidCredential.GetAccountById(_configData.AccountId); Assert.IsNull(accountObject); }
protected void RptTableMappings_OnItemCreated(object sender, RepeaterItemEventArgs e) { if (!(e.Item.DataItem is GcDynamicTemplateMappings map)) { return; } var slug = Client.GetAccountById(Convert.ToInt32(map.AccountId)).Slug; if (e.Item.FindControl("btnEditTemplateMap") is Button buttonEditTemplateMap) { var serializedStatusMaps = JsonConvert.SerializeObject(map.StatusMaps); var serializedEpiFieldMaps = JsonConvert.SerializeObject(map.EpiFieldMaps); buttonEditTemplateMap.PostBackUrl = $"~/modules/GatherContentImport/NewGcMappingStep4.aspx?AccountId={map.AccountId}" + $"&ProjectId={map.ProjectId}&TemplateId={map.TemplateId}&PostType={map.PostType}&Author={map.Author}" + $"&DefaultStatus={map.DefaultStatus}&EpiContentType={map.EpiContentType}&StatusMaps={serializedStatusMaps}" + $"&EpiFieldMaps={serializedEpiFieldMaps}&PublishedDateTime={map.PublishedDateTime}"; } if (e.Item.FindControl("lnkAccountSlug") is HyperLink linkAccountSlug) { linkAccountSlug.NavigateUrl = $"https://{slug}.gathercontent.com/"; } if (e.Item.FindControl("lnkProject") is HyperLink linkProject) { linkProject.NavigateUrl = $"https://{slug}.gathercontent.com/projects/view/{map.ProjectId}"; } if (e.Item.FindControl("lnkTemplate") is HyperLink linkTemplate) { linkTemplate.NavigateUrl = $"https://{slug}.gathercontent.com/templates/{map.TemplateId}"; } if (e.Item.FindControl("chkTemplate") is CheckBox checkBoxTemplate) { checkBoxTemplate.ID = $"{map.TemplateId}"; } if (e.Item.FindControl("btnItemsReview") is Button buttonItemsReview) { buttonItemsReview.PostBackUrl = "~/modules/GatherContentImport/ReviewItemsForImport.aspx?" + $"TemplateId={map.TemplateId}&ProjectId={map.ProjectId}"; } }
private void PopulateForm() { if (_credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup your GatherContent config first!');" + "window.location='/modules/GcEpiPlugin/GatherContentConfigSetup.aspx'</script>"); Visible = false; return; } _client = new GcConnectClient(_credentialsStore.ToList().First().ApiKey, _credentialsStore.ToList().First().Email); var accountId = Convert.ToInt32(_credentialsStore.ToList().First().AccountId); Session["AccountId"] = accountId; accountName.Text = _client.GetAccountById(accountId).Name; var projects = _client.GetProjectsByAccountId(accountId); projects.ToList().ForEach(i => rblGcProjects.Items.Add(new ListItem(i.Name, i.Id.ToString()))); rblGcProjects.SelectedIndex = 0; Session["ProjectId"] = rblGcProjects.SelectedValue; Session["PostType"] = null; Session["Author"] = null; Session["DefaultStatus"] = null; }
protected void RptGcItems_OnItemCreated(object sender, RepeaterItemEventArgs e) { // Initializing the local variables. Client = new GcConnectClient(_credentialsStore.First().ApiKey, _credentialsStore.First().Email); var gcItem = e.Item.DataItem as GcItem; var defaultParentIdFromQuery = Server.UrlDecode(Request.QueryString["DefaultParentId"]); var enableItemFlag = true; var parentId = string.Empty; // This is to make sure we only fetch mappings associated with this GcAccount. _mappingsStore = GcDynamicUtilities.RetrieveStore <GcDynamicTemplateMappings>(). FindAll(i => i.AccountId == _credentialsStore.First().AccountId); // Fetch the mapping for current template. var currentMapping = _mappingsStore.First(i => i.TemplateId == Session["TemplateId"].ToString()); var recycleBin = _contentRepository.GetDescendents(ContentReference.WasteBasket).ToList(); if (gcItem == null) { return; } // Set the values of form components. if (e.Item.FindControl("statusName") is Label statusNameLabel) { statusNameLabel.Text = gcItem.CurrentStatus.Data.Name; } if (e.Item.FindControl("updatedAt") is Label updatedAtLabel) { updatedAtLabel.Text = gcItem.UpdatedAt.Date?.ToLocalTime().ToShortDateString(); } if (e.Item.FindControl("lnkIsImported") is HyperLink linkIsImported) { linkIsImported.Text = "---------"; _defaultParentId = currentMapping.PostType == "PageType" ? (defaultParentIdFromQuery ?? "1") : (defaultParentIdFromQuery ?? "3"); foreach (var cs in _contentStore) { // Check if the item in the Gather Content items list is in the content store. if (cs.ItemId != gcItem.Id) { /* * <summary> * We want to clear this list because we want the drop down to load from selected default parent and * if the previous item was already imported then the drop down would have all the options in them. * This helps in avoiding recursion-overhead. This also prevents data persistence on page reloads. * </summary> */ _sortedContent.Clear(); continue; } // Item is already imported, so set the flag to false. enableItemFlag = false; if (currentMapping.PostType == "PageType") { try { var pageData = _contentRepository.Get <PageData>(cs.ContentGuid); // Setting the parentId and making sure the drop down loads from Root Page. _defaultParentId = "1"; parentId = pageData.ParentLink.ID.ToString(); // If page is in trash, then set the import status to 'Page in Trash'. if (recycleBin.Contains(pageData.ContentLink)) { linkIsImported.Text = "Page in Trash"; parentId = "2"; break; } // Set the import status to 'Page Imported' and add a link to the page. linkIsImported.Text = "Page Imported"; linkIsImported.NavigateUrl = pageData.LinkURL; break; } catch (Exception ex) { Console.WriteLine(ex); if (ex is TypeMismatchException) { continue; } // This is in case the user moved the page to trash and deleted it permanently. if (!(ex is ContentNotFoundException)) { continue; } GcDynamicUtilities.DeleteItem <GcDynamicImports>(cs.Id); enableItemFlag = true; } } else { try { // ReSharper disable once SuspiciousTypeConversion.Global var blockData = _contentRepository.Get <BlockData>(cs.ContentGuid) as IContent; // ReSharper disable once PossibleNullReferenceException // Setting the parentId and making sure the drop down loads from Root Folder. parentId = blockData.ParentLink.ID.ToString(); _defaultParentId = "3"; // If the block is in trash, then set the import status to 'Block in Trash'. if (recycleBin.Contains(blockData.ContentLink)) { linkIsImported.Text = "Block in Trash"; parentId = "2"; break; } // Set the import status to 'Block Imported'. linkIsImported.Text = "Block Imported"; break; } catch (Exception ex) { Console.WriteLine(ex); if (ex is TypeMismatchException) { continue; } // This is in case the user moved the page to trash and deleted it permanently. if (!(ex is ContentNotFoundException)) { continue; } GcDynamicUtilities.DeleteItem <GcDynamicImports>(cs.Id); enableItemFlag = true; } } } } if (e.Item.FindControl("ddlParentId") is DropDownList dropDownListParentId) { // This control sets the parent under which the items are imported. dropDownListParentId.ID = $"ddl{gcItem.Id}"; if (currentMapping.PostType == "PageType") { // Get the parent page data. var parentData = _contentRepository.Get <PageData>(ContentReference.Parse(_defaultParentId)); dropDownListParentId.Items.Add(new ListItem(parentData.PageName, parentData.ContentLink.ID.ToString())); // To reduce the recursion-overhead, we only sort the content once and store it in a global variable instead. if (_sortedContent.IsNullOrEmpty()) { SortContent <PageData>(_contentRepository.Get <PageData>(ContentReference.Parse(_defaultParentId)), _sortedContent); } foreach (var pageData in _sortedContent) { if (recycleBin.Contains(pageData.ContentLink) || pageData.ContentLink.ID == 2) { // If the page is in trash, then add recycle bin page to the drop down so that it can be shown as the parent. if (parentId == "2") { dropDownListParentId.Items.Add(new ListItem( _contentRepository.Get <PageData>(ContentReference.WasteBasket).Name, "2")); } } else { var parentPage = _contentRepository.Get <PageData>(pageData.ParentLink); dropDownListParentId.Items.Add(new ListItem(parentPage.Name + " => " + pageData.Name, pageData.ContentLink.ID.ToString())); } } } else if (currentMapping.PostType == "BlockType") { // Get the parent page data. var parentData = _contentRepository.Get <ContentFolder>(ContentReference.Parse(_defaultParentId)); dropDownListParentId.Items.Add(new ListItem(parentData.Name, parentData.ContentLink.ID.ToString())); // To reduce the recursion-overhead, we only sort the content once and store it in a global variable instead. if (_sortedContent.IsNullOrEmpty()) { SortContent <ContentFolder>(_contentRepository.Get <ContentFolder>(ContentReference.Parse(_defaultParentId)), _sortedContent); } if (parentId == "2") { // If the block is in trash, then add recycle bin page to the drop down so that it can be shown as the parent. dropDownListParentId.Items.Add(new ListItem( _contentRepository.Get <PageData>(ContentReference.WasteBasket).Name, "2")); } foreach (var contentFolder in _sortedContent) { var parentFolder = _contentRepository.Get <ContentFolder>(contentFolder.ParentLink); dropDownListParentId.Items.Add(new ListItem(parentFolder.Name + " => " + contentFolder.Name, contentFolder.ContentLink.ID.ToString())); } } // If item is enabled, then enable the drop down containing the parents. Else, set the drop down to the content's parent value. if (enableItemFlag) { dropDownListParentId.Enabled = true; } else { dropDownListParentId.SelectedValue = parentId; } } if (e.Item.FindControl("chkItem") is CheckBox checkBoxItemImport) { checkBoxItemImport.ID = $"chkImport{gcItem.Id}"; if (enableItemFlag) { checkBoxItemImport.Enabled = true; checkBoxItemImport.Visible = true; btnImportItem.Enabled = true; } } if (e.Item.FindControl("chkUpdateContent") is CheckBox checkBoxItemUpdate) { if (!enableItemFlag) { checkBoxItemUpdate.ID = $"chkUpdate{gcItem.Id}"; // ReSharper disable once PossibleInvalidOperationException if (_contentStore.Any(i => i.ItemId == gcItem.Id && gcItem.UpdatedAt.Date.Value.ToLocalTime() > i.ImportedAt)) { var importedItem = _contentStore.Find(x => x.ItemId == gcItem.Id); var content = currentMapping.PostType == "PageType" ? _contentRepository.Get <PageData>(importedItem.ContentGuid) // ReSharper disable once SuspiciousTypeConversion.Global : _contentRepository.Get <BlockData>(importedItem.ContentGuid) as IContent; // ReSharper disable once PossibleNullReferenceException if (!recycleBin.Contains(content.ContentLink)) { checkBoxItemUpdate.Enabled = true; checkBoxItemUpdate.Visible = true; btnUpdateItem.Enabled = true; btnUpdateItem.Visible = true; } } } } if (e.Item.FindControl("importedOn") is Label importedOnLabel) { importedOnLabel.Text = enableItemFlag ? "---------" : _contentStore.Find(x => x.ItemId == gcItem.Id).ImportedAt.ToShortDateString(); } if (!(e.Item.FindControl("lnkItemName") is HyperLink linkItemName)) { return; } linkItemName.Text = gcItem.Name; linkItemName.NavigateUrl = $"https://{Client.GetAccountById(Convert.ToInt32(_credentialsStore.First().AccountId)).Slug}" + $".gathercontent.com/item/{gcItem.Id}"; }
protected void RptGcItems_OnItemCreated(object sender, RepeaterItemEventArgs e) { var gcItem = e.Item.DataItem as GcItem; var queryDefaultParentId = Server.UrlDecode(Request.QueryString["DefaultParentId"]); var enableItemFlag = true; var credentialsStore = GcDynamicCredentials.RetrieveStore().ToList().First(); var contentStore = GcDynamicImports.RetrieveStore(); var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); var parentId = ""; var recycleBin = contentRepository.GetDescendents(ContentReference.Parse("2")).ToList(); Client = new GcConnectClient(credentialsStore.ApiKey, credentialsStore.Email); var currentMapping = GcDynamicTemplateMappings .RetrieveStore().First(i => i.TemplateId == Session["TemplateId"].ToString()); if (gcItem == null) { return; } if (e.Item.FindControl("statusName") is Label statusNameLabel) { statusNameLabel.Text = gcItem.CurrentStatus.Data.Name; } if (e.Item.FindControl("updatedAt") is Label updatedAtLabel) { updatedAtLabel.Text = gcItem.UpdatedAt.Date?.ToShortDateString(); } if (e.Item.FindControl("lnkIsImported") is HyperLink linkIsImported) { linkIsImported.Text = "---------"; if (currentMapping.PostType == "PageType") { _defaultParentId = queryDefaultParentId.IsNullOrEmpty() ? "1" : queryDefaultParentId; foreach (var cs in contentStore) { //Try to create page data of each page in the content store that matches the gcItemId. try { if (cs.ItemId != gcItem.Id) { continue; } var pageData = contentRepository.Get <PageData>(cs.ContentGuid); //Setting the parentId and making sure the drop down loads from Root Page. parentId = pageData.ParentLink.ID.ToString(); enableItemFlag = false; _defaultParentId = "1"; //if page is in trash, then set the import status to 'Page in Trash'. if (recycleBin.Contains(pageData.ContentLink)) { linkIsImported.Text = "Page in Trash"; parentId = "2"; break; } linkIsImported.Text = "Page Imported"; linkIsImported.NavigateUrl = pageData.LinkURL; break; } catch (Exception ex) { Console.WriteLine(ex); //This is in case the user moved the page to trash and deleted it permanently. if (ex is TypeMismatchException) { continue; } GcDynamicImports.DeleteItem(cs.Id); } } } else { _defaultParentId = queryDefaultParentId.IsNullOrEmpty() ? "3" : queryDefaultParentId; foreach (var cs in contentStore) { try { if (cs.ItemId != gcItem.Id) { continue; } // ReSharper disable once SuspiciousTypeConversion.Global var blockData = contentRepository.Get <BlockData>(cs.ContentGuid) as IContent; // ReSharper disable once PossibleNullReferenceException //Setting the parentId and making sure the drop down loads from Root Folder. parentId = blockData.ParentLink.ID.ToString(); enableItemFlag = false; _defaultParentId = "3"; //if the block is in trash, then set the import status to 'Block in Trash'. if (recycleBin.Contains(blockData.ContentLink)) { linkIsImported.Text = "Block in Trash"; parentId = "2"; break; } linkIsImported.Text = "Block Imported"; break; } catch (Exception ex) { Console.WriteLine(ex); //This is in case the user moved the block to trash and deleted it permanently. if (ex is TypeMismatchException) { continue; } GcDynamicImports.DeleteItem(cs.Id); } } } } if (e.Item.FindControl("ddlParentId") is DropDownList dropDownListParentId) { dropDownListParentId.ID = $"ddl{gcItem.Id}"; if (currentMapping.PostType == "PageType") { var parentData = contentRepository.Get <PageData>(ContentReference.Parse(_defaultParentId)); dropDownListParentId.Items.Add(new ListItem(parentData.PageName, parentData.ContentLink.ID.ToString())); foreach (var cr in contentRepository.GetDescendents(ContentReference.Parse(_defaultParentId))) { try { var pageData = contentRepository.Get <PageData>(cr); if (recycleBin.Contains(pageData.ContentLink) || pageData.ContentLink.ID == 2) { //if the page is in trash, then add recycle bin to the drop down. if (parentId == "2") { dropDownListParentId.Items.Add(new ListItem( contentRepository.Get <PageData>(ContentReference.WasteBasket).Name, "2")); } } else { dropDownListParentId.Items.Add(new ListItem(pageData.PageName, pageData.ContentLink.ID.ToString())); } } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } } else { // ReSharper disable once SuspiciousTypeConversion.Global var parentData = contentRepository.Get <ContentFolder>(ContentReference.Parse(_defaultParentId)); // ReSharper disable once PossibleNullReferenceException dropDownListParentId.Items.Add(new ListItem(parentData.Name, parentData.ContentLink.ID.ToString())); foreach (var cr in contentRepository.GetDescendents(ContentReference.Parse(_defaultParentId))) { try { // ReSharper disable once SuspiciousTypeConversion.Global var contentFolder = contentRepository.Get <ContentFolder>(cr); // ReSharper disable once PossibleNullReferenceException if (parentId == "2") { dropDownListParentId.Items.Add(new ListItem( contentRepository.Get <PageData>(ContentReference.WasteBasket).Name, "2")); } dropDownListParentId.Items.Add(new ListItem(contentFolder.Name, contentFolder.ContentLink.ID.ToString())); } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } } if (enableItemFlag) { dropDownListParentId.Enabled = true; } else { dropDownListParentId.SelectedValue = parentId; } } if (e.Item.FindControl("chkItem") is CheckBox checkBoxItem) { checkBoxItem.ID = $"chk{gcItem.Id}"; if (enableItemFlag) { checkBoxItem.Enabled = true; checkBoxItem.Visible = true; btnImportItem.Enabled = true; } } if (!(e.Item.FindControl("lnkItemName") is HyperLink linkItemName)) { return; } linkItemName.Text = gcItem.Name; linkItemName.NavigateUrl = $"https://{Client.GetAccountById(Convert.ToInt32(credentialsStore.AccountId)).Slug}" + $".gathercontent.com/item/{gcItem.Id}"; }
protected void RptTableMappings_OnItemCreated(object sender, RepeaterItemEventArgs e) { if (!(e.Item.DataItem is GcDynamicTemplateMappings map)) { return; } Client = new GcConnectClient(_credentialsStore.ToList().First().ApiKey, _credentialsStore.ToList().First().Email); var slug = Client.GetAccountById(Convert.ToInt32(map.AccountId)).Slug; if (e.Item.FindControl("btnEditTemplateMap") is Button buttonEditTemplateMap) { var serializedStatusMaps = JsonConvert.SerializeObject(map.StatusMaps); var serializedEpiFieldMaps = JsonConvert.SerializeObject(map.EpiFieldMaps); buttonEditTemplateMap.PostBackUrl = $"~/modules/GcEpiPlugin/NewGcMappingStep4.aspx?AccountId={map.AccountId}" + $"&ProjectId={map.ProjectId}&TemplateId={map.TemplateId}&PostType={map.PostType}&Author={map.Author}" + $"&DefaultStatus={map.DefaultStatus}&EpiContentType={map.EpiContentType}&StatusMaps={serializedStatusMaps}" + $"&EpiFieldMaps={serializedEpiFieldMaps}&PublishedDateTime={map.PublishedDateTime}"; } if (e.Item.FindControl("lnkAccountSlug") is HyperLink linkAccountSlug) { linkAccountSlug.NavigateUrl = $"https://{slug}.gathercontent.com/"; } if (e.Item.FindControl("lnkProject") is HyperLink linkProject) { if (Client.GetProjectById(Convert.ToInt32(map.ProjectId)).Name != null) { linkProject.Text = Client.GetProjectById(Convert.ToInt32(map.ProjectId)).Name; linkProject.NavigateUrl = $"https://{slug}.gathercontent.com/templates/{map.ProjectId}"; } else { linkProject.Text = "Project is deleted"; } } if (e.Item.FindControl("lnkTemplate") is HyperLink linkTemplate) { if (Client.GetTemplateById(Convert.ToInt32(map.TemplateId)).Name != null) { linkTemplate.Text = Client.GetTemplateById(Convert.ToInt32(map.TemplateId)).Name; linkTemplate.NavigateUrl = $"https://{slug}.gathercontent.com/templates/{map.TemplateId}"; } else { linkTemplate.Text = "Template is deleted"; } } if (e.Item.FindControl("chkTemplate") is CheckBox checkBoxTemplate) { checkBoxTemplate.ID = $"{map.TemplateId}"; } if (e.Item.FindControl("btnItemsReview") is Button buttonItemsReview) { buttonItemsReview.PostBackUrl = "~/modules/GcEpiPlugin/ReviewItemsForImport.aspx?" + $"TemplateId={map.TemplateId}&ProjectId={map.ProjectId}"; } if (e.Item.FindControl("publishedOn") is Label publishedOnLabel) { publishedOnLabel.Text = map.PublishedDateTime; } }