public async Task <ScItemsResponse> GetItemById(string itemId, PayloadType itemLoadType, List <ScopeType> itemScopeTypes, string itemLanguage = "en") { try { using (ISitecoreWebApiSession session = GetSession()) { IReadItemsByIdRequest request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(itemId) .Payload(itemLoadType) .AddScope(itemScopeTypes) .Language(itemLanguage) .Build(); return(await session.ReadItemAsync(request)); } } catch (SitecoreMobileSdkException ex) { Log.Error("Error in GetItemById, id {0} . Error: {1}", itemId, ex.Message); throw ex; } catch (Exception ex) { Log.Error("Error in GetItemById, id {0} . Error: {1}", itemId, ex.Message); throw ex; } }
private async void SendRequest() { try { using (ISitecoreWebApiSession session = this.instanceSettings.GetSession()) { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(queryTextField.Text) .Build(); this.ShowLoader(); ScItemsResponse response = await session.ReadItemAsync(request); this.HideLoader(); if (response.ResultCount > 0) { this.ShowItemsList(response); } else { AlertHelper.ShowLocalizedAlertWithOkOption("Message", "Item is not exist"); } } } catch (Exception e) { this.HideLoader(); AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message); } }
public async Task <ScItemsResponse> GetItemByPath(string itemPath, PayloadType itemLoadType, List <ScopeType> itemScopeTypes, string itemLanguage = "en") { try { using (ISitecoreWebApiSession session = await SitecoreSession) { IReadItemsByPathRequest request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(itemPath) .Payload(itemLoadType) .AddScope(itemScopeTypes) .Language(itemLanguage) .Build(); return(await session.ReadItemAsync(request)); } } catch (SitecoreMobileSdkException ex) { this._loggingService.Log("Error in GetItemByPath, id {0} . Error: {1}", itemPath, ex.Message); throw ex; } catch (Exception ex) { this._loggingService.Log("Error in GetItemByPath, id {0} . Error: {1}", itemPath, ex.Message); throw ex; } }
private async void SendRequest() { try { using (ISitecoreWebApiSession session = this.instanceSettings.GetSession()) { var builder = ItemWebApiRequestBuilder.ReadItemsRequestWithId(itemIdTextField.Text) .Payload(this.currentPayloadType) .AddFieldsToRead(this.fieldNameTextField.Text); if (this.parentScopeButton.Selected) { builder = builder.AddScope(ScopeType.Parent); } if (this.selfScopeButton.Selected) { builder = builder.AddScope(ScopeType.Self); } if (this.childrenScopeButton.Selected) { builder = builder.AddScope(ScopeType.Children); } var request = builder.Build(); this.ShowLoader(); ScItemsResponse response = await session.ReadItemAsync(request); if (response.Any()) { this.ShowItemsList(response); //items serialization test ScItem item = response[0] as ScItem; string json = JsonConvert.SerializeObject(item); ScItem restoredItem = JsonConvert.DeserializeObject <ScItem>(json); Console.WriteLine(restoredItem.DisplayName); } else { AlertHelper.ShowLocalizedAlertWithOkOption("Message", "Item is not exist"); } } } catch (Exception e) { this.CleanupTableViewBindings(); AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message); } finally { BeginInvokeOnMainThread(delegate { this.HideLoader(); this.FieldsTableView.ReloadData(); }); } }
private async void SendRequest() { try { using (ISitecoreWebApiSession session = this.instanceSettings.GetSession()) { var builder = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(this.ItemPathField.Text) .Payload(this.currentPayloadType) .AddFieldsToRead(this.fieldNameTextField.Text); if (this.parentScopeButton.Selected) { builder = builder.AddScope(ScopeType.Parent); } if (this.selfScopeButton.Selected) { builder = builder.AddScope(ScopeType.Self); } if (this.childrenScopeButton.Selected) { builder = builder.AddScope(ScopeType.Children); } var request = builder.Build(); this.ShowLoader(); ScItemsResponse response = await session.ReadItemAsync(request); if (response.Any()) { this.ShowItemsList(response); } else { AlertHelper.ShowLocalizedAlertWithOkOption("Message", "Item is not exist"); } } } catch (Exception e) { this.CleanupTableViewBindings(); AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message); } finally { BeginInvokeOnMainThread(delegate { this.FieldsTableView.ReloadData(); this.HideLoader(); }); } }
//gets the item or child item on specifying the query public async Task <ScItemsResponse> GetItemByQuery(string query, string itemLanguage = "en") { try { using (ISitecoreWebApiSession session = GetSession()) { IReadItemsByQueryRequest request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(query).Language(itemLanguage).Build(); return(await session.ReadItemAsync(request)); } } catch (SitecoreMobileSdkException ex) { Log.Error("Error in GetItemByQuery, id{0}. Error{1}", query, ex.Message); throw ex; } catch (Exception ex) { Log.Error("Error in GetItemByQuery, id{0}. Error{1}", query, ex.Message); throw ex; } }