示例#1
0
        /// <summary>
        /// 根据 ArticleID 获取文章实体
        /// </summary>
        /// <param name="inArticleID"></param>
        /// <returns></returns>
        public static MContent GetArticle(long inArticleID)
        {
            string sql = @" SELECT * FROM wz_Content WHERE Origin = '今日头条' AND ArticleID = @inArticleID ";

            SqlParameter para = new SqlParameter("@inArticleID", SqlDbType.BigInt)
            {
                Value = inArticleID
            };

            DataTable dt    = SqlHelper.ExecuteDataTable(CommandType.Text, sql, "", para);
            MContent  model = null;

            if (dt.Rows.Count > 0)
            {
                model = new MContent
                {
                    ArticleID   = Convert.ToInt64(dt.Rows[0]["ArticleID"]),
                    DomainID    = Convert.ToInt32(dt.Rows[0]["DomainID"]),
                    Title       = dt.Rows[0]["Title"].ToString(),
                    Conten      = dt.Rows[0]["Conten"].ToString(),
                    ReleaseTime = Convert.ToInt64(dt.Rows[0]["ReleaseTime"])
                };
            }
            return(model);
        }
        public IActionResult Index()
        {
            ArrayList bestSellerList = new ArrayList();
            ArrayList newArrivalList = new ArrayList();
            ArrayList productList    = new ArrayList();

            MContent bestSellerCodes = (MContent)GetContentCache().GetValue("code/Best_Seller_Products");

            foreach (string code in bestSellerCodes.Values.Select(kvp => kvp.Value).ToList())
            {
                MProduct product = (MProduct)GetProductsCache().GetValue(code);
                bestSellerList.Add(product);
                productList.Add(product);
            }

            MContent newArrivalCodes = (MContent)GetContentCache().GetValue("code/New_Arrival_Products");

            foreach (string code in newArrivalCodes.Values.Select(kvp => kvp.Value).ToList())
            {
                MProduct product = (MProduct)GetProductsCache().GetValue(code);
                newArrivalList.Add(product);
                productList.Add(product);
            }
            ViewBag.BestSellerList = bestSellerList;
            ViewBag.NewArrivalList = newArrivalList;
            ViewBag.ProductList    = productList;
            return(View());
        }
示例#3
0
        /// <summary>
        /// 随机获取文章
        /// </summary>
        /// <param name="top"></param>
        /// <param name="domainId"></param>
        /// <returns></returns>
        public static List <MContent> GetRandomArticles(int top, int domainId)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append(" SELECT TOP " + top + " * FROM wz_Content WHERE Origin = '今日头条' ");
            if (domainId != 0)
            {
                sql.Append(" AND DomainID = " + domainId);
            }
            sql.Append(" ORDER BY NEWID() ");

            DataTable       dt   = SqlHelper.ExecuteDataTable(CommandType.Text, sql.ToString());
            List <MContent> list = new List <MContent>();

            foreach (DataRow item in dt.Rows)
            {
                MContent model = new MContent
                {
                    ArticleID   = Convert.ToInt32(item["ArticleID"]),
                    Title       = item["Title"].ToString(),
                    ReleaseTime = Convert.ToInt64(item["ReleaseTime"]),
                    DomainID    = Convert.ToInt32(item["DomainID"]),
                    Conten      = item["Conten"].ToString()
                };
                list.Add(model);
            }

            return(list);
        }
示例#4
0
        public override void UpdateView(MBase model)
        {
            MContent mContent = model as MContent;

            vItemIcon.gameObject.SetActive(false);
            vEquipmentIcon.gameObject.SetActive(false);
            vCharacterIcon.gameObject.SetActive(false);
            contentChild.SetActive(false);
            switch (mContent.type)
            {
            case ContentType.item:
                SetItem(mContent);
                break;

            case ContentType.horse:
            case ContentType.weapon:
            case ContentType.clothes:
                SetEquipment(mContent);
                break;

            case ContentType.character:
                SetCharacter(mContent);
                break;

            default:
                SetContent(mContent);
                break;
            }
        }
示例#5
0
    MStatementGroup BuildStatementGroup(MContent x, VirtualIdentifierTable t)
    {
        var res = new MStatementGroup();

        res.statements = x.subs.Map((h) => BuildStatement(h, t));
        res.captures   = new CaptureTable().Fold(res.statements, (h, v) => h.Merge(v.captures));
        return(res);
    }
示例#6
0
        private void SetCharacter(MContent mContent)
        {
            MCharacter character = new MCharacter();

            character.CharacterId = mContent.content_id;
            character.Level       = 0;
            vCharacterIcon.gameObject.SetActive(true);
            vCharacterIcon.BindingContext = character.ViewModel;
            vCharacterIcon.UpdateView();
            ContentName = character.Master.name;
        }
示例#7
0
 private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (e.NewTextValue.Length > 2)
     {
         lstMC.BindingContext = MContent.BindingWithGrouping(e.NewTextValue);
     }
     else if (string.IsNullOrEmpty(e.NewTextValue))
     {
         lstMC.BindingContext = MContent.BindingWithGrouping();
     }
 }
示例#8
0
        private void SetEquipment(MContent mContent)
        {
            MEquipment equipment = new MEquipment();

            equipment.EquipmentId   = mContent.content_id;
            equipment.EquipmentType = (App.Model.Master.MEquipment.EquipmentType)System.Enum.Parse(typeof(App.Model.Master.MEquipment.EquipmentType), mContent.type.ToString(), true);
            vEquipmentIcon.gameObject.SetActive(true);
            vEquipmentIcon.BindingContext = equipment.ViewModel;
            vEquipmentIcon.UpdateView();
            ContentName = equipment.Master.name;
        }
示例#9
0
        private void SetItem(MContent mContent)
        {
            MItem item = new MItem();

            item.ItemId = mContent.content_id;
            item.Cnt    = 1;
            vItemIcon.gameObject.SetActive(true);
            vItemIcon.BindingContext = item.ViewModel;
            vItemIcon.UpdateView();
            ContentName = item.Master.name;
        }
示例#10
0
        private void SetContent(MContent mContent)
        {
            contentChild.SetActive(true);
            Image[] icons = contentChild.transform.Find("Icon").GetComponentsInChildren <Image>(true);
            foreach (Image icon in icons)
            {
                icon.gameObject.SetActive(icon.name == mContent.type.ToString());
            }
            Text num = contentChild.GetComponentInChildren <Text>();

            num.text    = mContent.value.ToString();
            ContentName = Language.Get(mContent.type.ToString());
        }
示例#11
0
        public SanalSiniflar()
        {
            InitializeComponent();
            lstMC.BindingContext = MContent.BindingWithGrouping();

            lstMC.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(async(t) =>
                {
                    await lstMC.ScaleTo(0.95, 100, Easing.CubicOut);
                    await lstMC.ScaleTo(1, 50, Easing.CubicIn);
                    await lstMC.RotateYTo(360, 1500, Easing.SpringIn);
                })
            }); //sağa, sola kaydırma, dokunma işlemleri icin
        }
示例#12
0
    MStatement BuildStatement(MContent x, VirtualIdentifierTable t)
    {
        switch (x.type)
        {
        case "StatementEmpty":
            return(new MStatementEmpty());

        case "StatementExp":
        {
            var exp = BuildExpression(x.subs[0], t);
            return(new MStatementExp()
                {
                    exp = exp, captures = exp.captures.Substract(t)
                });
        }

        case "StatementRetExp":
        {
            var exp = BuildExpression(x.subs[0], t);
            return(new MStatementRet()
                {
                    exp = exp, captures = exp.captures.Substract(t)
                });
        }

        case "StatementRetEmpty":
            return(new MStatementRetEmpty());

        case "StatementLoop":
        {
            var cond = BuildExpression(x.subs[0], t);
            var exp  = BuildExpression(x.subs[1], t);
            return(new MStatementLoop()
                {
                    condition = cond, exp = exp, captures = exp.captures.Substract(t)
                });
        }

        default: break;
        }
        throw new Exception("unknown statement type : " + x.type + " at line " + x.line);
    }
示例#13
0
        protected override int Execute()
        {
            ILogger logger = GetLogger();
            CTable  t      = XmlToCTable();

            INoSqlContext ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext");

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            SaveContent opr = (SaveContent)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContent");

            try
            {
                ArrayList types = t.GetChildArray("Contents");
                foreach (CTable pt in types)
                {
                    MContent mc = new MContent();
                    mc.Name          = pt.GetFieldValue("Name");
                    mc.Type          = pt.GetFieldValue("Type");
                    mc.LastMaintDate = DateTime.Now;
                    ArrayList values = pt.GetChildArray("Values");

                    foreach (CTable value in values)
                    {
                        mc.Values = new Dictionary <string, string>();
                        foreach (CField field in value.GetTableFields())
                        {
                            mc.Values[field.GetName()] = field.GetValue();
                        }
                        LogUtils.LogInformation(logger, "Adding content : [{0}][{1}]", mc.Type, mc.Name);
                    }

                    opr.Apply(mc);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error : {0}", e);
            }

            return(0);
        }
示例#14
0
        public void SaveBlankObject()
        {
            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationManipulate <MContent>)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContent");

            MContent dat = new MContent();

            try
            {
                int result = opt.Apply(dat);
                Assert.Fail();
            }
            catch (Exception)
            {
                //Error should be thrown.
                Assert.Pass();
            }
        }
        private IEnumerable <MContent> getDummyContents()
        {
            var content1 = new MContent();

            content1.Name         = "001";
            content1.Type         = "txt";
            content1.Values["EN"] = "one";

            var content2 = new MContent();

            content2.Name         = "002";
            content2.Type         = "jpg";
            content2.Values["EN"] = "two";

            var list = new List <MContent>();

            list.Add(content1);
            list.Add(content2);
            IEnumerable <MContent> dummy = (IEnumerable <MContent>)list;

            return(dummy);
        }
示例#16
0
        public void SaveTest()
        {
            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationManipulate <MContent>)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContent");

            MContent dat = new MContent();

            dat.Name         = "001";
            dat.Type         = "txt";
            dat.Values["EN"] = "one";
            try
            {
                int result = opt.Apply(dat);
                Assert.AreEqual(result, 0);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
        public void Setup()
        {
            var httpContext       = new DefaultHttpContext();
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            var mockController = new Mock <AboutController>()
            {
                CallBase = true
            };

            var iCacheMock = new Mock <ICacheContext>();

            mockController.Setup(foo => foo.GetContentCache()).Returns(iCacheMock.Object);
            mockController.Setup(foo => foo.GetProductTypeCache()).Returns(iCacheMock.Object);
            mockController.Setup(foo => foo.GetProductsCache()).Returns(iCacheMock.Object);

            MContent bestSellers = new MContent();

            bestSellers.Values = new Dictionary <string, string>();
            bestSellers.Values.Add("b1", "ITEM-001");
            bestSellers.Values.Add("b2", "ITEM-002");
            iCacheMock.Setup(foo => foo.GetValue("code/Best_Seller_Products")).Returns(bestSellers);

            MContent newArrivals = new MContent();

            newArrivals.Values = new Dictionary <string, string>();
            newArrivals.Values.Add("n1", "ITEM-003");
            newArrivals.Values.Add("n2", "ITEM-004");
            newArrivals.Values.Add("n3", "ITEM-005");
            iCacheMock.Setup(foo => foo.GetValue("code/New_Arrival_Products")).Returns(newArrivals);

            controller = mockController.Object;
            controller.ControllerContext = controllerContext;
        }
示例#18
0
        /// <summary>
        /// 获取文章列表
        /// </summary>
        /// <returns></returns>
        public static List <MContent> GetArticles(int inPageIndex, int domainId, string search)
        {
            int           pagesize = 10;
            StringBuilder sql      = new StringBuilder();

            sql.Append(" SELECT TOP(" + pagesize + ") * FROM ( ");
            sql.Append(" SELECT ROW_NUMBER() OVER( ORDER BY ReleaseTime DESC ) ");
            sql.Append(" AS ROWNUMBER,* FROM wz_Content WITH(NOLOCK) WHERE Origin = '今日头条' ");
            if (domainId != 0)
            {
                sql.Append("  AND DomainID = " + domainId + " ");
            }
            if (!string.IsNullOrEmpty(search))
            {
                sql.Append(" AND Title LIKE '%" + search + "%' ");
            }
            sql.Append(" ) A WHERE A.ROWNUMBER > ((" + inPageIndex + ") * " + pagesize + ") ");

            DataTable       dt   = SqlHelper.ExecuteDataTable(CommandType.Text, sql.ToString());
            List <MContent> list = new List <MContent>();

            foreach (DataRow item in dt.Rows)
            {
                MContent model = new MContent
                {
                    ArticleID   = Convert.ToInt32(item["ArticleID"]),
                    Title       = item["Title"].ToString(),
                    ReleaseTime = Convert.ToInt64(item["ReleaseTime"]),
                    DomainID    = Convert.ToInt32(item["DomainID"]),
                    Conten      = item["Conten"].ToString()
                };
                list.Add(model);
            }

            return(list);
        }
示例#19
0
    public void Compile(string filePath, bool output = false)
    {
        string source = "";

        try
        {
            source = Compile(filePath, compilerPath);
            string   json  = Compile(filePath, compilerPath);
            MContent croot = JsonConvert.DeserializeObject <MContent>(json);
            program = BuildStatementGroup(croot, new VirtualIdentifierTable()
            {
                // builtin identifiers.
                "ReadChar",
                "ReadInt",
                "ReadFloat",
                "Write",
                "ToChar",
                "ToInt",
                "ToFloat",
            });
            if (output)
            {
                WriteLine("Compile Finished!");
            }
        }
        catch (CompileErrorException e) { WriteLine(e.Message); }
        catch (Exception e)
        {
            #if BACK_TRACE
            WriteLine(e.Message + "\n" + e.StackTrace);
            #else
            WriteLine(e.Message);
            #endif
        }
        return;
    }
        public void Setup()
        {
            var httpContext       = new DefaultHttpContext();
            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };

            mockController = new Mock <HomeController>()
            {
                CallBase = true
            };

            iCacheMock = new Mock <ICacheContext>();
            mockController.Setup(foo => foo.GetContentCache()).Returns(iCacheMock.Object);
            mockController.Setup(foo => foo.GetProductTypeCache()).Returns(iCacheMock.Object);
            mockController.Setup(foo => foo.GetProductsCache()).Returns(iCacheMock.Object);
            mockController.Setup(foo => foo.GetMetricsCache()).Returns(iCacheMock.Object);

            var iBusinessOpr = new Mock <IBusinessOperationManipulate <MMetric> >();

            mockController.Setup(foo => foo.GetMetricIncreaseOperation()).Returns(iBusinessOpr.Object);

            MContent newArrivals = new MContent();

            newArrivals.Values = new Dictionary <string, string>();
            newArrivals.Values.Add("n1", "ITEM-003");
            newArrivals.Values.Add("n2", "ITEM-004");
            newArrivals.Values.Add("n3", "ITEM-005");
            iCacheMock.Setup(foo => foo.GetValue("code/New_Arrival_Products")).Returns(newArrivals);

            Dictionary <string, BaseModel> cacheData = new Dictionary <string, BaseModel>();
            MProductType product1 = new MProductType();

            product1.Code = "ITEM-001";
            cacheData.Add("ITEM-001", product1);
            iCacheMock.Setup(foo => foo.GetValues()).Returns(cacheData);

            controller = mockController.Object;
            controller.ControllerContext = controllerContext;

            MContent establishedDate = new MContent();

            establishedDate.Values = new Dictionary <string, string>();
            establishedDate.Values.Add("EN", "2019-01-01");

            MContent bestSellers = new MContent();

            bestSellers.Values = new Dictionary <string, string>();
            bestSellers.Values.Add("b1", "ITEM-001");
            bestSellers.Values.Add("b2", "ITEM-002");
            iCacheMock.Setup(foo => foo.GetValue("code/Best_Seller_Products")).Returns(bestSellers);

            MMetric shipped = new MMetric();

            shipped.Value = 2000;
            iCacheMock.Setup(foo => foo.GetValue("shipped")).Returns(shipped);

            var contentCache = new Dictionary <string, BaseModel>();

            contentCache["cfg/Established_Date"] = establishedDate;
            cacheData.Add("cfg/Established_Date", establishedDate);
            contentCache["code/Best_Seller_Products"] = bestSellers;
            controller.ViewBag.Contents = contentCache;
            controller.ViewBag.Lang     = "EN";
        }
示例#21
0
 private void lstMC_Refreshing(object sender, System.EventArgs e)
 {
     MContent.RefreshCount++;
     lstMC.BindingContext = MContent.BindingWithGrouping();
     lstMC.IsRefreshing   = false;
 }
示例#22
0
    MExp BuildExpression(MContent x, VirtualIdentifierTable t)
    {
        MExp BuildDis()
        {
            switch (x.type)
            {
            case "Identifier":
            {
                if (!t.ContainsAbove(x.value))
                {
                    throw new LogicException("identifier [" + x.value + "] not found! ", x.line, x.column);
                }
                var cap = new CaptureTable();
                if (!t.Contains(x.value))
                {
                    cap.Add(x.value);
                }
                return(new MExpIdentifier()
                    {
                        identifier = x.value, captures = cap
                    });
            }

            case "FuncDef":
            {
                string[] fparams = x.subs.Slice(1, x.subs.Length - 1).Map((h) => h.value);
                var      g       = new VirtualIdentifierTable()
                {
                    parent = t
                }.Fold(fparams, (h, v) => h.Insert(v));
                var statements = BuildStatementGroup(x.subs[0], g);
                return(new MExpFuncDef()
                    {
                        statements = statements,
                        formalParams = fparams,
                        captures = new CaptureTable().Fold(statements.statements, (a, p) => a.Merge(p.captures))
                    });
            }

            case "ExpFuncExec":
            {
                var func    = BuildExpression(x.subs[0], t);
                var aparams = x.subs.Slice(1, x.subs.Length - 1).Map((h) => BuildExpression(h, t));
                var cap     = func.captures.Fold(aparams, (h, v) => h.Merge(v.captures));
                return(new MExpFuncExec()
                    {
                        func = func, actualParams = aparams, captures = cap
                    });
            }

            case "ExpArray":
            {
                var initValue = BuildExpression(x.subs[0], t);
                var size      = BuildExpression(x.subs[1], t);
                var cap       = initValue.captures.Merge(size.captures);
                return(new MExpArray()
                    {
                        initValue = initValue, size = size, captures = cap
                    });
            }

            case "ExpIndex":
            {
                var arr = BuildExpression(x.subs[0], t);
                var ind = BuildExpression(x.subs[1], t);
                var cap = arr.captures.Merge(ind.captures);
                return(new MExpIndex()
                    {
                        array = arr, index = ind, captures = cap
                    });
            }

            case "ExpAssign":
            {
                // Add the key first, if context does not contains.
                if (x.subs[0].type == "Identifier" && !t.ContainsAbove(x.subs[0].value))
                {
                    t.Add(x.subs[0].value);
                }
                var leftExp  = BuildExpression(x.subs[0], t);
                var rightExp = BuildExpression(x.subs[1], t);
                var cap      = leftExp.captures.Merge(rightExp.captures);
                return(new MExpAssign()
                    {
                        op = x.value, leftExp = leftExp, rightExp = rightExp, captures = cap
                    });
            }

            case "ExpNegative":
            {
                var e = BuildExpression(x.subs[0], t);
                return(new MExpNegative()
                    {
                        exp = e, captures = e.captures
                    });
            }

            case "ExpNot":
            {
                var e = BuildExpression(x.subs[0], t);
                return(new MExpNot()
                    {
                        exp = e, captures = e.captures
                    });
            }

            /// These tags are distinct for priority purpose.
            /// As grammer tree is here the priority can be ignored.
            case "ExpLogic":
            case "ExpMul":
            case "ExpAdd":
            case "ExpCmp":
            {
                var l = BuildExpression(x.subs[0], t);
                var r = BuildExpression(x.subs[1], t);
                return(new MExpCalc()
                    {
                        left = l, right = r, op = x.value, captures = l.captures.Merge(r.captures)
                    });
            }

            case "ExpIf":
            {
                var cond = BuildExpression(x.subs[0], t);
                var fit  = BuildExpression(x.subs[1], t);
                var nfit = BuildExpression(x.subs[2], t);
                var cap  = cond.captures.Merge(fit.captures).Merge(nfit.captures);
                return(new MExpIf()
                    {
                        cond = cond, fit = fit, nfit = nfit, captures = cap
                    });
            }

            case "Literal.Char":

                return(new MExpLiteral()
                {
                    value = new MChar(x.value[0])
                });

            case "Literal.Int":
                return(new MExpLiteral()
                {
                    value = new MInt(int.Parse(x.value)),
                });

            case "Literal.Float":
                return(new MExpLiteral()
                {
                    value = new MFloat(double.Parse(x.value))
                });
            }
            throw new Exception("unknown expression type : " + x.type + " at line " + x.line);
        }

        var exp = BuildDis();

        exp.line = x.line;
        exp.col  = x.column;
        Debug.Assert(exp.captures != null);
        return(exp);
    }