Exemplo n.º 1
0
        private static void CredentialsSample(AuthenticatedSitecoreDataContext context)
        {
            var query = new SitecoreItemQuery(SitecoreQueryType.Read)
            {
                ItemId = "{11111111-1111-1111-1111-111111111111}",
                QueryScope = new[] { SitecoreItemScope.Self }
            };

            ISitecoreWebResponse response = context.GetResponse<SitecoreWebResponse>(query);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                WriteResponseMeta(response);

                WebApiItem item = response.Result.Items[0];

                Wl("path", item.Path);
                Nl();
            }
            else
            {
                WriteError(response);
            }

            Nl();
        }
Exemplo n.º 2
0
        private static void ItemQuerySample(SitecoreDataContext context)
        {
            var query = new SitecoreItemQuery(SitecoreQueryType.Read)
                                {
                                    ItemId = "{11111111-1111-1111-1111-111111111111}",
                                    QueryScope = new[] {SitecoreItemScope.Self, SitecoreItemScope.Children}
                                };

            ISitecoreWebResponse response = context.GetResponse<SitecoreWebResponse>(query);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                WriteResponseMeta(response);

                foreach (WebApiItem item in response.Result.Items)
                {
                    Wl("path", item.Path);
                }
            }
            else
            {
                WriteError(response);
            }

            Nl();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Item updating sample using item id
        /// </summary>
        /// <para>
        ///     Requires an authenticated data context
        /// </para>
        /// <para>
        ///     The user must have write permissions on the item
        /// </para>
        /// <param name="context">The context.</param>
        private static void UpdateItemIdSample(AuthenticatedSitecoreDataContext context)
        {
            var query = new SitecoreItemQuery(SitecoreQueryType.Update)
            {
                ItemId = "{11111111-1111-1111-1111-111111111111}",
                QueryScope = new[]
                                 {
                                     SitecoreItemScope.Self,
                                     SitecoreItemScope.Children
                                 },
                Database = "master",
                FieldsToUpdate = new Dictionary<string, string>
                                                   {
                                                       { "Field Name", "Value" },
                                                       { "{11111111-1111-1111-1111-111111111111}", "Value" }
                                                   },
                FieldsToReturn = new List<string>
                                                    {
                                                        "Field Name",
                                                        "{11111111-1111-1111-1111-111111111111}"
                                                    }
            };

            ISitecoreWebResponse response = context.GetResponse<SitecoreWebResponse>(query);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                WriteResponseMeta(response);

                foreach (WebApiItem item in response.Result.Items)
                {
                    Wl("path", item.Path);
                    WriteFields(item);
                }
            }
            else
            {
                WriteError(response);
            }

            Nl();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Item deletion sample
        /// </summary>
        /// <para>
        ///     Requires an authenticated data context
        /// </para>
        /// <para>
        ///     The user must have delete permissions on the item
        /// </para>
        /// <param name="context">The context.</param>
        private static void DeleteQuerySample(AuthenticatedSitecoreDataContext context)
        {
            // WARNING: all items in the query scope and their descendants will be deleted
            // only items in the query scope count toward the response count
            var query = new SitecoreItemQuery(SitecoreQueryType.Delete)
            {
                ItemId = "{11111111-1111-1111-1111-111111111111}",
                QueryScope = new[] { SitecoreItemScope.Self },
                Database = "web"
            };

            ISitecoreWebResponse response = context.GetResponse<SitecoreWebResponse>(query);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                WriteResponseMeta(response);

                Wl("deletion count", response.Result.Count);

                if (response.Result.ItemIds != null)
                {
                    foreach (string id in response.Result.ItemIds)
                    {
                        Wl("id", id);
                    }
                }
            }
            else
            {
                WriteError(response);
            }

            Nl();
        }