Example #1
0
        // ===========
        // Constructor
        // ===========

        /// <summary>
        /// LogSender constructor.
        /// </summary>
        /// <param name="environmentType">The environment type of this publishing system. (DEV, SIT, UAT or LIVE).</param>
        /// <param name="systemType">The type of this publishing system. (REST, SOAP, Website, WindowsService, ConsoleApplication, Other)</param>
        /// <param name="publishingSystemName">The name of the publishing system.</param>
        public LogSender(StaticData.EnvironmentType environmentType, StaticData.SystemType systemType, string publishingSystemName = "")
        {
            _publishingSystem = string.IsNullOrEmpty(publishingSystemName)
                ? GetPublishingSystem(Assembly.GetCallingAssembly().GetName().Name, environmentType, systemType).Result
                : GetPublishingSystem(publishingSystemName, environmentType, systemType).Result;
        }
Example #2
0
        /// <summary>
        /// Gets the publishing system info from the CLS Database, if it doesn't exist then it will be created.
        /// </summary>
        /// <param name="publishingSystemName">The name of the publishing system.</param>
        /// <param name="environmentType">The environment type of this publishing system. (DEV, SIT, UAT or LIVE).</param>
        /// <param name="systemType">The type of this publishing system. (REST, SOAP, Website, WindowsService, ConsoleApplication, Other)</param>
        /// <returns>The publishing system object from the CLS Web Service/Database.</returns>
        private static async Task <PublishingSystem> GetPublishingSystem(
            string publishingSystemName,
            StaticData.EnvironmentType environmentType,
            StaticData.SystemType systemType)
        {
            if (UseWebService)
            {
                // HTTP GET
                using (var client = new HttpClient())
                {
                    // Setting Authorization
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", OAuthResponse.access_token);

                    // Setting Base address
                    client.BaseAddress = new Uri(Endpoint);

                    // Setting content type
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // Initialization

                    var requestString = $"CLS/PublishingSystem" +
                                        $"?publishingSystemName={publishingSystemName}" +
                                        $"&environmentType={environmentType}" +
                                        $"&systemType={systemType}";

                    // HTTP GET
                    var response = await client.GetAsync(requestString).ConfigureAwait(false);

                    // Verification
                    if (response.IsSuccessStatusCode)
                    {
                        var jsonResult = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result).ToString();
                        var model      = JsonConvert.DeserializeObject <PublishingSystem>(jsonResult, new JsonSerializerSettings
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        });
                        return(model);
                    }
                }

                return(null);
            }
            else
            {
                var uow = new UnitOfWork(new DBEntities());

                // get static data objects from database
                var environmentTypeObj =
                    uow.Repository <EnvironmentType>().First(x => x.Name == environmentType.ToString());
                var systemTypeObj = uow.Repository <PublishingSystemType>().First(x => x.Name == systemType.ToString());

                // check if publishing system exists in database
                var pSystem = uow.Repository <PublishingSystem>().FirstOrDefault(x =>
                                                                                 x.Name == publishingSystemName && x.EnvironmentTypeId == environmentTypeObj.Id &&
                                                                                 x.PublishingSystemTypeId == systemTypeObj.Id);

                // if the publishing system doesn't exist in the database then create it
                if (pSystem == null)
                {
                    pSystem = uow.Repository <PublishingSystem>().Put(new PublishingSystem
                    {
                        EnvironmentType      = environmentTypeObj,
                        PublishingSystemType = systemTypeObj,
                        Name = publishingSystemName
                    });
                    TryCommit(uow);
                }

                // return the publishing system
                return(pSystem);
            }
        }