protected override void OnActionExecuting(ActionExecutingContext filterContext) { //不能应用在子方法上 if (filterContext.IsChildAction) { return; } #if DEBUG //清空执行的sql语句数目 RDBSHelper.ExecuteCount = 0; //清空执行的sql语句细节 RDBSHelper.ExecuteDetail = string.Empty; #endif //页面开始执行时间 WorkContext.StartExecuteTime = DateTime.Now; //当用户为会员时,更新用户的在线时间 if (WorkContext.Uid > 0) { Users.UpdateUserOnlineTime(WorkContext.Uid); } //更新在线用户 Asyn.UpdateOnlineUser(WorkContext.Uid, WorkContext.Sid, WorkContext.NickName, WorkContext.IP, WorkContext.RegionId); //更新PV统计 Asyn.UpdatePVStat(WorkContext.StoreId, WorkContext.Uid, WorkContext.RegionId, WebHelper.GetBrowserType(), WebHelper.GetOSType()); }
public MonoGameGame(LSetting config, Loon game) : base(config, game) { this._start = JavaSystem.NanoTime(); this._log = new MonoGameLog(); this._assets = new MonoGameAssets(this); this._asyn = new MonoGameAsyn <object>(this._log, frame); }
/// <summary> /// 启动 /// </summary> public void StartUp() { Asyn.Exec(() => { Syn.Wait(() => DateTime.Now >= this.StartTime); if (!this.HasShutDown) { this.Exec(); } Asyn.Exec(() => { Syn.Wait(() => { if (this.HasShutDown) { return(true); } else { if (DateTime.Now - this.Last >= this.Interval) { this.Exec(); } return(false); } }); }); }); }
/// <summary> /// 店铺搜索 /// </summary> public ActionResult Search() { //搜索词 string word = WebHelper.GetQueryString("word"); if (word.Length == 0) { return(View("~/mobile/views/shared/prompt.cshtml", new PromptModel(WorkContext.UrlReferrer, "请输入关键词"))); } //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, word); //判断搜索词是否为店铺分类名称,如果是则重定向到店铺分类页面 int storeCid = Stores.GetStoreCidByStoreIdAndName(WorkContext.StoreId, word); if (storeCid > 0) { return(Redirect(Url.Action("class", new RouteValueDictionary { { "storeId", WorkContext.StoreId }, { "storeCid", storeCid } }))); } //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); //检查当前页数 if (page < 1) { page = 1; } //商品总数量 int totalCount = 0; //商品列表 List <PartProductInfo> productList = null; Searches.SearchStoreProducts(20, page, word, WorkContext.StoreId, storeCid, 0, 0, sortColumn, sortDirection, ref totalCount, ref productList); //分页对象 PageModel pageModel = new PageModel(20, page, totalCount); //视图对象 StoreSearchModel model = new StoreSearchModel() { Word = word, SortColumn = sortColumn, SortDirection = sortDirection, PageModel = pageModel, ProductList = productList }; return(View(model)); }
private void Form1_Load(object sender, System.EventArgs e) { Asyn.Exec(() => { this.Invoke(() => { this.Close(); }); }); }
/// <summary> /// 获取设备分区 /// </summary> public override void LoadDevicePartitions() { try { Asyn?.Advance(1, LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_JiaZaiXiTongFenQuLieBiao)); var rootTable = new DSK_PART_TABLE(); var result = FileServiceCoreDll.GetMirrorFilePartitions(ref rootTable, Device.Source.ToString()); if (result != 0) { LoggerManagerSingle.Instance.Error("1/123获取镜像文件的分区信息失败并返回"); return; } if (rootTable.next == IntPtr.Zero) //无法读取分区,需要进行深度分区扫描 { var handle = FileServiceCoreDll.MountDisk(Device.Handle, -1, (ulong)Device.TotalSectors, 0x12); if (handle == IntPtr.Zero) { LoggerManagerSingle.Instance.Error(string.Format("2/123获取镜像文件的分区信息成功;无法读取分区,需要进行深度分区扫描;加载磁盘句柄失败(句柄:{0}, disNum:{1},扇区数:{2},设备类型:0x12)", Device.Handle, -1, Device.TotalSectors)); } FindVolumeCallBack fv = (ref FIND_VOLUME_PROGRESS pdi) => { return(0); }; try { result = FileServiceCoreDll.GetPhysicalPartitionsByScall(handle, fv, 0, 1, ref rootTable); } catch (Exception ex) { LoggerManagerSingle.Instance.Error("深度查找分区异常", ex); } if (result != 0) { LoggerManagerSingle.Instance.Error("3/123获取镜像文件的分区信息成功; 无法读取分区,需要进行深度分区扫描; 深度查找分区失败并返回"); return; } var parts = CreatePartition(rootTable); Device.Parts.AddRange(parts); FileServiceCoreDll.UnloadDeviceHandle(ref handle); } else { var parts = CreatePartition(rootTable); Device.Parts.AddRange(parts); } } catch (Exception ex) { LoggerManagerSingle.Instance.Error("获取设备分区异常", ex); } }
public MonoGameGame(LSetting config, Loon game) : base(config, game) { this._plat = game; this._start = JavaSystem.NanoTime(); this._contentManager = new MonoGameContentManager(game.GetContentManager().ServiceProvider, game.GetContentManager().RootDirectory); this._asyn = new MonoGameAsyn <object>(_log, frame); this._log = new MonoGameLog(config.appName); this._support = new NativeSupport(); this._assets = new MonoGameAssets(this); this._inputer = new MonoGameInputMake(this); this._graphics = new MonoGameGraphics(this, game.GetGraphicsDevice(), config.Width, config.Height); this.InitProcess(); }
public ActionResult KeyWordSearch() { //搜索词 string keyword = WebHelper.GetQueryString("keyword"); WorkContext.SearchWord = WebHelper.HtmlEncode(keyword); if (keyword.Length == 0) { return(PromptView(WorkContext.UrlReferrer, "请输入搜索词")); } if (!SecureHelper.IsSafeSqlString(keyword)) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, keyword); //获取当前搜索词匹配缓存结果 ProductSearchKeyInfo keyInfo = BMACache.Get(keyword) as ProductSearchKeyInfo; if (keyInfo != null && string.IsNullOrEmpty(keyInfo.Name)) //无匹配 { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } if (keyInfo == null) //未匹配过 { keyInfo = Searches.GetProductSearchKey(keyword); if (keyInfo == null || string.IsNullOrEmpty(keyInfo.Name)) { keyInfo = new ProductSearchKeyInfo() { Name = "", keyType = -1, ToId = -1 }; } BMACache.Insert(keyword, keyInfo); } //再次判断搜索词匹配结果 if (keyInfo != null && string.IsNullOrEmpty(keyInfo.Name)) //无匹配 { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } return(Redirect(Url.Action("categorysearch", new RouteValueDictionary { { "keyword", keyword }, { "searchKeyType", keyInfo.keyType }, { "searchKeyId", keyInfo.ToId } }))); }
/// <summary> /// 导出单个文件到指定目录 /// isCover是否覆盖已存在的文件,默认不覆盖 /// </summary> private void ExportFile(FNodeX file, string savePath, bool isMedia = false, bool isCover = false) { var path = FileHelper.ConnectPath(savePath, file.Directory.ToSafeString(), (isMedia && file.IsDelete) ? "Del_" + file.FileName : file.FileName); if (!file.IsFolder) { path = path.TrimEnd('\\'); } if (!isCover && File.Exists(path)) { return; } const int t = 500 * 1024 * 1024; if (file.Size > t) { return; } Directory.CreateDirectory(FileHelper.GetFilePath(path)); RecoveryFile(file, path); Asyn?.Advance(0, string.Format(LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_WenJianHuiFuChengGong), file.FullPath.TrimEnd(@"\"))); var creatime = BaseTypeExtension.ToSafeDateTime(file.Source.CreateTime); if (creatime != null) { File.SetCreationTime(path, (DateTime)creatime); } var accessTime = BaseTypeExtension.ToSafeDateTime(file.Source.LastAccessTime); if (accessTime != null) { File.SetLastAccessTime(path, (DateTime)accessTime); } var modifyTime = BaseTypeExtension.ToSafeDateTime(file.Source.ModifyTime); if (modifyTime != null) { File.SetLastWriteTime(path, (DateTime)modifyTime); } }
/// <summary> /// 店铺搜索 /// </summary> public ActionResult Search() { //搜索词 string keyword = WebHelper.GetQueryString("keyword"); if (keyword.Length > 0 && !SecureHelper.IsSafeSqlString(keyword)) { return(View("~/mobile/views/shared/prompt.cshtml", new PromptModel(WorkContext.UrlReferrer, "您搜索的商品不存在"))); } //判断搜索词是否为店铺分类名称,如果是则重定向到店铺分类页面 int storeCid = Stores.GetStoreCidByStoreIdAndName(WorkContext.StoreId, keyword); if (storeCid > 0) { return(Redirect(Url.Action("class", new RouteValueDictionary { { "storeId", WorkContext.StoreId }, { "storeCid", storeCid } }))); } //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); //分页对象 PageModel pageModel = new PageModel(20, page, Searches.GetSearchStoreProductCount(keyword, WorkContext.StoreId, 0, 0, 0)); //视图对象 StoreSearchModel model = new StoreSearchModel() { Word = keyword, SortColumn = sortColumn, SortDirection = sortDirection, PageModel = pageModel, ProductList = Searches.SearchStoreProducts(pageModel.PageSize, pageModel.PageNumber, keyword, WorkContext.StoreId, 0, 0, 0, sortColumn, sortDirection) }; //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, keyword); return(View(model)); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { //不能应用在子方法上 if (filterContext.IsChildAction) { return; } //当用户为会员时,更新用户的在线时间 if (WorkContext.Uid > 0) { Users.UpdateUserOnlineTime(WorkContext.Uid); } //更新在线用户 Asyn.UpdateOnlineUser(WorkContext.Uid, WorkContext.Sid, WorkContext.NickName, WorkContext.IP, WorkContext.RegionId); //更新PV统计 Asyn.UpdatePVStat(WorkContext.StoreId, WorkContext.Uid, WorkContext.RegionId, WebHelper.GetBrowserType(), WebHelper.GetOSType()); }
/// <summary> /// 获取文件系统 /// </summary> /// <returns></returns> public FNodeX GetFileSystem() { _isStop = false; if (Device == null) { return(null); } // 打开设备 OpenDevice(); // 加载设备分区 if (Device.Parts.Count == 0) { LoadDevicePartitions(); } var fileTree = new FNodeX { IsRoot = true }; int count = Device.Parts.Count; // 构建分区文件系统 foreach (var part in Device.Parts) { RunPartition = (FileSystemPartition)part; Asyn?.Advance(1 / count, string.Format(LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_ZuZhuangFenQuDeWenJianXiTongSh), RunPartition.Name)); MountDevice(); var tree = ScanFileSystem(Device, RunPartition); if (tree == null) { continue; } // 扫描设备 fileTree.Collection.Add(tree); if (_isStop) { break; } } LoggerManagerSingle.Instance.Info(string.Format("扫描文件系统结束, 得到文件/文件夹数:{0}", AllFileNodeX.Count)); Asyn?.Advance(1, LanguageHelperSingle.Instance.GetLanguageByKey(Languagekeys.FileServiceLanguage_File_WenJianXiTongZuZhuangWanBi)); return(fileTree); }
private void Exec() { this.Last = DateTime.Now; switch (this.Mode) { case AgentMode.New: lock (this.Process) { Asyn.Exec(() => this.Process.Start()); } break; case AgentMode.Restart: lock (this.Process) { this.Kill(); Asyn.Exec(() => this.Process.Start()); } break; case AgentMode.Singleton: lock (this.Process) { if (this.HasExited()) { Asyn.Exec(() => this.Process.Start()); } } break; } }
/// <summary> /// 搜索 /// </summary> public ActionResult Search() { //搜索词 string word = WebHelper.GetQueryString("word"); //分类id int cateId = WebHelper.GetQueryInt("cateId"); //品牌id int brandId = WebHelper.GetQueryInt("brandId"); //筛选价格 int filterPrice = WebHelper.GetQueryInt("filterPrice"); //筛选属性 string filterAttr = WebHelper.GetQueryString("filterAttr"); //是否只显示有货 int onlyStock = WebHelper.GetQueryInt("onlyStock"); //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); //搜索词处理 WorkContext.SearchWord = word; if (word.Length == 0) { return(PromptView(WorkContext.UrlReferrer, "请输入搜索词")); } //检查当前页数 if (page < 1) { page = 1; } //筛选属性处理 List <int> attrValueIdList = new List <int>(); foreach (string attrValueId in StringHelper.SplitString(filterAttr, "-")) { int temp = TypeHelper.StringToInt(attrValueId); if (temp > 0) { attrValueIdList.Add(temp); } } //分类信息 CategoryInfo categoryInfo = null; //分类价格范围列表 string[] catePriceRangeList = null; //分类筛选属性及其值列表 List <KeyValuePair <AttributeInfo, List <AttributeValueInfo> > > cateAAndVList = null; //分类列表 List <CategoryInfo> categoryList = null; //品牌信息 BrandInfo brandInfo = null; //品牌列表 List <BrandInfo> brandList = null; //商品总数量 int totalCount = 0; //商品列表 List <StoreProductInfo> productList = null; //搜索 Searches.SearchMallProducts(20, page, word, cateId, brandId, filterPrice, attrValueIdList, onlyStock, sortColumn, sortDirection, ref categoryInfo, ref catePriceRangeList, ref cateAAndVList, ref categoryList, ref brandInfo, ref brandList, ref totalCount, ref productList); if (productList == null) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //分页对象 PageModel pageModel = new PageModel(20, page, totalCount); //视图对象 MallSearchModel model = new MallSearchModel() { Word = word, CateId = cateId, BrandId = brandId, FilterPrice = filterPrice, FilterAttr = filterAttr, OnlyStock = onlyStock, SortColumn = sortColumn, SortDirection = sortDirection, FilterAttrValueIdList = attrValueIdList, CategoryInfo = categoryInfo, CatePriceRangeList = catePriceRangeList, AAndVList = cateAAndVList, CategoryList = categoryList, BrandInfo = brandInfo, BrandList = brandList, PageModel = pageModel, ProductList = productList }; //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, word); return(View(model)); }
/// <summary> /// 商品 /// </summary> public ActionResult Product() { //商品id int pid = GetRouteInt("pid"); if (pid == 0) { pid = WebHelper.GetQueryInt("pid"); } //判断商品是否存在 ProductInfo productInfo = Products.GetProductById(pid); if (productInfo == null) { return(PromptView("/", "你访问的商品不存在")); } //店铺信息 StoreInfo storeInfo = Stores.GetStoreById(productInfo.StoreId); if (storeInfo.State != (int)StoreState.Open) { return(PromptView("/", "你访问的商品不存在")); } //商品存在时 ProductModel model = new ProductModel(); //商品id model.Pid = pid; //商品信息 model.ProductInfo = productInfo; //商品分类 model.CategoryInfo = Categories.GetCategoryById(productInfo.CateId); //商品品牌 model.BrandInfo = Brands.GetBrandById(productInfo.BrandId); //店铺信息 model.StoreInfo = storeInfo; //店长信息 model.StoreKeeperInfo = Stores.GetStoreKeeperById(storeInfo.StoreId); //店铺区域 model.StoreRegion = Regions.GetRegionById(storeInfo.RegionId); //店铺等级信息 model.StoreRankInfo = StoreRanks.GetStoreRankById(storeInfo.StoreRid); //商品图片列表 model.ProductImageList = Products.GetProductImageList(pid); //扩展商品属性列表 model.ExtProductAttributeList = Products.GetExtProductAttributeList(pid); //商品SKU列表 model.ProductSKUList = Products.GetProductSKUListBySKUGid(productInfo.SKUGid); //商品库存数量 model.StockNumber = Products.GetProductStockNumberByPid(pid); //单品促销 model.SinglePromotionInfo = Promotions.GetSinglePromotionByPidAndTime(pid, DateTime.Now); //买送促销活动列表 model.BuySendPromotionList = Promotions.GetBuySendPromotionList(productInfo.StoreId, pid, DateTime.Now); //赠品促销活动 model.GiftPromotionInfo = Promotions.GetGiftPromotionByPidAndTime(pid, DateTime.Now); //赠品列表 if (model.GiftPromotionInfo != null) { model.ExtGiftList = Promotions.GetExtGiftList(model.GiftPromotionInfo.PmId); } //套装商品列表 model.SuitProductList = Promotions.GetProductAllSuitPromotion(pid, DateTime.Now); //满赠促销活动 model.FullSendPromotionInfo = Promotions.GetFullSendPromotionByStoreIdAndPidAndTime(productInfo.StoreId, pid, DateTime.Now); //满减促销活动 model.FullCutPromotionInfo = Promotions.GetFullCutPromotionByStoreIdAndPidAndTime(productInfo.StoreId, pid, DateTime.Now); //广告语 model.Slogan = model.SinglePromotionInfo == null ? "" : model.SinglePromotionInfo.Slogan; //商品促销信息 model.PromotionMsg = Promotions.GeneratePromotionMsg(model.SinglePromotionInfo, model.BuySendPromotionList, model.FullSendPromotionInfo, model.FullCutPromotionInfo); //商品折扣价格 model.DiscountPrice = Promotions.ComputeDiscountPrice(model.ProductInfo.ShopPrice, model.SinglePromotionInfo); //关联商品列表 model.RelateProductList = Products.GetRelateProductList(pid); //用户浏览历史 model.UserBrowseHistory = BrowseHistories.GetUserBrowseHistory(WorkContext.Uid, pid); //商品咨询类型列表 model.ProductConsultTypeList = ProductConsults.GetProductConsultTypeList(); //更新浏览历史 if (WorkContext.Uid > 0) { Asyn.UpdateBrowseHistory(WorkContext.Uid, pid); } //更新商品统计 Asyn.UpdateProductStat(pid, WorkContext.RegionId); return(View(model)); }
static void Main(string[] args) { // MemberInfo[] members = typeof(Test2).GetPropertiesAndFields().ToArray(); // string json = JsonConvert.SerializeObject(new Test1 { Md5 = "test".MD5(Encoding.UTF8), Msg = Guid.Empty.ToBase64() }); Test1 test1 = JsonConvert.DeserializeObject <Test1>(json); Assert.IsTrue(test1.Md5 == "test".MD5(Encoding.UTF8)); Assert.IsTrue(test1.Msg == Guid.Empty.ToBase64()); // Uri uri = new Uri("https://item.jd.com/37175085087.html"); Assert.IsTrue(uri.GetExtension() == ".html"); // uri = new Uri("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1"); Assert.IsTrue(uri.SchemaAndHost() == "https://www.baidu.com"); Assert.IsTrue(uri.GetUri("/test/test.html").OriginalString == "https://www.baidu.com/test/test.html"); Assert.IsTrue(uri.IsInternalLink(uri.GetUri("/test/test.html"))); Assert.IsFalse(uri.IsInternalLink(new Uri("https://cn.bing.com/"))); // Kernel32.AddConsoleCtrlHandler(() => { // }); // RegEdit.UpdateWebBrowserVersion(); // { Asyn.Exec(() => { Tcp.Listen("127.0.0.1", 10601, (stream) => { string request = stream.ReadLine(Encoding.UTF8); Console.WriteLine("request:" + request); stream.Write(request.ToByteArray(Encoding.UTF8)); }); }); } { string response = Tcp.SendLine("127.0.0.1", 10601, "test", Encoding.UTF8); Console.WriteLine("response:" + response); response = Tcp.SendLine("127.0.0.1", 10601, "test", Encoding.UTF8); Console.WriteLine("response:" + response); } // Asyn.Exec(() => { NamedPipe.Server("testPipe", (stream) => { string request = stream.ReadLine(Encoding.UTF8); Console.WriteLine("request:" + request); stream.WriteLine(request, Encoding.UTF8); }); }); { string response = NamedPipe.SendLine("testPipe", "hello", Encoding.UTF8); Console.WriteLine("response:" + response); response = NamedPipe.SendLine("testPipe", "hello", Encoding.UTF8); Console.WriteLine("response:" + response); } // Cmd.Exec("ping bibaoke.com"); // Cmd.Exec("TestForm1.exe"); // { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://265.com"); using (WebResponse response = request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { byte[] data1 = stream.ToByteArray(); string text1 = data1.ToString(Encoding.UTF8); WebClient client = new WebClient(); byte[] data2 = client.DownloadData("http://265.com"); string text2 = data2.ToString(Encoding.UTF8); Assert.IsTrue(data1.Length == data2.Length); } } } // string testString = "test string"; string file = Application.SetupDir.CombinePath(Guid.NewGuid()); file.Write(testString, Encoding.UTF8); Assert.IsTrue(file.ReadString(Encoding.UTF8) == testString); file.DeleteFile(); // Pool pool = new Pool(50); for (int i = 0; i < 100; i++) { pool.Execute(i, j => Console.WriteLine(j)); } pool.Execute(() => Thread.Sleep(1000)); pool.Wait(); // int number1 = "10".ToInt(); string number2String = null; int?number2 = number2String.ToInt(); Assert.IsTrue(number1 == 10); Assert.IsTrue(number2 == null); // byte[] data = "测试字符串".ToByteArray(Encoding.UTF8); Base64 base64 = new Base64(data); HexString hex = new HexString(data); Assert.IsTrue(base64.ToHexString() == hex.ToString()); Assert.IsTrue(base64 == hex.ToBase64()); // Assert.IsTrue(new Uri("http://bibaoke.com/post/74").GetUri("71") == new Uri("http://bibaoke.com/post/71")); Assert.IsTrue(new Uri("http://bibaoke.com/post/74").GetUri("/post/71") == new Uri("http://bibaoke.com/post/71")); Assert.IsTrue(new Uri("http://bibaoke.com").GetUri("post/71") == new Uri("http://bibaoke.com/post/71")); // Assert.IsTrue(new Uri("http://bibaoke.com/icon").SetQuery("char=和") == new Uri("http://bibaoke.com/icon?char=和")); Assert.IsTrue( new Uri("http://bibaoke.com/icon?char=和").SetQuery("color=white") == new Uri("http://bibaoke.com/icon?char=和&color=white")); // Assert.IsTrue(new Uri("http://jianzhimao.com.com").GetDomain() == "com.com"); Assert.IsTrue(new Uri("http://pconline.com.cn").GetDomain() == "pconline.com.cn"); // Assert.IsTrue(2.Pow(3) == 8); // Assert.IsTrue("نیک تم | قالب وردپرس, قالب اورجينال فارسي و قالب وردپرس شرکتی".HasUnicode()); // Encoding gbk = MyEncoding.GBK; // Assert.IsTrue("".SplitByWhiteSpace().Length == 0); Assert.IsTrue(" ".SplitByWhiteSpace().Length == 0); Assert.IsTrue(" test1 test2 ".SplitByWhiteSpace()[1] == "test2"); // Assert.IsTrue(new int[] { 1, 2 }.ExtArray(new int[0]).Length == 2); // Assert.IsTrue("test".Repeat(2) == "testtest"); // int[] testArray = new int[100]; 100.Each(index => testArray[index] = index); IEnumerable <int> enumerator = testArray.GetEnumerator(50); int count = 0; enumerator.Each((index, item) => { Assert.IsTrue(item == index + 50); count++; }); Assert.IsTrue(count == 50); // Assert.IsTrue("abcd".SubstringUnsafe(1, 2) == "bc"); Assert.IsTrue("".SubstringUnsafe(0) == ""); // file = Application.SetupDir.CombinePath("testReadBytes.txt"); Assert.IsTrue(file.ReadString(Encoding.UTF8, true) == "abc"); file.Write("abcd", Encoding.UTF8); Assert.IsTrue(file.ReadString(Encoding.UTF8, true) == "abcd"); // Regex pattern = @"(?<order>order\s+by\s+.*?)\s*$".ToRegex( RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase); Assert.IsTrue( pattern.Match("select * from user order by dept desc, id asc").GetValue("order") == "order by dept desc, id asc"); Assert.IsTrue( pattern.Match("select * from user order by id ").GetValue("order") == "order by id"); // Assert.IsTrue("90".IsInt()); Assert.IsTrue("-90".IsInt()); Assert.IsTrue("0".IsInt()); Assert.IsTrue("-9".IsInt()); Assert.IsTrue("-19".IsInt()); Assert.IsTrue("09".IsInt()); Assert.IsTrue("9".IsInt()); Assert.IsFalse("1.9".IsInt()); Assert.IsTrue(" 19".IsInt()); Assert.IsTrue("19".IsInt()); Assert.IsTrue("19 ".IsInt()); Assert.IsFalse("1九".IsInt()); // Assert.IsTrue("192.168.1.1".IsIpv4()); Assert.IsFalse("192.168.1".IsIpv4()); // Agent agent = new Agent("ping vaiying.com -t", AgentMode.Restart, TimeSpan.FromSeconds(2)); agent.StartUp(); Thread.Sleep(3000); agent.ShutDown(); // DateTime startTime = DateTime.Now.AddSeconds(2); Agent notepad = new Agent("notepad", AgentMode.Singleton, startTime.Hour, startTime.Minute, startTime.Second); notepad.StartUp(); Thread.Sleep(1000); notepad.ShutDown(); // long l = 10; Assert.IsTrue(l.ToInt() == 10); l = int.MinValue; Assert.IsTrue(l.ToInt() == int.MinValue); // Syn.Wait(() => { 100.Each((index) => { Console.WriteLine(index); Thread.Sleep(10); }); return(true); }); // try { Syn.Wait(TimeSpan.FromSeconds(1), () => { return(false); }); } catch (TimeoutException ex) { Console.WriteLine(ex.Message); } // Process.GetCurrentProcess().Kill(); }
/// <summary> /// 搜索 /// </summary> public ActionResult Search() { //搜索词 string keyword = WebHelper.GetQueryString("keyword"); WorkContext.SearchWord = WebHelper.HtmlEncode(keyword); if (keyword.Length == 0) { return(PromptView(WorkContext.UrlReferrer, "请输入搜索词")); } if (!SecureHelper.IsSafeSqlString(keyword)) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, keyword); //判断搜索词是否为分类名称,如果是则重定向到分类页面 int cateId = Categories.GetCateIdByName(keyword); if (cateId > 0) { return(Redirect(Url.Action("category", new RouteValueDictionary { { "cateId", cateId } }))); } else { cateId = WebHelper.GetQueryInt("cateId"); } //分类列表 List <CategoryInfo> categoryList = null; //分类信息 CategoryInfo categoryInfo = null; //品牌列表 List <BrandInfo> brandList = null; //品牌id int brandId = Brands.GetBrandIdByName(keyword); if (brandId > 0)//当搜索词为品牌名称时 { //获取品牌相关的分类 categoryList = Brands.GetBrandCategoryList(brandId); //由于搜索结果的展示是以分类为基础的,所以当分类不存在时直接将搜索结果设为“搜索的商品不存在” if (categoryList.Count == 0) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } if (cateId > 0) { categoryInfo = Categories.GetCategoryById(cateId); } else { //当没有进行分类的筛选时,将分类列表中的首项设为当前选中的分类 categoryInfo = categoryList[0]; cateId = categoryInfo.CateId; } brandList = new List <BrandInfo>(); brandList.Add(Brands.GetBrandById(brandId)); } else//当搜索词为商品关键词时 { //获取商品关键词相关的分类 categoryList = Searches.GetCategoryListByKeyword(keyword); //由于搜索结果的展示是以分类为基础的,所以当分类不存在时直接将搜索结果设为“搜索的商品不存在” if (categoryList.Count == 0) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } if (cateId > 0) { categoryInfo = Categories.GetCategoryById(cateId); } else { categoryInfo = categoryList[0]; cateId = categoryInfo.CateId; } //根据商品关键词获取分类相关的品牌 brandList = Searches.GetCategoryBrandListByKeyword(cateId, keyword); if (brandList.Count == 0) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } brandId = WebHelper.GetQueryInt("brandId"); } //最后再检查一遍分类是否存在 if (categoryInfo == null) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //筛选价格 int filterPrice = WebHelper.GetQueryInt("filterPrice"); //筛选属性 string filterAttr = WebHelper.GetQueryString("filterAttr"); //是否只显示有货 int onlyStock = WebHelper.GetQueryInt("onlyStock"); //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); //分类筛选属性及其值列表 List <KeyValuePair <AttributeInfo, List <AttributeValueInfo> > > cateAAndVList = Categories.GetCategoryFilterAAndVList(cateId); //分类价格范围列表 string[] catePriceRangeList = StringHelper.SplitString(categoryInfo.PriceRange, "\r\n"); //筛选属性处理 List <int> attrValueIdList = new List <int>(); string[] filterAttrValueIdList = StringHelper.SplitString(filterAttr, "-"); if (filterAttrValueIdList.Length != cateAAndVList.Count)//当筛选属性和分类的筛选属性数目不对应时,重置筛选属性 { if (cateAAndVList.Count == 0) { filterAttr = "0"; } else { int count = cateAAndVList.Count; StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) { sb.Append("0-"); } filterAttr = sb.Remove(sb.Length - 1, 1).ToString(); } } else { foreach (string attrValueId in filterAttrValueIdList) { int temp = TypeHelper.StringToInt(attrValueId); if (temp > 0) { attrValueIdList.Add(temp); } } } //分页对象 PageModel pageModel = new PageModel(20, page, Searches.GetSearchProductCount(keyword, cateId, brandId, filterPrice, catePriceRangeList, attrValueIdList, onlyStock)); //视图对象 SearchModel model = new SearchModel() { Word = keyword, CateId = cateId, BrandId = brandId, FilterPrice = filterPrice, FilterAttr = filterAttr, OnlyStock = onlyStock, SortColumn = sortColumn, SortDirection = sortDirection, CategoryList = categoryList, CategoryInfo = categoryInfo, BrandList = brandList, CatePriceRangeList = catePriceRangeList, AAndVList = cateAAndVList, PageModel = pageModel, ProductList = Searches.SearchProducts(pageModel.PageSize, pageModel.PageNumber, keyword, cateId, brandId, filterPrice, catePriceRangeList, attrValueIdList, onlyStock, sortColumn, sortDirection) }; return(View(model)); }
/// <summary> /// 商品 /// </summary> public ActionResult Product() { //商品id int pid = GetRouteInt("pid"); if (pid == 0) { pid = WebHelper.GetQueryInt("pid"); } //判断商品是否存在 PartProductInfo productInfo = Products.GetPartProductById(pid); if (productInfo == null) { return(PromptView(Url.Action("index", "home"), "你访问的商品不存在")); } //商品存在时 ProductModel model = new ProductModel(); //商品id model.Pid = pid; //商品信息 model.ProductInfo = productInfo; //商品分类 model.CategoryInfo = Categories.GetCategoryById(productInfo.CateId); //商品品牌 model.BrandInfo = Brands.GetBrandById(productInfo.BrandId); //商品图片列表 model.ProductImageList = Products.GetProductImageList(pid); //商品SKU列表 model.ProductSKUList = Products.GetProductSKUListBySKUGid(productInfo.SKUGid); //商品库存数量 model.StockNumber = Products.GetProductStockNumberByPid(pid); //单品促销 model.SinglePromotionInfo = Promotions.GetSinglePromotionByPidAndTime(pid, DateTime.Now); //买送促销活动列表 model.BuySendPromotionList = Promotions.GetBuySendPromotionList(pid, DateTime.Now); //赠品促销活动 model.GiftPromotionInfo = Promotions.GetGiftPromotionByPidAndTime(pid, DateTime.Now); //赠品列表 if (model.GiftPromotionInfo != null) { model.ExtGiftList = Promotions.GetExtGiftList(model.GiftPromotionInfo.PmId); } //套装商品列表 model.SuitProductList = Promotions.GetProductAllSuitPromotion(pid, DateTime.Now); //满赠促销活动 model.FullSendPromotionInfo = Promotions.GetFullSendPromotionByPidAndTime(pid, DateTime.Now); //满减促销活动 model.FullCutPromotionInfo = Promotions.GetFullCutPromotionByPidAndTime(pid, DateTime.Now); //广告语 model.Slogan = model.SinglePromotionInfo == null ? "" : model.SinglePromotionInfo.Slogan; //商品促销信息 model.PromotionMsg = Promotions.GeneratePromotionMsg(model.SinglePromotionInfo, model.BuySendPromotionList, model.FullSendPromotionInfo, model.FullCutPromotionInfo); //商品折扣价格 model.DiscountPrice = Promotions.ComputeDiscountPrice(model.ProductInfo.ShopPrice, model.SinglePromotionInfo); //关联商品列表 model.RelateProductList = Products.GetRelateProductList(pid); //更新浏览历史 if (WorkContext.Uid > 0) { Asyn.UpdateBrowseHistory(WorkContext.Uid, pid); } //更新商品统计 Asyn.UpdateProductStat(pid, WorkContext.RegionId); return(View(model)); }
private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //启动一个等待线程 Asyn.Exec(() => { int times = 0; while (times < 20) { Thread.Sleep(1000); Document document = null; //交还 UI 线程获取这个时候的文档 this.Invoke(new Action(() => { document = HtmlParser.Parse(this.webBrowser1.Document.Body.InnerHtml); })); //绑定选择器 var q = Selector.Bind(document); //获取页面所有的商品 var sku = q(".j-sku-item"); List <Tuple <string, string> > list = new List <Tuple <string, string> >(); foreach (Element i in sku) { //商品名称 string name = q(i).find( ".p-name a em").text(); //商品价格 string price = q(i).find( ".p-price .J_price:first").text(); if (name.IsNotWhiteSpace() && price.IsNotWhiteSpace()) { list.Add(new Tuple <string, string>(name, price)); } //如果找不到商品名称或商品价格 //说明 ajax 请求还没完成 else { list.Clear(); break; } } if (list.Count > 0) { foreach (var i in list) { Console.WriteLine(i.Item1 + Symbol.Tab + i.Item2); } break; } times++; } this.Invoke(new Action(() => { this.Close(); })); }); }
/// <summary> /// 搜索 /// </summary> public ActionResult Search() { //搜索词 string word = WebHelper.GetQueryString("word"); //分类id int cateId = WebHelper.GetQueryInt("cateId"); //品牌id int brandId = WebHelper.GetQueryInt("brandId"); //筛选价格 int filterPrice = WebHelper.GetQueryInt("filterPrice"); //筛选属性 string filterAttr = WebHelper.GetQueryString("filterAttr"); //是否只显示有货 int onlyStock = WebHelper.GetQueryInt("onlyStock"); //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); WorkContext.SearchWord = word; if (word.Length == 0) { return(PromptView(WorkContext.UrlReferrer, "请输入搜索词")); } //检查当前页数 if (page < 1) { page = 1; } //筛选属性处理 List <int> attrValueIdList = new List <int>(); string[] filterAttrValueIdList = StringHelper.SplitString(filterAttr, "-"); foreach (string attrValueId in filterAttrValueIdList) { int temp = TypeHelper.StringToInt(attrValueId); if (temp > 0) { attrValueIdList.Add(temp); } } //分类信息 CategoryInfo categoryInfo = null; //分类价格范围列表 string[] catePriceRangeList = null; //分类筛选属性及其值列表 List <KeyValuePair <AttributeInfo, List <AttributeValueInfo> > > cateAAndVList = null; //分类列表 List <CategoryInfo> categoryList = null; //品牌信息 BrandInfo brandInfo = null; //品牌列表 List <BrandInfo> brandList = null; //商品总数量 int totalCount = 0; //商品列表 List <PartProductInfo> productList = null; //搜索 Searches.SearchProducts(20, page, word, cateId, brandId, filterPrice, attrValueIdList, onlyStock, sortColumn, sortDirection, ref categoryInfo, ref catePriceRangeList, ref cateAAndVList, ref categoryList, ref brandInfo, ref brandList, ref totalCount, ref productList); if (productList == null) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //当筛选属性和分类的筛选属性数目不对应时,重置筛选属性 if (cateAAndVList == null) { filterAttr = "0"; } else { if (filterAttrValueIdList.Length != cateAAndVList.Count) { if (cateAAndVList.Count == 0) { filterAttr = "0"; } else { int count = cateAAndVList.Count; StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) { sb.Append("0-"); } filterAttr = sb.Remove(sb.Length - 1, 1).ToString(); } } } //用户浏览历史 List <PartProductInfo> userBrowseHistory = BrowseHistories.GetUserBrowseHistory(WorkContext.Uid, 0); //分页对象 PageModel pageModel = new PageModel(20, page, totalCount); //视图对象 SearchModel model = new SearchModel() { Word = word, CateId = cateId, BrandId = brandId, FilterPrice = filterPrice, FilterAttr = filterAttr, OnlyStock = onlyStock, SortColumn = sortColumn, SortDirection = sortDirection, FilterAttrValueIdList = attrValueIdList, CategoryInfo = categoryInfo, CatePriceRangeList = catePriceRangeList, AAndVList = cateAAndVList, CategoryList = categoryList, BrandInfo = brandInfo, BrandList = brandList, PageModel = pageModel, ProductList = productList, UserBrowseHistory = userBrowseHistory }; //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, word); return(View(model)); }