Beispiel #1
0
        public ActionResult DBProviders()
        {
            NameValueList providers = new NameValueList();

            try
            {
                foreach (Provider provider in System.Enum.GetValues(typeof(Provider)))
                {
                    string value = provider.ToString();
                    providers.Add(new ListItem()
                    {
                        Name = value, Value = value
                    });
                }

                return(Json(providers, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                _logger.Error(e.ToString());
                _CustomErrorLog = new CustomErrorLog();
                _CustomError    = _CustomErrorLog.customErrorLogger(ErrorMessages.errUIDBProviders, e, _logger);
                return(Json(new { success = false, message = "[ Message Id " + _CustomError.msgId + "] - " + _CustomError.errMessage, stackTraceDescription = _CustomError.stackTraceDescription }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public static bool Save(Transaction trans, params string[] fields)
        {
            NameValueList config = OriData;

            lock (Singleton)
            {
                Transaction _trans = trans;
                if (_trans == null)
                {
                    _trans = new Transaction(true);
                }
                bool res = true;
                foreach (var nv in OriData)
                {
                    if (fields.Length == 0 || nv.Name.In(fields))
                    {
                        object        d   = Burst.Utils.Serialize(nv.Value, SerializeType);
                        NameValueList pms = new NameValueList();
                        pms.Add("@" + KeyFieldName, nv.Name);
                        pms.Add("@" + TypeFieldName, nv.Value.GetType().AssemblyQualifiedName);
                        pms.Add("@" + ValueFieldName, d);
                        Command cmd = DbProvider.Adapter.GetReplaceCommand(TableName, nv.Name, KeyFieldName, pms, DbProvider);
                        res = cmd.ExecuteNonQuery(_trans) > -1 && res;
                    }
                }
                if (trans != null)
                {
                    return(res);
                }
                return(_trans.Commit());
            }
        }
        private void CopyCollection(NameValueList dest, object collection)
        {
            if (dest == null || collection == null)
            {
                return;
            }

            if (collection is SortedDictionary <string, object> sorteddict)
            {
                foreach (var kvp in sorteddict)
                {
                    this.Items.Add(new NameValuePair(kvp.Key, kvp.Value));
                }
            }
            else if (collection is Dictionary <string, object> dict)
            {
                foreach (var kvp in dict)
                {
                    this.Items.Add(new NameValuePair(kvp.Key, kvp.Value));
                }
            }
            else if (collection is IEnumerable <(string, object)> kvparray)
            {
                foreach (var a in kvparray)
                {
                    this.Items.Add(new NameValuePair(a.Item1, a.Item2));
                }
            }
Beispiel #4
0
 public DbConnectException(Exception InnerException, NameValueList Config)
     : base(string.Empty, InnerException)
 {
     this.ConnectionString  = Config.Get <string>("ConnectionString");
     this.DbProviderFactory = Config.Get <DbProviderFactory>("DbProviderFactory");
     this.DbAdapter         = Config.Get <IDbAdapter>("DbAdapter");
 }
Beispiel #5
0
        public static Command GetInsertCommand(InsertType iops, IEnumerable <NameValue> pms)
        {
            if (pms.Count() == 0)
            {
                return(null);
            }
            StringBuilder ss = new StringBuilder(), vs = new StringBuilder();
            NameValueList pre  = new NameValueList(pms);
            NameValueList _pms = new NameValueList();

            foreach (var fi in AllFields)
            {
                if (pre.ContainsKey(fi.Attribute.DbFieldName))
                {
                    if (iops == InsertType.New && fi.Key)
                    {
                        continue;
                    }
                    ss.AppendFormat("{0},", fi.EnsuredName);
                    vs.AppendFormat("@{0},", fi.Attribute.DbFieldName);
                    _pms.Add(GetFieldValue(fi, InsertType.None, pre[fi.Attribute.DbFieldName]));
                }
            }
            if (ss.Length > 0)
            {
                ss.Remove(ss.Length - 1, 1);
                vs.Remove(vs.Length - 1, 1);
            }
            return(DbProvider.CreateCommand(string.Format("insert into {0} ({1}) values ({2})", EnsuredTableName, ss, vs), _pms));
        }
Beispiel #6
0
        /// <summary>
        /// Adds or updates a name-value pair in this request's Cookie header.
        /// To automatically maintain a cookie "session", consider using a CookieJar or CookieSession instead.
        /// </summary>
        /// <param name="request">The IFlurlRequest.</param>
        /// <param name="name">The cookie name.</param>
        /// <param name="value">The cookie value.</param>
        /// <returns>This IFlurlClient instance.</returns>
        public static IFlurlRequest WithCookie(this IFlurlRequest request, string name, object value)
        {
            var cookies = new NameValueList <string>(request.Cookies);

            cookies.AddOrReplace(name, value.ToInvariantString());
            return(request.WithHeader("Cookie", CookieCutter.ToRequestHeader(cookies)));
        }
 public DbConnectException(Exception InnerException, NameValueList Config)
     : base(string.Empty, InnerException)
 {
     this.ConnectionString = Config.Get<string>("ConnectionString");
     this.DbProviderFactory = Config.Get<DbProviderFactory>("DbProviderFactory");
     this.DbAdapter = Config.Get<IDbAdapter>("DbAdapter");
 }
Beispiel #8
0
        public static bool Delete(Transaction trans, params string[] fields)
        {
            NameValueList config = OriData;

            lock (Singleton)
            {
                Transaction _trans = trans;
                if (_trans == null)
                {
                    _trans = new Transaction(true);
                }
                bool res = true;
                foreach (var nv in OriData)
                {
                    if (fields.Length == 0 || nv.Name.In(fields))
                    {
                        Command cmd = new Command(string.Format("delete from {0}", EnsuredTableName));
                        Builder.AppendWhere(cmd, new Where(WhereType.Key, nv.Name), KeyFieldName, DbProvider.Adapter);
                        res = cmd.ExecuteNonQuery(_trans) > -1 && res;
                    }
                }
                if (trans != null)
                {
                    return(res);
                }
                return(_trans.Commit());
            }
        }
Beispiel #9
0
        public Command CreateCommand(string cmd, NameValueList pms)
        {
            Command res = new Command(cmd, pms);

            res.DbProvider = this;
            return(res);
        }
Beispiel #10
0
        /// <summary>
        /// Adds or updates a name-value pair in this request's Cookie header.
        /// To automatically maintain a cookie "session", consider using a CookieJar or CookieSession instead.
        /// </summary>
        /// <param name="request">The IFlurlRequest.</param>
        /// <param name="name">The cookie name.</param>
        /// <param name="value">The cookie value.</param>
        /// <returns>This IFlurlClient instance.</returns>
        public static IFlurlRequest WithCookie(this IFlurlRequest request, string name, object value)
        {
            var cookies = new NameValueList <string>(request.Cookies, true);            // cookie names are case-sensitive https://stackoverflow.com/a/11312272/62600

            cookies.AddOrReplace(name, value.ToInvariantString());
            return(request.WithHeader("Cookie", CookieCutter.ToRequestHeader(cookies)));
        }
Beispiel #11
0
        /// <summary>
        /// This method is called when the AccountControl's Load event has been fired.
        /// </summary>
        /// <param name="sender">The <see cref="object"/> that fired the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> of the event.</param>
        private void AccountControl_Load(object sender, EventArgs e)
        {
            if (account == null)
            {
                return;
            }
            account.Transactions.Sort(delegate(AccountTransaction x, AccountTransaction y) {
                return(x.Date.CompareTo(y.Date));
            });
            grid.SelectionChanged += GridOnSelectionChanged;
            NameValueList settings = ctx.Settings.Get(this);

            for (int i = 0; i < grid.Columns.Count; i++)
            {
                grid.Columns[i].Width = settings[string.Format("GridColumn{0}", i)].ToInt(100);
            }
            grid.Rows.Clear();
            foreach (AccountTransaction t in account.Transactions)
            {
                int             ind = grid.Rows.Add();
                DataGridViewRow row = grid.Rows[ind];
                row.Tag = t;
                row.Cells["Date"].Value    = t.Date.ToString("yyyy-MM-dd");
                row.Cells["Amount"].Value  = t.Amount.Format();
                row.Cells["Comment"].Value = t.Comment;
                row.Cells["User"].Value    = Plug.Users.GetByID(t.UserID).Username;
            }
            checkBox1.Checked     = string.Equals(settings["ShowAll"], "true");
            dateTimePicker1.Value = new DateTime(settings["FilterDate"].ToLong(DateTime.Now.Ticks));
        }
Beispiel #12
0
        private IReadOnlyNameValueList <string> LoadHeaders()
        {
            var result = new NameValueList <string>(false);

            foreach (var h in ResponseMessage.Headers)
            {
                foreach (var v in h.Value)
                {
                    result.Add(h.Key, v);
                }
            }

            if (ResponseMessage.Content?.Headers == null)
            {
                return(result);
            }

            foreach (var h in ResponseMessage.Content.Headers)
            {
                foreach (var v in h.Value)
                {
                    result.Add(h.Key, v);
                }
            }

            return(result);
        }
Beispiel #13
0
        public void SchemaTestMethod()
        {
            var pms = new NameValueList();

            pms.Add("");
            var schema = new DbSchema(DbProvider.Initialize(pms));
        }
Beispiel #14
0
        public override string BuildConnectionString(NameValueList pms)
        {
            StringBuilder res = new StringBuilder("Provider=Microsoft.Jet.OLEDB.4.0;");

            if (pms.ContainsKey("FilePath"))
            {
                if (!string.IsNullOrEmpty(pms["FilePath"] as string))
                {
                    res.AppendFormat("Data Source={0};", Path.GetFullPath(pms["FilePath"] as string));
                }
            }
            if (pms.ContainsKey("Password"))
            {
                if (!string.IsNullOrEmpty(pms["Password"] as string))
                {
                    res.AppendFormat("Password={0};", pms["Password"]);
                }
            }
            if (pms.ContainsKey("ExtraConfiguration"))
            {
                if (pms["ExtraConfiguration"] is NameValueList)
                {
                    foreach (NameValue nv in pms["ExtraConfiguration"] as NameValueList)
                    {
                        res.AppendFormat("{0}={1};", nv.Name, nv.Value);
                    }
                }
            }
            return(res.ToString());
        }
Beispiel #15
0
        public static Command GetUpdateCommand(Where where, IEnumerable <NameValue> pms)
        {
            if (pms.Count() == 0)
            {
                return(null);
            }
            StringBuilder ss   = new StringBuilder();
            NameValueList pre  = new NameValueList(pms);
            NameValueList _pms = new NameValueList();

            foreach (var fi in AllFields)
            {
                if (pre.ContainsKey(fi.Attribute.DbFieldName))
                {
                    ss.AppendFormat("{0}=@{1},", fi.EnsuredName, fi.Attribute.DbFieldName);
                    _pms.Add(GetFieldValue(fi, InsertType.None, pre[fi.Attribute.DbFieldName]));
                }
            }
            if (ss.Length > 0)
            {
                ss.Remove(ss.Length - 1, 1);
            }
            Command cmd = DbProvider.CreateCommand(string.Format("update {0} set {1}", EnsuredTableName, ss), _pms);

            Builder.AppendWhereByEnsuredKey(cmd, where, KeyField.EnsuredName, DbProvider.Adapter);
            return(cmd);
        }
Beispiel #16
0
        /// <summary>
        /// 从默认配置中初始化数据连接参数,包括连接字符串(ConnectionString)、DbProviderFactory、DbAdapter。
        /// </summary>
        /// <returns>初始化成功时,返回DbProvider,否则,返回null。</returns>
        public static DbProvider Initialize()
        {
            DbConnection _conn = null;
            DbProvider   res   = new DbProvider();

            try
            {
                res._config["DbAdapter"] = Activator.CreateInstance(Type.GetType(ConfigurationManager.AppSettings["DbAdapter"]));
                res.Adapter.InitializeOptions(res.Options);
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["DbProviderFactory"]) && res.Options["DefaultDbProviderFactory"] != null)
                {
                    res._config["DbProviderFactory"] = _getInstance <DbProviderFactory>(res.Options["DefaultDbProviderFactory"]);
                }
                else
                {
                    res._config["DbProviderFactory"] = Activator.CreateInstance(Type.GetType(ConfigurationManager.AppSettings["DbProviderFactory"]));
                }
                res._config["ConnectionString"] = ConfigurationManager.AppSettings["ConnectionString"];
                if (string.IsNullOrEmpty(res.ConnectionString))
                {
                    NameValueList DbParameters = new NameValueList();
                    DbParameters.Add("Host", ConfigurationManager.AppSettings["DbHost"]);
                    DbParameters.Add("Database", ConfigurationManager.AppSettings["DbDatabase"]);
                    DbParameters.Add("FilePath", ConfigurationManager.AppSettings["DbFilePath"]);
                    DbParameters.Add("Username", ConfigurationManager.AppSettings["DbUsername"]);
                    DbParameters.Add("Password", ConfigurationManager.AppSettings["DbPassword"]);
                    DbParameters.Add("Charset", ConfigurationManager.AppSettings["DbCharset"]);
                    DbParameters.Add("Version", ConfigurationManager.AppSettings["DbVersion"]);
                    DbParameters.Add("ReadOnly", ConfigurationManager.AppSettings["DbReadOnly"]);
                    res._config["ConnectionString"] = res.Adapter.BuildConnectionString(DbParameters);
                }
                _conn = res.Provider.CreateConnection();
                _conn.ConnectionString = res.ConnectionString;
                _conn.Open();
                res._config["DbSchema"] = res.Adapter.GetSchema(_conn);
                if (Current == null)
                {
                    Current = res;
                }
                return(res);
            }
            catch (Exception e)
            {
                #if DEBUG
                DbConnectException dce = new DbConnectException(e, res._config);
                Debug.WriteLine(dce);
                throw dce;
                #endif

                return(null);
            }
            finally
            {
                try
                {
                    _conn.Close();
                }
                catch { }
            }
        }
Beispiel #17
0
        /// <summary>
        /// 使用若干参数初始化数据连接参数。
        /// </summary>
        /// <param name="Parameters">参数,包括DbProviderFactory(String类型表示的完整限定名称或DbProviderFactory类型)、DbAdapter(String类型表示的类型完整限定名称或DbAdapter类型),及连接字符串(ConnectionString)或当前IDbAdapter.BuildConnectionString所需参数。</param>
        /// <returns>初始化成功时,返回DbProvider,否则,返回null。</returns>
        public static DbProvider Initialize(NameValueList Parameters)
        {
            DbConnection _conn = null;
            DbProvider   res   = new DbProvider();

            try
            {
                IDbAdapter DbAdapter = _getInstance <IDbAdapter>(Parameters["DbAdapter"]);
                if (DbAdapter != null)
                {
                    res._config["DbAdapter"] = DbAdapter;
                    DbAdapter.InitializeOptions(res.Options);
                }
                DbProviderFactory DbProviderFactory = _getInstance <DbProviderFactory>(Parameters["DbProviderFactory"]);
                if (DbProviderFactory != null)
                {
                    res._config["DbProviderFactory"] = DbProviderFactory;
                }
                else if (res.Options["DefaultDbProviderFactory"] != null)
                {
                    res._config["DbProviderFactory"] = _getInstance <DbProviderFactory>(res.Options["DefaultDbProviderFactory"]);
                }
                if (Parameters["ConnectionString"] is string)
                {
                    res._config["ConnectionString"] = Parameters["ConnectionString"];
                }
                else
                {
                    res._config["ConnectionString"] = res.Adapter.BuildConnectionString(Parameters);
                }
                _conn = res.Provider.CreateConnection();
                _conn.ConnectionString = res.ConnectionString;
                _conn.Open();
                res._config["DbSchema"] = res.Adapter.GetSchema(_conn);
                if (Current == null)
                {
                    Current = res;
                }
                return(res);
            }
            catch (Exception e)
            {
                #if DEBUG
                DbConnectException dce = new DbConnectException(e, res._config);
                Debug.WriteLine(dce);
                throw dce;
                #endif

                return(null);
            }
            finally
            {
                try
                {
                    _conn.Close();
                }
                catch { }
            }
        }
        public void Get_by_name_uppercase_should_get_expected_value()
        {
            var list = new NameValueList {
                new KeyValuePair<string, string>("name", "value")
            };

            Assert.That(list["NAME"], Is.EqualTo("value"));
        }
        public void Set_by_name_for_new_name_should_add_name_and_value_to_list()
        {
            var expectedList = new[] { new KeyValuePair<string, string>("name", "value") };
            var list = new NameValueList();

            list["name"] = "value";
            Assert.That(list, Is.EqualTo(expectedList));
        }
Beispiel #20
0
        public static void Set(string name, Object data)
        {
            NameValueList config = OriData;

            lock (Singleton)
            {
                config.Add(name, data);
            }
        }
        public void Set_by_name_for_name_with_different_case_should_update_existing_value()
        {
            var expectedList = new[] { new KeyValuePair<string, string>("name", "second") };
            var list = new NameValueList {
                new KeyValuePair<string, string>("name", "first")
            };

            list["NAME"] = "second";
            Assert.That(list, Is.EqualTo(expectedList));
        }
Beispiel #22
0
 public Command(string cmd, NameValueList pms)
 {
     if (string.IsNullOrEmpty(cmd))
         cmd = "";
     this._cmd = new StringBuilder(cmd);
     this._pms = new NameValueList();
     if (pms != null)
         foreach (NameValue i in pms)
             this._pms.Add(i.Name, i.Value);
     this._dbprovider = Burst.Data.DbProvider.Current;
 }
Beispiel #23
0
 public Command(string cmd, params object[] pms)
 {
     if (string.IsNullOrEmpty(cmd))
         cmd = "";
     this._cmd = new StringBuilder(cmd);
     this._pms = new NameValueList();
     if (pms != null)
         for (int i = 0; i < pms.Length; i++)
             this._pms.Add("@" + i, pms[i]);
     this._dbprovider = Burst.Data.DbProvider.Current;
 }
Beispiel #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        public void UnloadControl(UnloadFinanceControlEventArgs e)
        {
            NameValueList settings = ctx.Settings.Get(this);

            for (int i = 0; i < grid.Columns.Count; i++)
            {
                settings[string.Format("GridColumn{0}", i)] = grid.Columns[i].Width.ToString();
            }
            settings["ShowAll"]    = checkBox1.Checked ? "true" : "false";
            settings["FilterDate"] = dateTimePicker1.Value.Ticks.ToString();
        }
Beispiel #25
0
 /*
  * public virtual void InitializeOwner(Transaction trans, params string[] fields)
  * {
  *  bool all = false;
  *  if (fields.Length == 0)
  *      all = true;
  *  foreach (MemberInfo mi in OwnerFields)
  *  {
  *      if (all || mi.Name.In(fields))
  *      {
  *          DataOwnerFieldAttribute a = mi.GetAttribute<DataOwnerFieldAttribute>();
  *          SetValue(mi.Name, a.GetMethod(
  *              new Where(a.OwnedFieldName + "=@0", Key), null, null, trans));
  *      }
  *  }
  * }
  * protected virtual void InitializeAutoLoadFields(Transaction trans)
  * {
  *  List<string> autoloadfields = new List<string>();
  *  foreach (MemberInfo mi in OwnerFields)
  *  {
  *      DataOwnerFieldAttribute a = mi.GetAttribute<DataOwnerFieldAttribute>();
  *      if (a.AutoLoad)
  *          autoloadfields.Add(mi.Name);
  *  }
  *  if (autoloadfields.Count > 0)
  *      InitializeOwner(trans, autoloadfields.ToArray());
  * }
  */
 protected virtual void InitializeOri(NameValueList nv, Transaction trans)
 {
     foreach (var fi in AllFields)
     {
         if (nv.ContainsKey(fi.Attribute.DbFieldName))
         {
             SetValue(fi.Attribute.DbFieldName, nv[fi.Attribute.DbFieldName]);
         }
     }
     //InitializeAutoLoadFields(trans);
 }
Beispiel #26
0
 protected void SetByAppSettings(NameValueList Data, string Key, Object DefaultValue)
 {
     if (Data == null)
     {
         Data = OriData;
     }
     Data[Key] = ConfigurationManager.AppSettings[Key];
     if (string.IsNullOrEmpty(Data.Get <string>(Key)))
     {
         Data[Key] = DefaultValue;
     }
 }
Beispiel #27
0
        public static void Reload(Transaction trans, params string[] fields)
        {
            lock (Singleton)
            {
                if (_buf == null)
                {
                    _buf = new NameValueList();
                }

                Command cmd = new Command(string.Format("select * from {0}", EnsuredTableName));
                if (fields.Length > 0)
                {
                    Builder.AppendWhere(
                        cmd,
                        new Compare(KeyFieldName, fields as object[]).ToWhere(),
                        KeyFieldName, DbProvider.Adapter
                        );
                }
                else
                {
                    _buf.Clear();
                }

                NameValueList _old_buf = _buf;
                _buf = new NameValueList();
                (Singleton as DbConfiguration <T>).Initialize();
                foreach (var i in _buf)
                {
                    if (!_old_buf.ContainsKey(i.Name))
                    {
                        _old_buf.Add(i);
                    }
                }
                _buf = _old_buf;

                NameValueList[] res = cmd.Execute(trans);
                foreach (var nv in res)
                {
                    try
                    {
                        _buf.Add(
                            nv.Get <string>(KeyFieldName),
                            Burst.Utils.DeserializeAs(
                                nv.Get <object>(ValueFieldName),
                                Type.GetType(nv.Get <string>(TypeFieldName)),
                                SerializeType
                                )
                            );
                    }
                    catch { }
                }
            }
        }
        public ActionResult InitializeUISettings()
        {
            NameValueList nvlSettings = _repository.GetGlobalVariables();

            JsonContainer <NameValueList> container = new JsonContainer <NameValueList>();

            container.items   = nvlSettings;
            container.success = true;
            container.total   = nvlSettings.Count;

            return(Json(container, JsonRequestBehavior.AllowGet));
        }
Beispiel #29
0
        private void LoginDialog_Load(object sender, System.EventArgs e)
        {
            if (ctx == null)
            {
                return;
            }
            NameValueList settings = ctx.Settings.Get(this);

            tbServer.Text     = settings["Flygaretorpet.se_Server"];
            tbEmail.Text      = settings["Flygaretorpet.se_Email"];
            tbPassword.Text   = settings["Flygaretorpet.se_Password"];
            checkBox1.Checked = !string.IsNullOrEmpty(tbServer.Text);
        }
Beispiel #30
0
        public static Tt Get <Tt>(string name)
        {
            NameValueList config = OriData;

            lock (Singleton)
            {
                if (config[name] == null)
                {
                    return(default(Tt));
                }
                return(Burst.Utils.DeserializeAs <Tt>(config[name]));
            }
        }
Beispiel #31
0
        /// <summary>
        /// 所需参数: Host, Database, Username, Password, ExtraConfiguration(NameValueList)。
        /// </summary>
        public virtual string BuildConnectionString(NameValueList pms)
        {
            string res = "";

            if (pms.ContainsKey("Host"))
            {
                if (!string.IsNullOrEmpty(pms["Host"] as string))
                {
                    res = string.Format("Server={0};", pms["Host"]);
                }
            }
            if (pms.ContainsKey("Database"))
            {
                if (!string.IsNullOrEmpty(pms["Database"] as string))
                {
                    res = string.Format("{0}Database={1};", res, pms["Database"]);
                }
            }
            if (pms.ContainsKey("Username"))
            {
                if (!string.IsNullOrEmpty(pms["Username"] as string))
                {
                    res = string.Format("{0}Uid={1};", res, pms["Username"]);
                }
            }
            if (pms.ContainsKey("Password"))
            {
                if (!string.IsNullOrEmpty(pms["Password"] as string))
                {
                    res = string.Format("{0}Pwd={1};", res, pms["Password"]);
                }
            }
            if (pms.ContainsKey("Charset"))
            {
                if (!string.IsNullOrEmpty(pms["Charset"] as string))
                {
                    res = string.Format("{0}Charset={1};", res, pms["Charset"]);
                }
            }
            if (pms.ContainsKey("ExtraConfiguration"))
            {
                if (pms["ExtraConfiguration"] is NameValueList)
                {
                    foreach (NameValue nv in pms["ExtraConfiguration"] as NameValueList)
                    {
                        res = string.Format("{0}{1}={2};", res, nv.Name, nv.Value);
                    }
                }
            }
            return(res);
        }
Beispiel #32
0
        public void GetAppList(string scope)
        {
            try
            {
                NameValueList appList = _dtoProvider.GetAppList(scope);

                HttpContext.Current.Response.ContentType = "application/xml";
                HttpContext.Current.Response.Write(Utility.SerializeDataContract <NameValueList>(appList));
            }
            catch (Exception ex)
            {
                ExceptionHander(ex);
            }
        }
Beispiel #33
0
 private void LoginDialog_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult != DialogResult.OK)
     {
         return;
     }
     if (string.IsNullOrEmpty(tbServer.Text.Trim()))
     {
         MessageBox.Show("Please enter a server");
         e.Cancel = true;
         return;
     }
     if (!tbServer.Text.Trim().Contains("."))
     {
         MessageBox.Show("Please enter a valid server...");
         e.Cancel = true;
         return;
     }
     if (tbServer.Text.Trim().Contains(":") || tbServer.Text.Trim().Contains("/") || tbServer.Text.Trim().Contains(" "))
     {
         MessageBox.Show("Server must be specified as \"server.domain\", without ports, protocols etc.");
         e.Cancel = true;
         return;
     }
     if (string.IsNullOrEmpty(tbEmail.Text.Trim()))
     {
         MessageBox.Show("Please enter an email");
         e.Cancel = true;
         return;
     }
     if (string.IsNullOrEmpty(tbPassword.Text.Trim()))
     {
         MessageBox.Show("Please enter a password");
         e.Cancel = true;
         return;
     }
     if (ctx != null)
     {
         if (checkBox1.Checked)
         {
             NameValueList settings = new NameValueList();
             settings["Flygaretorpet.se_Server"]   = tbServer.Text;
             settings["Flygaretorpet.se_Email"]    = tbEmail.Text;
             settings["Flygaretorpet.se_Password"] = tbPassword.Text;
             ctx.Settings.Set(this, settings);
             return;
         }
         ctx.Settings.Set(this, new NameValueList());
     }
 }
Beispiel #34
0
 public override string BuildConnectionString(NameValueList pms)
 {
     StringBuilder res = new StringBuilder("Provider=Microsoft.Jet.OLEDB.4.0;");
     if (pms.ContainsKey("FilePath"))
         if (!string.IsNullOrEmpty(pms["FilePath"] as string))
             res.AppendFormat("Data Source={0};", Path.GetFullPath(pms["FilePath"] as string));
     if (pms.ContainsKey("Password"))
         if (!string.IsNullOrEmpty(pms["Password"] as string))
             res.AppendFormat("Password={0};", pms["Password"]);
     if (pms.ContainsKey("ExtraConfiguration"))
         if (pms["ExtraConfiguration"] is NameValueList)
             foreach (NameValue nv in pms["ExtraConfiguration"] as NameValueList)
                 res.AppendFormat("{0}={1};", nv.Name, nv.Value);
     return res.ToString();
 }
Beispiel #35
0
        public NameValueList SaveFields()
        {
            var nvList = new NameValueList();

            // Find all fields that are persistable, and record those of them that have non-null values
            for (int idx = this.RepeaterIndex + 1; idx < this.EndingIndex; idx++)
            {
                var field = this.Form.Fields[idx];
                if (field is SBSPersistableFormField && field.Value != null)
                {
                    nvList.Add(new NameValuePair(field.Name, field.Value));
                }
            }

            return(nvList);
        }
Beispiel #36
0
        /// <summary>
        ///
        /// </summary>
        private void FilterItems()
        {
            foreach (DataGridViewRow row in grid.Rows)
            {
                AccountTransaction trans = row.Tag as AccountTransaction;
                if (trans == null)
                {
                    continue;
                }
                row.Visible = checkBox1.Checked || (trans.Date.Year == dateTimePicker1.Value.Year && trans.Date.Month == dateTimePicker1.Value.Month);
            }
            NameValueList settings = ctx.Settings.Get(this);

            settings["ShowAll"]    = checkBox1.Checked ? "true" : "false";
            settings["FilterDate"] = dateTimePicker1.Value.Ticks.ToString();
        }
Beispiel #37
0
        public void UnloadControl(UnloadFinanceControlEventArgs e)
        {
            if (ctx == null || ctx.TreeNode == null)
            {
                return;
            }
            NameValueList settings = ctx.Settings.Get(this);

            settings["SelectedAccount"] = "";
            if (ac != null)
            {
                ac.UnloadControl(e);
                settings["SelectedAccount"] = ac.AccountID.ToString();
            }
            ctx.TreeNode.TreeView.AfterSelect -= TreeViewOnAfterSelect;
            ctx.TreeNode.Nodes.Clear();
        }
Beispiel #38
0
 /// <summary>
 /// 所需参数: Host, Database, Username, Password, ExtraConfiguration(NameValueList)。
 /// </summary>
 public virtual string BuildConnectionString(NameValueList pms)
 {
     string res = "";
     if (pms.ContainsKey("Host"))
         if (!string.IsNullOrEmpty(pms["Host"] as string))
             res = string.Format("Data Source={0};", pms["Host"]);
     if (pms.ContainsKey("Database"))
         if (!string.IsNullOrEmpty(pms["Database"] as string))
             res = string.Format("{0}Initial Catalog={1};", res, pms["Database"]);
     if (pms.ContainsKey("Username"))
         if (!string.IsNullOrEmpty(pms["Username"] as string))
             res = string.Format("{0}User ID={1};", res, pms["Username"]);
     if (pms.ContainsKey("Password"))
         if (!string.IsNullOrEmpty(pms["Password"] as string))
             res = string.Format("{0}Password={1};", res, pms["Password"]);
     if (pms.ContainsKey("ExtraConfiguration"))
         if (pms["ExtraConfiguration"] is NameValueList)
             foreach (NameValue nv in pms["ExtraConfiguration"] as NameValueList)
                 res = string.Format("{0}{1}={2};", res, nv.Name, nv.Value);
     return res;
 }
Beispiel #39
0
 public virtual Command GetReplaceCommand(string tableName, object key, string keyFieldName, NameValueList pms, DbProvider provider)
 {
     return null;
 }
Beispiel #40
0
 public virtual void InitializeOptions(NameValueList options)
 {
     options["DefaultDbProviderFactory"] = System.Data.SqlClient.SqlClientFactory.Instance;
 }
Beispiel #41
0
 private void LoginDialog_FormClosing( object sender, FormClosingEventArgs e )
 {
     if( DialogResult != DialogResult.OK ) {
         return;
     }
     if( string.IsNullOrEmpty( tbServer.Text.Trim() ) ) {
         MessageBox.Show( "Please enter a server" );
         e.Cancel = true;
         return;
     }
     if( !tbServer.Text.Trim().Contains( "." ) ) {
         MessageBox.Show( "Please enter a valid server..." );
         e.Cancel = true;
         return;
     }
     if( tbServer.Text.Trim().Contains( ":" ) || tbServer.Text.Trim().Contains( "/" ) || tbServer.Text.Trim().Contains( " " ) ) {
         MessageBox.Show( "Server must be specified as \"server.domain\", without ports, protocols etc." );
         e.Cancel = true;
         return;
     }
     if( string.IsNullOrEmpty( tbEmail.Text.Trim() ) ) {
         MessageBox.Show( "Please enter an email" );
         e.Cancel = true;
         return;
     }
     if( string.IsNullOrEmpty( tbPassword.Text.Trim() ) ) {
         MessageBox.Show( "Please enter a password" );
         e.Cancel = true;
         return;
     }
     if( ctx != null ) {
         if( checkBox1.Checked ) {
             NameValueList settings = new NameValueList();
             settings[ "Flygaretorpet.se_Server" ] = tbServer.Text;
             settings[ "Flygaretorpet.se_Email" ] = tbEmail.Text;
             settings[ "Flygaretorpet.se_Password" ] = tbPassword.Text;
             ctx.Settings.Set( this, settings );
             return;
         }
         ctx.Settings.Set( this, new NameValueList());
     }
 }
Beispiel #42
0
 public void SchemaTestMethod()
 {
     var pms = new NameValueList();
     pms.Add("");
     var schema = new DbSchema(DbProvider.Initialize(pms));
 }
Beispiel #43
0
 public override void InitializeOptions(NameValueList options)
 {
     options["DefaultDbProviderFactory"] = "System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.76.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139";
 }
Beispiel #44
0
        public NameValueList[] Execute(Transaction trans)
        {
            DbConnection conn = null;
            DbDataReader r = null;
            bool err = false;
            try
            {
                DbCommand cmd;
                if (trans != null)
                    cmd = this.AsCommonCommand(trans.CurrentConnection.OriConnection, trans.CurrentTransaction);
                else
                {
                    conn = DbProvider.Current.CreateConnection();
                    conn.Open();
                    cmd = this.AsCommonCommand(conn, null);
                }
                r = cmd.ExecuteReader();
                List<NameValueList> res = new List<NameValueList>();
                List<string> keys = new List<string>();
                while (r.Read())
                {
                    NameValueList data = new NameValueList();
                    for (int i = 0; i < r.FieldCount; i++)
                    {
                        if (res.Count == 0)
                            keys.Add(r.GetName(i));
                        data.Add(keys[i], r.GetValue(i));
                    }
                    res.Add(data);
                }
                r.Close();
                return res.ToArray();
            }
            catch (Exception e)
            {
                err = true;
                if (trans != null)
                    trans.success = false;
                
                #if DEBUG
                    CommandException ce = new CommandException("Execute", this, e);
                    Debug.WriteLine(ce);
                    throw ce;
                #endif

                return new NameValueList[] { };
            }
            finally
            {
                try
                {
                    r.Close();
                }
                catch (Exception e)
                {
                    if (trans != null)
                        trans.success = false;

                    #if DEBUG
                        if (!err)
                        {
                            CommandException ce = new CommandException("Execute", this, e);
                            Debug.WriteLine(ce);
                            throw ce;
                        }
                    #endif
                }
                try
                {
                    if (trans == null)
                        conn.Close();
                }
                catch (Exception e)
                {
                    if (trans != null)
                        trans.success = false;

                    #if DEBUG
                        if (!err)
                        {
                            CommandException ce = new CommandException("Execute", this, e);
                            Debug.WriteLine(ce);
                            throw ce;
                        }
                    #endif
                }
            }
        }
        public static void Generate(
            IGenerator generator,
            DTE DTE, GeneralProperty[] GeneralProperties,
            bool OverwriteAll,
            bool ToPascalName,
            bool GenerateInitializer,
            NameValueList InitializeParameters,
            string Namespace
        )
        {
            Project _project = Utils.GetProject(DTE);
            ProjectItem pi = Utils.GetSelectedDirectory(DTE);

            ProjectItems _currentDirectory = null;
            string _path = null;
            string _language = null;
            string _fileExtension = null;

            if (pi != null)
            {
                _currentDirectory = pi.ProjectItems;
                _path = pi.Properties.Item("FullPath").Value.ToString();
            }
            else
            {
                _currentDirectory = _project.ProjectItems;
                _path = _project.Properties.Item("FullPath").Value.ToString();
            }

            if (_project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageCSharp)
            {
                _language = "CSharp";
                _fileExtension = ".cs";
            }
            else if (_project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVB)
            {
                _language = "VisualBasic";
                _fileExtension = ".vb";
            }

            //Generate
            foreach (GeneralProperty gp in GeneralProperties)
            {
                if (string.IsNullOrWhiteSpace(gp.ClassName))
                {
                    if (ToPascalName)
                        gp.ClassName = gp.TableName.ToPascalName();
                    else
                        gp.ClassName = gp.TableName;
                }
                foreach (GFieldInfo fieldinfo in gp.Fields)
                    if (string.IsNullOrWhiteSpace(fieldinfo.DisplayName))
                    {
                        if (ToPascalName)
                            fieldinfo.DisplayName = fieldinfo.Name.ToPascalName();
                        else
                            fieldinfo.DisplayName = fieldinfo.Name;
                    }
                /*
                foreach (OwnerFieldInfo ownerfieldinfo in gp.OwnerFields)
                    if (string.IsNullOrWhiteSpace(ownerfieldinfo.DisplayName))
                    {
                        if (ToPascalName)
                            ownerfieldinfo.DisplayName = ownerfieldinfo.Name.ToPascalName();
                        else
                            ownerfieldinfo.DisplayName = ownerfieldinfo.Name;
                    }
                */

                ProjectItem _baseItem = null;

                string basefile = Path.Combine(_path, gp.ClassName + _fileExtension);
                if (OverwriteAll)
                    File.WriteAllText(basefile, generator.GenerateBaseFile(gp, Namespace, _language));
                try
                {
                    _baseItem = _currentDirectory.Item(Path.GetFileName(basefile));
                }
                catch
                {
                    if (!OverwriteAll)
                        File.WriteAllText(basefile, generator.GenerateBaseFile(gp, Namespace, _language));
                    _baseItem = _currentDirectory.AddFromFile(basefile);
                }

                string fieldsfile = Path.Combine(_path, gp.ClassName + ".Fields" + _fileExtension);
                File.WriteAllText(fieldsfile, generator.GenerateFieldsFile(gp, Namespace, _language));
                try
                {
                    _baseItem.ProjectItems.Item(Path.GetFileName(fieldsfile));
                }
                catch
                {
                    _baseItem.ProjectItems.AddFromFile(fieldsfile);
                }

                /*
                string ownerfieldsfile = Path.Combine(_path, gp.ClassName + ".OwnerFields" + _fileExtension);
                if (OverwriteAll && File.Exists(ownerfieldsfile) || gp.OwnerFields.Count > 0)
                {
                    File.WriteAllText(ownerfieldsfile, generator.GenerateOwnerFieldsFile(gp, Namespace, _language));
                    try
                    {
                        _baseItem.ProjectItems.Item(Path.GetFileName(ownerfieldsfile));
                    }
                    catch
                    {
                        _baseItem.ProjectItems.AddFromFile(ownerfieldsfile);
                    }
                }
                */
            }

            if (GenerateInitializer)
            {
                var init_file = Path.Combine(_path, "DbInitializer" + _fileExtension);
                File.WriteAllText(
                    init_file,
                    generator.GenerateInitializeFile(InitializeParameters, Namespace, _language)
                );
                try
                {
                    _currentDirectory.Item(Path.GetFileName(init_file));
                }
                catch
                {
                    _currentDirectory.AddFromFile(init_file);
                }
            }
        }
        public string GenerateInitializeFile(NameValueList Parameters, string Namespace, string Language)
        {
            CodeCompileUnit ccu = new CodeCompileUnit();
            System.CodeDom.CodeNamespace cns = new System.CodeDom.CodeNamespace(Namespace);
            cns.Imports.Add(new CodeNamespaceImport("System"));
            cns.Imports.Add(new CodeNamespaceImport("Burst"));
            cns.Imports.Add(new CodeNamespaceImport("Burst.Data"));
            CodeTypeDeclaration model = new CodeTypeDeclaration("DbInitializer");
            model.TypeAttributes = TypeAttributes.Public;

            var init = new CodeMemberMethod();
            init.Attributes = MemberAttributes.Static | MemberAttributes.Public;
            init.Name = "InitializeDb";
            init.ReturnType = new CodeTypeReference(typeof(bool));
            init.Parameters.Add(new CodeParameterDeclarationExpression(typeof(bool), "InitializeEntities"));
            init.Statements.Add(new CodeVariableDeclarationStatement(typeof(NameValueList), "__pms", new CodeObjectCreateExpression(typeof(Burst.NameValueList))));
            foreach (var nv in Parameters)
            {
                CodeExpression value;
                var _type = nv.Value.GetType();
                if(_type.IsValueType || _type == typeof(string))
                    value = new CodePrimitiveExpression(nv.Value);
                else
                    value = new CodeObjectCreateExpression(_type);
                init.Statements.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("__pms"), "Add",
                    new CodePrimitiveExpression(nv.Name),
                    value
                )));
            }
            init.Statements.Add(new CodeVariableDeclarationStatement(
                typeof(Burst.Data.DbProvider),
                "__provider",
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(typeof(Burst.Data.DbProvider)),
                    "Initialize",
                    new CodeVariableReferenceExpression("__pms")
                )
            ));
            var init_entities = new List<CodeStatement>();
            foreach (var c in Entities)
                init_entities.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(c), "InitializeDbInfo"
                )));
            init.Statements.Add(new CodeConditionStatement(
                new CodeBinaryOperatorExpression(
                    new CodeVariableReferenceExpression("__provider"),
                    CodeBinaryOperatorType.IdentityInequality,
                    new CodePrimitiveExpression(null)
                ),
                new CodeStatement[] {
                    new CodeConditionStatement(
                        new CodeArgumentReferenceExpression("InitializeEntities"),
                        init_entities.ToArray()
                    ),
                    new CodeMethodReturnStatement(new CodePrimitiveExpression(true))
                },
                new CodeStatement[] {
                    new CodeMethodReturnStatement(new CodePrimitiveExpression(false))
                }
            ));
            model.Members.Add(init);

            cns.Types.Add(model);
            ccu.Namespaces.Add(cns);
            return _getString(ccu, Language);
        }
Beispiel #47
0
 public virtual Command GetReplaceCommand(string tableName, object key, string keyFieldName, NameValueList pms, DbProvider provider)
 {
     StringBuilder vs = new StringBuilder();
     foreach (string s in pms.Keys)
         vs.AppendFormat("{0},", s);
     if (vs.Length > 0)
         vs.Remove(vs.Length - 1, 1);
     string cmd = string.Format("replace into {0} values ({1})", tableName, vs);
     return provider.CreateCommand(cmd, pms);
 }
Beispiel #48
0
 public virtual void InitializeOptions(NameValueList options)
 {
     options["DefaultDbProviderFactory"] = "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D";
 }
Beispiel #49
0
 public override void InitializeOptions(NameValueList options)
 {
     options["DefaultDbProviderFactory"] = System.Data.OleDb.OleDbFactory.Instance;
 }
Beispiel #50
0
 public AdapterProperty()
 {
     pms = new NameValueList();
 }
        public void Get_by_name_should_return_null_if_not_found()
        {
            var list = new NameValueList();

            Assert.That(list["invalid"], Is.Null);
        }