Пример #1
0
        public Person createPerson(
            string firstName,
            string lastName,
            string middleName,
            int?id                        = null,
            bool isAdmin                  = false,
            bool isLockedOut              = false,
            string username               = null,
            string password               = null,
            bool encryptPassword          = false,
            string credentials            = null,
            string nickname               = null,
            string badgeNumber            = null,
            string externalId             = null,
            ExternalSystem system         = null,
            DateTime?added                = null,
            Dictionary <int, string> UDFs = null,
            EntityAction action           = EntityAction.InsertOnSubmit
            )
        {
            var entity = Factory.CreatePerson(firstName, lastName, middleName, id, isAdmin, isLockedOut, username, password, encryptPassword, credentials, nickname, badgeNumber, added, UDFs);

            DbAction(entity, action);

            if (!string.IsNullOrWhiteSpace(externalId) && system != null && action == EntityAction.InsertAndSubmit)
            {
                var keys = CreateExternalApplicationKey(EntityType.Person, externalId, system.Id, entity.Id);
                DbAction(keys, action);
            }

            return(entity);
        }
Пример #2
0
 public S2Importer(string connStr, S2API api)
 {
     db           = new RSMDataModelDataContext(connStr);
     _api         = api;
     ExportSystem = api.ExportSystem;
     ImportSystem = api.ImportSystem;
 }
Пример #3
0
        public static Setting CreateSetting(
            int id,
            string name,
            string label,
            string value,
            int orderBy           = 0,
            bool viewable         = true,
            string inputType      = InputTypes.Text,
            ExternalSystem system = null
            )
        {
            var entity = new Setting
            {
                Id             = id,
                Name           = name,
                Label          = label,
                Value          = value,
                OrderBy        = orderBy,
                Viewable       = viewable,
                InputType      = inputType,
                ExternalSystem = system,
                SystemId       = (system == null ? default(int) : system.Id)
            };

            return(entity);
        }
Пример #4
0
        protected override void Seed(InstrumEntitiesContext context)
        {
            new List <Instrument>
            {
                new Instrument {
                    Id = new Guid("1D37D829-AA79-4A26-911A-6AC68743F233"), Name = new InstrumentName()
                    {
                        Name = "Volvo B"
                    }, ISIN = "S12345678910", MIC = "XSTO", CurrencyCode = "SEK", LifeCycleStatus = 1
                },
                new Instrument {
                    Id = new Guid("6D37D829-AA79-4A26-911A-6AC68743F233"), Name = new InstrumentName()
                    {
                        Name = "Volvo B"
                    }, ISIN = "S12345678910", MIC = "XSTO", CurrencyCode = "SEK", LifeCycleStatus = 1
                }
            }.ForEach(x => context.Instruments.Add(x));

            new List <InstrumentSubscription>
            {
                new InstrumentSubscription {
                    InstrumentId = new Guid("3D37D829-AA79-4A26-911A-6AC68743F233"), SystemId = new Guid("2D37D829-AA79-4A26-911A-6AC68743F233")
                }
            }.ForEach(instrumentSubscription => context.InstrumentSubscriptions.Add(instrumentSubscription));

            var portiaSystem = new ExternalSystem {
                Id = new Guid("5D37D829-AA79-4A26-911A-6AC68743F233")
            };

            context.ExternalSystems.Add(portiaSystem);

            context.SaveChanges();
        }
Пример #5
0
        // PUT api/ExternalSystem/5
        public IHttpActionResult PutExternalSystem(int id, ExternalSystem externalsystem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != externalsystem.ExternalSystemId)
            {
                return(BadRequest());
            }

            db.Entry(externalsystem).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExternalSystemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #6
0
 public S2Importer(S2API api)
 {
     db           = new RSMDataModelDataContext();
     _api         = api;
     ExportSystem = api.ExportSystem;
     ImportSystem = api.ImportSystem;
 }
        public async Task <ExternalSystem> AddOrUpdate(ExternalSystem externalSystem)
        {
            var externalSystemDbo = await _externalSystemRepository.Get(externalSystem.Id);

            externalSystemDbo = _mapper.Map(externalSystem, externalSystemDbo);

            return(_mapper.Map <ExternalSystem>(await _externalSystemRepository.AddOrUpdate(externalSystemDbo)));
        }
Пример #8
0
 public BosiStatusModel(ExternalSystem system, Severity severity, DateTime lastAction)
 {
     SystemId     = system.Id;
     SystemName   = system.Name;
     Direction    = (ExternalSystemDirection)system.Direction;
     Severity     = (int)severity;
     SeverityName = LogEntry.GetSeverityName(severity);
     LastAction   = lastAction;
 }
Пример #9
0
        public static ExternalSystem ToModel(this RSMDB.ExternalSystem from, ExternalSystem existing = null)
        {
            var entity = existing == null ? new ExternalSystem() : existing;

            entity.Id        = from.Id;
            entity.Name      = from.Name;
            entity.Direction = (RSMDB.ExternalSystemDirection)from.Direction;

            return(entity);
        }
Пример #10
0
        public IHttpActionResult GetExternalSystem(int id)
        {
            ExternalSystem externalsystem = db.ExternalSystems.Find(id);

            if (externalsystem == null)
            {
                return(NotFound());
            }

            return(Ok(externalsystem));
        }
Пример #11
0
        public bool ValidateCredential(ExternalSystem system, NetworkCredential credential)
        {
            switch (system)
            {
            case ExternalSystem.Bricklink:
                return(_bricklinkLoginApi.Login(new CookieContainer(), credential.UserName, credential.Password));

            default:
                throw new NotSupportedException(string.Format("The system {0} is not supported", system));
            }
        }
Пример #12
0
        private BosiStatusModel CreateBosiStatusModel(ExternalSystem system, BatchHistory batch, Severity severity)
        {
            var defaultDate = DateTime.Parse("01/01/1970");

            var count = EventLogger.CountLogEntriesWithStatus(system.Id, severity, batch == null ? defaultDate : batch.RunEnd);

            return(count > 0 ? new BosiStatusModel(system, severity, batch)
            {
                LogCount = count
            } : null);
        }
Пример #13
0
        public IHttpActionResult PostExternalSystem(ExternalSystem externalsystem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ExternalSystems.Add(externalsystem);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = externalsystem.ExternalSystemId }, externalsystem));
        }
Пример #14
0
        public void ExternalSystem_Get()
        {
            var criteria = new ExternalSystem {
                Id = S2In.Id
            };
            var result = criteria.Get();

            Assert.IsNotNull(result, "Missing results");
            Assert.IsTrue(result.Succeeded, result.ToString());
            Assert.IsNotNull(result.Entity, "Missing entity");
            Assert.IsTrue(result.Entity.EntityType == S2In.EntityType, "EntityType mismatch");
        }
Пример #15
0
        public IHttpActionResult DeleteExternalSystem(int id)
        {
            ExternalSystem externalsystem = db.ExternalSystems.Find(id);

            if (externalsystem == null)
            {
                return(NotFound());
            }

            db.ExternalSystems.Remove(externalsystem);
            db.SaveChanges();

            return(Ok(externalsystem));
        }
Пример #16
0
        public void SetCredential(ExternalSystem system, NetworkCredential credential)
        {
            var serializer = new TypedXmlSerializer <SerializableNetworkCredential>();
            var temp       = new SerializableNetworkCredential
            {
                UserName = credential.UserName,
                Password = credential.Password,
                Domain   = credential.Domain
            };

            var data = serializer.SerializeToString(temp);

            _appDataService.WriteAppData(GetAppDataKey(system), data);
        }
Пример #17
0
        public static ExternalSystem CreateExternalSystem(
            int id,
            string name,
            ExternalSystemDirection direction
            )
        {
            var entity = new ExternalSystem
            {
                Id        = id,
                Name      = name,
                Direction = (int)direction
            };

            return(entity);
        }
Пример #18
0
        public NetworkCredential GetCredential(ExternalSystem system)
        {
            var appData = _appDataService.GetAppData(GetAppDataKey(system));

            if (string.IsNullOrWhiteSpace(appData))
            {
                return(null);
            }

            var serializer = new TypedXmlSerializer <SerializableNetworkCredential>();
            var temp       = serializer.Deserialize(appData);
            var result     = new NetworkCredential(temp.UserName, temp.Password, temp.Domain);

            return(result);
        }
Пример #19
0
            public override Result <Task.Config> Load()
            {
                var result   = base.Load();
                var settings = new TaskSettings(Task);

                Link     = settings.GetValue(Config.LinkName);
                Username = settings.GetValue(Config.UserName);
                Password = settings.GetValue(Config.PasswordName);

                var systemId = settings.GetIntValue(Config.SourceSystemName);
                var criteria = new ExternalSystem {
                    Id = systemId
                };
                var system = criteria.Get();

                if (system.Failed)
                {
                    return(result.Fail(Task.LogError("source system id {0} not found.", systemId.ToString())));
                }

                SourceSystem = system.Entity;

                ExportPerson       = settings.GetBoolValue(Config.ExportPersonName);
                ExportAccessEvents = settings.GetBoolValue(Config.ExportAccessEventsName);
                ExportCompany      = settings.GetBoolValue(Config.ExportCompanyName);

                var companies = settings.GetValue(Config.ExportCompaniesName);

                ExportCompanies = !string.IsNullOrWhiteSpace(companies) ? companies.Split(',') : new string[0];

                var from = settings.GetValue(Config.LastEventName);

                if (from == null)
                {
                    return(result.Fail(Task.LogError("last event setting {0} not found.", Config.LastEventName)));
                }

                DateTime date;

                LastEvent = ((from.Trim().Length == 0) || !DateTime.TryParse(from, out date))
                                        ? DateTime.Now.Subtract(TimeSpan.FromDays(30)) : date;

                result.Entity = this;

                return(result);
            }
Пример #20
0
            public override Result <Task.Config> Load()
            {
                var result = base.Load();

                var settings = new TaskSettings(Task);

                Link         = settings.GetValue(Config.LinkName);
                Username     = settings.GetValue(Config.UserName);
                Password     = settings.GetValue(Config.PasswordName);
                LastUpdated  = settings.GetDateValue(Config.LastUpdatedName);
                LastUpdated  = (LastUpdated == DateTime.MinValue) ? DateTime.Now.Subtract(TimeSpan.FromDays(1095)) : LastUpdated;
                SourceSystem = settings.GetExternalSystem(Config.SourceSystemName);

                result.Entity = this;

                return(result);
            }
Пример #21
0
        public async Task should_get_forbidden_if_cookie_does_not_match()
        {
            const string notMatchedToken = "not_matched_token";

            ExternalSystem
            .WithService(BaseAddress)
            .Api($"session/{notMatchedToken}", HttpStatusCode.NotFound, "get session");

            var request = new HttpRequestMessage(HttpMethod.Get, "/");

            request.Headers.Add("Cookie", $"X-Session-Token={notMatchedToken}");

            HttpResponseMessage response = await Client.SendAsync(request);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
            ExternalSystem["get session"].VerifyHasBeenCalled();
        }
Пример #22
0
        public Person CreatePerson(
            string extId,
            ExternalSystem system,
            string firstName,
            string lastName,
            string middleName             = null,
            DateTime?added                = null,
            DateTime?externalUpdated      = null,
            Dictionary <int, string> UDFs = null
            )
        {
            var entity = Factory.CreatePerson(extId, system);

            entity.FirstName       = firstName;
            entity.LastName        = lastName;
            entity.MiddleName      = middleName;
            entity.Added           = added != null ? (DateTime)added : entity.Added;
            entity.ExternalUpdated = externalUpdated != null ? (DateTime)externalUpdated : entity.ExternalUpdated;

            if (UDFs != null)
            {
                entity.udf1  = UDFs.ContainsKey(1) ? UDFs[1] : null;
                entity.udf2  = UDFs.ContainsKey(2) ? UDFs[2] : null;
                entity.udf3  = UDFs.ContainsKey(3) ? UDFs[3] : null;
                entity.udf4  = UDFs.ContainsKey(4) ? UDFs[4] : null;
                entity.udf5  = UDFs.ContainsKey(5) ? UDFs[5] : null;
                entity.udf6  = UDFs.ContainsKey(6) ? UDFs[6] : null;
                entity.udf7  = UDFs.ContainsKey(7) ? UDFs[7] : null;
                entity.udf8  = UDFs.ContainsKey(8) ? UDFs[8] : null;
                entity.udf9  = UDFs.ContainsKey(9) ? UDFs[9] : null;
                entity.udf10 = UDFs.ContainsKey(10) ? UDFs[10] : null;
                entity.udf11 = UDFs.ContainsKey(11) ? UDFs[11] : null;
                entity.udf12 = UDFs.ContainsKey(12) ? UDFs[11] : null;
                entity.udf13 = UDFs.ContainsKey(13) ? UDFs[13] : null;
                entity.udf14 = UDFs.ContainsKey(14) ? UDFs[14] : null;
                entity.udf15 = UDFs.ContainsKey(15) ? UDFs[15] : null;
                entity.udf16 = UDFs.ContainsKey(16) ? UDFs[16] : null;
                entity.udf17 = UDFs.ContainsKey(17) ? UDFs[17] : null;
                entity.udf18 = UDFs.ContainsKey(18) ? UDFs[18] : null;
                entity.udf19 = UDFs.ContainsKey(19) ? UDFs[19] : null;
                entity.udf20 = UDFs.ContainsKey(20) ? UDFs[20] : null;
            }

            return(entity);
        }
Пример #23
0
        public async Task should_redirect_to_login_page_if_not_authorized()
        {
            const string notMatchedToken = "not_matched_token";

            ExternalSystem
            .WithService(BaseAddress)
            .Api($"session/{notMatchedToken}", HttpStatusCode.NotFound, "get session");

            var request = new HttpRequestMessage(HttpMethod.Get, "unauthorized/ok");

            request.Headers.Add("Cookie", $"X-Session-Token={notMatchedToken}");

            HttpResponseMessage response = await Client.SendAsync(request);

            Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
            Assert.Equal($"{BaseAddress}/login.html", response.Headers.Location.AbsoluteUri);
            ExternalSystem["get session"].VerifyHasBeenCalled();
        }
Пример #24
0
        public Setting createSetting(
            int id,
            string name,
            string label,
            string value,
            int orderBy           = 0,
            bool viewable         = true,
            string inputType      = InputTypes.Text,
            ExternalSystem system = null,
            EntityAction action   = EntityAction.InsertOnSubmit
            )
        {
            var entity = Factory.CreateSetting(id, name, label, value, orderBy, viewable, inputType, system);

            DbAction(entity, action);

            return(entity);
        }
Пример #25
0
        public Setting createSetting(
            ExternalSystem system,
            string prefix,
            Setting model,
            string value        = null,
            string inputType    = null,
            EntityAction action = EntityAction.InsertOnSubmit
            )
        {
            var entity = createSetting(model.Name, model.Label,
                                       value != null ? value : model.Value,
                                       prefix, model.OrderBy, model.Viewable,
                                       inputType != null ? inputType : model.InputType,
                                       system, action);

            DbAction(entity, action);

            return(entity);
        }
        public async Task <ActionResult> AddOrUpdate([FromBody] ExternalSystem externalSystem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var result = await _externalSystemStrategy.AddOrUpdate(externalSystem);

                return(Ok(result));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                throw;
            }
        }
Пример #27
0
        private static ApiUser MapApiUser(ExternalSystem externalSystem)
        {
            var externalSystemPermission = externalSystem.ExternalSystemPermission;

            var apiUser = new ApiUser
            {
                ExternalSystemId       = externalSystemPermission.Username,
                CompanyId              = externalSystemPermission.Company,
                BusinessCategory       = (ApiBusinessCategory)Enum.Parse(typeof(ApiBusinessCategory), externalSystemPermission.Businesscategory),
                EmployeeType           = (ApiEmployeeType)Enum.Parse(typeof(ApiEmployeeType), externalSystemPermission.Employeetype),
                AuthorisedApiEndpoints = externalSystemPermission.UserParameters.Split(',').Where(s => ApiEndpointsMap.ContainsKey(s)).Select(s => ApiEndpointsMap[s]).ToList(),
                FullName      = externalSystemPermission.FullName,
                TradingName   = externalSystemPermission.TradingName,
                ContactName   = externalSystem.ContactName,
                ContactEmail  = externalSystem.ContactEmail,
                ContactNumber = externalSystem.ContactNumber,
            };

            return(apiUser);
        }
Пример #28
0
        public BosiStatusModel(ExternalSystem system, Severity severity, BatchHistory lastBatch)
        {
            var defaultDate = DateTime.Parse("01/01/1970");

            SystemId     = system.Id;
            SystemName   = system.Name;
            Direction    = (ExternalSystemDirection)system.Direction;
            Severity     = (int)severity;
            SeverityName = LogEntry.GetSeverityName(severity);

            if (lastBatch == null)
            {
                LastAction = defaultDate;
                Outcome    = BatchOutcome.Success;
                Message    = "Success";
            }
            else
            {
                LastAction = lastBatch.RunEnd;
                Outcome    = BatchOutcome.DataError;
                Message    = lastBatch.Message;
            }
        }
Пример #29
0
        public Setting createSetting(
            string name,
            string label,
            string value,
            string prefix         = null,
            int orderBy           = 0,
            bool viewable         = true,
            string inputType      = InputTypes.Text,
            ExternalSystem system = null,
            EntityAction action   = EntityAction.InsertOnSubmit
            )
        {
            if (!string.IsNullOrEmpty(prefix))
            {
                name = string.Format("{0}.{1}", prefix, name);
            }

            var entity = Factory.CreateSetting(name, label, value, orderBy, viewable, inputType, system);

            DbAction(entity, action);

            return(entity);
        }
Пример #30
0
        public static bool IsAuthorized <T>(
            OrationiDatabaseContext dbContext,
            string token,
            Guid messageId,
            out T response,
            out ExternalSystem externalSystem)
            where T : ResponseBase, new()
        {
            var message = dbContext.Messages.FirstOrDefault(m => m.Id == messageId);

            if (message is null)
            {
                response = new T
                {
                    IsError = true,
                    Error   = $"Request {messageId} not found"
                };
                externalSystem = null;
                return(false);
            }

            return(IsAuthorized <T>(dbContext, token, message.RequestCodeId, out response, out externalSystem));
        }