Inheritance: ConfigurationElement
Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Configuration.Configuration rootWebConfig1             = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
        System.Configuration.KeyValueConfigurationElement msmqSetting = rootWebConfig1.AppSettings.Settings["MSMQ_CONFIG"];

        ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();

        configMap.ExeConfigFilename = msmqSetting.Value;
        Configuration config      = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
        string        POSGATEPath = config.AppSettings.Settings["QueueFolder"].Value;

        string fileName = Path.GetFileName(Request.Files[0].FileName);
        string path     = POSGATEPath + Request.Form["CompanyID"] + "\\" + Request.Form["RetailID"] + "\\" + Request.Form["TerminalID"];

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        try
        {
            Request.Files[0].SaveAs(path + "\\" + fileName);
            Response.Write("SUCCESS");
        }
        catch (Exception ex)
        {
            Response.Write("FAIL");
        }
    }
Ejemplo n.º 2
0
        public void LoadApikeyFromConfig()
        {
            // Try web.config

            System.Configuration.Configuration rootWebConfig1 =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);

            System.Configuration.KeyValueConfigurationElement customSetting =
                rootWebConfig1.AppSettings.Settings["CloudmersiveApikey"];

            if (customSetting != null)
            {
                Apikey = customSetting.Value;
            }
            else
            {
                // No web config, try App.config

                string apikeySettingValue = ConfigurationManager.AppSettings["CloudmersiveApikey"];

                if (apikeySettingValue != null)
                {
                    Apikey = apikeySettingValue;
                }
            }
        }
Ejemplo n.º 3
0
    private bool runMSMQ(string companyCode, string retailID, string terminalID, string mode, string tables)
    {
        bool results = false;

        System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
        System.Configuration.KeyValueConfigurationElement customSetting = rootWebConfig1.AppSettings.Settings["MSMQAPP"];
        string MSMQPath = customSetting.Value;

        string paths = MSMQPath;

        if (tables != "")
        {
            tables = " " + tables;
        }
        if (File.Exists(paths))
        {
            string           argsstr   = mode + tables + " " + companyCode + " " + retailID + " " + terminalID;
            Process          myprocess = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo(paths, argsstr);
            myprocess.StartInfo = startInfo;
            myprocess.StartInfo.UseShellExecute = true;
            myprocess.Start();

            myprocess.WaitForExit();
            if (myprocess.HasExited)
            {
                results = true;
            }
        }
        else
        {
            results = false;
        }
        return(results);
    }
Ejemplo n.º 4
0
        private void IntialValue()
        {
            myLogging = new MyLogger();
            //// initialize our UploadDir
            if (Session["UploadDir"] != null)
            {
                UploadDir = Session["UploadDir"].ToString();
            }
            else
            {
                System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
                if (rootWebConfig1.AppSettings.Settings.Count > 0)
                {
                    System.Configuration.KeyValueConfigurationElement customSetting = rootWebConfig1.AppSettings.Settings["53UploadDir"];
                    if (customSetting != null)
                    {
                        UploadDir = HttpContext.Current.Server.MapPath(customSetting.Value);
                    }
                }
                else
                {
                    myLogging.LogError("No Upload directory loaded, setting to default directory.", "Warning");
                    UploadDir = HttpContext.Current.Server.MapPath("/CSharp/My53Finan/Uploads/");
                }

                //saving it to session
                Session["UploadDir"] = UploadDir;
            }
        }
Ejemplo n.º 5
0
        internal static bool SetSetting(string Key, string Value)
        {
            bool result = false;
            try
            {
                System.Configuration.Configuration config =
                  ConfigurationManager.OpenExeConfiguration(
                                       ConfigurationUserLevel.None);

                config.AppSettings.Settings.Remove(Key);
                var kvElem = new KeyValueConfigurationElement(Key, Value);
                config.AppSettings.Settings.Add(kvElem);

                // Save the configuration file.
                config.Save(ConfigurationSaveMode.Modified);

                // Force a reload of a changed section.
                ConfigurationManager.RefreshSection("appSettings");

                result = true;
            }
            finally
            { }
            return result;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Init configuration
            System.Configuration.Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration(null);

            //Read configurations from Web.config
            if (rootWebConfig.AppSettings.Settings.Count > 0)
            {
                System.Configuration.KeyValueConfigurationElement host     = rootWebConfig.AppSettings.Settings["host"];
                System.Configuration.KeyValueConfigurationElement user     = rootWebConfig.AppSettings.Settings["user"];
                System.Configuration.KeyValueConfigurationElement dbName   = rootWebConfig.AppSettings.Settings["dbName"];
                System.Configuration.KeyValueConfigurationElement password = rootWebConfig.AppSettings.Settings["password"];
                System.Configuration.KeyValueConfigurationElement port     = rootWebConfig.AppSettings.Settings["port"];

                if (host != null && user != null && dbName != null && password != null && port != null)
                {
                    connString = String.Format("Server={0}; User Id={1}; Database={2}; Port={3}; Password={4}; SSL Mode=Prefer; Trust Server Certificate=true",
                                               host.Value, user.Value, dbName.Value, port.Value, password.Value);
                }
                else
                {
                    lblNotifycation.Text = "Không có kết nối với cơ sở dữ liệu";
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds a <see cref="Preloader"/> the configuration.
 /// </summary>
 /// <param name="element">The preloader configuration.</param>
 public void Add(KeyValueConfigurationElement element)
 {
     if (element != null)
     {
         this.BaseAdd(element);
     }
 }
        public static void storeConfigurationValue(string configurationKey, string configurationValue)
        {
            KeyValueConfigurationElement configurationElement = new KeyValueConfigurationElement(configurationKey, configurationValue);

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.AppSettings.Settings.Remove(configurationKey);
            config.AppSettings.Settings.Add(configurationElement);
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }
Ejemplo n.º 9
0
 public static void setItem(string key, string value)
 {
     System.Configuration.KeyValueConfigurationElement b = AppCfg.cfg.AppSettings.Settings[key];
     if (b == null)
     {
         AppCfg.cfg.AppSettings.Settings.Add(key, "0");
     }
     AppCfg.cfg.AppSettings.Settings[key].Value = value;
     AppCfg.cfg.Save();
 }
Ejemplo n.º 10
0
        private Settings()
        {
            Logger.Trace("Load: Configuration loading...");

            _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            _nameConfiguration = _configuration.AppSettings.Settings[KeyHostedNetworkName];
            _keyConfiguration = _configuration.AppSettings.Settings[KeyHostedNetworkKey];

            Logger.Trace("Load: Configuration loaded");
            Logger.Info("Load: Name: {0}, Key: {1}", _nameConfiguration.Value, _keyConfiguration.Value);
        }
Ejemplo n.º 11
0
        public static void SetConfigValue(string keyName, string newValue)
        {

            System.Configuration.Configuration config =
              ConfigurationManager.OpenExeConfiguration(
              ConfigurationUserLevel.None);

            config.AppSettings.Settings.Remove(keyName);
            System.Configuration.KeyValueConfigurationElement element = new System.Configuration.KeyValueConfigurationElement(keyName, newValue);
            config.AppSettings.Settings.Add(element);
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }
        public string GetAppSettingKeyValue(string key)
        {
// string virtualPath = "C:\\StudentMailer 2.1.1";
            System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
            if (rootWebConfig1.AppSettings.Settings.Count > 0)
            {
                System.Configuration.KeyValueConfigurationElement customSetting = rootWebConfig1.AppSettings.Settings[key];
                if (customSetting != null)
                {
                    return(customSetting.Value);
                }
            }
            return(null);
        }
Ejemplo n.º 13
0
    public string[] GetAllFiles(string companyID, string retailID, string terminalID)
    {
        System.Configuration.Configuration rootWebConfig1             = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
        System.Configuration.KeyValueConfigurationElement msmqSetting = rootWebConfig1.AppSettings.Settings["MSMQ_CONFIG"];

        ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();

        configMap.ExeConfigFilename = msmqSetting.Value;
        Configuration config      = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
        string        POSGATEPath = config.AppSettings.Settings["LocalOutFolder"].Value;
        string        fileDirPath = POSGATEPath + companyID + "\\" + retailID + "\\" + terminalID;

        string[] fileEntries = Directory.GetFiles(fileDirPath);
        return(fileEntries);
    }
 public void Add(KeyValueConfigurationElement keyValue)
 {
     keyValue.Init();
     KeyValueConfigurationElement element = (KeyValueConfigurationElement) base.BaseGet(keyValue.Key);
     if (element == null)
     {
         this.BaseAdd(keyValue);
     }
     else
     {
         element.Value = element.Value + "," + keyValue.Value;
         int index = base.BaseIndexOf(element);
         base.BaseRemoveAt(index);
         this.BaseAdd(index, element);
     }
 }
Ejemplo n.º 15
0
        public override object GetInitializer(Type serviceType)
        {
            string logPath = DefaultLogPath;

            System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
            if (rootWebConfig.AppSettings.Settings.Count > 0)
            {
                System.Configuration.KeyValueConfigurationElement logPathElem = rootWebConfig.AppSettings.Settings["LogPath"];
                if (logPathElem != null)
                {
                    logPath = logPathElem.Value;
                }
            }

            return(Path.Combine(logPath, string.Format("{0}.log", serviceType)));
        }
Ejemplo n.º 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                String propertyId = Request.QueryString["PropertyId"];


                Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
                if (rootWebConfig1.AppSettings.Settings.Count > 0)
                {
                    System.Configuration.KeyValueConfigurationElement RESTSetting = rootWebConfig1.AppSettings.Settings["RestURL"];
                    if (RESTSetting != null)
                    {
                        RestURL                   = String.Format("{0}{1}", RESTSetting.Value, propertyId);
                        RestURLPictures           = String.Format("{0}{1}", RestURL, "/pictures?callback=?");
                        this.HdnPicturesURL.Value = RestURLPictures;
                    }
                }

                if (!String.IsNullOrEmpty(propertyId))
                {
                    PropertyBLL pBLL = new PropertyBLL();
                    Property    prop = pBLL.GetPropertyById(int.Parse(propertyId));

                    this.HdnPropertyId.Value = propertyId;

                    this.LitPropertyHeaderDescription.Text = prop.StreetAddress.ToString();
                    //Property Details
                    this.LitPrice.Text    = string.Format("{0:C}", prop.Price);
                    this.LitLocation.Text =
                        String.Format("{0}, {1}", prop.StreetAddress.ToString(), prop.City.ToString());

                    this.LitBedrooms.Text  = prop.Beds.ToString();
                    this.LitBathrooms.Text = prop.Baths.ToString();

                    this.LitStatus.Text = (prop.StatusId == 1) ? "Available" : "Sold";

                    this.LitMLSId.Text       = prop.MLSId.ToString();
                    this.LitDescription.Text = prop.Description.ToString();

                    string jcontent = String.Format("window.open('{0}')", prop.VirtualTourUrl);

                    string myScript = String.Format(@"function ShowMorePictures(){0}({1}){2};", "{", jcontent, "}");
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myScript, true);
                }
            }
        }
Ejemplo n.º 17
0
 public void SetAppSetting(string _strKey, string _strValue)
 {
     if (null != this.oConfig)
     {
         KeyValueConfigurationElement kvElement = this.oConfig.AppSettings.Settings[_strKey];
         if (null == kvElement)
         {
             kvElement = new KeyValueConfigurationElement(_strKey, _strValue);
             this.oConfig.AppSettings.Settings.Add(kvElement);
         }
         else
         {
             kvElement.Value = _strValue;
         }
         this.oConfig.Save();
     }
 }
Ejemplo n.º 18
0
        protected internal override object GetRuntimeObject()
        {
            KeyValueInternalCollection col = new KeyValueInternalCollection();

            foreach (string key in Settings.AllKeys)
            {
                KeyValueConfigurationElement ele = Settings[key];
                col.Add(ele.Key, ele.Value);
            }

            if (!ConfigurationManager.ConfigurationSystem.SupportsUserConfig)
            {
                col.SetReadOnly();
            }

            return(col);
        }
        public void Add(KeyValueConfigurationElement keyValue)
        {
            keyValue.Init();
            KeyValueConfigurationElement element = (KeyValueConfigurationElement)base.BaseGet(keyValue.Key);

            if (element == null)
            {
                this.BaseAdd(keyValue);
            }
            else
            {
                element.Value = element.Value + "," + keyValue.Value;
                int index = base.BaseIndexOf(element);
                base.BaseRemoveAt(index);
                this.BaseAdd(index, element);
            }
        }
Ejemplo n.º 20
0
        internal static bool SetAppConfigSetting(string key, string value)
        {
            try {
                var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                config.AppSettings.Settings.Remove(key);
                var kvElem = new KeyValueConfigurationElement(key, value);
                config.AppSettings.Settings.Add(kvElem);

                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");

                return true;
            } catch {
                return false;
            }
        }
 public void StartSacta()
 {
     if (sModule == null)
     {
         //System.Diagnostics.Debug.Assert(false);
         System.Configuration.Configuration config           = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
         System.Configuration.KeyValueConfigurationElement s = config.AppSettings.Settings["Sistema"];
         IdSistema = s.Value;
         sModule   = new Sacta.SactaModule(IdSistema, MySqlConnectionToCd40);
         sModule.Start();
         sModule.SactaActivityChanged += new Utilities.GenericEventHandler <System.Collections.Generic.Dictionary <string, object> >(sModule_SactaActivityChanged);
     }
     else
     {
         sModule.Start();
     }
 }
Ejemplo n.º 22
0
        private MailClass GetMailConfiguration()
        {
            MailClass objMail = new MailClass();

            //Request.ApplicationPath Retrieves the root of the application
            System.Configuration.Configuration rootWebConfig1 =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            //System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/OSL");

            if (0 < rootWebConfig1.AppSettings.Settings.Count)
            {
                //SMPT Server
                System.Configuration.KeyValueConfigurationElement customSettingSMTPSever =
                    rootWebConfig1.AppSettings.Settings["SMPTServer"];
                if (null != customSettingSMTPSever)
                {
                    objMail.SMTPSever = customSettingSMTPSever.Value;
                }

                //MailUser
                System.Configuration.KeyValueConfigurationElement customSettingMailUser =
                    rootWebConfig1.AppSettings.Settings["MailUser"];
                if (null != customSettingMailUser)
                {
                    objMail.Mailuser = customSettingMailUser.Value;
                }

                //MailPassword
                System.Configuration.KeyValueConfigurationElement customSettingMailPassword =
                    rootWebConfig1.AppSettings.Settings["MailPswd"];
                if (null != customSettingMailPassword)
                {
                    objMail.MailPswd = customSettingMailPassword.Value;
                }

                //To Mail
                System.Configuration.KeyValueConfigurationElement customSettingToMail =
                    rootWebConfig1.AppSettings.Settings["ToMail"];
                if (null != customSettingToMail)
                {
                    objMail.ToMail = customSettingToMail.Value;
                }
            }
            return(objMail);
        }
Ejemplo n.º 23
0
        public static KeyValueConfigurationElement GetSetting(string key)
        {
            Configuration webConfig =
            WebConfigurationManager.OpenWebConfiguration("/");

            var customSetting = new KeyValueConfigurationElement("", "");
            if (webConfig.AppSettings.Settings.Count > 0)
            {
                customSetting =
                    webConfig.AppSettings.Settings[key];
                if (customSetting != null)
                    Console.WriteLine("customsetting1 application string = \"{0}\"",
                        customSetting.Value);
                else
                    throw new NullReferenceException(key + " not specified in Web.Config");
            }
            return customSetting;
        }
Ejemplo n.º 24
0
 // private static string connectionString = "PACKET SIZE=4096;USER ID=palisadmin;PASSWORD=palisadmin;DATA SOURCE=localhost;PERSIST SECURITY INFO=False;INITIAL CATALOG=";
 //private static string connectionString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;//"SERVER=GURPREET-PC\\SQLEXPRESS;Integrated Security=True; Initial Catalog=PALISDB;Connection timeout=60";
 public static string getConnectionString(String app)
 {
     System.Configuration.Configuration rootWebConfig1 =
         System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/QuickForms3");
     System.Configuration.KeyValueConfigurationElement customSetting =
         rootWebConfig1.AppSettings.Settings["PalisConnectionString"];
     if (customSetting != null)
     {
         Console.WriteLine("customsetting1 application string = \"{0}\"",
                           customSetting.Value);
         return(customSetting.Value + app);
     }
     else
     {
         Console.WriteLine("No customsetting1 application string");
         throw new Exception();
     }
 }
        public new KeyValueConfigurationElement this[string key] {
            get {
                return((KeyValueConfigurationElement)BaseGet(key));
            }
#if DONT_COMPILE
            // if we ever expose this element this will be handy
            set {
                int index = -1; // append by default
                KeyValueConfigurationElement tempElement = (KeyValueConfigurationElement)BaseGet(key);
                if (tempElement != null)
                {
                    index = BaseIndexOf(tempElement);
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
#endif
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 获取App.config
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetAppConfig(string key)
        {
            var config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);

            if (!config.HasFile)
            {
                return(null);
            }
            System.Configuration.KeyValueConfigurationElement k = config.AppSettings.Settings[key];
            if (k == null)
            {
                return(null);
            }
            else
            {
                return(System.Configuration.ConfigurationManager.AppSettings[key].ToString());
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// This method reads app settings the local app.config file for the calling assembly/dll"/>
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="obj">valid return value if returned true</param>
        /// <returns>true if value exists</returns>
        public static bool GetDllConfigAppSetting(string setting, out object obj)
        {
            try
            {
                // The dllPath can't just use Assembly.GetExecutingAssembly().Location as ASP.NET doesn't copy the config to shadow copy path
                var dllPath   = new Uri(System.Reflection.Assembly.GetCallingAssembly().GetName().CodeBase).LocalPath;
                var dllConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(dllPath);

                // Get the appSettings section
                var appSettings = (System.Configuration.AppSettingsSection)dllConfig.GetSection("appSettings");
                System.Configuration.KeyValueConfigurationElement element = appSettings.Settings[setting];
                obj = element.Value;
                return(true);
            }
            catch (Exception ex)
            {
                throw new ArgumentNullException(string.Format("ConfigurationManager.GetDllConfigAppSetting(...) - error attempting to get value from dll 'appSettings' section , param:{0} - {1}", setting, ex.Message), ex);
            }
        }
        //
        // Methods
        //

        public void Add(KeyValueConfigurationElement keyValue) {
            // Need to initialize in order to get the key
            keyValue.Init();

            // the appsettings add works more like a namevalue collection add in that it appends values
            // when add is called and teh key already exists.
            KeyValueConfigurationElement oldValue = (KeyValueConfigurationElement)BaseGet(keyValue.Key);
            if (oldValue == null) {
                BaseAdd(keyValue);
            }
            else {
                oldValue.Value += "," + keyValue.Value;
                int index = BaseIndexOf(oldValue);
                BaseRemoveAt(index);
                BaseAdd(index, oldValue);
            }


        }
    public void EndSacta()
    {
        if (sModule == null)
        {
            //System.Diagnostics.Debug.Assert(false);
            System.Configuration.Configuration config           = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
            System.Configuration.KeyValueConfigurationElement s = config.AppSettings.Settings["Sistema"];
            IdSistema = s.Value;
            sModule   = new Sacta.SactaModule(IdSistema, MySqlConnectionToCd40);
            sModule.Stop();
        }
        else
        {
            sModule.Stop();
        }

        EstadoSacta = (byte)0;

        sModule = null;
    }
Ejemplo n.º 30
0
        /// <summary>
        /// 设置App.config
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool SetAppConfig(string key, string value)
        {
            var config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);

            if (!config.HasFile)
            {
                return(false);   // throw new ArgumentException("程序配置文件缺失!");
            }
            System.Configuration.KeyValueConfigurationElement k = config.AppSettings.Settings[key];
            if (k == null)
            {
                config.AppSettings.Settings.Add(key, value);
            }
            else
            {
                config.AppSettings.Settings[key].Value = value;
            }
            config.Save(System.Configuration.ConfigurationSaveMode.Modified);
            System.Configuration.ConfigurationManager.RefreshSection("appSettings");
            return(true);
        }
        //
        // Methods
        //

        public void Add(KeyValueConfigurationElement keyValue)
        {
            // Need to initialize in order to get the key
            keyValue.Init();

            // the appsettings add works more like a namevalue collection add in that it appends values
            // when add is called and teh key already exists.
            KeyValueConfigurationElement oldValue = (KeyValueConfigurationElement)BaseGet(keyValue.Key);

            if (oldValue == null)
            {
                BaseAdd(keyValue);
            }
            else
            {
                oldValue.Value += "," + keyValue.Value;
                int index = BaseIndexOf(oldValue);
                BaseRemoveAt(index);
                BaseAdd(index, oldValue);
            }
        }
Ejemplo n.º 32
0
        public static void SetEnvironmentValue(Configuration config, bool isNew, string configName, string configValue, bool deleteEnvironment)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config", "config cannot be a null reference (Nothing in Visual Basic)!");
            }
            if (string.IsNullOrEmpty(configName))
            {
                throw new ArgumentNullException("configName", "configName cannot be a null reference (Nothing in Visual Basic)!");
            }
            if (string.IsNullOrEmpty(configName))
            {
                throw new ArgumentNullException("configValue", "configValue cannot be a null reference (Nothing in Visual Basic)!");
            }

            if (!deleteEnvironment)
            {
                if (!isNew)
                {
                    try
                    {
                        System.Configuration.KeyValueConfigurationElement configSetting = config.AppSettings.Settings[configName];
                        configSetting.Value = configValue;
                    }
                    catch
                    {
                        config.AppSettings.Settings.Add(configName, configValue);
                    }
                }
                else
                {
                    config.AppSettings.Settings.Add(configName, configValue);
                }
            }
            else
            {
                config.AppSettings.Settings.Remove(configName);
            }
            config.Save();
        }
        public StaffADProfile GetStaffProfile()
        {
            logWriter.WriteErrorLog(string.Format("Entered GetStaffProfile"));

            try
            {
                System.Configuration.Configuration rootWebConfig              = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
                System.Configuration.KeyValueConfigurationElement sADUser     = null;
                System.Configuration.KeyValueConfigurationElement sADPassword = null;
                System.Configuration.KeyValueConfigurationElement sDomain     = null;

                if (rootWebConfig.AppSettings.Settings.Count > 0)
                {
                    sADUser     = rootWebConfig.AppSettings.Settings["sADUser"];
                    sADPassword = rootWebConfig.AppSettings.Settings["sADPassword"];
                    sDomain     = rootWebConfig.AppSettings.Settings["sDomain"];
                    if (sADUser == null)
                    {
                        staffADProfile = null;
                        logWriter.WriteErrorLog(string.Format("No ad admin profile application string"));
                    }
                    else
                    {
                        staffADProfile = GetStaffInformation(sADUser.Value.ToString(), sADPassword.Value.ToString(), sDomain.Value.ToString());
                    }
                }
                else
                {
                    staffADProfile = null;
                }
            }
            catch (Exception ex)
            {
                staffADProfile = null;
                logWriter.WriteErrorLog(string.Format(" GetStaffProfile : Exception / {0} / {1}", staffADProfile.employee_number, ex.Message));
            }

            return(staffADProfile);
        }
Ejemplo n.º 34
0
        public void WriteAppSetting(string name, string value)
        {
            if (Configuration.AppSettings.Settings[name] == null)
            {
                var setting  = new KeyValueConfigurationElement(name, value);
                Configuration.AppSettings.Settings.Add(setting);
            }

            Configuration.AppSettings.Settings[name].Value = value;
            SaveConfiguration();
        }
 public void Add(string key, string value)
 {
     KeyValueConfigurationElement keyValue = new KeyValueConfigurationElement(key, value);
     this.Add(keyValue);
 }
Ejemplo n.º 36
0
        private static object ConvertType(KeyValueConfigurationElement val, Type type)
        {
            Contract.Requires(val != null);
            Contract.Requires(val.Value != null);
            Contract.Requires(type != null);

            try
            {
                return val.Value.Cast(type);
            }
            catch
            {
                return null;
            }
        }
 public void Add(KeyValueConfigurationElement keyValue)
 {
     Contract.Requires(keyValue != null);
 }
 public void Add(String key, String value) {
     KeyValueConfigurationElement element = new KeyValueConfigurationElement(key, value);
     Add(element);
 }
 public void Remove(KeyValueConfigurationElement keyValue)
 {
     if (BaseIndexOf(keyValue) >= 0)
         BaseRemove(keyValue.Key);
 }
 public void Add(KeyValueConfigurationElement keyValue)
 {
     keyValue.Init();
     BaseAdd(keyValue);
 }
		public void Add (KeyValueConfigurationElement keyValue)
		{
			keyValue.Init ();
			BaseAdd (keyValue);
		}
        public void Add(string key, string value)
        {
            KeyValueConfigurationElement keyValue = new KeyValueConfigurationElement(key, value);

            this.Add(keyValue);
        }
 public void Add(KeyValueConfigurationElement keyValue)
 {
   Contract.Requires(keyValue != null);
 }
 private ISetting WriteAppSetting()
 {
     var el = new KeyValueConfigurationElement("Test", "Test");
     Isolate.WhenCalled(() => el.Key).WillReturn("Test");
     var setting = SettingFactory.CreateSecureSetting(el);
     _configSettingSource.Add(setting);
     return setting;
 }
Ejemplo n.º 45
0
    public string BackupFile(string companyID, string retailID, string terminalID, string fileName)
    {
        System.Configuration.Configuration rootWebConfig1             = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
        System.Configuration.KeyValueConfigurationElement msmqSetting = rootWebConfig1.AppSettings.Settings["MSMQ_CONFIG"];

        ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();

        configMap.ExeConfigFilename = msmqSetting.Value;
        Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);

        string POSGATEPath       = config.AppSettings.Settings["LocalOutFolder"].Value;
        string POSGATEBackupPath = config.AppSettings.Settings["BackupSentFolder"].Value;
        string mode           = config.AppSettings.Settings["BackupMode"].Value.ToLower();
        string filePath       = companyID + "\\" + retailID + "\\" + terminalID;
        string sourcePath     = POSGATEPath + filePath;
        string sourceFilePath = sourcePath + "\\" + fileName;
        string destPath       = POSGATEBackupPath + filePath;
        string destFilePath   = destPath + "\\" + fileName;
        string result         = "FAIL to move/delete " + sourceFilePath;

        if (!Directory.Exists(destPath))
        {
            Directory.CreateDirectory(destPath);
        }
        if (File.Exists(sourceFilePath))
        {
            if (mode == "move")
            {
                File.Move(sourceFilePath, destFilePath);
                result = "File Moved to " + destFilePath;
            }
            else if (mode == "delete")
            {
                File.Delete(sourceFilePath);
                result = "File Deleted : " + sourceFilePath;
            }
        }
        else
        {
            return("File does not exist");
        }
        return(result);

        /*System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
         * System.Configuration.KeyValueConfigurationElement msmqSetting = rootWebConfig1.AppSettings.Settings["MSMQ_CONFIG"];
         * string strSQL = "";
         * try
         * {
         *  string path = Path.GetTempFileName();
         *  FileStream fs = File.Open("GG" + path, FileMode.Open);
         *  return "TRY";
         * }
         * catch (Exception ex1)
         * {
         *  try
         *  {
         *      return "CATCH-TRY";
         *  }
         *  catch (Exception ex2)
         *  {
         *      return "CATCH-CATCH";
         *  }
         * }
         * finally
         * {
         *  strSQL += "FINALLY";
         *  Console.Write(strSQL);
         * }
         * return strSQL;*/
    }
Ejemplo n.º 46
0
        static void Main(string[] args)
        {
            //<snippet1>
            // Obtains the machine configuration settings on the local machine.
            System.Configuration.Configuration machineConfig =
                System.Web.Configuration.WebConfigurationManager.OpenMachineConfiguration();
            machineConfig.SaveAs("c:\\machineConfig.xml");
            //</snippet1>


            //<snippet2>
            // Obtains the configuration settings for a Web application.
            System.Configuration.Configuration webConfig =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Temp");
            webConfig.SaveAs("c:\\webConfig.xml");
            //</snippet2>


            //<snippet3>
            // Obtains the configuration settings for the <anonymousIdentification> section.
            System.Configuration.Configuration config =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Temp");
            System.Web.Configuration.SystemWebSectionGroup systemWeb =
                config.GetSectionGroup("system.web")
                as System.Web.Configuration.SystemWebSectionGroup;
            System.Web.Configuration.AnonymousIdentificationSection sectionConfig =
                systemWeb.AnonymousIdentification;
            if (sectionConfig != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<anonymousIdentification> attributes:\r\n");
                System.Configuration.PropertyInformationCollection props =
                    sectionConfig.ElementInformation.Properties;
                foreach (System.Configuration.PropertyInformation prop in props)
                {
                    sb.AppendFormat("{0} = {1}\r\n", prop.Name.ToString(), prop.Value.ToString());
                }
                Console.WriteLine(sb.ToString());
            }
            //</snippet3>


            //<snippet4>
            IntPtr userToken = System.Security.Principal.WindowsIdentity.GetCurrent().Token;

            // Obtains the machine configuration settings on a remote machine.
            System.Configuration.Configuration remoteMachineConfig =
                System.Web.Configuration.WebConfigurationManager.OpenMachineConfiguration
                    (null, "ServerName", userToken);
            remoteMachineConfig.SaveAs("c:\\remoteMachineConfig.xml");

            // Obtains the root Web configuration settings on a remote machine.
            System.Configuration.Configuration remoteRootConfig =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration
                    (null, null, null, "ServerName", userToken);
            remoteRootConfig.SaveAs("c:\\remoteRootConfig.xml");

            // Obtains the configuration settings for the
            // W3SVC/1/Root/Temp application on a remote machine.
            System.Configuration.Configuration remoteWebConfig =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration
                    ("/Temp", "1", null, "ServerName", userToken);
            remoteWebConfig.SaveAs("c:\\remoteWebConfig.xml");
            //</snippet4>


            //<snippet5>
            // Updates the configuration settings for a Web application.
            System.Configuration.Configuration updateWebConfig =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Temp");
            System.Web.Configuration.CompilationSection compilation =
                updateWebConfig.GetSection("system.web/compilation")
                as System.Web.Configuration.CompilationSection;
            Console.WriteLine("Current <compilation> debug = {0}", compilation.Debug);
            compilation.Debug = true;
            if (!compilation.SectionInformation.IsLocked)
            {
                updateWebConfig.Save();
                Console.WriteLine("New <compilation> debug = {0}", compilation.Debug);
            }
            else
            {
                Console.WriteLine("Could not save configuration.");
            }
            //</snippet5>


            //<snippet6>
            System.Configuration.Configuration rootWebConfig =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot");
            System.Configuration.ConnectionStringSettings connString;
            if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
            {
                connString =
                    rootWebConfig.ConnectionStrings.ConnectionStrings["NorthwindConnectionString"];
                if (connString != null)
                {
                    Console.WriteLine("Northwind connection string = \"{0}\"",
                                      connString.ConnectionString);
                }
                else
                {
                    Console.WriteLine("No Northwind connection string");
                }
            }
            //</snippet6>


            //<snippet7>
            System.Configuration.Configuration rootWebConfig1 =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
            if (rootWebConfig1.AppSettings.Settings.Count > 0)
            {
                System.Configuration.KeyValueConfigurationElement customSetting =
                    rootWebConfig1.AppSettings.Settings["customsetting1"];
                if (customSetting != null)
                {
                    Console.WriteLine("customsetting1 application string = \"{0}\"",
                                      customSetting.Value);
                }
                else
                {
                    Console.WriteLine("No customsetting1 application string");
                }
            }
            //</snippet7>
        }
        public void SetValue(ElementProperty property, object value)
        {
            if (mergeElement == null) throw new InvalidOperationException("TODO");

            string valueToSet = (string) Convert.ChangeType(value, typeof(string));
            string propertyName = property.ConfigurationName;

            if (!mergeElement.OverriddenProperties.AllKeys.Contains(propertyName))
            {
                var overriddenProperty = new KeyValueConfigurationElement(propertyName, valueToSet);
                this.mergeElement.OverriddenProperties.Add(overriddenProperty);
            }
            else
            {
                mergeElement.OverriddenProperties[propertyName].Value = valueToSet;
            }
        }
 public void Add (KeyValueConfigurationElement keyValue)
 {
 }
Ejemplo n.º 49
0
		/// <summary>
		/// Gets or sets a key/value pair in the collection of settings
		/// </summary>
		public new string this[string name]
		{
			get { KeyValueConfigurationElement kv = Settings[name]; return kv == null ? null : kv.Value; }
			set
			{
				KeyValueConfigurationElement kv = Settings[name];
				if (kv == null) Settings.Add(kv = new KeyValueConfigurationElement(name, value));
				else kv.Value = value;
			}
		}
        public void Add(String key, String value)
        {
            KeyValueConfigurationElement element = new KeyValueConfigurationElement(key, value);

            Add(element);
        }
Ejemplo n.º 51
0
        public bool SaveImage(HttpPostedFile image, string title, out string LargePicture, out string SmallPicture)
        {
            bool result         = true;
            int  MaxWidth       = 512;
            int  MaxHeight      = 400;
            int  ThumbMaxWidth  = 205;
            int  ThumbMaxHeight = 160;

            LargePicture = null;
            SmallPicture = null;

            String LargePicturePath     = null;
            String ThumbnailPicturePath = null;

            System.Configuration.Configuration rootWebConfig1 =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

            if (0 < rootWebConfig1.AppSettings.Settings.Count)
            {
                System.Configuration.KeyValueConfigurationElement largPicSettings = rootWebConfig1.AppSettings.Settings["LargePicturePath"];
                System.Configuration.KeyValueConfigurationElement thPicSettings   = rootWebConfig1.AppSettings.Settings["ThumbnailPicturePath"];

                if (null != largPicSettings)
                {
                    LargePicturePath = largPicSettings.Value;
                }
                if (null != thPicSettings)
                {
                    ThumbnailPicturePath = thPicSettings.Value;
                }
            }

            // Ensure a unique filename
            string upFileName = Guid.NewGuid().ToString() + image.FileName.Substring(image.FileName.LastIndexOf("."));

            // Should put this into a config file.
            string LargeFile = String.Format("{0}{1}", LargePicturePath, upFileName);
            string ThumbFile = String.Format("{0}{1}", ThumbnailPicturePath, upFileName);

            try
            {
                System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(image.InputStream);
                System.Drawing.Image LargeImage    = Utilities.ToMaxSize(UploadedImage, MaxWidth, MaxHeight);
                System.Drawing.Image ThumbImage    = Utilities.ToMaxSize(UploadedImage, ThumbMaxWidth, ThumbMaxHeight);

                LargeImage.Save(Request.PhysicalApplicationPath + LargeFile, ImageFormat.Jpeg);
                ThumbImage.Save(Request.PhysicalApplicationPath + ThumbFile, ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {
                result = false;
            }

            if (result)
            {
                LargePicture = LargeFile.Replace('\\', '/');
                SmallPicture = ThumbFile.Replace('\\', '/');

                Picture p = new Picture();
                p.Name       = title;
                p.PropertyId = master.PropertyId;
                p.Url        = LargePicture;
                p.Thumbnail  = SmallPicture;
                p.IsMain     = false;

                PropertyBLL pBLL = new PropertyBLL();
                result = pBLL.SaveImage(p);
            }
            return(result);
        }