public string GetPublishingSystem(string publishingSystemName, string environmentType, string systemType)
        {
            var user = _uow.Repository <AspNetUser>().FirstOrDefault(x => x.Email == RequestContext.Principal.Identity.Name);

            if (user == null)
            {
                return($"Unable to find a user with the credentials in the current context.");
            }

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

            // 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)
            {
                var publishingSystemModel = new PublishingSystem
                {
                    EnvironmentTypeId      = environmentTypeObj.Id,
                    PublishingSystemTypeId = systemTypeObj.Id,
                    Name = publishingSystemName
                };

                var publishingSystemOwnerModel = new PublishingSystemOwner
                {
                    UserId           = user.Id,
                    PublishingSystem = publishingSystemModel
                };

                _uow.Repository <PublishingSystemOwner>().Put(publishingSystemOwnerModel);

                _uow.Commit();

                pSystem = _uow.Repository <PublishingSystem>().FirstOrDefault(x =>
                                                                              x.Name == publishingSystemName && x.EnvironmentTypeId == environmentTypeObj.Id &&
                                                                              x.PublishingSystemTypeId == systemTypeObj.Id);
            }

            var publishingSystem = new PublishingSystem
            {
                Id = pSystem.Id,
                EnvironmentTypeId      = pSystem.EnvironmentTypeId,
                PublishingSystemTypeId = pSystem.PublishingSystemTypeId,
                Name = pSystem.Name
            };

            var result = JsonConvert.SerializeObject(publishingSystem,
                                                     new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            // return the publishing system
            return(result);
        }
예제 #2
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;
        }