Ejemplo n.º 1
0
        public void HelloWorld()
        {
            // Retrieve the connection string from the configuration store.
            // You can get the string from your Azure portal.
            var connectionString = Environment.GetEnvironmentVariable("APPCONFIGURATION_CONNECTION_STRING");

            // Instantiate a client that will be used to call the service.
            var client = new ConfigurationClient(connectionString);

            // Create a Configuration Setting to be stored in the Configuration Store.
            var setting = new ConfigurationSetting("some_key", "some_value");

            // There are two ways to store a Configuration Setting:
            //   -AddAsync creates a setting only if the setting does not already exist in the store.
            //   -SetAsync creates a setting if it doesn't exist or overrides an existing setting
            client.Set(setting);

            // Retrieve a previously stored Configuration Setting by calling GetAsync.
            ConfigurationSetting gotSetting = client.Get("some_key");

            Debug.WriteLine(gotSetting.Value);

            // Delete the Configuration Setting from the Configuration Store when you don't need it anymore.
            client.Delete("some_key");
        }
 protected virtual void Load()
 {
     foreach (string variable in ConfigurationClient.Get <string[]>(ConfNamespace, "variables", new string[0]))
     {
         Add(variable, ConfigurationClient.Get <string>(ConfNamespace, variable, string.Empty));
     }
 }
        private bool LoadExpansion(TreeIter iter)
        {
            string key = GetStationKeyName(model.GetStation(iter));

            if (key != null)
            {
                return(ConfigurationClient.Get <bool>("plugins.radio.stations",
                                                      String.Format("{0}_expanded", key), true));
            }

            return(true);
        }
        private T Get <T> (string ns, string key, T fallback)
        {
            T result;

            if (ConfigurationClient.TryGet <T> (source_ns + ns, key, out result))
            {
                return(result);
            }

            if (source_ns != parent_source_ns)
            {
                return(ConfigurationClient.Get <T> (parent_source_ns + ns, key, fallback));
            }

            return(fallback);
        }
Ejemplo n.º 5
0
        public void MockClient()
        {
            // Create a mock response
            var mockResponse = new Mock <Response>();
            // Create a client mock
            var mock = new Mock <ConfigurationClient>();

            // Setup client method
            mock.Setup(c => c.Get("Key", It.IsAny <string>(), It.IsAny <DateTimeOffset>(), It.IsAny <CancellationToken>()))
            .Returns(new Response <ConfigurationSetting>(mockResponse.Object, ConfigurationClientModelFactory.ConfigurationSetting("Key", "Value")));

            // Use the client mock
            ConfigurationClient  client  = mock.Object;
            ConfigurationSetting setting = client.Get("Key");

            Assert.AreEqual("Value", setting.Value);
        }
Ejemplo n.º 6
0
        private static bool ConfirmUnmap(IUnmapableSource source)
        {
            string key        = "no_confirm_unmap_" + source.GetType().Name.ToLower();
            bool   do_not_ask = ConfigurationClient.Get <bool> ("sources", key, false);

            if (do_not_ask)
            {
                return(true);
            }

            Hyena.Widgets.HigMessageDialog dialog = new Hyena.Widgets.HigMessageDialog(
                ServiceManager.Get <GtkElementsService> ().PrimaryWindow,
                Gtk.DialogFlags.Modal,
                Gtk.MessageType.Question,
                Gtk.ButtonsType.Cancel,
                String.Format(Catalog.GetString("Are you sure you want to delete this {0}?"),
                              source.GenericName.ToLower()),
                source.Name);

            dialog.AddButton(Gtk.Stock.Delete, Gtk.ResponseType.Ok, false);

            Gtk.Alignment alignment = new Gtk.Alignment(0.0f, 0.0f, 0.0f, 0.0f);
            alignment.TopPadding = 10;
            Gtk.CheckButton confirm_button = new Gtk.CheckButton(String.Format(Catalog.GetString(
                                                                                   "Do not ask me this again"), source.GenericName.ToLower()));
            confirm_button.Toggled += delegate {
                do_not_ask = confirm_button.Active;
            };
            alignment.Add(confirm_button);
            alignment.ShowAll();
            dialog.LabelVBox.PackStart(alignment, false, false, 0);

            try {
                if (dialog.Run() == (int)Gtk.ResponseType.Ok)
                {
                    ConfigurationClient.Set <bool> ("sources", key, do_not_ask);
                    return(true);
                }

                return(false);
            } finally {
                dialog.Destroy();
            }
        }
        private void Set <T> (string ns, string key, T val)
        {
            string conf_ns = source_ns + ns;
            T      result;

            if (source_ns != parent_source_ns)
            {
                if (!ConfigurationClient.TryGet <T> (conf_ns, key, out result) &&
                    val != null && val.Equals(ConfigurationClient.Get <T> (parent_source_ns + ns, key, default(T))))
                {
                    conf_ns = null;
                }
            }

            if (conf_ns != null)
            {
                ConfigurationClient.Set <T> (conf_ns, key, val);
            }
        }
        public static ProfileConfiguration LoadActive(MediaProfileManager manager, string id)
        {
            string profile_id = ConfigurationClient.Get <string>(MakeConfNamespace(id), "active_profile", string.Empty);

            if (profile_id == string.Empty)
            {
                return(null);
            }

            foreach (Profile profile in manager.GetAvailableProfiles())
            {
                if (profile.Id == profile_id)
                {
                    profile.LoadConfiguration(id);
                    return(profile.Configuration);
                }
            }

            return(null);
        }
        public void Load()
        {
            lock (this) {
                if (source == null)
                {
                    return;
                }

                loaded = false;

                foreach (Column column in this)
                {
                    if (column.Id != null)
                    {
                        string @namespace = MakeNamespace(column.Id);
                        column.Visible = ConfigurationClient.Get <bool> (@namespace, "visible", column.Visible);
                        column.Width   = ConfigurationClient.Get <double> (@namespace, "width", column.Width);
                    }
                }

                // Create a copy so we can read the original index
                List <Column> columns = new List <Column> (Columns);

                Columns.Sort(delegate(Column a, Column b) {
                    int a_order = a.Id == null ? -1 : ConfigurationClient.Get <int> (
                        MakeNamespace(a.Id), "order", columns.IndexOf(a));
                    int b_order = b.Id == null ? -1 : ConfigurationClient.Get <int> (
                        MakeNamespace(b.Id), "order", columns.IndexOf(b));

                    return(a_order.CompareTo(b_order));
                });

                string sort_ns        = String.Format("{0}.{1}.{2}", root_namespace, unique_source_id, "sort");
                string sort_column_id = ConfigurationClient.Get <string> (sort_ns, "column", null);
                if (sort_column_id != null)
                {
                    ISortableColumn sort_column = null;
                    foreach (Column column in this)
                    {
                        if (column.Id == sort_column_id)
                        {
                            sort_column = column as ISortableColumn;
                            break;
                        }
                    }

                    if (sort_column != null)
                    {
                        int      sort_dir  = ConfigurationClient.Get <int> (sort_ns, "direction", 0);
                        SortType sort_type = sort_dir == 0 ? SortType.None : sort_dir == 1 ? SortType.Ascending : SortType.Descending;
                        sort_column.SortType = sort_type;
                        base.SortColumn      = sort_column;
                    }
                }
                else
                {
                    base.SortColumn = null;
                }

                loaded = true;
            }

            OnUpdated();
        }