Esempio n. 1
0
        /// <summary>
        /// Executes the setting method async.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="settingStorePartitions">The settingStorePartitions.</param>
        /// <param name="settingCollection">collection of settings.</param>
        /// <returns>Async task.</returns>
        public Task <SettingCollection> CallSettingMethodAsync(SettingMethods method, SettingStorePartitions settingStorePartitions, SettingCollection settingCollection)
        {
            var requestUri = this.CreateRequestUri(RelativePaths.Settings);
            var batch      = new SettingBatch
            {
                SettingStorePartitions = settingStorePartitions,
                SettingCollection      = settingCollection,
                Method = method.ToString()
            };

            return(this.SendAsync <SettingBatch, SettingCollection>(requestUri, HttpMethod.Post, batch));
        }
Esempio n. 2
0
        public Uri BuildSettingsRequestUri(SettingMethods method)
        {
            var uriBuilder = new UriBuilder(Url)
            {
                UserName = UserName,
                Password = Password
            };

            var pathBuilder = new StringBuilder(uriBuilder.Path);

            pathBuilder.Append("/musicFolderSettings.view");
            uriBuilder.Path = Regex.Replace(pathBuilder.ToString(), "/+", "/");

            var queryBuilder = new StringBuilder();

            queryBuilder.AppendFormat("{0}", method.GetXmlEnumAttribute());

            uriBuilder.Query = queryBuilder.ToString();

            return(uriBuilder.Uri);
        }
Esempio n. 3
0
        /// <summary>
        /// Overwrite/create config using base config as a template
        /// </summary>
        public void Save()
        {
            // Get the base config and split it line by line
            var baseConf = Encoding.Default.GetString(Resources.BaseConfig)
                           .Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            using (var sr = new StreamWriter(CfgFilePath)) {
                // Loop though each line, replacing placeholder values
                foreach (var s in baseConf)
                {
                    var match = CfgRegex.Match(s);

                    // Was not a setting
                    if (!match.Success)
                    {
                        sr.WriteLine(s);
                        continue;
                    }

                    SettingType type;
                    // Is the user-provided key valid?
                    try {
                        type = SettingMethods.GetType(match.Groups[2].Value);
                    } catch (InvalidOperationException) {
                        continue;
                    }

                    // Get current setting value or default
                    var val = _settings.GetString(type);

                    // Replace value in the config line
                    var replacement = CfgRegex.Replace(s, "$1$2$3") +
                                      (string.IsNullOrEmpty(val) ? "#none" : val);

                    // Write substituted line
                    sr.WriteLine(replacement);
                }
            }
        }
Esempio n. 4
0
        public virtual async Task <bool> SettingChangeRequestAsync(SettingMethods method, CancellationToken?cancelToken = null)
        {
            var requestUri    = SubsonicServer.BuildSettingsRequestUri(method);
            var clientHandler = GetClientHandler();
            var client        = GetClient(clientHandler);

            cancelToken?.ThrowIfCancellationRequested();

            bool success;

            try
            {
                using (var response = cancelToken.HasValue ? await client.GetAsync(requestUri, cancelToken.Value) : await client.GetAsync(requestUri))
                    success = response.IsSuccessStatusCode;
            }
            catch (Exception ex)
            {
                throw new SubsonicApiException(ex.Message, ex);
            }

            cancelToken?.ThrowIfCancellationRequested();

            return(success);
        }
Esempio n. 5
0
 /// <summary>
 /// Executes the setting method async.
 /// </summary>
 /// <param name="method">The method.</param>
 /// <param name="settingStorePartitions">The settingStorePartitions.</param>
 /// <param name="setting">the setting.</param>
 /// <returns>Async task.</returns>
 public Task <SettingCollection> CallSettingMethodAsync(SettingMethods method, SettingStorePartitions settingStorePartitions, Setting setting)
 {
     return(this.CallSettingMethodAsync(method, settingStorePartitions, new SettingCollection {
         setting
     }));
 }
Esempio n. 6
0
 public virtual async Task <bool> GetSettingChangeResponseAsync(SettingMethods method, CancellationToken?cancelToken = null)
 {
     return(await SubsonicRequest.SettingChangeRequestAsync(method, cancelToken));
 }