public void Initialization()
        {
            object1 = new DataObject { Id = 1 };
            object1.Add("x", 2);
            object1.Add("y", 2);

            object2 = new DataObject { Id = 2 };
            object2.Add("x", 5);
            object2.Add("y", 2);

            object3 = new DataObject { Id = 3 };
            object3.Add("x", 4);
            object3.Add("y", 3);

            object4 = new DataObject { Id = 4 };
            object4.Add("x", 3);
            object4.Add("y", 6);

            object5 = new DataObject { Id = 5 };
            object5.Add("x", 8);
            object5.Add("y", 8);

            object6 = new DataObject { Id = 6 };
            object6.Add("x", 9);
            object6.Add("y", 7);
        }
Пример #2
0
        public void Register()
        {
            L2Database DB     = new L2Database();
            DataObject Object = new DataObject();

            Object.Add("login", _UserName);
            Object.Add("password", _PassWord);
            DB.Table("account").Add(Object);
        }
Пример #3
0
        public override void Handle(ref Page page, ISpider spider)
        {
            var cache = new DataObject();

            cache.Add("Identity", _spider.Identity);
            cache.Add("Name", _spider.Name);
            cache.Add("TaskId", _spider.TaskId);
            cache.Add("Url", page.Url);
            cache.Add("Content", page.Content);

            _pipeline.Process(typeof(CrawlCache).FullName, new List <DataObject>
            {
                cache
            });
        }
        public void InputOutputTest()
        {
            var test = new DataObject { Id = 1 };
            test.Add("x", 2);
            test.Add("y", 2);

            Assert.AreEqual(1, test.Id);
            Assert.AreEqual((double)2, test.Get("x"));
            Assert.AreEqual((double)2, test.Get("y"));

            foreach (DictionaryEntry item in test)
            {
                Assert.AreEqual((double)2, item.Value);
                Assert.IsTrue((string)item.Key == "x" || (string)item.Key == "y");
            }
        }
Пример #5
0
            protected override DataObject HandleDataOject(DataObject data, Page page)
            {
                var soldStr = data.TryGetValue("sold");

                if (soldStr == null)
                {
                    data.Add("sold", "-1");
                    return(data);
                }
                else
                {
                    var sold  = int.Parse(soldStr?.ToString());
                    var price = float.Parse(data.TryGetValue("price")?.ToString());

                    if (price >= 100 && price < 5000)
                    {
                        if (sold <= 1)
                        {
                            if (!page.SkipTargetUrls)
                            {
                                page.SkipTargetUrls = true;
                            }
                        }
                        else
                        {
                            return(data);
                        }
                    }
                    else if (price < 100)
                    {
                        if (sold <= 5)
                        {
                            if (!page.SkipTargetUrls)
                            {
                                page.SkipTargetUrls = true;
                            }
                        }
                        else
                        {
                            return(data);
                        }
                    }
                    else
                    {
                        if (sold == 0)
                        {
                            if (!page.SkipTargetUrls)
                            {
                                page.SkipTargetUrls = true;
                            }
                        }
                        else
                        {
                            return(data);
                        }
                    }
                    return(data);
                }
            }
Пример #6
0
        public void Login()
        {
            L2Database DB     = new L2Database();
            DataObject Object = new DataObject();

            Object.Add("lastlogin", DateTime.Now);
            DB.Table("account").Update(Object, new WhereStatement("login", _UserName).Add("password", _PassWord));
        }
Пример #7
0
 public void PutObject(string key, object obj)
 {
     if (DataObject.ContainsKey(key))
     {
         throw new ArgumentException("La llave ya existe");
     }
     DataObject.Add(key, obj);
 }
Пример #8
0
 protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context)
 {
     return ob1.Add(ob2);
 }
        private DataObject EvaluateBinary(DataObject left, SqlExpressionType binaryType, DataObject right)
        {
            if (binaryType.IsAll())
                return left.Any(binaryType.SubQueryPlainType(), right, context);
            if (binaryType.IsAny())
                return left.All(binaryType.SubQueryPlainType(), right, context);

            switch (binaryType) {
                case SqlExpressionType.Add:
                    return left.Add(right);
                case SqlExpressionType.Subtract:
                    return left.Subtract(right);
                case SqlExpressionType.Multiply:
                    return left.Multiply(right);
                case SqlExpressionType.Divide:
                    return left.Divide(right);
                case SqlExpressionType.Modulo:
                    return left.Modulus(right);
                case SqlExpressionType.GreaterThan:
                    return left.IsGreaterThan(right);
                case SqlExpressionType.GreaterOrEqualThan:
                    return left.IsGreterOrEqualThan(right);
                case SqlExpressionType.SmallerThan:
                    return left.IsSmallerThan(right);
                case SqlExpressionType.SmallerOrEqualThan:
                    return left.IsSmallerOrEqualThan(right);
                case SqlExpressionType.Equal:
                    return left.IsEqualTo(right);
                case SqlExpressionType.NotEqual:
                    return left.IsNotEqualTo(right);
                case SqlExpressionType.Is:
                    return left.Is(right);
                case SqlExpressionType.IsNot:
                    return left.IsNot(right);
                case SqlExpressionType.Like:
                    return left.IsLike(right);
                case SqlExpressionType.NotLike:
                    return left.IsNotLike(right);
                case SqlExpressionType.And:
                    return left.And(right);
                case SqlExpressionType.Or:
                    return left.Or(right);
                case SqlExpressionType.XOr:
                    return left.XOr(right);
                // TODO: ANY and ALL
                default:
                    throw new ExpressionEvaluateException(String.Format("The type {0} is not a binary expression or is not supported.", binaryType));
            }
        }
Пример #10
0
        private DataObject EvaluateBinary(DataObject left, SqlExpressionType binaryType, DataObject right)
        {
            if (binaryType.IsAll())
            {
                return(left.Any(binaryType.SubQueryPlainType(), right, context));
            }
            if (binaryType.IsAny())
            {
                return(left.All(binaryType.SubQueryPlainType(), right, context));
            }

            switch (binaryType)
            {
            case SqlExpressionType.Add:
                return(left.Add(right));

            case SqlExpressionType.Subtract:
                return(left.Subtract(right));

            case SqlExpressionType.Multiply:
                return(left.Multiply(right));

            case SqlExpressionType.Divide:
                return(left.Divide(right));

            case SqlExpressionType.Modulo:
                return(left.Modulus(right));

            case SqlExpressionType.GreaterThan:
                return(left.IsGreaterThan(right));

            case SqlExpressionType.GreaterOrEqualThan:
                return(left.IsGreterOrEqualThan(right));

            case SqlExpressionType.SmallerThan:
                return(left.IsSmallerThan(right));

            case SqlExpressionType.SmallerOrEqualThan:
                return(left.IsSmallerOrEqualThan(right));

            case SqlExpressionType.Equal:
                return(left.IsEqualTo(right));

            case SqlExpressionType.NotEqual:
                return(left.IsNotEqualTo(right));

            case SqlExpressionType.Is:
                return(left.Is(right));

            case SqlExpressionType.IsNot:
                return(left.IsNot(right));

            case SqlExpressionType.Like:
                return(left.IsLike(right));

            case SqlExpressionType.NotLike:
                return(left.IsNotLike(right));

            case SqlExpressionType.And:
                return(left.And(right));

            case SqlExpressionType.Or:
                return(left.Or(right));

            case SqlExpressionType.XOr:
                return(left.XOr(right));

            // TODO: ANY and ALL
            default:
                throw new ExpressionEvaluateException(String.Format("The type {0} is not a binary expression or is not supported.", binaryType));
            }
        }
Пример #11
0
 public override DataObject Evaluate(DataObject ob1, DataObject ob2, IGroupResolver group, IVariableResolver resolver, IQueryContext context)
 {
     return ob1.Add(ob2);
 }
Пример #12
0
 protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context)
 {
     return(ob1.Add(ob2));
 }
Пример #13
0
        public override void Process(string entityName, List <DataObject> datas)
        {
            EntityAdapter metadata;

            if (EntityAdapters.TryGetValue(entityName, out metadata))
            {
                NetworkCenter.Current.Execute("pp", () =>
                {
                    if (metadata.InsertModel)
                    {
                        using (var conn = ConnectionStringSettings.GetDbConnection())
                        {
                            var cmd         = conn.CreateCommand();
                            cmd.CommandText = metadata.InsertSql;
                            cmd.CommandType = CommandType.Text;

                            foreach (var data in datas)
                            {
                                cmd.Parameters.Clear();

                                foreach (var column in metadata.Columns)
                                {
                                    var value     = data[$"{column.Name}"];
                                    var parameter = CreateDbParameter($"@{column.Name}", value);
                                    cmd.Parameters.Add(parameter);
                                }

                                cmd.ExecuteNonQuery();
                            }
                        }
                    }
                    else
                    {
                        using (var conn = ConnectionStringSettings.GetDbConnection())
                        {
                            foreach (var data in datas)
                            {
                                bool needUpdate;
                                if (CheckIfSameBeforeUpdate)
                                {
                                    var selectCmd         = conn.CreateCommand();
                                    selectCmd.CommandText = metadata.SelectSql;
                                    selectCmd.CommandType = CommandType.Text;
                                    if (string.IsNullOrEmpty(metadata.Table.Primary))
                                    {
                                        var primaryParameter = CreateDbParameter($"@{Core.Environment.IdColumn}", data[Core.Environment.IdColumn]);
                                        selectCmd.Parameters.Add(primaryParameter);
                                    }
                                    else
                                    {
                                        var columns = metadata.Table.Primary.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(c => c.Trim());
                                        foreach (var column in columns)
                                        {
                                            var primaryParameter = CreateDbParameter($"@{column}", data[$"{column}"]);
                                            selectCmd.Parameters.Add(primaryParameter);
                                        }
                                    }

                                    var reader     = selectCmd.ExecuteReader();
                                    DataObject old = new DataObject();
                                    if (reader.Read())
                                    {
                                        for (int i = 0; i < reader.FieldCount; ++i)
                                        {
                                            old.Add(reader.GetName(i), reader.GetString(i));
                                        }
                                    }
                                    reader.Dispose();
                                    selectCmd.Dispose();

                                    // the primary key is not exists.
                                    if (old.Count == 0)
                                    {
                                        continue;
                                    }

                                    string oldValue = string.Join("-", old.Values);

                                    StringBuilder newValueBuilder = new StringBuilder();
                                    foreach (var column in metadata.Table.UpdateColumns)
                                    {
                                        var v = data[$"$.{column}"];
                                        newValueBuilder.Append($"-{v}");
                                    }
                                    string newValue = newValueBuilder.ToString().Substring(1, newValueBuilder.Length - 1);
                                    needUpdate      = oldValue != newValue;
                                }
                                else
                                {
                                    needUpdate = true;
                                }

                                if (needUpdate)
                                {
                                    var cmd         = conn.CreateCommand();
                                    cmd.CommandText = metadata.UpdateSql;
                                    cmd.CommandType = CommandType.Text;

                                    foreach (var column in metadata.Table.UpdateColumns)
                                    {
                                        var parameter = CreateDbParameter($"@{column}", data[$"{column}"]);
                                        cmd.Parameters.Add(parameter);
                                    }

                                    if (string.IsNullOrEmpty(metadata.Table.Primary))
                                    {
                                        var primaryParameter    = CreateDbParameter($"@{Core.Environment.IdColumn}", data[Core.Environment.IdColumn]);
                                        primaryParameter.DbType = DbType.String;
                                        cmd.Parameters.Add(primaryParameter);
                                    }
                                    else
                                    {
                                        var columns = metadata.Table.Primary.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(c => c.Trim());
                                        foreach (var column in columns)
                                        {
                                            var primaryParameter = CreateDbParameter($"@{column}", data[$"{column}"]);
                                            cmd.Parameters.Add(primaryParameter);
                                        }
                                    }
                                    cmd.ExecuteNonQuery();
                                }
                            }
                        }
                    }
                });
            }
        }