public override void OnInitInstance() { base.OnInitInstance(); DicName = $"{GetType().Name}${ID.Value}"; Hot.AddWaveQueue(DicName); Timer.AddTrigger(1000, OnPorling); }
public override void OnInitInstance() { base.OnInitInstance(); Hot.AddRowID(ID.Value, 211, 42); // Device 2 : Mic Hot.AddRowID(0x8000 | ID.Value, 212, 4); // Blank Space }
public override void OnInitInstance() { base.OnInitInstance(); Hot.AddRowID(ID.Value, 201, 42); // Device 1 : Loopback Hot.AddRowID(0x8000 | ID.Value, 202, 4); // Blank Space }
public IEnumerable <Post> GetUncheckedPosts(int limit) { var posts = Hot.Take(limit).Where(x => x.Valid); Console.WriteLine($"Found {posts.Count()} unchecked posts"); return(posts); }
private bool HotCheck(KMSelectable selectable) { if (selectable == hotHolder && (Hot.Equals(Faucet) || Hot.Equals(Pipe))) { return(true); } return(false); }
public override BinNode <T> Insert(T e) { BinNode <T> x = Search(e); if (x != null) { return(x); } //空树,第一次插入节点 if (Hot == null) { Root = new BinNode <T>(e); Size++; UpdateHeight(Root); } else { if (Lt(e, Hot.Data)) { x = Hot.InsertAsLc(e); } else { x = Hot.InsertAsRc(e); } Size++; UpdateHeightAbove(x); } //一直到根节点 for (BinNode <T> g = Hot; g != null; g = g.Parent) { if (!g.AvlBalanced()) { bool isLchild = g.IsLChild; bool isRoot = g == Root; var y = RotateAt(TallerChild(TallerChild(g))); if (!isRoot) { if (isLchild) { y.Parent.LChild = y; } else { y.Parent.RChild = y; } } break; } else { UpdateHeight(g); } } return(x); }
public void Cast() { _Cooldown = Convert.ToDecimal(TrackedSpell.Cooldown); Hot h = TrackedSpell as Hot; if (h != null) { _ActiveOnTarget = Convert.ToDecimal(h.HotDuration); } }
private void ClearQueue() { var dic = Hot.GetWavDictionary(DicName); foreach (var /*<audioName,queue>*/ kv in dic) { var queue = kv.Value; lock (queue) { queue.Clear(); } } }
static void SubjectBasedHotSoTerminalNotificationPreservedForLateComers() { var hot = new Hot(); hot.Subscribe( v => WriteLine($"early: {v}"), e => WriteLine($"early: {e.Message}"), () => WriteLine("early done!")); Thread.Sleep(6000); hot.Subscribe(v => WriteLine($"late: {v}"), e => WriteLine($"late: {e.Message}"), () => WriteLine("late done!")); }
private WaveFileWriter makeWriter(string audioName, DateTime timeGenerated) { var path = Path.Combine(Hot.Setting.RecordingFilesPath, $"TalkLog.{timeGenerated:yyyyMMdd.HHmmss}.{audioName}.wav"); try { var fmt = Hot.GetWavFormat(audioName); FileUtil.PrepareDirectory(Path.GetDirectoryName(path)); var writer = new WaveFileWriter(path, fmt); return(writer); } catch { return(null); } }
public ActionResult coreInfo() { var lastUpdate = CoreInfo.GetLastUpdate(); var message = Hot.GetHotNews(); return(Json(new { LastUpdate = lastUpdate, WowToken = CoreInfo.GetWowToken(), LastUpdateString = Time.TimeStampToDateTime(lastUpdate).ToString("MM-dd HH:mm"), Hot1 = message[0], Hot2 = message[1], Hot3 = message[2], } )); }
public override void OnInitInstance() { base.OnInitInstance(); Hot.FirstSpeech = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute / 10 * 10, 0); TarPane = Pane.GetPane("GuiViewMain"); Hot.AddRowID(ROWID_TIMELINE, orderNo: 100, layoutHeight: 24); // Set Timeline Height Hot.AddRowID(-999, 101, 4); // Dummy Space Hot.TimelineParts = new PartsTimeline { Hot = Hot, Rect = CodeRect.FromLTRB(0, ROWID_TIMELINE, 0, ROWID_TIMELINE), PartsPositioner = TalkPositioner, PartsPositionCorder = TalkPosCoder, }; Parts.Add(TarPane, Hot.TimelineParts); }
public override BinNode <T> Insert(T e) { BinNode <T> x = Search(e); if (x != null) { return(x); } if (Hot == null) { Root = new BinNode <T>(e); Size++; UpdateHeight(Root); Root.Color = RbColor.RbBlack; return(x); } x = Lt(e, Hot.Data) ? Hot.InsertAsLc(e) : Hot.InsertAsRc(e); Size++; UpdateHeightAbove(x); x.Color = RbColor.RbRed; SolveDoubleRed(x); return(x); }
public override IList ReadList(string content) { CollectHot list = new CollectHot(); try { JArray jsonArray = JArray.Parse(content); Hot status = null; if (jsonArray != null) { foreach (var j in jsonArray.Children()) { status = j.ToObject <Hot>(); //status.recommend_cover_pic = status.recommend_cover_pic.Replace(Const_def.Hot320Url, Const_def.Hot240Url); status.Media.User.Avatar = string.Concat(status.Media.User.Avatar, Const_def.Hot60Url); list.Add(status); } } } catch { } return(list); }
private void SaveWave() { var dic = Hot.GetWavDictionary(DicName); foreach (var /*<audioName,queue>*/ kv in dic) { var items = new List <(byte[] Buffer, int Length, DateTime TimeGenerated)>(); var queue = kv.Value; lock (queue) { while (queue.Count > 0) { items.Add(queue.Dequeue()); } } if (items.Count > 0) { var i0 = items[0]; if (Writers.TryGetValue(kv.Key, out var writer) == false) { writer = Writers.GetValueOrDefault(kv.Key, true, audioName => makeWriter(audioName, i0.TimeGenerated)); if (writer != null) { isPrePlaying = true; } else { Writers.Remove(kv.Key); } } foreach (var item in items) { writer?.Write(item.Buffer, 0, item.Length); } } } }
public void Init() { //somewhat different from TSO audio - need to scan content for .hot files, then load them all //hot contains EVT, tracks, hitlists and patches... //...which are added to our global database. WAVSounds.Init(); MP3Sounds.Init(); XASounds.Init(); UTKSounds.Init(); var FilePattern = new Regex(@".*\.hot"); List <string> matchedFiles = new List <string>(); foreach (var file in ContentManager.TS1AllFiles) { if (FilePattern.IsMatch(file.Replace('\\', '/'))) { matchedFiles.Add(file); } } foreach (var file in matchedFiles) { //load associated HIT, HSM var cFile = Path.Combine(ContentManager.TS1BasePath, file); var bPath = cFile.Substring(0, cFile.Length - 4); //path without .hot extension var hsm = new HSM(PathCaseTools.Insensitive(bPath + ".hsm")); var hit = new HITFile(PathCaseTools.Insensitive(bPath + ".hit")); var hot = new Hot(cFile, hsm); var group = new HITResourceGroup() { hsm = hsm, hit = hit, hot = hot }; foreach (var trk in hot.Tracks) { if (TracksById.ContainsKey(trk.Key) && TracksById[trk.Key].SubroutineID != trk.Value.SubroutineID) { } TracksById[trk.Key] = trk.Value; } foreach (var patch in hot.Patches) { if (PatchesById.ContainsKey(patch.Key) && patch.Value.Filename != PatchesById[patch.Key].Filename) { } PatchesById[patch.Key] = patch.Value; } foreach (var hls in hot.Hitlists) { if (HitlistsById.ContainsKey(hls.Key) && HitlistsById[hls.Key].IDs.Count != hls.Value.IDs.Count) { } HitlistsById[hls.Key] = hls.Value; } foreach (var evt in hot.Events) { _Events[evt.Key] = new HITEventRegistration() { Name = evt.Value.Name, EventType = (FSO.Files.HIT.HITEvents)evt.Value.EventType, TrackID = evt.Value.TrackID, ResGroup = group }; } } var musics = Events.Where(x => x.Value.EventType == HITEvents.kSetMusicMode).Select(x => x.Key + ": " + x.Value.TrackID).ToList(); var stations = Events.Where(x => x.Value.EventType == HITEvents.kTurnOnTV).Select(x => x.Key + ": " + x.Value.TrackID.ToString()).ToList(); //.Select(x => x.Key + ": " + new string(new char[] { (char)(x.Value.TrackID & 0xFF), (char)((x.Value.TrackID >> 8) & 0xFF), (char)((x.Value.TrackID >> 16) & 0xFF), (char)((x.Value.TrackID >> 24) & 0xFF) })).ToList(); }
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; }
public override void ParseParameter(string param) { base.ParseParameter(param); var rnd = new Random(DateTime.Now.Ticks.GetHashCode()); var lines = param.Split(',').Select(a => a.Trim()).Where(a => !string.IsNullOrWhiteSpace(a)).ToList(); var ms = 1200; var sessionid = 1; var col = Color.DarkRed; var queue = new Queue <(int ms, SpeechEvent ev)>(); Id fid = default; if (lines.FirstOrDefault() is string c1) { if (c1.ToLower().StartsWith("id=")) { try { var val = int.Parse(StrUtil.Mid(c1, 3)); fid = Id.From(val); } catch { } lines.RemoveAt(0); } } if (fid == default) { if (GetRoot().FindChildFeatures(typeof(FeatureAudioLoopback2)).FirstOrDefault() is FeatureAudioLoopback2 f) { fid = f.ID; } else { fid = ID; } } Hot.AddRowID(fid.Value, fid.Value * 10, 42); // Device Dummy Hot.AddRowID(0x8000 | fid.Value, fid.Value * 10 + 1, 4); // Blank Space foreach (var line in lines) { if (line.StartsWith("+")) { try { var val = int.Parse(StrUtil.Mid(line, 1)); ms += val; } catch { } continue; } if (line.StartsWith("#")) { try { var argb = Convert.ToInt32(StrUtil.Mid(line, 1), 16); col = Color.FromArgb(argb); if (col.A == 0) { col = Color.FromArgb(255, col.R, col.G, col.B); } } catch { } continue; } queue.Enqueue((ms, new SpeechEvent { RowID = fid.Value, Action = SpeechEvent.Actions.Start, TimeGenerated = DateTime.Now, SessionID = $"DUMMY-{sessionid:000}", })); queue.Enqueue((ms, new SpeechEvent { RowID = fid.Value, Action = SpeechEvent.Actions.SetColor, TimeGenerated = DateTime.Now, SessionID = $"DUMMY-{sessionid:000}", Text = col.ToArgb().ToString(), })); ms += (int)(rnd.NextDouble() * 1000 + 200); var len = 1; var buildstr = ""; for (var i = 0; i < line.Length; i += len) { len = (int)(rnd.NextDouble() * 5 + 1); buildstr += StrUtil.Mid(line, i, len) ?? ""; if (!string.IsNullOrWhiteSpace(buildstr)) { queue.Enqueue((ms, new SpeechEvent { RowID = fid.Value, Action = SpeechEvent.Actions.Recognizing, TimeGenerated = DateTime.Now, SessionID = $"DUMMY-{sessionid:000}", Text = buildstr, })); ms += (int)(rnd.NextDouble() * 300 + 100); } } ms += 500; queue.Enqueue((ms, new SpeechEvent { RowID = fid.Value, Action = SpeechEvent.Actions.Recognized, TimeGenerated = DateTime.Now, SessionID = $"DUMMY-{sessionid:000}", Text = buildstr, })); sessionid++; ms += 1000; } while (queue.Count > 0) { var item = queue.Dequeue(); Timer.AddTrigger(item.ms, () => { item.ev.TimeGenerated = DateTime.Now; Hot.SpeechEventQueue.Enqueue(item.ev); Token.Add(TokenSpeechEventQueued, this); if (Pane.Control.InvokeRequired) { Pane.Control.Invoke(new InvokeMethod(() => { GetRoot().FlushFeatureTriggers(); })); } else { GetRoot().FlushFeatureTriggers(); } }); } }
private List <Product> SetupProductList() { List <Product> result = new List <Product>(); #region Products creation Product product1 = new Cold(); product1.Id = 1; product1.Name = "product 1"; product1.Price = new Decimal(10); result.Add(product1); Product product2 = new Consistant(); product2.Id = 2; product2.Name = "product 2"; product2.Price = new Decimal(20); result.Add(product2); Product product3 = new Fluid(); product3.Id = 3; product3.Name = "product 3"; product3.Price = new Decimal(30); result.Add(product3); Product product4 = new Hot(); product4.Id = 4; product4.Name = "product 4"; product4.Price = new Decimal(40); result.Add(product4); Product product5 = new Usefull(); product5.Id = 5; product5.Name = "product 5"; product5.Price = new Decimal(50); result.Add(product5); Product product6 = new Useless(); product6.Id = 6; product6.Name = "product 6"; product6.Price = new Decimal(60); result.Add(product6); Product product7 = new Usable(); product7.Id = 7; product7.Name = "product 7"; product7.Price = new Decimal(70); result.Add(product7); Product product8 = new Cold(); product8.Id = 8; product8.Name = "product 8"; product8.Price = new Decimal(80); result.Add(product8); Product product9 = new Cold(); product9.Id = 9; product9.Name = "product 9"; product9.Price = new Decimal(90); result.Add(product9); Product product10 = new Cold(); product10.Id = 10; product10.Name = "product 10"; product10.Price = new Decimal(100); result.Add(product10); #endregion return(result); }
public void BuildHot(Hot ht) => drink.Hot = ht;
private async Task <bool> MakeAudioConfigAsync(SpeechHandler handler) { Debug.Assert(handler.Device != null); // NAudio Setting var wavein = CreateCaptureInstance(handler.Device); var waveoutFormat = new WaveFormat(16000, 16, 1); wavein.StartRecording(); // Azure Cognitive Service Setting var audioformat = AudioStreamFormat.GetWaveFormatPCM((uint)waveoutFormat.SampleRate, (byte)waveoutFormat.BitsPerSample, (byte)waveoutFormat.Channels); handler.AudioInputStream = AudioInputStream.CreatePushStream(audioformat); handler.AudioConfig = AudioConfig.FromStreamInput(handler.AudioInputStream); // Silence Generate DateTime preEvent = DateTime.Now; var silenceData = new byte[waveoutFormat.BlockAlign]; // Appliation Preparation Hot.SetWavFormat(DisplayName, waveoutFormat); // for file saving // NAudio Voice event wavein.DataAvailable += (s, e) => { if (e.BytesRecorded > 0) { var now = DateTime.Now; using (var ms = new MemoryStream()) { var memoryWriter = new WaveFileWriter(ms, waveoutFormat); ms.SetLength(0); // Delete file header. var samples = Resample(wavein.WaveFormat, e.Buffer, e.BytesRecorded, waveoutFormat); foreach (var sample in samples) { memoryWriter.WriteSample(sample); } Hot.AddWavToAllQueue(DisplayName, ms.GetBuffer(), (int)ms.Length, now); // for file saving handler.AudioInputStream.Write(ms.GetBuffer(), (int)ms.Length); // for Azure Cognitive Speech to Text } try { Token.Add(TokenWavDataQueued, this); // TODO: Need Confirm it must be fixed with Tono.Gui.WinForm 1.1.2 - System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' // It must be not fixed yet. so I added try-catch. } catch { // No Action because the above token is a QoS 0 message. But it's necessary to disappear exception messages that's why catch them here. } preEvent = DateTime.Now; } else { if (_talkID != null) { var spms = (double)waveoutFormat.SampleRate / 1000; // samples per ms var n = (int)(spms * (DateTime.Now - preEvent).TotalMilliseconds); for (var i = n; i >= 0; i--) { handler.AudioInputStream.Write(silenceData, silenceData.Length); // send silence to azure to get realtime event (othewise, azure will wait untile next event timing even if there is no event long time) } } preEvent = DateTime.Now; } }; handler.StopRequested += (s, e) => { wavein.StopRecording(); // Stop NAudio recording }; return(await Task.FromResult(true)); }
static void Main(string[] args) { #region Object creation Shop shop = new Shop(); shop.Id = 1; shop.Name = "My Grocerie"; shop.Finance = new Decimal(1200); shop.Credit = new Decimal(1500); Client client1 = new Client(); client1.Id = 1; client1.Money = new Decimal(100.20); client1.Name = "Eude"; client1.Surname = "Jean"; Address address1 = new Address(); address1.Id = 1; address1.City = "Rennes"; address1.Path = "Voie"; address1.Way = "La guenardiere"; address1.Number = "6"; client1.Address = address1; shop.Clients.Add(client1); Client client2 = new Client(); client2.Id = 2; client2.Money = new Decimal(50); client2.Name = "Marc"; client2.Surname = "Jack"; Address address2 = new Address(); address2.Id = 2; address2.City = "Rennes"; address2.Path = "Voie"; address2.Way = "La guenardiere"; address2.Number = "6"; client2.Address = address2; shop.Clients.Add(client2); Client client3 = new Client(); client3.Id = 3; client3.Money = new Decimal(30.80); client3.Name = "Ulé"; client3.Surname = "Ivon"; Address address3 = new Address(); address3.Id = 3; address3.City = "Rennes"; address3.Path = "Voie"; address3.Way = "La guenardiere"; address3.Number = "6"; client3.Address = address3; shop.Clients.Add(client3); Owner owner = new Owner(); owner.Id = 4; owner.Name = "Montant"; owner.Surname = "Ive"; Address address4 = new Address(); address4.Id = 4; address4.City = "Rennes"; address4.Path = "Voie"; address4.Way = "La guenardiere"; address4.Number = "6"; owner.Address = address4; shop.Owners.Add(owner); #region Products creation Product product1 = new Cold(); product1.Id = 1; product1.Name = "product 1"; product1.Price = new Decimal(10); shop.Products.Add(product1); Product product2 = new Consistant(); product2.Id = 2; product2.Name = "product 2"; product2.Price = new Decimal(20); shop.Products.Add(product2); Product product3 = new Fluid(); product3.Id = 3; product3.Name = "product 3"; product3.Price = new Decimal(30); shop.Products.Add(product3); Product product4 = new Hot(); product4.Id = 4; product4.Name = "product 4"; product4.Price = new Decimal(40); shop.Products.Add(product4); Product product5 = new Usefull(); product5.Id = 5; product5.Name = "product 5"; product5.Price = new Decimal(50); shop.Products.Add(product5); Product product6 = new Useless(); product6.Id = 6; product6.Name = "product 6"; product6.Price = new Decimal(60); shop.Products.Add(product6); Product product7 = new Usable(); product7.Id = 7; product7.Name = "product 7"; product7.Price = new Decimal(70); shop.Products.Add(product7); Product product8 = new Cold(); product8.Id = 8; product8.Name = "product 8"; product8.Price = new Decimal(80); shop.Products.Add(product8); Product product9 = new Cold(); product9.Id = 9; product9.Name = "product 9"; product9.Price = new Decimal(90); shop.Products.Add(product9); Product product10 = new Cold(); product10.Id = 10; product10.Name = "product 10"; product10.Price = new Decimal(100); shop.Products.Add(product10); #endregion #endregion #region Print object in console //Console.WriteLine(shop); shop.PrintItemCategories(); /*Console.WriteLine(owner); * Console.WriteLine(product1); * Console.WriteLine(product2); * Console.WriteLine(product3); * Console.WriteLine(product4); * Console.WriteLine(product5); * Console.WriteLine(product6); * Console.WriteLine(product7); * Console.WriteLine(product8); * Console.WriteLine(product9); * Console.WriteLine(product10); * Console.WriteLine(client1); * Console.WriteLine(client2); * Console.WriteLine(client3);*/ //shop.PrintItemCategories1(); Console.ReadKey(); #endregion }