public override void Seed(IDbContext context) { var organisation = new OrganisationSettings(); organisation.Names.Add(new LocalisedName { Language = CultureInfo.CurrentCulture.Name, Name = "Apira LTD" }); organisation.Urls.Add(new LocalisedName { Language = CultureInfo.CurrentCulture.Name, Name = "https://apira.co.uk/" }); var contact = new PersonContact { ContactType = Kernel.Federation.MetaData.Configuration.Organisation.ContactType.Technical, Forename = new LocalisedName { Name = "John", Language = CultureInfo.CurrentCulture.Name }, Surname = new LocalisedName { Name = "Murphy", Language = CultureInfo.CurrentCulture.Name }, }; contact.Emails.Add(new LocalisedName { Language = CultureInfo.CurrentCulture.Name, Name = "*****@*****.**" }); contact.Phones.Add(new Phone { Type = PhoneType.Working, Number = "020 xxx" }); contact.Organisations.Add(organisation); organisation.Contacts.Add(contact); Seeder._cache.Add(Seeder.Organisation, organisation); context.Add <OrganisationSettings>(organisation); }
public override void Seed(IDbContext context) { var organisation = new OrganisationSettings(); organisation.Names.Add(new LocalisedName { Language = CultureInfo.CurrentCulture.Name, Name = "Company name." }); organisation.Urls.Add(new LocalisedName { Language = CultureInfo.CurrentCulture.Name, Name = "https://company.co.uk/" }); var contact = new PersonContact { ContactType = Kernel.Federation.MetaData.Configuration.Organisation.ContactType.Technical, Forename = new LocalisedName { Name = "John", Language = CultureInfo.CurrentCulture.Name }, Surname = new LocalisedName { Name = "Doe", Language = CultureInfo.CurrentCulture.Name }, }; contact.Emails.Add(new LocalisedName { Language = CultureInfo.CurrentCulture.Name, Name = "*****@*****.**" }); contact.Phones.Add(new Phone { Type = PhoneType.Working, Number = "020 123 456" }); contact.Organisations.Add(organisation); organisation.Contacts.Add(contact); Seeder._cache.Add(Seeder.Organisation, organisation); context.Add <OrganisationSettings>(organisation); }
private List <string> ListMatchingUserName(string startsWith) { // To avoid lots of SQL calls here, we try to make use of caching as best we can // 1. Have we got a cached Dictionary to check yet? Dictionary <string, List <string> > dictionary = Cache[Globals.CacheKeys.UserNameDictionaryCacheEntry] as Dictionary <string, List <string> >; if (null == dictionary) // Create one { dictionary = new Dictionary <string, List <string> >(); } // 2. Do we have an entry in the dictionary already or do we have to fetch and store? List <string> resultList = null; if (dictionary.ContainsKey(startsWith)) { resultList = dictionary[startsWith]; } else { int?orgId = null; OrganisationSettings settings = new OrganisationSettings(); if (!string.IsNullOrEmpty(settings.OrganisationId)) { orgId = Convert.ToInt32(settings.OrganisationId); } resultList = ApartmentMethods.ListUserName(Membership.ApplicationName, orgId, startsWith); dictionary.Add(startsWith, resultList); Cache[Globals.CacheKeys.UserNameDictionaryCacheEntry] = dictionary; } return(resultList); }
/// <summary> /// Based on passed param, either use the authorisation code in UI to init a new org or /// check for a stored org cookie which would have originally been set up the same way. /// </summary> /// <param name="useNewAuthCode">When true, auth code control is used to init a new org.</param> private void InitOrganisation(bool useNewAuthCode) { // NOTE: Removed as it caused any security redirect to log off the user and they couldn't use Back button :-( //// Clear any current login so that there are no cross-org logins possible. //FormsAuthentication.SignOut(); //Roles.DeleteCookie(); //Cache[Globals.CacheKeys.ODS] = DateTime.Now.ToString(); OrganisationSettings settings = useNewAuthCode ? OrganisationSettings.Validate(_authorisationCode.Text) : new OrganisationSettings(); bool organisationIsValid = (null != settings && settings.IsValid); ToggleControlVisibility(organisationIsValid); // Clear the auth code textbox once the value has been validated or not found. _authorisationCode.Text = string.Empty; _organisationName.Text = organisationIsValid ? settings.OrganisationName : string.Empty; _organisationUnique.IsValid = organisationIsValid; //Clear the dictionary if (useNewAuthCode) { Dictionary <string, List <string> > dictionary = new Dictionary <string, List <string> >(); Cache[Globals.CacheKeys.UserNameDictionaryCacheEntry] = dictionary; } this.MainForm.DefaultButton = organisationIsValid ? _loginButton.UniqueID : _updateButton.UniqueID; Control focusControl = organisationIsValid ? _userNameCombo as Control : _authorisationCode; focusControl.Focus(); }
private static OrganisationConfiguration BuidOrganisationConfiguration(OrganisationSettings organisationSettings) { var orgConfiguration = new OrganisationConfiguration { OrganisationContacts = new ContactConfiguration() }; if (organisationSettings != null) { organisationSettings.Names.Aggregate(orgConfiguration.Names, (t, next) => { t.Add(new LocalizedConfigurationEntry { Name = next.Name, DisplayName = String.IsNullOrEmpty(next.DisplayName) ? next.Name : next.DisplayName, Language = new CultureInfo(next.Language) }); return(t); }); organisationSettings.Urls.Aggregate(orgConfiguration.Urls, (t, next) => { t.Add(new LocalizedUrlEntry { Url = new Uri(next.Name), Language = new CultureInfo(next.Language) }); return(t); }); organisationSettings.Contacts.Aggregate(orgConfiguration.OrganisationContacts.PersonContact, (t, next) => { var contact = new Kernel.Federation.MetaData.Configuration.Organisation.ContactPerson { ContactType = next.ContactType, ForeName = next.Forename.Name, SurName = next.Surname.Name, }; next.Emails.Aggregate(contact.Emails, (t1, next1) => { contact.Emails.Add(next1.Name); return(t1); }); next.Phones.Aggregate(contact.PhoneNumbers, (t2, next2) => { contact.PhoneNumbers.Add(next2.Number); return(t2); }); t.Add(contact); return(t); }); } return(orgConfiguration); }
public UserLogin GetUserLogin() { MembershipUser loginUser = Membership.GetUser(); UserLogin settings = new UserLogin(); if (loginUser != null) { settings.UserName = loginUser.UserName; settings.UserUserId = Utilities.ToGuid(loginUser.ProviderUserKey); //settings.UserSiteId = SiteMethods.GetSiteIdForEmployee(settings.UserUserId); //settings.UserLicenseKeys = General.ListLicenseKeyByUserId(settings.UserUserId); OrganisationSettings orgSetting = new OrganisationSettings(); settings.UserOrganisationId = Convert.ToInt32(orgSetting.OrganisationId); settings.UserOrganisation = ApartmentMethods.GetOrganisation(settings.UserOrganisationId); //settings.UserSite = settings.UserSiteId.HasValue ? SiteMethods.GetSite(settings.UserSiteId.Value) : null; //settings.ActiveModules = Role.ListActiveModules(); settings.AspUser = GetAspUser(settings.UserUserId); //settings.UserEmployeeId = EmployeeMethods.GetEmployeeId(settings.UserUserId); settings.RoleComponentPermissions = ApartmentMethods.ListRoleComponentPermissionByUser(settings.UserUserId); if (!settings.AspUser.OrganisationId.HasValue) { settings.UserRoleAuths = ApartmentMethods.ListUserRoleAuth(null, settings.UserUserId, null); } else { settings.UserRoleAuths = ApartmentMethods.ListUserRoleAuth(settings.UserOrganisationId, settings.UserUserId, null); } if (settings.UserSite == null && settings.UserRoleAuths != null && settings.UserRoleAuths.Count > 0 && settings.UserRoleAuths.Count(i => i.SiteId.HasValue) > 0) { settings.UserSiteId = settings.UserRoleAuths.FirstOrDefault(i => i.SiteId.HasValue).SiteId.Value; List <Site> sites = ApartmentMethods.ListSite(null, settings.UserSiteId.Value, true, false); if (sites.Count > 0) { settings.UserSite = sites[0]; } } } return(settings); }
// If we're using the combo, put combo value into the original username textbox so normal processing can occur private void Login1_LoggingIn(object sender, LoginCancelEventArgs e) { Login1.UserName = _userNameCombo.AllowCustomText && _userNameCombo.Value == string.Empty ? _userNameCombo.Text : _userNameCombo.Value; MembershipUser userInfo = Membership.GetUser(Login1.UserName); if (userInfo != null) { OrganisationSettings settings = new OrganisationSettings(); List <AspUser> aspUserList = ApartmentMethods.ListAspUser(null, (Guid)userInfo.ProviderUserKey, null); if (aspUserList == null || aspUserList.Count == 0 || (aspUserList[0].OrganisationId.HasValue && aspUserList[0].OrganisationId != Convert.ToInt32(settings.OrganisationId))) { this.ExtraErrorInformation.Text = Properties.Resources.UserLoginWrongOrg; e.Cancel = true; } } Response.Cookies["ActiveModule"].Value = string.Empty; }
private void ImportCsvs(ImportCsvsRequest request, LogController controller, ImportCsvsResponse response) { var organisationSettings = new OrganisationSettings(XrmService); controller.LogLiteral("Preparing Import"); var csvFiles = request.FolderOrFiles == ImportCsvsRequest.CsvImportOption.Folder ? FileUtility.GetFiles(request.Folder.FolderPath).Where(f => f.EndsWith(".csv")) : request.CsvsToImport.Select(c => c.Csv.FileName).ToArray(); var entities = new List <Entity>(); var countToImport = csvFiles.Count(); var countImported = 0; //this part maps the csvs into entity clr objects //then will just call the shared import method foreach (var csvFile in csvFiles) { try { //try think if better way controller.UpdateProgress(countImported++, countToImport, string.Format("Reading {0}", csvFile)); var getTypeResponse = GetTargetType(XrmService, csvFile); var type = getTypeResponse.LogicalName; var primaryField = XrmService.GetPrimaryNameField(type); var fileInfo = new FileInfo(csvFile); CsvUtility.ConstructTextSchema(fileInfo.Directory.FullName, Path.GetFileName(csvFile)); var rows = CsvUtility.SelectAllRows(csvFile); var rowNumber = 0; foreach (var row in rows) { rowNumber++; try { var entity = new Entity(type); var keyColumns = rows.First() .GetColumnNames() .Where(c => c.StartsWith("key|")); if (keyColumns.Any()) { var fieldValues = new Dictionary <string, object>(); foreach (var key in keyColumns) { var fieldName = MapColumnToFieldSchemaName(XrmService, type, key); var columnValue = row.GetFieldAsString(key); if (columnValue != null) { columnValue = columnValue.Trim(); } fieldValues.Add(fieldName, columnValue); } var matchingEntity = GetMatchingEntities(type, fieldValues); if (matchingEntity.Count() > 1) { throw new Exception(string.Format("Specified Match By Name But More Than One {0} Record Matched To The Keys Of {1}", type, string.Join(",", fieldValues.Select(kv => kv.Key + "=" + kv.Value)))); } if (matchingEntity.Count() == 1) { entity.Id = matchingEntity.First().Id; } } else if (request.MatchByName && !getTypeResponse.IsRelationship) { var primaryFieldColumns = rows.First() .GetColumnNames() .Where(c => MapColumnToFieldSchemaName(XrmService, type, c) == primaryField).ToArray(); var primaryFieldColumn = primaryFieldColumns.Any() ? primaryFieldColumns.First() : null; if (request.MatchByName && primaryFieldColumn.IsNullOrWhiteSpace()) { throw new NullReferenceException(string.Format("Match By Name Was Specified But No Column In The CSV Matched To The Primary Field {0} ({1})", XrmService.GetFieldLabel(primaryField, type), primaryField)); } var columnValue = row.GetFieldAsString(primaryFieldColumn); if (columnValue != null) { columnValue = columnValue.Trim(); } var matchingEntity = GetMatchingEntities(type, primaryField, columnValue); if (matchingEntity.Count() > 1) { throw new Exception(string.Format("Specified Match By Name But More Than One {0} Record Matched To Name Of {1}", type, columnValue)); } if (matchingEntity.Count() == 1) { entity.Id = matchingEntity.First().Id; } } foreach (var column in row.GetColumnNames()) { var field = MapColumnToFieldSchemaName(XrmService, type, column); if (true)//(getTypeResponse.IsRelationship || XrmService.IsWritable(field, type)) { var stringValue = row.GetFieldAsString(column); if (stringValue != null) { stringValue = stringValue.Trim(); } if (getTypeResponse.IsRelationship) { //bit of hack //for csv relationships just set to a string and map it later //as the referenced record may not be created yet entity.SetField(field, stringValue); } else if (XrmService.IsLookup(field, type)) { //for lookups am going to set to a empty guid and allow the import part to replace with a correct guid if (!stringValue.IsNullOrWhiteSpace()) { entity.SetField(field, new EntityReference(XrmService.GetLookupTargetEntity(field, type), Guid.Empty) { Name = stringValue }); } } else { entity.SetField(field, XrmService.ParseField(field, type, stringValue, request.DateFormat == DateFormat.American)); } } } if (XrmService.FieldExists("transactioncurrencyid", type) && !entity.GetLookupGuid("transactioncurrencyid").HasValue) { entity.SetLookupField("transactioncurrencyid", organisationSettings.BaseCurrencyId, "transactioncurrency"); } entities.Add(entity); } catch (Exception ex) { response.AddResponseItem(new ImportCsvsResponseItem(string.Format("Error Parsing Row {0} To Entity", rowNumber), csvFile, ex)); } } } catch (Exception ex) { response.AddResponseItem(new ImportCsvsResponseItem("Not Imported", csvFile, ex)); } } var imports = DoImport(entities, controller, request.MaskEmails); foreach (var item in imports) { response.AddResponseItem(new ImportCsvsResponseItem(item)); } }