/// <summary> /// Pushes a set of frames to IIS. Will trigger a connect if needed. /// </summary> private void PushStream(MediaStream stream, FileRoot TargetMp4fFile) { if (stream == null || stream.Frames == null) { return; // no frames. } SanitiseStream(stream); if (stream.Frames.Count < 1) { return; // no frames. } if (!PushServer.IsConnected(stream.TrackId)) { ConnectAndPushHeaders(stream, TargetMp4fFile); } // set start-of-fragment time from PTS stream.Offset = stream.Frames[0].FramePresentationTime - stream.Frames[0].FrameDuration; // Push the fragment var fragment_handler = TargetMp4fFile.GenerateFragment(stream); PushServer.PushData(stream.TrackId, fragment_handler.MoofData()); PushServer.PushData(stream.TrackId, fragment_handler.MdatData()); }
public StatusCodeResult Get(string title) { Console.WriteLine("Manually sending message: " + title); PushServer.SendToAll(new Notification { Title = title, Message = "Manual notification", Icon = "icon.png" }); return(Ok()); }
/// <summary> /// Used once per connection, this opens a long-life HTTP stream /// and pushes the very basic MP4 parts needed to get IIS working. /// </summary> private void ConnectAndPushHeaders(MediaStream stream, FileRoot TargetMp4fFile) { SmilGenerator smil = new SmilGenerator("HCS Encoder by Iain Ballard.", stream); smil.ApproxBitrate = stream.Bitrate; MP4_Mangler.ExtraBoxes.SmoothSmil ssmil = new MP4_Mangler.ExtraBoxes.SmoothSmil(smil.Generate()); PushServer.Connect(stream.TrackId); // This pushes to the subpath: Streams({id}-stream{index}) // push headers (only done once per track) // each one needs it's own HTTP Chunk, so don't concat! PushServer.PushData(stream.TrackId, TargetMp4fFile.GenerateFileSpec()); PushServer.PushData(stream.TrackId, ssmil.deepData()); PushServer.PushData(stream.TrackId, TargetMp4fFile.GenerateHeaders()); }
/// <summary> /// Shut down the streams and close connections. /// </summary> public void Close() { byte[] EOS = Mp4fFile.GenerateFooters(); // End-Of-Stream signal // Close off all streams, taking them out of live mode: foreach (var stream in Streams) { try { PushServer.PushData(stream.TrackId, EOS); } catch { } } // Final close: PushServer.Close(); }
static void Main(string[] args) { PushServer server = new PushServer(); server.Start(); while (true) { Console.Clear(); Console.WriteLine("{0}", DateTime.Now); Thread.Sleep(1000); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { PushServer.Start(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors(builder => builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() ); app.UseMvc(); }
public StatusCodeResult Post([FromBody] JObject subscription) { Console.WriteLine("Receiving subscription details"); try { var endPoint = subscription["endpoint"].ToString(); var authentication = subscription["keys"]["auth"].ToString(); var cryptoKey = subscription["keys"]["p256dh"].ToString(); PushServer.AddClient(new PushClient(endPoint, cryptoKey, authentication)); return(Ok()); } catch { return(new StatusCodeResult(400)); } }
/// <summary> /// 推送(短信、微信) /// </summary> public static void PushContentFunction() { try { while (true) { PushServer ps = new PushServer(); U_AccessToken accessTokenModel = new U_AccessToken(); accessTokenModel.UserKey = ConfigSugar.GetAppString("WeChatCorpID"); accessTokenModel.UserPassword = ConfigSugar.GetAppString("WeChatSecret"); string responseMsg = ""; bool result = false; #region 推送图文 List <Business_WeChatPush_Information> listImgPush = ps.GetImgPushList();//获取要推送的数据 List <U_Content> contentList = new List <U_Content>(); foreach (var imgPush in listImgPush) { //主表信息 U_Content content = new U_Content(); content.Message = imgPush.Message; content.MessageType = imgPush.MessageType; content.Title = imgPush.Title; content.CoverDescption = imgPush.CoverDescption; content.CoverImg = imgPush.CoverImg; content.PushType = imgPush.PushType; content.VGUID = imgPush.VGUID; content.RevenueType = 0; content.PushObject = ps.GetPushUserWeChat(imgPush);//获取推送信息接收者信息列表 contentList.Add(content); //子表信息 var moreGraphicList = ps.GetMoreGraphicList(imgPush.VGUID); PushFunction.PushFunction pf = PushFunctionFactory.PushFunc(PushMode.WeChat, MsgType.SingleTextAndImg); foreach (var item in moreGraphicList) { U_Content contentGraphic = new U_Content(); contentGraphic.Message = item.Message; contentGraphic.Title = item.Title; contentGraphic.CoverDescption = item.CoverDescption; contentGraphic.CoverImg = item.CoverImg; contentGraphic.VGUID = item.VGUID; contentGraphic.RevenueType = item.Ranks; contentList.Add(contentGraphic); } var pushPersonList = contentList[0].PushObject; //如果发送对象超过1000个则需要分批发送 if (pushPersonList.Count > 1000) { int pushCount = (pushPersonList.Count / 1000) + 1;//分批发送(发送次数) for (int i = 0; i < pushCount; i++) { contentList[0].PushObject = pushPersonList.Skip(i * 1000).Take(1000).ToList(); //定时发送 if (contentList[0].TimedSendTime != null) { if (DateTime.Now >= contentList[0].TimedSendTime) { pf.Push(accessTokenModel, contentList); } } else { pf.Push(accessTokenModel, contentList); } } } else { //定时发送 if (contentList[0].TimedSendTime != null) { if (DateTime.Now >= contentList[0].TimedSendTime) { pf.Push(accessTokenModel, contentList); } } else { pf.Push(accessTokenModel, contentList); } } } #endregion List <Business_WeChatPush_Information> pushList = ps.GetPushList();//获取要推送的数据 //循环推送数据列表(获取要推送人员列表) foreach (var item in pushList) { try { PushFunction.PushFunction pf = PushFunctionFactory.PushFunc((PushMode)item.PushType, (MsgType)item.MessageType); if (item.PushType == 1)//微信 { U_Content content = new U_Content(); //content.PushObject = "@all"; //content.Message = "D:\\567925.png"; content.Message = item.Message; content.ExercisesVGUID = item.ExercisesVGUID; content.MessageType = item.MessageType; content.Title = item.Title; content.CoverDescption = item.CoverDescption; content.CoverImg = item.CoverImg; content.PushType = item.PushType; content.VGUID = item.VGUID; content.RevenueType = item.RevenueType; content.RedpacketMoney = item.RedpacketMoney; content.RedpacketType = item.RedpacketType; content.RedpacketMoneyFrom = item.RedpacketMoneyFrom; content.RedpacketMoneyTo = item.RedpacketMoneyTo; List <Business_Personnel_Information> pushPersonList = ps.GetPushUserWeChat(item);//获取推送信息接收者信息列表 content.PushObject = pushPersonList; //如果发送对象超过1000个则需要分批发送 if (pushPersonList.Count > 1000) { int pushCount = (pushPersonList.Count / 1000) + 1;//分批发送(发送次数) for (int i = 0; i < pushCount; i++) { content.PushObject = pushPersonList.Skip(i * 1000).Take(1000).ToList(); //定时发送 if (item.TimedSendTime != null) { if (DateTime.Now >= item.TimedSendTime) { pf.Push(accessTokenModel, content); } } else { pf.Push(accessTokenModel, content); } } } else { //定时发送 if (item.TimedSendTime != null) { if (DateTime.Now >= item.TimedSendTime) { pf.Push(accessTokenModel, content); } } else { pf.Push(accessTokenModel, content); } } } else//短信 { List <Business_Personnel_Information> pushPersonList = ps.GetPushUserSms(item);//获取推送信息接收者信息列表 List <U_Content> uCountList = new List <U_Content>(); foreach (var person in pushPersonList) { U_Content content = new U_Content(); content.Message = item.Message; content.MessageType = item.MessageType; content.Title = item.Title; content.CoverDescption = item.CoverDescption; content.CoverImg = item.CoverImg; content.PushType = item.PushType; content.VGUID = item.VGUID; content.PushObject = new List <Business_Personnel_Information>(); content.PushObject.Add(person); uCountList.Add(content); } //定时发送 if (item.TimedSendTime != null) { if (DateTime.Now >= item.TimedSendTime) { pf.Push(accessTokenModel, uCountList); } } else { pf.Push(accessTokenModel, uCountList); } } } catch (Exception ex) { LogManager.WriteLog(LogFile.Error, ex.ToString()); } } Thread.Sleep(5 * 1000); } } catch (Exception ex) { Console.WriteLine(ex.Message); LogManager.WriteLog(LogFile.Error, ex.ToString()); } }
protected override void OnStart(string[] args) { server = builder.Build(Port, MaxConnect); server.Start(); //Program.Start(args); }
/// <summary> /// 更新是否查看推送状态 /// </summary> /// <param name="contentModel"></param> /// <returns></returns> public bool UpdateIsReadStatus(U_Content contentModel, string invalidusers = "") { PushServer _ps = new PushServer(); return(_ps.UpdateIsReadStatus(contentModel, invalidusers)); }
/// <summary> /// 插入企业付款信息 /// </summary> /// <param name="paymentInfos"></param> /// <returns></returns> public bool InsertPaymentInfos(List <Business_Enterprisepayment_Information> paymentInfos) { PushServer _ps = new PushServer(); return(_ps.InsertPaymentInfos(paymentInfos)); }
/// <summary> /// 插入红包信息 /// </summary> /// <param name="redpacketPushInfos"></param> /// <returns></returns> public bool InsertRedPacketInfo(List <Business_Redpacket_Push_Information> redpacketPushInfos) { PushServer _ps = new PushServer(); return(_ps.InsertRedPacketInfo(redpacketPushInfos)); }
/// <summary> /// 更新推送消息为已发送 /// </summary> /// <param name="contentModel"></param> /// <returns></returns> public bool UpdatePushStatus(U_Content contentModel) { PushServer _ps = new PushServer(); return(_ps.UpdatePushStatus(contentModel)); }
static void Main(string[] args) { _ResetEvent = new ManualResetEvent(false); Console.WriteLine("-------------------------------------------------------"); Console.WriteLine(" THE DUMMY PROGRAMMER - TEST PUSH NOTIFICATIONS SERVER "); Console.WriteLine("-------------------------------------------------------"); Console.WriteLine(); _PushServer = new PushServer <int>(); _PushServer.InitStarted += _PushServer_InitStarted; _PushServer.InitEnded += _PushServer_InitEnded; _PushServer.ShutdownStarted += _PushServer_ShutdownStarted; _PushServer.ShutdownEnded += _PushServer_ShutdownEnded; _PushServer.StartAsync(); _ResetEvent.WaitOne(); if (!_InitOk) { Console.WriteLine("Press a key to exit..."); Console.ReadKey(); return; } while (true) { Console.WriteLine($"Enter the client number (0-{int.MaxValue}) you want to send a notification and the message separated by comma or 'EXIT' to close this program"); string Command = Console.ReadLine(); if (Command == "EXIT") { break; } string[] CommandParts = Command.Split(','); if (CommandParts.Length < 2) { Console.WriteLine("Invalid command"); continue; } if (!System.Text.RegularExpressions.Regex.Match(CommandParts[0], @"\d{1,4}").Success) { Console.WriteLine("Invalid client number"); continue; } int ClientID = int.Parse(CommandParts[0]); string Message = CommandParts[1]; _PushServer.SendPushMessage(ClientID, Message); } _PushServer.Stop(); _ResetEvent.WaitOne(); Console.WriteLine("Press a key to close..."); Console.ReadKey(); }