コード例 #1
0
        public void GetAllProfiles()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);

            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            profile["Name"] = "Fred Flintstone";
            profile.Save();

            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty           getProp1 = new SettingsProperty("Name");

            getProp1.PropertyType = typeof(String);
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");

            int total;
            ProfileInfoCollection profiles = provider.GetAllProfiles(
                ProfileAuthenticationOption.All, 0, 10, out total);

            Assert.AreEqual(1, total);
        }
コード例 #2
0
        public void AnonymousUserSettingNonAnonymousProperties()
        {
            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", false);
            ctx.Add("UserName", "user1");

            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            SettingsProperty property1             = new SettingsProperty("color");

            property1.PropertyType = typeof(string);
            property1.Attributes["AllowAnonymous"] = false;
            SettingsPropertyValue value = new SettingsPropertyValue(property1);

            value.PropertyValue = "blue";
            values.Add(value);

            provider.SetPropertyValues(ctx, values);

            DataTable dt = FillTable("SELECT * FROM my_aspnet_Applications");

            Assert.AreEqual(0, dt.Rows.Count);
            dt = FillTable("SELECT * FROM my_aspnet_Users");
            Assert.AreEqual(0, dt.Rows.Count);
            dt = FillTable("SELECT * FROM my_aspnet_Profiles");
            Assert.AreEqual(0, dt.Rows.Count);
        }
コード例 #3
0
        public void AuthenticatedDateTime()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);

            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            DateTime date = DateTime.Now;

            profile["BirthDate"] = date;
            profile.Save();

            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty           getProp1 = new SettingsProperty("BirthDate");

            getProp1.PropertyType = typeof(DateTime);
            getProp1.SerializeAs  = SettingsSerializeAs.Xml;
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");

            SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);

            Assert.AreEqual(1, getValues.Count);
            SettingsPropertyValue getValue1 = getValues["BirthDate"];

            Assert.AreEqual(date, getValue1.PropertyValue);
        }
コード例 #4
0
        public void AuthenticatedStringProperty()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);

            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            profile["Name"] = "Fred Flintstone";
            profile.Save();

            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty           getProp1 = new SettingsProperty("Name");

            getProp1.PropertyType = typeof(String);
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");

            SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);

            Assert.AreEqual(1, getValues.Count);
            SettingsPropertyValue getValue1 = getValues["Name"];

            Assert.AreEqual("Fred Flintstone", getValue1.PropertyValue);
        }
コード例 #5
0
        private static SettingsContext GetContext(string username)
        {
            var context = new SettingsContext();

            context.Add("UserName", username);
            context.Add("IsAuthenticated", true);
            return(context);
        }
コード例 #6
0
        public void Initialize(string username, bool isAuthenticated)
        {
            _settingsContext = new SettingsContext();
            _settingsContext.Add("UserName", username);
            _settingsContext.Add("IsAuthenticated", isAuthenticated);
            SettingsProviderCollection spc = new SettingsProviderCollection();

            spc.Add(ProfileManager.Provider);
            base.Initialize(Context, ProfileBase.Properties, spc);
        }
コード例 #7
0
        public void Init()
        {
            _options = TestDbOptions.GetInMemoryOptions <SettingsContext>();
            var context = new SettingsContext(_options);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            _emrs = Builder <EmrSystem> .CreateListOfSize(2).Build().ToList();

            _docket = Builder <Docket> .CreateNew().Build();

            _iqcareExtract = Builder <Extract> .CreateNew().With(x => x.DocketId = _docket.Id).With(x => x.EmrSystemId = _emrs.First().Id).Build();

            _iqcareExtract.ExtractSql = @"SELECT * FROM [AppAdmin]";
            _kenyaExtract             = Builder <Extract> .CreateNew().With(x => x.DocketId = _docket.Id).With(x => x.EmrSystemId = _emrs.Last().Id).Build();

            _kenyaExtract.ExtractSql = @"SELECT * FROM psmart";

            _mssql =
                new DatabaseProtocol(DatabaseType.MicrosoftSQL, @".\koske14", "sa", "maun", "iqcare");
            _mysql =
                new DatabaseProtocol(DatabaseType.MySQL, @"localhost", "root", "root", "openmrs");

            context.Add(_docket);
            context.AddRange(_emrs);
            context.AddRange(new List <Extract> {
                _iqcareExtract, _kenyaExtract
            });
            context.SaveChanges();
        }
コード例 #8
0
        public void Initialize(string username, bool isAuthenticated)
        {
            if (username != null)
            {
                this._UserName = username.Trim();
            }
            else
            {
                this._UserName = username;
            }
            SettingsContext context = new SettingsContext();

            context.Add("UserName", this._UserName);
            context.Add("IsAuthenticated", isAuthenticated);
            this._IsAuthenticated = isAuthenticated;
            base.Initialize(context, s_Properties, ProfileManager.Providers);
        }
コード例 #9
0
        public void StringCollectionAsProperty()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);

            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            StringCollection colors = new StringCollection();

            colors.Add("red");
            colors.Add("green");
            colors.Add("blue");
            profile["FavoriteColors"] = colors;
            profile.Save();

            DataTable dt = FillTable("SELECT * FROM my_aspnet_Applications");

            Assert.AreEqual(1, dt.Rows.Count);
            dt = FillTable("SELECT * FROM my_aspnet_Users");
            Assert.AreEqual(1, dt.Rows.Count);
            dt = FillTable("SELECT * FROM my_aspnet_Profiles");
            Assert.AreEqual(1, dt.Rows.Count);

            // now retrieve them
            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty           getProp1 = new SettingsProperty("FavoriteColors");

            getProp1.PropertyType = typeof(StringCollection);
            getProp1.SerializeAs  = SettingsSerializeAs.Xml;
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");
            SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);

            Assert.AreEqual(1, getValues.Count);
            SettingsPropertyValue getValue1 = getValues["FavoriteColors"];
            StringCollection      outValue  = (StringCollection)getValue1.PropertyValue;

            Assert.AreEqual(3, outValue.Count);
            Assert.AreEqual("red", outValue[0]);
            Assert.AreEqual("green", outValue[1]);
            Assert.AreEqual("blue", outValue[2]);
        }
コード例 #10
0
        public void SettingValuesCreatesAnAppAndUserId()
        {
            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", false);
            ctx.Add("UserName", "user1");

            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            SettingsProperty property1             = new SettingsProperty("color");

            property1.PropertyType = typeof(string);
            property1.Attributes["AllowAnonymous"] = true;
            SettingsPropertyValue value = new SettingsPropertyValue(property1);

            value.PropertyValue = "blue";
            values.Add(value);

            provider.SetPropertyValues(ctx, values);

            DataTable dt = FillTable("SELECT * FROM my_aspnet_applications");

            Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_applications is not 1");

            dt = FillTable("SELECT * FROM my_aspnet_users");
            Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_users is not 1");


            dt = FillTable("SELECT * FROM my_aspnet_profiles");
            Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_profiles is not 1");

            values["color"].PropertyValue = "green";
            provider.SetPropertyValues(ctx, values);

            dt = FillTable("SELECT * FROM my_aspnet_applications");
            Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_applications is not 1 after setting property");

            dt = FillTable("SELECT * FROM my_aspnet_users");
            Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_users is not 1 after setting property");

            dt = FillTable("SELECT * FROM my_aspnet_profiles");
            Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_profiles is not 1 after setting property");
        }
コード例 #11
0
        public void Initialize(string username, bool isAuthenticated)
        {
            if (username != null)
            {
                _UserName = username.Trim();
            }
            else
            {
                _UserName = username;
            }
            //if (string.IsNullOrEmpty(_UserName))
            //    throw new ArgumentException(SR.GetString(SR.Membership_InvalidUserName), "username");
            SettingsContext sc = new SettingsContext();

            sc.Add("UserName", _UserName);
            sc.Add("IsAuthenticated", isAuthenticated);
            _IsAuthenticated = isAuthenticated;
            base.Initialize(sc, s_Properties, ProfileManager.Providers);
        }
コード例 #12
0
        public void Init()
        {
            _options = TestDbOptions.GetInMemoryOptions <SettingsContext>();
            var context = new SettingsContext(_options);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();
            _iqcareEmr = new EmrSystem("IQCare", "v1");
            _iqcareEmr.AddProtocol(new DatabaseProtocol(DatabaseType.MicrosoftSQL, @".\koske14", "sa", "maun", "iqcare"));
            _iqcareEmr.AddRestProtocol(new RestProtocol("http://192.168.1.10/api", "xys"));
            context.Add(_iqcareEmr);
            context.SaveChanges();
        }
コード例 #13
0
        public void GetPropertyValues_NonExistantUserIsCreated_CreateUserInstanceIsCalled()
        {
            var userRepository   = A.Fake <IUserRepository>();
            var profileProvider  = GetProfileProvider(userRepository);
            var context          = new SettingsContext();
            var settings         = new SettingsPropertyCollection();
            var settingsProperty = GetSettingsProperty <string>("name");

            settings.Add(settingsProperty);
            context.Add("UserName", "njupiter\\username");
            A.CallTo(() => userRepository.GetUserByUserName("username", "njupiter")).Returns(null);
            profileProvider.GetPropertyValues(context, settings);
            A.CallTo(() => userRepository.CreateUserInstance("username", "njupiter")).MustHaveHappened(Repeated.Exactly.Once);
        }
コード例 #14
0
        public List <SettingsPropertyValueSerializable> GetPropertyValues(List <object> keys, List <object> values, List <SettingsPropertyValueSerializable> properties)
        {
            SettingsContext sc = new SettingsContext();

            for (int i = 0; i < keys.Count; i++)
            {
                sc.Add(keys[i], values[i]);
            }

            SettingsPropertyCollection properties2 = new SettingsPropertyCollection();

            foreach (SettingsPropertyValue settingsPropertyValue in properties)
            {
                properties2.Add(new SettingsProperty(settingsPropertyValue.Name, settingsPropertyValue.Property.PropertyType, settingsPropertyValue.Property.Provider, settingsPropertyValue.Property.IsReadOnly, settingsPropertyValue.Property.DefaultValue, settingsPropertyValue.Property.SerializeAs, settingsPropertyValue.Property.Attributes, settingsPropertyValue.Property.ThrowOnErrorDeserializing, settingsPropertyValue.Property.ThrowOnErrorSerializing));
            }

            return(SqlProfileProvider.GetPropertyValues(sc, properties2).Cast <SettingsPropertyValueSerializable>().ToList());;
        }
コード例 #15
0
        public void SetPropertyValues(List <object> keys, List <object> values, List <SettingsPropertyValueSerializable> properties)
        {
            SettingsContext sc = new SettingsContext();

            for (int i = 0; i < keys.Count; i++)
            {
                sc.Add(keys[i], values[i]);
            }

            SettingsPropertyValueCollection properties2 = new SettingsPropertyValueCollection();

            foreach (SettingsPropertyValue settingsPropertyValue in properties)
            {
                properties2.Add(settingsPropertyValue);
            }

            SqlProfileProvider.SetPropertyValues(sc, properties2);
        }
コード例 #16
0
        private static async Task SortOutBaseUrl(string baseUrl, SettingsContext settingsDb, GlobalSettings ombiSettingsContent)
        {
            var setBaseUrl = false;

            if (ombiSettingsContent == null)
            {
                Console.WriteLine("Creating new Settings entity");
                ombiSettingsContent = new GlobalSettings
                {
                    SettingsName = "OmbiSettings",
                    Content      = JsonConvert.SerializeObject(new OmbiSettings())
                };
                var strat = settingsDb.Database.CreateExecutionStrategy();
                await strat.ExecuteAsync(async() =>
                {
                    using var tran = await settingsDb.Database.BeginTransactionAsync();
                    settingsDb.Add(ombiSettingsContent);
                    await settingsDb.SaveChangesAsync();
                    await tran.CommitAsync();
                });
            }
            var ombiSettings = JsonConvert.DeserializeObject <OmbiSettings>(ombiSettingsContent.Content);

            if (ombiSettings == null)
            {
                if (baseUrl.HasValue() && baseUrl.StartsWith("/"))
                {
                    setBaseUrl   = true;
                    ombiSettings = new OmbiSettings
                    {
                        BaseUrl = baseUrl
                    };

                    ombiSettingsContent.Content = JsonConvert.SerializeObject(ombiSettings);
                    var strat = settingsDb.Database.CreateExecutionStrategy();
                    await strat.ExecuteAsync(async() =>
                    {
                        using (var tran = await settingsDb.Database.BeginTransactionAsync())
                        {
                            settingsDb.Update(ombiSettingsContent);
                            await settingsDb.SaveChangesAsync();
                            await tran.CommitAsync();
                        }
                    });
                }
            }
            else if (baseUrl.HasValue() && !baseUrl.Equals(ombiSettings.BaseUrl))
            {
                setBaseUrl           = true;
                ombiSettings.BaseUrl = baseUrl;

                ombiSettingsContent.Content = JsonConvert.SerializeObject(ombiSettings);
                var strat = settingsDb.Database.CreateExecutionStrategy();
                await strat.ExecuteAsync(async() =>
                {
                    using (var tran = await settingsDb.Database.BeginTransactionAsync())
                    {
                        settingsDb.Update(ombiSettingsContent);
                        await settingsDb.SaveChangesAsync();
                        await tran.CommitAsync();
                    }
                });
            }
            else
            {
                // The base url might have changed in the settings, so just rewrite
                setBaseUrl = true;
                baseUrl    = ombiSettings.BaseUrl.HasValue() ? ombiSettings.BaseUrl : string.Empty;
            }


            if (setBaseUrl)
            {
                var trimmedBaseUrl   = baseUrl.EndsWith('/') ? baseUrl.TrimEnd('/') : baseUrl;
                var process          = AppContext.BaseDirectory;
                var ombiInstalledDir = Path.GetDirectoryName(process);
                var indexPath        = Path.Combine(ombiInstalledDir, "ClientApp", "dist", "index.html");
                if (!File.Exists(indexPath))
                {
                    var error = $"Can't set the base URL because we cannot find the file at '{indexPath}', if you are trying to set a base url please report this on Github!";
                    Console.WriteLine(error);
                    return;
                }
                var indexHtml = await File.ReadAllTextAsync(indexPath);

                var sb = new StringBuilder(indexHtml);

                const string scriptRegex  = "<script.type=.+>window.+=.+;<.script>";
                const string baseUrlRegex = "<base.href=\".+\">";

                indexHtml = Regex.Replace(indexHtml, scriptRegex, $"<script type='text/javascript'>window[\"baseHref\"] = '{trimmedBaseUrl}';</script>");

                indexHtml = Regex.Replace(indexHtml, baseUrlRegex, $"<base href=\"{trimmedBaseUrl}/\">");

                try
                {
                    await File.WriteAllTextAsync(indexPath, indexHtml);
                }
                catch (UnauthorizedAccessException)
                {
                    Console.WriteLine("Error attempting to write Base URL, see here: https://docs.ombi.app/info/known-faults/#unauthorized-access-to-indexhtml");
                }

                Console.WriteLine($"Wrote new baseurl at {indexPath}");
            }
        }