Ejemplo n.º 1
0
 private static void Validate(this IEnumerable <ValidationAttribute> validations, SettingName settingName, object value)
 {
     foreach (var validation in validations)
     {
         validation.Validate(value, $"Setting {settingName.ToString().QuoteWith("'")} is not valid.");
     }
 }
Ejemplo n.º 2
0
        protected override ISetting Read(SettingName name)
        {
            var exeConfig = OpenExeConfiguration();
            var element   = exeConfig.AppSettings.Settings[name.ToString()];

            return(element is null ? default : new Setting(name, element.Value));
        }
Ejemplo n.º 3
0
        private string ReadString(SettingsSection section, SettingName name, string defaultValue, bool decrypt = false)
        {
            try
            {
                var sb = new StringBuilder(Win32.MAX_PATH);
                Win32.GetPrivateProfileString(section.ToString(),
                                              name.ToString(),
                                              defaultValue,
                                              sb,
                                              (uint)sb.Capacity,
                                              _iniFilePath);

                var result = sb.ToString();

                if (decrypt)
                {
                    var data = Convert.FromBase64String(result);
                    result = Encoding.UTF8.GetString(data);
                }

                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show(new WindowWrapper(PluginBase.nppData._nppHandle), ex.Message, Main.PluginName, MessageBoxButtons.OK);
                return(defaultValue);
            }
        }
Ejemplo n.º 4
0
        private void WriteString(SettingsSection section, SettingName name, string value, bool encrypt = false)
        {
            if (encrypt)
            {
                var bytes = Encoding.UTF8.GetBytes(value);
                value = Convert.ToBase64String(bytes);
            }

            Win32.WritePrivateProfileString(section.ToString(), name.ToString(), value, _iniFilePath);
        }
Ejemplo n.º 5
0
        public Setting GetSetting(SettingName settingName)
        {
            if (!SettingsMap.ContainsKey(settingName))
            {
                throw new SettingHasNoMappedType();
            }

            var settingsValue = typeof(AppSettings).GetProperty(settingName.ToString())?.GetValue(_settings, null)
                                ?.ToString();

            return(new Setting(settingName, settingsValue, SettingsMap[settingName]));
        }
Ejemplo n.º 6
0
        public bool CheckSetting(SettingName settingName)
        {
            bool ret = true;
            try
            {
                // var settings = IsolatedStorageSettings.ApplicationSettings;
                // txtInput is a TextBox defined in XAML.
                if (settings.Contains(settingName.ToString()))
                {

                    var store = IsolatedStorageFile.GetUserStoreForApplication();
                    switch (settingName)
                    {
                        case SettingName.Shares:
                            ret =  store.DirectoryExists("/Shares");
                            break;
                        case SettingName.Users:
                            ret = store.FileExists("/Users/Users.xml");
                            break;
                        case SettingName.Activity:
                            ret = store.FileExists("/Activity/Activity.xml");
                            break;
                        default:
                            throw new Exception("Setting not implemented " + settingName.ToString() + "!!!");
                    }

                }
                else
                {
                    ret = false;
                }

            } catch(Exception)
            {
                // insabbiamento
                ret = false;
            }

            return ret;
        }
Ejemplo n.º 7
0
        public void Read_CallsServicesAndInternalOverload()
        {
            var settingName        = new SettingName("prefix", "namespace", "type", "member", "instance");
            var settingNameFactory = Mock.Create <ISettingNameFactory>();
            var settingConverter   = Mock.Create <ISettingConverter>();

            settingNameFactory
            .Arrange(x => x.CreateProviderSettingName(
                         Arg.Matches <SettingName>(sn => sn == settingName),
                         Arg.IsAny <SettingProviderNaming>())
                     )
            .Returns(settingName)
            .OccursOnce();

            settingConverter
            .Arrange(x => x.Deserialize(
                         Arg.Matches <object>(value => value == (object)"TestValue"),
                         Arg.Matches <Type>(type => type == typeof(string))
                         ))
            .Returns("TestValue")
            .OccursOnce();

            var settingProvider = Mock.Create <SettingProvider>(Behavior.CallOriginal, settingNameFactory, settingConverter);

            Mock
            .NonPublic
            .Arrange <ISetting>(
                settingProvider,
                nameof(SettingProvider.Read),
                ArgExpr.Matches <SettingName>(sn => sn == settingName)
                )
            .Returns(new Setting(settingName.ToString(), "TestValue"))
            .MustBeCalled();

            var setting = settingProvider.Read(new SelectQuery(settingName, typeof(string)));

            settingNameFactory.Assert();
            settingProvider.Assert();
            settingConverter.Assert();

            Assert.IsNotNull(setting);
            Assert.AreEqual(settingName, setting.Name);
            Assert.AreEqual("TestValue", setting.Value);
        }
Ejemplo n.º 8
0
        public Settings GetByName(SettingName settingname)
        {
            String[] projection =
            {
                FeedEntry.Id,
                FeedEntry.COLUMN_NAME_NAME,
                FeedEntry.COLUMN_NAME_VAL_1,
                FeedEntry.COLUMN_NAME_VAL_2,
                FeedEntry.COLUMN_NAME_VAL_3,
                FeedEntry.COLUMN_NAME_VAL_4,
                FeedEntry.COLUMN_NAME_VAL_5,
            };
            String selection = FeedEntry.COLUMN_NAME_NAME + " = ?";

            String[]     selectionArgs = { settingname.ToString() };
            String       sortOrder     = FeedEntry.COLUMN_NAME_NAME + " DESC";
            SQLiteCursor cursor        = (SQLiteCursor)db.Query(
                FeedEntry.TABLE_NAME,                     // The table to query
                projection,                               // The columns to return
                selection,                                // The columns for the WHERE clause
                selectionArgs,                            // The values for the WHERE clause
                null,                                     // don't group the rows
                null,                                     // don't filter by row groups
                sortOrder                                 // The sort order
                );

            cursor.MoveToFirst();
            Settings result = null;

            if (cursor.Count > 0)
            {
                result       = new Settings();
                result.Id    = cursor.GetLong(cursor.GetColumnIndexOrThrow(FeedEntry.Id));
                result.Name  = (SettingName)Enum.Parse(typeof(SettingName), cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_NAME)));
                result.Val_1 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_1));
                result.Val_2 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_2));
                result.Val_3 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_3));
                result.Val_4 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_4));
                result.Val_5 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_5));
                cursor.Close();
            }
            return(result);
        }
Ejemplo n.º 9
0
        private void Setup(SettingName settingName, string url)
        {
            var componentName = settingName.ToString().Replace("Path", "");

            logger.Trace($"Install {componentName} started.");

            var downloadPath = FileHelper.GetUnusedFileName(Path.GetTempPath(), $"{componentName}.7z");

            logger.Trace($"{componentName} setup file path is {downloadPath}");

            var urlTesseract = "https://drive.google.com/uc?export=download&id=1tVu45QDZJK_x2jmpHJP9w2zD3DodhJ23";

            urlTesseract = url;

            (FindName($"RadProgressBarDownload{componentName}") as FrameworkElement).Visibility = Visibility.Visible;

            (FindName($"StatusInstall{componentName}") as RadMaskedTextInput).Value = "Downloading";

            (FindName($"BtnInstall{componentName}") as RadButton).IsEnabled = false;

            try
            {
                logger.Trace($"{componentName} setup file will be downloaded from {urlTesseract}");

                (FindName($"RadProgressBarDownload{componentName}") as RadProgressBar).Visibility = Visibility.Visible;

                using (WebClient webClient = new WebClient())
                {
                    webClient.DownloadProgressChanged += DownloadProgressChanged;
                    webClient.DownloadFileCompleted   += DownloadFileCompleted;
                    webClient.DownloadFileAsync(new Uri(urlTesseract), downloadPath, new DownloadFileAsyncState()
                    {
                        DownloadPath = downloadPath, SettingName = settingName
                    });
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"Exception has been thrown when downloading {componentName} setup file.");

                (FindName($"BtnInstall{componentName}") as RadButton).IsEnabled = true;
            }
        }
Ejemplo n.º 10
0
        private void Check(SettingName settingName)
        {
            var componentName = settingName.ToString().Replace("Path", "");

            (FindName($"Installed{componentName}") as FrameworkElement).Visibility              = Visibility.Collapsed;
            (FindName($"NotInstalled{componentName}") as FrameworkElement).Visibility           = Visibility.Visible;
            (FindName($"RadProgressBarDownload{componentName}") as FrameworkElement).Visibility = Visibility.Hidden;

            bool isOk = false;

            if (settingName == SettingName.ImageMagickPath)
            {
                isOk = SetupManager.Instance.IsImageMagickInstalled;
            }

            //if (SetupManager.CheckOcrComponent(settingName))
            {
                (FindName($"Installed{componentName}") as FrameworkElement).Visibility    = Visibility.Visible;
                (FindName($"NotInstalled{componentName}") as FrameworkElement).Visibility = Visibility.Collapsed;
                (FindName($"BtnInstall{componentName}") as RadButton).Content             = "Reinstall";
            }

            (FindName($"BtnInstall{componentName}") as RadButton).IsEnabled = true;
        }
Ejemplo n.º 11
0
 private static string SettingNameAsString(SettingName setting)
 {
     return(setting
            .ToString()
            .Replace('_', '-'));
 }
Ejemplo n.º 12
0
 public async Task<SettingEntity> FindNamedAsync(SettingName name)
 {
     return await GroupGetAsync<SettingEntity>(name.ToString()).ConfigureAwait(false);
 }
Ejemplo n.º 13
0
 private void Remove(SettingName section)
 {
     Remove(section.ToString());
 }
Ejemplo n.º 14
0
 protected void AddSection(SettingName settingName)
 {
     CreateConfigurationDir(settingName.ToString() as string);
     CreateConfigurationFile(settingName.ToString(), settingName.ToString());
 }
Ejemplo n.º 15
0
 protected void AddSection(SettingName settingName)
 {
     var node = CreateElement(settingName.ToString());
     FirstChild.AppendChild(node);
 }
 public async Task <SettingEntity> FindNamedAsync(SettingName name)
 {
     return(await GroupGetAsync <SettingEntity>(name.ToString()).ConfigureAwait(false));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Retrieve the setting with the given name; throws if the entity does not exist.
 /// </summary>
 /// <param name="name">The name of the setting to retrieve. See also <see cref="SettingName"/>.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
 /// <returns>The setting.</returns>
 public async Task <SettingEntity> FindNamedAsync(SettingName name, CancellationToken cancellationToken = default)
 {
     return(await GroupGetAsync <SettingEntity>(name.ToString(), cancellationToken : cancellationToken).ConfigureAwait(false));
 }