diff --git a/.gitignore b/.gitignore index 2bdf631..0c85ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,3 @@ packages/ *.config *.nupkg *.nuspec -Contentstack.core/docfx_project/* diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100755 index 0000000..33115b9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +### Version: 1.1.0 +#### Date: Apr-12-2019 + +##### New Features: +- ContentstackClient + - added method 'GetContentTypes' + - added method 'SyncRecursive' + - added method 'SyncRecursiveLanguage' + - added method 'SyncPaginationToken' + - added method 'SyncToken' + +- CotentType + - added method 'Fetch' + + ### Version: 1.0.6 + #### Date: Apr-12-2019 + +Localization support for Query and Entry is added. + +### Version: 1.0.0 +#### Date: Apr-12-2019 + +- Introduce ContentStack SDK for DOTNET. diff --git a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj index 33352ab..a5ea355 100644 --- a/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj +++ b/Contentstack.AspNetCore/Contentstack.AspNetCore.csproj @@ -6,9 +6,13 @@ contentstack.aspnetcore Contentstack Contentstack - 0.0.1 + 1.1.0 1.0.0 Main release + Copyright (c) 2012-2019 Contentstack (http://app.contentstack.com). All Rights Reserved + + https://github.com/contentstack/contentstack-dotnet + v1.0.0 diff --git a/Contentstack.Core.Tests/ContentTypeTest.cs b/Contentstack.Core.Tests/ContentTypeTest.cs new file mode 100644 index 0000000..31e6603 --- /dev/null +++ b/Contentstack.Core.Tests/ContentTypeTest.cs @@ -0,0 +1,50 @@ +using System; +using Xunit; +using Contentstack.Core.Models; +using System.Threading.Tasks; +using Contentstack.Core.Configuration; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Collections; + +namespace Contentstack.Core.Tests +{ + public class ContentTypeTest + + { + ContentstackClient client = StackConfig.GetStack(); + String source = "source"; + + [Fact] + public async Task FetchContenTypeSchema() + { + ContentType contenttype = client.ContentType(source); + var result = await contenttype.Fetch(); + if (result == null) + { + Assert.False(true, "contenttype.FetchSchema() is not match with expected result."); + } + else + { + Assert.True(true); + } + } + + [Fact] + public async Task GetContentTypes() + { + var result = await client.GetContentTypes(); + + if (result == null) + { + Assert.False(true, "client.getContentTypes is not match with expected result."); + } + else + { + Assert.True(true); + + } + } + } +} diff --git a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj index d30d430..dd80891 100644 --- a/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj +++ b/Contentstack.Core.Tests/Contentstack.Core.Tests.csproj @@ -4,7 +4,7 @@ netcoreapp2.0 false - 0.0.1 + 1.1.0 @@ -12,6 +12,7 @@ + @@ -33,6 +34,7 @@ + diff --git a/Contentstack.Core.Tests/StackConfig.cs b/Contentstack.Core.Tests/StackConfig.cs index 72fe74c..05d7b20 100644 --- a/Contentstack.Core.Tests/StackConfig.cs +++ b/Contentstack.Core.Tests/StackConfig.cs @@ -2,6 +2,7 @@ using Contentstack.Core; using Contentstack.Core.Models; using System.Configuration; +using Microsoft.Extensions.Options; namespace Contentstack.Core.Tests { @@ -17,6 +18,30 @@ System.Configuration.Configuration assemblyConfiguration } } + public static ContentstackClient GetSyncStack() + { + StackConfig config = new StackConfig(); + if (config.assemblyConfiguration.HasFile && string.Compare(config.assemblyConfiguration.FilePath, config.currentConfiguration.FilePath, true) != 0) + { + config.assemblyConfiguration.SaveAs(config.currentConfiguration.FilePath); + ConfigurationManager.RefreshSection("appSettings"); + ConfigurationManager.RefreshSection("connectionStrings"); + } + string apiKey = ConfigurationManager.AppSettings["sync_api_key"]; + string accessToken = ConfigurationManager.AppSettings["sync_access_token"]; + string environment = ConfigurationManager.AppSettings["sync_environment"]; + string host = ConfigurationManager.AppSettings["host"]; + Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions + { + ApiKey = apiKey, + AccessToken = accessToken, + Environment = environment, + Host = host + }; + + ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper(contentstackOptions)); + return contentstackClient; + } public static ContentstackClient GetStack() { @@ -30,16 +55,16 @@ public static ContentstackClient GetStack() string apiKey = ConfigurationManager.AppSettings["api_key"]; string accessToken = ConfigurationManager.AppSettings["access_token"]; string environment = ConfigurationManager.AppSettings["environment"]; - + string host = ConfigurationManager.AppSettings["host"]; Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions { ApiKey = apiKey, AccessToken = accessToken, - Environment = environment + Environment = environment, + Host = host }; - ContentstackClient contentstackClient = new ContentstackClient(apiKey, accessToken, environment); - + ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper(contentstackOptions)); return contentstackClient; } diff --git a/Contentstack.Core.Tests/SyncStackTest.cs b/Contentstack.Core.Tests/SyncStackTest.cs new file mode 100644 index 0000000..f4ece25 --- /dev/null +++ b/Contentstack.Core.Tests/SyncStackTest.cs @@ -0,0 +1,136 @@ +using System; +using Xunit; +using Contentstack.Core.Configuration; +using System.Threading.Tasks; + +namespace Contentstack.Core.Tests +{ + public class SyncStackTest + { + ContentstackClient client = StackConfig.GetSyncStack(); + + [Fact] + public async Task SyncInit() + { + + var result = await client.SyncRecursive(); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + + [Fact] + public async Task SyncSyncType() + { + + var result = await client.SyncRecursive(SyncType: Models.SyncType.asset_published); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] + public async Task SyncContentType() + { + + var result = await client.SyncRecursive(ContentTypeUid: "session"); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] + public async Task SyncStartFrom() + { + + var result = await client.SyncRecursive(StartFrom:DateTime.Now); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] + public async Task SyncTypeWithContentType() + { + + var result = await client.SyncRecursive(SyncType: Models.SyncType.entry_published, ContentTypeUid: "session"); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + [Fact] + public async Task SyncTypeWithStartFrom() + { + + var result = await client.SyncRecursive(SyncType: Models.SyncType.entry_published, StartFrom:DateTime.Now); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + + [Fact] + public async Task SyncPaginationToken() + { + + var result = await client.SyncPaginationToken("blt99c1e34e65f6cc0fd1d82b"); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + + [Fact] + public async Task SyncToken() + { + + var result = await client.SyncToken("blt08854bd48e43a740951809"); + + if (result == null) + { + Assert.False(true, "Entry.Fetch is not match with expected result."); + } + else + { + Assert.True(true); + } + } + } +} diff --git a/Contentstack.Core/Configuration/ContentstackOptions.cs b/Contentstack.Core/Configuration/ContentstackOptions.cs index 4793b34..c95fc57 100644 --- a/Contentstack.Core/Configuration/ContentstackOptions.cs +++ b/Contentstack.Core/Configuration/ContentstackOptions.cs @@ -21,5 +21,14 @@ public class ContentstackOptions /// public string Environment { get; set; } + /// + /// The Host used to set host url for the ContentStack API. + /// + public string Host { get; set; } + + /// + /// The Version number for the ContentStack API. + /// + public string Version { get; set; } } } diff --git a/Contentstack.Core/Contentstack.Core.csproj b/Contentstack.Core/Contentstack.Core.csproj index b42e6b0..0847152 100644 --- a/Contentstack.Core/Contentstack.Core.csproj +++ b/Contentstack.Core/Contentstack.Core.csproj @@ -5,10 +5,15 @@ contentstack.csharp Contentstack .NET SDK for the Contentstack Content Delivery API. - 1.0.6 + 1.1.0 Contentstack - Localization support for Query and Entry is added. - 0.0.1 + Fetching Content-Type schema +Stack Sync implemented + 1.1.0 + Copyright © 2012-2019 Contentstack. All Rights Reserved + + true + v1.1.0 @@ -40,6 +45,7 @@ + diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index f65f964..c9e4612 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -1,14 +1,21 @@ -using System; +using System; using System.Collections.Generic; using Contentstack.Core.Internals; using Contentstack.Core.Configuration; using Microsoft.Extensions.Options; using Contentstack.Core.Models; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using System.Linq; +using System.Threading.Tasks; +using System.Net; +using System.IO; +using System.Collections; namespace Contentstack.Core { /// - /// To fetch stack level information of your application from Built.io Contentstack server. + /// To fetch stack level information of your application from Contentstack server. /// public class ContentstackClient { @@ -22,6 +29,25 @@ internal string StackApiKey private ContentstackOptions _options; + internal string _SyncUrl + { + get + { + Config config = this.config; + return String.Format("{0}/stacks/sync", + config.BaseUrl); + } + } + private Dictionary UrlQueries = new Dictionary(); + private Dictionary _Headers = new Dictionary(); + private string _Url + { + get { + return String.Format("{0}/content_types/", config.BaseUrl); + } + } + private Dictionary _StackHeaders = new Dictionary(); + /// /// Initializes a instance of the class. /// @@ -49,6 +75,14 @@ public ContentstackClient(IOptions options) this.SetHeader("access_token", _options.AccessToken); Config cnfig = new Config(); cnfig.Environment = _options.Environment; + if (_options.Host != null) + { + cnfig.Host = _options.Host; + } + if (_options.Version != null) + { + cnfig.Version = _options.Version; + } this.SetConfig(cnfig); } @@ -74,13 +108,16 @@ public ContentstackClient(ContentstackOptions options) : /// ContentType contentType = stack.ContentType("contentType_name"); /// /// - public ContentstackClient(string apiKey, string accessToken, string environment) : + public ContentstackClient(string apiKey, string accessToken, string environment, string host = null, string version = null) : this(new OptionsWrapper(new ContentstackOptions() - { - ApiKey = apiKey, - AccessToken = accessToken, - Environment = environment - })) + { + ApiKey = apiKey, + AccessToken = accessToken, + Environment = environment, + Host = host, + Version = version + } + )) { } @@ -97,6 +134,60 @@ private ContentstackClient() { } #endregion #region Internal Constructor + internal static ContentstackError GetContentstackError(Exception ex) + { + Int32 errorCode = 0; + string errorMessage = string.Empty; + HttpStatusCode statusCode = HttpStatusCode.InternalServerError; + ContentstackError contentstackError = new ContentstackError(ex); + Dictionary errors = null; + //ContentstackError.OtherErrors errors = null; + + try + { + System.Net.WebException webEx = (System.Net.WebException)ex; + + using (var exResp = webEx.Response) + using (var stream = exResp.GetResponseStream()) + using (var reader = new StreamReader(stream)) + { + errorMessage = reader.ReadToEnd(); + JObject data = JObject.Parse(errorMessage.Replace("\r\n", "")); + //errorCode = ContentstackConvert.ToInt32(data.Property("error_code").Value); + //errorMessage = ContentstackConvert.ToString(data.Property("error_message").Value); + + JToken token = data["error_code"]; + if (token != null) + errorCode = token.Value(); + + token = data["error_message"]; + if (token != null) + errorMessage = token.Value(); + + token = data["errors"]; + if (token != null) + errors = token.ToObject>(); + + var response = exResp as HttpWebResponse; + if (response != null) + statusCode = response.StatusCode; + } + } + catch + { + errorMessage = ex.Message; + } + + contentstackError = new ContentstackError() + { + ErrorCode = errorCode, + ErrorMessage = errorMessage, + StatusCode = statusCode, + Errors = errors + }; + + return contentstackError; + } internal ContentstackClient(String stackApiKey) { this.StackApiKey = stackApiKey; @@ -114,6 +205,65 @@ internal void SetConfig(Config cnfig) #endregion #region Public Functions + /// + /// This method fetchs information of a all content types. + /// + /// + /// + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// ContentType contentType = stack.GetContentTypes(); + /// + /// + /// The List of content types schema. + public async Task GetContentTypes() + { + Dictionary headers = GetHeader(_LocalHeaders); + Dictionary headerAll = new Dictionary(); + Dictionary mainJson = new Dictionary(); + + //Dictionary urlQueries = new Dictionary(); + + if (headers != null && headers.Count() > 0) + { + foreach (var header in headers) + { + headerAll.Add(header.Key, (String)header.Value); + } + + if (headers.ContainsKey("environment")) + { + UrlQueries.Add("environment", headers["environment"]); + //Url = Url + "?environment=" + headers["environment"]; + } + else if (headers.ContainsKey("environment_uid")) + { + UrlQueries.Add("environment_uid", headers["environment_uid"]); + //Url = Url + "?environment_uid=" + headers["environment_uid"]; + } + else + { + + mainJson.Add("environment", this.config.Environment); + } + } + + foreach (var kvp in UrlQueries) + { + mainJson.Add(kvp.Key, kvp.Value); + } + try + { + HTTPRequestHandler RequestHandler = new HTTPRequestHandler(); + var outputResult = await RequestHandler.ProcessRequest(_Url, headers, mainJson); + JObject data = JsonConvert.DeserializeObject(outputResult.Replace("\r\n", ""), ContentstackConvert.JsonSerializerSettings); + IList contentTypes = (IList)data["content_types"]; + return contentTypes; + } + catch (Exception ex) + { + throw GetContentstackError(ex); + } + } /// /// Represents a ContentType. Creates ContenntType Instance. @@ -285,7 +435,7 @@ public void RemoveHeader(string key) } /// - /// To set headers for Built.io Contentstack rest calls. + /// To set headers for Contentstack rest calls. /// /// header name. /// header value against given header name. @@ -307,41 +457,176 @@ public void SetHeader(string key, string value) } } + /// + /// Syncs the recursive. + /// + /// The recursive. + /// Sync type. + /// Content type uid. + /// Start from Date. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// stack.SyncRecursive("SyncType"); + /// + /// + /// + public async Task SyncRecursive(SyncType SyncType = SyncType.All, string ContentTypeUid = null, DateTime? StartFrom = null) + { + SyncStack syncStack = await Sync(SyncType: SyncType, ContentTypeUid: ContentTypeUid, StartFrom: StartFrom); + syncStack = await SyncPageinationRecursive(syncStack); + return syncStack; + } - ///// - ///// set environment. - ///// - ///// environment uid/name - ///// true - If environment uid is present - ///// false - If environment uid is not present - ///// - ///// - ///// //"blt5d4sample2633b" is a dummy Stack API key - ///// //"blt6d0240b5sample254090d" is dummy access token. - ///// Stack stack = Contentstack.Stack("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); - ///// stack.SetEnvironment("stag", false); - ///// - ///// - //public void SetEnvironment(string environment, bool isEnvironmentUid) - //{ - // if (!string.IsNullOrEmpty(environment)) - // { - // if (isEnvironmentUid) - // { - // RemoveHeader("environment"); - // SetHeader("environment_uid", environment); - // } - // else - // { - // RemoveHeader("environment_uid"); - // SetHeader("environment", environment); - // } - // } - //} + /// + /// Syncs the recursive with language. + /// + /// The recursive with language. + /// Sync type. + /// Content type uid. + /// Start from Date. + /// Lang. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// stack.SyncRecursiveLanguage("SyncType", "Language"); + /// + /// + /// + public async Task SyncRecursiveLanguage(Language Lang, SyncType SyncType = SyncType.All, string ContentTypeUid = null, DateTime? StartFrom = null) + { + SyncStack syncStack = await SyncLanguage(Lang: Lang, SyncType: SyncType, ContentTypeUid: ContentTypeUid, StartFrom: StartFrom); + syncStack = await SyncPageinationRecursive(syncStack); + return syncStack; + } + /// + /// Syncs the pagination token. + /// + /// The pagination token. + /// Pagination token. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// stack.SyncPaginationTokenn("blt123343"); + /// + /// + + public async Task SyncPaginationToken(string paginationToken) + { + return await GetResultAsync(PaginationToken: paginationToken); + } + + /// + /// Syncs the token. + /// + /// The token. + /// Sync token. + /// + /// + /// //"blt5d4sample2633b" is a dummy Stack API key + /// //"blt6d0240b5sample254090d" is dummy access token. + /// ContentstackClient stack = new ContentstackClinet("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag"); + /// stack.SyncToken("blt123343"); + /// + /// + public async Task SyncToken(string SyncToken) + { + return await GetResultAsync(SyncToken: SyncToken); + } #endregion #region Private Functions + + + private async Task SyncPageinationRecursive(SyncStack syncStack) + { + while (syncStack.pagination_token != null) + { + SyncStack newSyncStack = await SyncPaginationToken(syncStack.pagination_token); + syncStack.items = syncStack.items.Concat(newSyncStack.items); + syncStack.pagination_token = newSyncStack.pagination_token; + syncStack.skip = newSyncStack.skip; + syncStack.total_count = newSyncStack.total_count; + syncStack.sync_token = newSyncStack.sync_token; + } + return syncStack; + } + + private async Task Sync(SyncType SyncType = SyncType.All, string ContentTypeUid = null, DateTime? StartFrom = null) + { + return await GetResultAsync(Init: "true", ContentTypeUid: ContentTypeUid, StartFrom: StartFrom); + } + + + private async Task SyncLanguage(Language Lang, SyncType SyncType = SyncType.All, string ContentTypeUid = null, DateTime? StartFrom = null) + { + return await GetResultAsync(Init: "true", ContentTypeUid: ContentTypeUid, StartFrom: StartFrom, Lang: GetLocaleCode(Lang)); + } + + //GetLanguage code + private string GetLocaleCode(Language language) + { + string localeCode = null; + try + { + int localeValue = (int)language; + LanguageCode[] languageCodeValues = Enum.GetValues(typeof(LanguageCode)).Cast().ToArray(); + localeCode = languageCodeValues[localeValue].ToString(); + localeCode = localeCode.Replace("_", "-"); + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + return localeCode; + } + + private Dictionary GetHeader(Dictionary localHeader) + { + Dictionary mainHeader = _StackHeaders; + Dictionary classHeaders = new Dictionary(); + + if (localHeader != null && localHeader.Count > 0) + { + if (mainHeader != null && mainHeader.Count > 0) + { + foreach (var entry in localHeader) + { + String key = entry.Key; + classHeaders.Add(key, entry.Value); + } + + foreach (var entry in mainHeader) + { + String key = entry.Key; + if (!classHeaders.ContainsKey(key)) + { + classHeaders.Add(key, entry.Value); + } + } + + return classHeaders; + + } + else + { + return localHeader; + } + + } + else + { + return _StackHeaders; + } + } + private Dictionary GetHeader() { @@ -349,6 +634,50 @@ private Dictionary GetHeader() return mainHeader; } + + + private async Task GetResultAsync(string Init = "false", string ContentTypeUid = null, DateTime? StartFrom = null, string SyncToken = null, string PaginationToken = null, string Lang = null) + { + //mainJson = null; + Dictionary mainJson = new Dictionary(); + if (Init != "false") + { + mainJson.Add("init", "true"); + mainJson.Add("environment", config.Environment); + } + if (StartFrom != null) + { + DateTime startFrom = StartFrom ?? DateTime.MinValue; + mainJson.Add("start_from", startFrom.ToString("yyyy-MM-dd")); + } + if (SyncToken != null) + { + mainJson.Add("sync_token", SyncToken); + } + if (PaginationToken != null) + { + mainJson.Add("pagination_token", PaginationToken); + } + if (ContentTypeUid != null) + { + mainJson.Add("content_type_uid", ContentTypeUid); + } + if (Lang != null) + { + mainJson.Add("locale", Lang); + } + try + { + HTTPRequestHandler requestHandler = new HTTPRequestHandler(); + string js = await requestHandler.ProcessRequest(_SyncUrl, _LocalHeaders, mainJson); + SyncStack stackSyncOutput = JsonConvert.DeserializeObject(js); + return stackSyncOutput; + } + catch (Exception ex) + { + throw GetContentstackError(ex); + } + } #endregion } diff --git a/Contentstack.Core/Internals/ContentStackError.cs b/Contentstack.Core/Internals/ContentStackError.cs index 0b91971..e6ba381 100644 --- a/Contentstack.Core/Internals/ContentStackError.cs +++ b/Contentstack.Core/Internals/ContentStackError.cs @@ -16,7 +16,7 @@ public class ContentstackError : Exception #region Public Variables /// - /// This is http response status code of REST request to built.io. + /// This is http response status code of REST request to Contentstack. /// public HttpStatusCode StatusCode; diff --git a/Contentstack.Core/Internals/ContentstackConstants.cs b/Contentstack.Core/Internals/ContentstackConstants.cs index 25b3448..3ea6e95 100644 --- a/Contentstack.Core/Internals/ContentstackConstants.cs +++ b/Contentstack.Core/Internals/ContentstackConstants.cs @@ -6,8 +6,6 @@ namespace Contentstack.Core.Internals internal class ContentstackConstants { #region Private Variable - private string _Entries = "entries"; - private string _CacheFolderName; private string _ContentTypes = "content_types"; #endregion diff --git a/Contentstack.Core/Internals/ContentstackConvert.cs b/Contentstack.Core/Internals/ContentstackConvert.cs index 0d42809..13dc24f 100644 --- a/Contentstack.Core/Internals/ContentstackConvert.cs +++ b/Contentstack.Core/Internals/ContentstackConvert.cs @@ -326,7 +326,7 @@ public static bool GetResponseTimeFromCacheFile(string filePath, long responseTi } } - catch (Exception e) + catch { //showLog("appUtils", "------------getJsonFromFilec catch-|" + e.toString()); return false; diff --git a/Contentstack.Core/Internals/HTTPRequestHandler.cs b/Contentstack.Core/Internals/HTTPRequestHandler.cs index cfc3de6..f636209 100644 --- a/Contentstack.Core/Internals/HTTPRequestHandler.cs +++ b/Contentstack.Core/Internals/HTTPRequestHandler.cs @@ -38,13 +38,13 @@ public async Task ProcessRequest(string Url, Dictionary var request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "application/json"; - request.Headers["user-agent"]="DOTNET 1.0.0"; + request.Headers["user-agent"]="DOTNET 1.1.0"; if (Headers != default(IDictionary)) { foreach (var header in Headers) { try { request.Headers[header.Key] = header.Value.ToString(); - } catch (Exception e) { + } catch { } } diff --git a/Contentstack.Core/Internals/StackOutput.cs b/Contentstack.Core/Internals/StackOutput.cs index 3c5ec26..7ae139b 100644 --- a/Contentstack.Core/Internals/StackOutput.cs +++ b/Contentstack.Core/Internals/StackOutput.cs @@ -15,13 +15,13 @@ internal class StackOutput private object _Output = default(object); private Dictionary _ObjectAttributes = new Dictionary(); private object _Schema = default(object); - private object _Stack = default(object); - private object _ContentType = default(object); - private object _ContentTypes = default(object); + //private object _Stack = default(object); + //private object _ContentType = default(object); + //private object _ContentTypes = default(object); private object _Object = default(object); private object _Objects = default(object); - private object _Asset = default(object); - private object _Assets = default(object); + //private object _Asset = default(object); + //private object _Assets = default(object); private object _Result = default(object); private object _ApplicationUser = default(object); private object _Tags = default(object); diff --git a/Contentstack.Net.sln b/Contentstack.Net.sln index dd07403..b6da882 100644 --- a/Contentstack.Net.sln +++ b/Contentstack.Net.sln @@ -132,6 +132,6 @@ Global $0.XmlFormattingPolicy = $9 $9.scope = application/xml $0.StandardHeader = $10 - version = 0.0.1 + version = 1.1.0 EndGlobalSection EndGlobal diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5180831 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2012-2019 Contentstack (http://app.contentstack.com). All Rights Reserved + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 782eb1d..c00d11f --- a/README.md +++ b/README.md @@ -1,113 +1,103 @@ -[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/) -# Contentstack dotnet - -.NET SDK for Contentstack's Content Delivery API - -## Getting Started - -This guide will help you get started with our .NET SDK to build apps powered by Contentstack. - -## SDK Installation and Setup - -To use the .NET SDK, download it from here - -Open the terminal and install the contentstack module via ‘Package Manager’ command - -``` console -PM> Install-Package contentstack.csharp -``` -And via ‘.Net CLI’ -``` console -dotnet add package contentstack.csharp -``` -To use the module in your application, you need to first Add Namespace to your class - -``` cs -using Contentstack.Core; // ContentstackClient -using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType -using Contentstack.Core.Configuration; // ContentstackOptions -``` - -## Initialize SDK - -You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK: - -``` cs -// Initialize the Contentstack -ContentstackClient stack = new ContentstackClient("api_key", "access_token", "enviroment_name"); -``` -or: - -``` cs -// -var options = new ContentstackOptions() -{ - ApiKey = "", - AccessToken = "" - Environment = "" -} -ContentstackClient stack = new ContentstackClient(options); -``` - -Once you have initialized the SDK, you can start getting content in your app. - -## Basic Queries - -### Get a Single Entry - -To retrieve a single entry from a content type, use the code snippet given below: -``` cs -Entry entry = client.ContentType("blog").Entry("blta464e9fbd048668c"); -entry.Fetch().ContinueWith((t) => { - if (!t.IsFaulted) { - Console.WriteLine("entry:" + t.Result); - } -}); -``` - -### Get Multiple Entries - -To retrieve multiple entries of a particular content type, use the code snippet given below: - -``` cs - -Query query = client.ContentType("blog").Query(); -query.Where("title", "welcome"); -query.IncludeSchema(); -query.IncludeCount(); -query.ToJSON(); -query.Find().ContinueWith((t) => { - if (!t.IsFaulted) { - Entry[] result = t.Result.Result; - Console.WriteLine("result" + result); - } -}); -``` -These were example of some of the basic queries of the SDK. For advanced queries, refer to our API reference documentation by visiting the link given below. - -## API Reference -Go through our .NET SDK API Reference guide to know about the methods that can be used to query your content in Contentstack. - -[Read .NET API Reference Guide](https://www.contentstack.com/docs/platforms/dot-net/api-reference/api/index.html) - -## Example -To help you get started, we have created a sample application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app. - -[.NET News Console App](https://www.contentstack.com/docs/example-apps/build-a-news-app-using-contentstack-dot-net-sdk) - - -### Helpful Links - -- [Contentstack Website](https://www.contentstack.com) -- [Official Documentation](https://contentstack.com/docs) -- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) - -### The MIT License (MIT) - -Copyright © 2012-2018 [Contentstack](https://www.contentstack.com/). All Rights Reserved - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/) +# Contentstack dotnet + +.NET SDK for Contentstack's Content Delivery API + +## Getting Started + +This guide will help you get started with our .NET SDK to build apps powered by Contentstack. + +## SDK Installation and Setup + +To use the .NET SDK, download it from here + +Open the terminal and install the contentstack module via ‘Package Manager’ command + +``` console +PM> Install-Package contentstack.csharp +``` +And via ‘.Net CLI’ +``` console +dotnet add package contentstack.csharp +``` +To use the module in your application, you need to first Add Namespace to your class + +``` cs +using Contentstack.Core; // ContentstackClient +using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType +using Contentstack.Core.Configuration; // ContentstackOptions +``` + +## Initialize SDK + +You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK: + +``` cs +// Initialize the Contentstack +ContentstackClient stack = new ContentstackClient("api_key", "access_token", "enviroment_name"); +``` +or: + +``` cs +// +var options = new ContentstackOptions() +{ + ApiKey = "", + AccessToken = "" + Environment = "" +} +ContentstackClient stack = new ContentstackClient(options); +``` + +Once you have initialized the SDK, you can start getting content in your app. + +## Basic Queries + +### Get a Single Entry + +To retrieve a single entry from a content type, use the code snippet given below: +``` cs +Entry entry = client.ContentType("blog").Entry("blta464e9fbd048668c"); +entry.Fetch().ContinueWith((t) => { + if (!t.IsFaulted) { + Console.WriteLine("entry:" + t.Result); + } +}); +``` + +### Get Multiple Entries + +To retrieve multiple entries of a particular content type, use the code snippet given below: + +``` cs + +Query query = client.ContentType("blog").Query(); +query.Where("title", "welcome"); +query.IncludeSchema(); +query.IncludeCount(); +query.ToJSON(); +query.Find().ContinueWith((t) => { + if (!t.IsFaulted) { + Entry[] result = t.Result.Result; + Console.WriteLine("result" + result); + } +}); +``` +These were example of some of the basic queries of the SDK. For advanced queries, refer to our API reference documentation by visiting the link given below. + +## API Reference +Go through our .NET SDK API Reference guide to know about the methods that can be used to query your content in Contentstack. + +[Read .NET API Reference Guide](https://www.contentstack.com/docs/platforms/dot-net/api-reference/api/index.html) + +## Example +To help you get started, we have created a sample application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app. + +[.NET News Console App](https://www.contentstack.com/docs/example-apps/build-a-news-app-using-contentstack-dot-net-sdk) + + +### Helpful Links + +- [Contentstack Website](https://www.contentstack.com) +- [Official Documentation](https://contentstack.com/docs) +- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) diff --git a/docfx_project/Template/styles/main.css b/docfx_project/Template/styles/main.css new file mode 100644 index 0000000..688095a --- /dev/null +++ b/docfx_project/Template/styles/main.css @@ -0,0 +1,75 @@ + +/* Custom Navbar + ------------------------------------------------------- */ +.navbar-inverse { + background-color: #ffffff; + opacity: 0.95; + border-color: #ffffff; +} +.navbar-inverse .navbar-brand { + color: #ffffff; +} +.navbar-inverse .navbar-brand:hover, +.navbar-inverse .navbar-brand:focus { + color: #ecdbff; +} +.navbar-inverse .navbar-text { + color: #ffffff; +} +.navbar-inverse .navbar-nav > li > a { + color: #000000; +} +.navbar-inverse .navbar-nav > li > a:hover, +.navbar-inverse .navbar-nav > li > a:focus { + color: #000000; +} +.navbar-inverse .navbar-nav > .active > a, +.navbar-inverse .navbar-nav > .active > a:hover, +.navbar-inverse .navbar-nav > .active > a:focus { + color: #000000; + background-color: #ffffff; +} +.navbar-inverse .navbar-nav > .open > a, +.navbar-inverse .navbar-nav > .open > a:hover, +.navbar-inverse .navbar-nav > .open > a:focus { + color: #000000; + background-color: #ffffff; +} +.navbar-inverse .navbar-toggle { + border-color: #ffffff; +} +.navbar-inverse .navbar-toggle:hover, +.navbar-inverse .navbar-toggle:focus { + background-color: #ffffff; +} +.navbar-inverse .navbar-toggle .icon-bar { + background-color: #ffffff; +} +.navbar-inverse .navbar-collapse, +.navbar-inverse .navbar-form { + border: none; +} +.navbar-inverse .navbar-link { + color: #ffffff; +} +.navbar-inverse .navbar-link:hover { + color: #ecdbff; +} +svg:hover path { + fill: #444444; +} +@media (max-width: 767px) { + .navbar-inverse .navbar-nav .open .dropdown-menu > li > a { + color: #ffffff; + } + .navbar-inverse .navbar-nav .open .dropdown-menu > li > a:hover, + .navbar-inverse .navbar-nav .open .dropdown-menu > li > a:focus { + color: #ecdbff; + } + .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a, + .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a:hover, + .navbar-inverse .navbar-nav .open .dropdown-menu > .active > a:focus { + color: #ecdbff; + background-color: #ffffff; + } +} \ No newline at end of file diff --git a/docfx_project/api/index.md b/docfx_project/api/index.md new file mode 100644 index 0000000..5e4a298 --- /dev/null +++ b/docfx_project/api/index.md @@ -0,0 +1,54 @@ + +# Contentstack - .Net SDK + +.NET SDK for Contentstack's Content Delivery API + +Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/). + +For more details about the namespaces and classes navigate menu to left. + +## Prerequisites + +To get started with C#, you will need: + +.net platform, IDE (Visual Studio) and NuGet. + +## SDK installation and setup + +The .Net SDK provided by contentstack.io is available for Xamarin, Windows Phone and legacy .Net applications. You can integrate contentstack with your application by following these steps. + +Open the terminal and install the contentstack module via 'Package Manager' command + +And via ‘.Net CLI’ + +To use the module in your application, you need to first Add Namespace to your class + +## Initialize SDK + +You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK: + +or: + +Once you have initialized the SDK, you can start getting content in your app. + +## Basic Queries + +### Get a Single Entry + +To retrieve a single entry from a content type, use the code snippet given below: + +### Get Multiple Entries + +To retrieve multiple entries of a particular content type, use the code snippet given below: + +## Example + +To help you get started, we have created a sample console application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app. + +[.NET News Console App](https://contentstack.com/docs/example-apps/build-a-news-app-using-contentstack-dot-net-sdk) + +## Helpful Links + +- [Contentstack Website](https://www.contentstack.com/) +- [Official Documentation](https://contentstack.com/docs) +- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) diff --git a/docfx_project/api/toc.yml b/docfx_project/api/toc.yml new file mode 100644 index 0000000..b73a62e --- /dev/null +++ b/docfx_project/api/toc.yml @@ -0,0 +1,31 @@ +### YamlMime:TableOfContent +- uid: Contentstack.AspNetCore + name: Contentstack.AspNetCore + items: + - uid: Contentstack.AspNetCore.IServiceCollectionExtensions + name: IServiceCollectionExtensions +- uid: Contentstack.Core + name: Contentstack.Core + items: + - uid: Contentstack.Core.ContentstackClient + name: ContentstackClient +- uid: Contentstack.Core.Internals + name: Contentstack.Core.Internals + items: + - uid: Contentstack.Core.Internals.CachePolicy + name: CachePolicy + - uid: Contentstack.Core.Internals.Language + name: Language +- uid: Contentstack.Core.Models + name: Contentstack.Core.Models + items: + - uid: Contentstack.Core.Models.ContentType + name: ContentType + - uid: Contentstack.Core.Models.Entry + name: Entry + - uid: Contentstack.Core.Models.Query + name: Query + - uid: Contentstack.Core.Models.SyncStack + name: SyncStack + - uid: Contentstack.Core.Models.SyncType + name: SyncType diff --git a/docfx_project/docfx.json b/docfx_project/docfx.json new file mode 100644 index 0000000..c58b504 --- /dev/null +++ b/docfx_project/docfx.json @@ -0,0 +1,68 @@ +{ + "metadata": [ + { + "src": [ + { + "files": [ + "src/**.csproj" + ] + } + ], + "dest": "api", + "disableGitFeatures": false, + "disableDefaultFilter": false, + "filter": "filterRules.yml" + + } + ], + "build": { + "content": [ + { + "files": [ + "toc.yml", + "index.md", + "api/**.yml", + "api/index.md" + ] + } + ], + "resource": [ + { + "files": [ + "images/**" + ] + } + ], + "overwrite": [ + { + "files": [ + "apidoc/**.md" + ], + "exclude": [ + "obj/**", + "_site/**" + ] + } + ], + "globalMetadata": { + "_appTitle": "Contentstack - .NET SDK Documentation", + "_appLogoPath": "images/logo.svg", + "_appFaviconPath": "images/favicon.ico", + "_appFooter": "Copyright © 2012-2019 Contentstack. All Rights Reserved", + "_enableSearch": "true" + }, + "dest": "_site", + "globalMetadataFiles": [], + "fileMetadataFiles": [], + "template": [ + "default", + "Template" + ], + "postProcessors": [], + "markdownEngineName": "markdig", + "noLangKeyword": false, + "keepFileLink": false, + "cleanupCacheHistory": false, + "disableGitFeatures": false + } +} \ No newline at end of file diff --git a/docfx_project/filterRules.yml b/docfx_project/filterRules.yml new file mode 100644 index 0000000..7ec1f19 --- /dev/null +++ b/docfx_project/filterRules.yml @@ -0,0 +1,24 @@ +apiRules: +- exclude: + uidRegex: ^Contentstack\.Core\.Tests +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.ResponseType + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.OrderBy + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.NetworkStatus + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.HttpMethods + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Internals\.ContentstackError + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Configuration + type: Class +- exclude: + uidRegex: ^Contentstack\.Core\.Models\.AssetLibrary + type: Class \ No newline at end of file diff --git a/docfx_project/images/favicon.ico b/docfx_project/images/favicon.ico new file mode 100755 index 0000000..a1c0f9f Binary files /dev/null and b/docfx_project/images/favicon.ico differ diff --git a/docfx_project/images/logo.svg b/docfx_project/images/logo.svg new file mode 100755 index 0000000..280c8cc --- /dev/null +++ b/docfx_project/images/logo.svg @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docfx_project/index.md b/docfx_project/index.md new file mode 100644 index 0000000..5e4a298 --- /dev/null +++ b/docfx_project/index.md @@ -0,0 +1,54 @@ + +# Contentstack - .Net SDK + +.NET SDK for Contentstack's Content Delivery API + +Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/). + +For more details about the namespaces and classes navigate menu to left. + +## Prerequisites + +To get started with C#, you will need: + +.net platform, IDE (Visual Studio) and NuGet. + +## SDK installation and setup + +The .Net SDK provided by contentstack.io is available for Xamarin, Windows Phone and legacy .Net applications. You can integrate contentstack with your application by following these steps. + +Open the terminal and install the contentstack module via 'Package Manager' command + +And via ‘.Net CLI’ + +To use the module in your application, you need to first Add Namespace to your class + +## Initialize SDK + +You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK: + +or: + +Once you have initialized the SDK, you can start getting content in your app. + +## Basic Queries + +### Get a Single Entry + +To retrieve a single entry from a content type, use the code snippet given below: + +### Get Multiple Entries + +To retrieve multiple entries of a particular content type, use the code snippet given below: + +## Example + +To help you get started, we have created a sample console application that is powered by Contentstack .NET SDK. Click on the link below to read the tutorial of the app. + +[.NET News Console App](https://contentstack.com/docs/example-apps/build-a-news-app-using-contentstack-dot-net-sdk) + +## Helpful Links + +- [Contentstack Website](https://www.contentstack.com/) +- [Official Documentation](https://contentstack.com/docs) +- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/) diff --git a/docfx_project/toc.yml b/docfx_project/toc.yml new file mode 100644 index 0000000..5990d63 --- /dev/null +++ b/docfx_project/toc.yml @@ -0,0 +1,3 @@ +- name: Api Documentation + href: api/ + homepage: api/index.md \ No newline at end of file