Esempio n. 1
0
        public async Task Test_PublishAsync()
        {
            var @event = new EventSample {
                Value = "a"
            };
            await _eventBus.PublishAsync(@event);

            Assert.Equal("1:a", @event.Result);
        }
Esempio n. 2
0
    public async Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true)
    {
        if (onUnitOfWorkComplete && UnitOfWorkManager.Current != null)
        {
            AddToUnitOfWork(
                UnitOfWorkManager.Current,
                new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext())
                );
            return;
        }

        await _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete : false);
    }
Esempio n. 3
0
        public async Task <object> Init(ClientInitRequestDto input)
        {
            var appName = _httpContextAccessor?.HttpContext.Request.Headers["AppName"].FirstOrDefault();

            await _eventBus.PublishAsync(new ClientInitEvent(input));

            var apps  = _appDefinitionManager.GetAll();
            var shops = await _shopRepository.GetListAsync();

            var categories = await _categoryRepository.GetPublicListAsync(new MallRequestDto()
            {
                ShopId = input.ShopId, AppName = appName
            });

            var spus = await _spuRepository.Include(x => x.Skus).ToListAsync();

            return(new
            {
                shops = ObjectMapper.Map <List <MallShop>, List <MallShopDto> >(shops),
                apps,
                appName,
                categories,
                spus = ObjectMapper.Map <List <ProductSpu>, List <ProductSpuDtoBase> >(spus),
            });
        }
Esempio n. 4
0
 public async Task PublishLocalEventsAsync(IEnumerable <UnitOfWorkEventRecord> localEvents)
 {
     foreach (var localEvent in localEvents)
     {
         await _localEventBus.PublishAsync(localEvent.EventType, localEvent.EventData, onUnitOfWorkComplete : false);
     }
 }
Esempio n. 5
0
 private async Task PublishPostChangedEventAsync(Guid blogId)
 {
     await _localEventBus.PublishAsync(
         new PostChangedEvent
     {
         BlogId = blogId
     });
 }
        public override async Task OnRefundStartedAsync(Payment payment, Refund refund)
        {
            using var uow = _unitOfWorkManager.Begin(isTransactional: true);

            uow.OnCompleted(async() =>
            {
                await _localEventBus.PublishAsync(new WeChatPayRefundEto(payment.Id, refund));
            });

            await uow.CompleteAsync();
        }
        public virtual Task OnRefundStartedAsync(Payment payment, IEnumerable <Refund> refunds, string displayReason = null)
        {
            _unitOfWorkManager.Current.OnCompleted(async() =>
            {
                await _localEventBus.PublishAsync(new WeChatPayRefundEto
                {
                    PaymentId     = payment.Id,
                    Refunds       = refunds,
                    DisplayReason = displayReason
                });
            });

            return(Task.CompletedTask);
        }
        public async Task Test_PublishAsync()
        {
            var event1 = new EventSample {
                Value = "a"
            };
            var event2 = new EventSample2();
            var event3 = new EventSample3();
            var events = new List <IEvent> {
                event1, event2, event3
            };
            await _eventBus.PublishAsync(events);

            Assert.Equal("1:a", event1.Result);
            Assert.Equal("23", event2.Result);
            Assert.Equal("54", event3.Result);
        }
Esempio n. 9
0
        public async Task <object> Init(ClientInitRequestDto input)
        {
            await _eventBus.PublishAsync(new ClientInitEvent(input));

            var apps = await _appProvider.GetAllAsync();

            var shops = await _shopRepository.GetListAsync();

            var appName = _httpContextAccessor?.HttpContext.Request.Headers["AppName"].FirstOrDefault();

            return(new
            {
                shops = ObjectMapper.Map <List <MallShop>, List <MallShopDto> >(shops),
                apps, appName
            });
        }
        public async Task PublishAsync(Type eventType, object eventData)
        {
            var eventName = eventType.GetCustomAttribute <EventNameAttribute>().Name;

            if (!_eventTypeCollection.ContainsKey(eventName))
            {
                return;
            }
            var eventTypeList = _eventTypeCollection[eventName];
            var eventJson     = JsonConvert.SerializeObject(eventData);

            foreach (var eType in eventTypeList)
            {
                var newEventData = JsonConvert.DeserializeObject(eventJson, eType);
                await _localEventBus.PublishAsync(eType, newEventData);
            }
        }
Esempio n. 11
0
        public virtual async Task <File> ChangeAsync(File file, string newFileName, string newMimeType, byte[] newFileContent, File oldParent, File newParent)
        {
            Check.NotNullOrWhiteSpace(newFileName, nameof(File.FileName));

            if (file.ParentId != oldParent?.Id)
            {
                throw new IncorrectParentException(oldParent);
            }

            var configuration = _configurationProvider.Get(file.FileContainerName);

            CheckFileName(newFileName, configuration);
            CheckDirectoryHasNoFileContent(file.FileType, newFileContent);

            if (newFileName != file.FileName || newParent?.Id != file.ParentId)
            {
                await CheckFileNotExistAsync(newFileName, newParent?.Id, file.FileContainerName, file.OwnerUserId);
            }

            if (oldParent != newParent)
            {
                await CheckNotMovingDirectoryToSubDirectoryAsync(file, newParent);
            }

            var oldBlobName = file.BlobName;

            var blobName = await _fileBlobNameGenerator.CreateAsync(file.FileType, newFileName, newParent, newMimeType,
                                                                    configuration.AbpBlobDirectorySeparator);

            _unitOfWorkManager.Current.OnCompleted(async() =>
                                                   await _localEventBus.PublishAsync(new FileBlobNameChangedEto
            {
                FileId            = file.Id,
                FileContainerName = file.FileContainerName,
                OldBlobName       = oldBlobName,
                NewBlobName       = blobName
            }));

            var hashString = _fileContentHashProvider.GetHashString(newFileContent);

            file.UpdateInfo(newFileName, newMimeType, file.SubFilesQuantity, newFileContent?.LongLength ?? 0,
                            hashString, blobName, oldParent, newParent);

            return(file);
        }
Esempio n. 12
0
        public async Task OnExceptionAsync(ExceptionContext context)
        {
            if (!context.ExceptionHandled)
            {
                await _localEventBus.PublishAsync(new CustomerExceptionEvent(context.Exception,
                                                                             context.ActionDescriptor?.DisplayName));

                ApiResponseModel model = ApiResponseModel.Create(
                    HttpStateCode.Status500InternalServerError,
                    CommonResponseType.Status500InternalServerError);

                context.Result = new ContentResult
                {
                    Content     = JsonConvert.SerializeObject(model),
                    StatusCode  = StatusCodes.Status200OK,
                    ContentType = "application/json; charset=utf-8"
                };
            }

            context.ExceptionHandled = true;

            await Task.CompletedTask;
        }
Esempio n. 13
0
 public Task PublishAsync <TEvent> (TEvent eventData)
     where TEvent : class
 {
     return(_localEventBus.PublishAsync(eventData));
 }
Esempio n. 14
0
        public override async Task Execute(IJobExecutionContext context)
        {
            Logger.LogInformation("开始抓取热点数据...");

            var tasks = new List <Task <HotItemDto <object> > >();
            var web   = new HtmlWeb();

            web.PreRequest += delegate(HttpWebRequest request)
            {
                request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                return(true);
            };

            foreach (var item in Hot.KnownSources.Dictionary)
            {
                var task = await Task.Factory.StartNew(async() =>
                {
                    var result = new object();
                    var source = item.Key;
                    var url    = item.Value;

                    try
                    {
                        switch (source)
                        {
                        case Hot.KnownSources.v2ex or Hot.KnownSources.juejin or Hot.KnownSources.csdn or Hot.KnownSources.zhihu or Hot.KnownSources.huxiu or Hot.KnownSources.douyin or Hot.KnownSources.woshipm or Hot.KnownSources.kaiyan:
                            {
                                using var client = _httpClient.CreateClient("hot");
                                client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66");

                                switch (source)
                                {
                                case not Hot.KnownSources.juejin:
                                    result = await client.GetStringAsync(url);
                                    break;

                                default:
                                    {
                                        var content = new ByteArrayContent("{\"id_type\":2,\"client_type\":2608,\"sort_type\":3,\"cursor\":\"0\",\"limit\":20}".GetBytes());
                                        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                                        var response = await client.PostAsync(url, content);
                                        result       = await response.Content.ReadAsStringAsync();
                                        break;
                                    }
                                }
                                break;
                            }

                        default:
                            {
                                var encoding = source is Hot.KnownSources.baidu or Hot.KnownSources.news163 or Hot.KnownSources.pojie52 or Hot.KnownSources.gaoloumi ? Encoding.GetEncoding("GB2312") : Encoding.UTF8;
                                result       = await web.LoadFromWebAsync(url, encoding);
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        result = string.Empty;
                    }

                    return(new HotItemDto <object>
                    {
                        Source = item.Key,
                        Result = result
                    });
                });

                tasks.Add(task);
            }
            Task.WaitAll(tasks.ToArray());

            var hots = new List <Hot>();

            Parallel.ForEach(tasks, new ParallelOptions {
                MaxDegreeOfParallelism = 10
            }, async task =>
            {
                var item   = await task;
                var source = item.Source;
                var result = item.Result;

                if (result.ToString().IsNullOrEmpty())
                {
                    Logger.LogError($"抓取失败:{source}...");
                    return;
                }

                var hot = new Hot()
                {
                    Source = source
                };

                async Task SaveAsync()
                {
                    await _hots.DeleteAsync(x => x.Source == source, autoSave: true);
                    await _hots.InsertAsync(hot);
                    Logger.LogInformation($"成功抓取:{source},{hot.Datas.Count} 条数据.");
                }

                try
                {
                    switch (source)
                    {
                    case Hot.KnownSources.cnblogs:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@id='post_list']/article/section/div/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", string.Empty)
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.v2ex:
                        {
                            var json  = result as string;
                            var nodes = JArray.Parse(json);

                            foreach (var node in nodes)
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = node["title"].ToString(),
                                    Url   = node["url"].ToString()
                                });
                            }

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.segmentfault:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='news-list']/div/div/a[2]").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.SelectSingleNode(".//div/h4").InnerText,
                                    Url   = $"https://segmentfault.com{x.GetAttributeValue("href", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.weixin:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//ul[@class='news-list']/li/div[@class='txt-box']/h3/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", "")
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.douban:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='channel-item']/div[@class='bd']/h3/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", "")
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.ithome:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@id='rank']/ul[@id='d-1']/li//a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", "")
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.oschina:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='ui items']/div/div/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", "")
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.kr36:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='list-wrapper']/div[@class='list-section-wrapper']/div[@class='article-list']/div/div/div/div/div/p/a").ToList();

                            nodes.ForEach(x =>
                            {
                                var url = $"https://36kr.com{x.GetAttributeValue("href", "")}";
                                if (!hot.Datas.Any(d => d.Url == url))
                                {
                                    hot.Datas.Add(new Data
                                    {
                                        Title = x.InnerText,
                                        Url   = url
                                    });
                                }
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.baidu:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//table[@class='list-table']//tr/td[@class='keyword']/a[@class='list-title']").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", "")
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.tieba:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//ul[@class='topic-top-list']/li//a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", "").Replace("amp;", "")
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.weibo:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//table/tbody/tr/td[2]/a").ToList();

                            nodes.ForEach(x =>
                            {
                                var url = x.GetAttributeValue("href", "");
                                if (url == "javascript:void(0);")
                                {
                                    url = x.GetAttributeValue("href_to", "");
                                }

                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"https://s.weibo.com{url}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.juejin:
                        {
                            var json  = result as string;
                            var nodes = JObject.Parse(json)["data"];

                            foreach (var node in nodes)
                            {
                                if ((int)node["item_type"] == 14)
                                {
                                    continue;
                                }

                                hot.Datas.Add(new Data
                                {
                                    Title = node["item_info"]["article_info"]["title"].ToString(),
                                    Url   = $"https://juejin.cn/post/{node["item_info"]["article_id"]}"
                                });
                            }

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.csdn:
                        {
                            var json  = result as string;
                            var nodes = JObject.Parse(json)["data"];

                            foreach (var node in nodes)
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = node["articleTitle"].ToString(),
                                    Url   = node["articleDetailUrl"].ToString()
                                });
                            }

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.toutiao:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='posts']/div[@class='post']/div[@class='content']/h3/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"https://toutiao.io{x.GetAttributeValue("href", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.imooc:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='articleCon js-usercard-box']/div/div/a[@class='title']").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"https://www.imooc.com{x.GetAttributeValue("href", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.zhihu:
                        {
                            var json  = result as string;
                            var nodes = JObject.Parse(json)["data"];

                            foreach (var node in nodes)
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = node["target"]["title"].ToString(),
                                    Url   = $"https://www.zhihu.com/question/{node["target"]["id"]}"
                                });
                            }

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.zhihudaily:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='box']/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"https://daily.zhihu.com{x.GetAttributeValue("href", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.news163:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='area-half left']/div[@class='tabBox']/div[@class='tabContents active']/table//tr/td[1]/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", "")
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.sspai:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='article']/div[@class='articleCard']/div/div/div/div[@class='card_content']/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"https://sspai.com{x.GetAttributeValue("href", "")}",
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.woshipm:
                        {
                            var json  = result as string;
                            var nodes = JObject.Parse(json)["payload"];

                            foreach (var node in nodes)
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = node["title"].ToString(),
                                    Url   = node["permalink"].ToString()
                                });
                            }

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.huxiu:
                        {
                            var json  = result as string;
                            var nodes = JObject.Parse(json)["data"];

                            foreach (var node in nodes)
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = node["title"].ToString(),
                                    Url   = $"https://www.huxiu.com/article/{node["aid"]}.html",
                                });
                            }

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.jandan:
                        {
                            var html    = result as HtmlDocument;
                            var content = HttpUtility.UrlDecode(html.DocumentNode.SelectSingleNode("//div[@id='list-hotposts']").InnerHtml);
                            content     = content.Replace("<script>", "")
                                          .Replace("</script>", "")
                                          .Replace("document.write(decodeURIComponent('", "")
                                          .Replace("'));", "");
                            html.LoadHtml(content);

                            var nodes = html.DocumentNode.SelectNodes("//li/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = x.GetAttributeValue("href", ""),
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.pojie52:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='tl']/table/tr/th/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"https://www.52pojie.cn/{x.GetAttributeValue("href", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.tianya:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@id='main']/div[@class='mt5']/table/tbody/tr/td[1]/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"http://bbs.tianya.cn/{x.GetAttributeValue("href", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.lssdjt:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='list']/li/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"http://m.lssdjt.com{x.GetAttributeValue("href", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.bilibili:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//ul[@class='rank-list']/li/div/div[@class='info']/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"https{x.GetAttributeValue("href", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.douyin:
                        {
                            var json  = result as string;
                            var nodes = JObject.Parse(json)["aweme_list"];

                            foreach (var node in nodes)
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = node["aweme_info"]["desc"].ToString(),
                                    Url   = node["aweme_info"]["share_url"].ToString()
                                });
                            }

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.kaiyan:
                        {
                            var json  = result as string;
                            var nodes = JObject.Parse(json)["dailyList"].FirstOrDefault()["videoList"];

                            foreach (var node in nodes)
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = node["title"].ToString(),
                                    Url   = $"https://www.kaiyanapp.com/detail.html?vid={node["id"]}"
                                });
                            }

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.gaoloumi:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//div[@class='tl']/table/tr/th/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText,
                                    Url   = $"http://gaoloumi.cc/{x.GetAttributeValue("href", "").Replace("amp;", "")}"
                                });
                            });

                            await SaveAsync();
                            break;
                        }

                    case Hot.KnownSources.github:
                        {
                            var html  = result as HtmlDocument;
                            var nodes = html.DocumentNode.SelectNodes("//article[@class='Box-row']/h1/a").ToList();

                            nodes.ForEach(x =>
                            {
                                hot.Datas.Add(new Data
                                {
                                    Title = x.InnerText.Replace("\n", "").Replace(" ", ""),
                                    Url   = $"https://github.com{x.GetAttributeValue("href", "")}",
                                });
                            });

                            await SaveAsync();
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    Logger.LogError($"结果解析失败:{source}...");
                    return;
                }
            });

            await _localEventBus.PublishAsync(new HotWorkerEventData());

            await Task.CompletedTask;
        }
Esempio n. 15
0
 public async Task ResetAsync()
 {
     await _localEventBus.PublishAsync(
         new CurrentApplicationConfigurationCacheResetEventData()
         );
 }
Esempio n. 16
0
 public Task PublishAsync <TEvent>(TEvent eventData, bool onUnitOfWorkComplete = true)
     where TEvent : class
 {
     return(_localEventBus.PublishAsync(eventData, onUnitOfWorkComplete));
 }
        /// <summary>
        /// 接收添加用户事件,发布本地事件
        /// </summary>
        /// <param name="eventData"></param>
        /// <returns></returns>
        public async Task HandleEventAsync(EntityCreatedEto <UserEto> eventData)
        {
            var localUserCreateEventData = new EntityCreatedEventData <UserEto>(eventData.Entity);

            await _localEventBus.PublishAsync(localUserCreateEventData);
        }
Esempio n. 18
0
        public async Task Query_TransactionResult_On_Irreversible_Chain()
        {
            var tx1 = _kernelTestHelper.GenerateTransaction();

            var(block11, results11) =
                GetNextBlockWithTransactionAndResults(_kernelTestHelper.BestBranchBlockList.Last().Header, new[] { tx1 });

            var tx2 = _kernelTestHelper.GenerateTransaction();

            var(block12, results12) =
                GetNextBlockWithTransactionAndResults(block11.Header, new[] { tx2 });

            // Add block 1
            await AddTransactionResultsWithPreMiningAsync(block11, new[] { results11.First() });

            // Add block 2
            await AddTransactionResultsWithPostMiningAsync(block12, new[] { results12.First() });


            #region Before LIB

            // Before LIB, transaction result is saved with PreMiningHash but not with PostMiningHash (normal BlockHash)
            {
                var queried = await _transactionResultService.GetTransactionResultAsync(tx2.GetHash());

                queried.ShouldBe(results12.First());
                // PreMiningHash
                var resultWithPreMiningHash =
                    await _transactionResultManager.GetTransactionResultAsync(tx1.GetHash(),
                                                                              block11.Header.GetPreMiningHash());

                resultWithPreMiningHash.ShouldBe(results11.First());

                // PostMiningHash
                var resultWithPostMiningHash =
                    await _transactionResultManager.GetTransactionResultAsync(tx1.GetHash(),
                                                                              block11.Header.GetHash());

                resultWithPostMiningHash.ShouldBeNull();
            }

            #endregion

            await _localEventBus.PublishAsync(new NewIrreversibleBlockFoundEvent()
            {
                BlockHash   = block11.GetHash(),
                BlockHeight = block11.Height
            });

            #region After LIB

            // After LIB, transaction result is re-saved with PostMiningHash (normal BlockHash)
            {
                var queried = await _transactionResultService.GetTransactionResultAsync(tx2.GetHash());

                queried.ShouldBe(results12.First());
                // PreMiningHash
                var resultWithPreMiningHash =
                    await _transactionResultManager.GetTransactionResultAsync(tx1.GetHash(),
                                                                              block11.Header.GetPreMiningHash());

                resultWithPreMiningHash.ShouldBeNull();

                // PostMiningHash
                var resultWithPostMiningHash =
                    await _transactionResultManager.GetTransactionResultAsync(tx1.GetHash(),
                                                                              block11.Header.GetHash());

                resultWithPostMiningHash.ShouldBe(results11.First());
            }

            #endregion
        }