public BackgroundController(ApplicationDbContext context) { this.db = context; asterisk = new Asterisk("192.168.137.129", 5038, "son", "123456"); //asterisk = new Asterisk("192.168.111.128", 5038, "son", "123456"); }
static void Main(string[] args) { Asterisk asterisk = new Asterisk("192.168.100.99", 5038, "son", "123456"); //asterisk.Login().Wait(); asterisk.Call("SIP/1002", "ActionId=hihi").Wait(); //ReminderSystemContext test = new ReminderSystemContext(); //test.User.Add(new User() { UserName = "******", Password = "******" }); //test.SaveChanges(); }
private void buttonTest_Click(object sender, EventArgs e) { DataRowView currentDataRowView = (DataRowView)dataGridView1.CurrentRow.DataBoundItem; AlarmDataSet.alarm_definitionRow alarm = (AlarmDataSet.alarm_definitionRow)currentDataRowView.Row; var numbers = m_ds.GetPhoneNumbers(comboBoxTestList.Text); Asterisk.Call(alarm.siteid, alarm.parameter, textBoxTest.Text, numbers); }
public void ProcessAlarms() { InstanceUtility.TouchProcessFile(); var alarmQueue = DB.GetNewAlarms(); string user = ConfigurationManager.AppSettings["pbx_username"]; string pass = ConfigurationManager.AppSettings["pbx_password"]; Logger.WriteLine("found " + alarmQueue.Rows.Count + " new alarms in the queue"); for (int i = 0; i < alarmQueue.Count; i++) { var alarm = alarmQueue[i]; LogDetails(alarm); string[] numbers = DB.GetPhoneNumbers(alarm.list); //string[] numbers = new string[] { "5272", "5272" }; Asterisk.Call(alarm.siteid, alarm.parameter, alarm.value.ToString("F2"), numbers, user, pass); Thread.Sleep(2000); string prevLog = ""; do { InstanceUtility.TouchProcessFile(); Thread.Sleep(2000); UpdatePiscesStatus(alarm); if (Asterisk.Log != prevLog) { prevLog = Asterisk.Log; Logger.WriteLine(" Asterisk: " + Asterisk.LogTime + " : " + Asterisk.Log); } DB.SaveTable(alarmQueue); if (Asterisk.ActiveChannels == 0) { UpdatePiscesStatus(alarm); break; // someone hungup or other loss of connection } if (Asterisk.MinutesElapsed >= 15) { UpdatePiscesStatus(alarm); break; } } while (Asterisk.Status == "unconfirmed"); } }
private void buttonTest_Click(object sender, EventArgs e) { DataRowView currentDataRowView = (DataRowView)dataGridView1.CurrentRow.DataBoundItem; AlarmDataSet.alarm_definitionRow alarm = (AlarmDataSet.alarm_definitionRow)currentDataRowView.Row; var numbers = m_ds.GetPhoneNumbers(comboBoxTestList.Text); var login = new Login(); if (login.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Asterisk.Call(alarm.siteid, alarm.parameter, textBoxTest.Text, numbers, login.Username, login.Password); } }
public List <Asterisk> GetAsterisks(Asterisk parent = null) { var asteriskList = new List <Asterisk>(); // If a parent asteroid was just destroyed, spawning 2 children if (parent != null) { if (parent.Size != Asterisk.AsteriskSize.Small) { for (int i = 0; i < 2; i++) { int direction = Game1.Random.NextDouble() >= 0.5 ? 1 : -1; asteriskList.Add(new Asterisk(_textures[(int)parent.Size - 1]) { Colour = _colours[Game1.Random.Next(_colours.Count)], Size = parent.Size - 1, Health = 1, Layer = 0.2f, Position = parent.Position, Velocity = new Vector2((float)Game1.Random.NextDouble() * Game1.Random.Next(1, 3), (float)Game1.Random.NextDouble() * Game1.Random.Next(1, 3)), AngleVelocity = (float)Game1.Random.NextDouble() * direction / 100 }); } } } else // Spawn a random new big asterisk { int direction = Game1.Random.NextDouble() >= 0.5 ? 1 : -1; var bigTexture = _textures[2]; int randX = Game1.Random.Next(2); int randY = Game1.Random.Next(2); asteriskList.Add(new Asterisk(_textures[2]) { Colour = _colours[Game1.Random.Next(_colours.Count)], Size = Asterisk.AsteriskSize.Large, Health = 1, Layer = 0.2f, Position = new Vector2(randX == 0 ? _textures[2].Width / 2 : Game1.ScreenWidth - _textures[2].Width / 2, randY == 0 ? _textures[2].Height / 2 : Game1.ScreenHeight - _textures[2].Height / 2), Velocity = new Vector2((float)Game1.Random.NextDouble() * Game1.Random.Next(1, 3), (float)Game1.Random.NextDouble() * Game1.Random.Next(1, 3)), AngleVelocity = (float)Game1.Random.NextDouble() * direction / 100 }); } return(asteriskList); }
///<Summary> /// Gets the answer ///</Summary> public void Execute(IJobExecutionContext context) { try { Log.Info("RelieveNumbersJob запущен!"); IQueryable <Phone2Client> P2CForRelieve = _phone2clientrepository.GetRowsForRelieveNumbers(); List <Phone2Client> InfoForAsterisk = new List <Phone2Client>(); if (P2CForRelieve.Count() > 0) { InfoForAsterisk = P2CForRelieve.ToList <Phone2Client>();//список телефонов для Asterisk } if (InfoForAsterisk.Count() > 0) { if (Asterisk.RelieveNumbers(InfoForAsterisk.Select(t => t.phone.Phone_Value).ToList <string>())) { foreach (Phone2Client item in InfoForAsterisk) { item.status = 0; _phone2clientrepository.Edit(item); } } else { Log.Error("Метод Asterisk RelieveNumbers вернул ошибку!"); } _phone2clientrepository.Save(); } Log.Info("RelieveNumbersJob успешно выполнен!"); Console.WriteLine("RelieveNumbersJob is running....." + DateTime.Now.ToString()); } catch (Exception ex) { Log.Error(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace)); Console.WriteLine("RelieveNumbersJob is running with error! " + DateTime.Now.ToString()); Console.WriteLine(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace)); } }
private static NextToken ReadToken(this IEnumerable <CodeCharacter> code) { code = code.SkipWhile(c => c.IsWhitespace); if (!code.Any()) { var token = new EndOfFile(); return(new NextToken(token, () => ReadToken(code))); } var firstTokenChar = code.First(); if (firstTokenChar.IsStartOfIdentifier) { var identifier = code .TakeWhile(c => c.IsBodyOfIdentifier) .Aggregate("", (s, c) => s + c.Value); code = code.SkipWhile(c => c.IsBodyOfIdentifier); var token = KeywordTable.ContainsKey(identifier) ? KeywordTable[identifier].Invoke() as Token : new Identifier(); token.Value = identifier; token.LineNumber = firstTokenChar.LineNumber; token.LinePosition = firstTokenChar.LinePosition; return(new NextToken(token, () => ReadToken(code))); } if (firstTokenChar.IsDigit) { var number = code .TakeWhile(c => c.IsDigit) .Aggregate("", (s, c) => s + c.Value); code = code.Skip(number.Length); var token = new IntegerConstant(); token.Value = number; token.LineNumber = firstTokenChar.LineNumber; token.LinePosition = firstTokenChar.LinePosition; return(new NextToken(token, () => ReadToken(code))); } if (firstTokenChar.IsStartOfStringLiteral) { var stringLiteral = code .Skip(1) .TakeWhile(c => c.Value != '"') .Aggregate("\"", (s, c) => s + c.Value) + '"'; Debug.WriteLine(stringLiteral); code = code.Skip(stringLiteral.Length); var token = new StringLiteral(); token.Value = stringLiteral; token.LineNumber = firstTokenChar.LineNumber; token.LinePosition = firstTokenChar.LinePosition; return(new NextToken(token, () => ReadToken(code))); } var t = new InvalidToken() as Token; switch (firstTokenChar.Value) { case '(': t = new LeftParen(); break; case ')': t = new RightParen(); break; case '{': t = new LeftCurlyBrace(); break; case '}': t = new RightCurlyBrace(); break; case '[': t = new LeftSquareBracket(); break; case ']': t = new RightSquareBracket(); break; case ',': t = new Comma(); break; case '*': t = new Asterisk(); break; case ';': t = new Semicolon(); break; } code = code.Skip(1); t.Value = firstTokenChar.Value.ToString(); t.LineNumber = firstTokenChar.LineNumber; t.LinePosition = firstTokenChar.LinePosition; return(new NextToken(t, () => ReadToken(code))); }
public virtual IEnumerator <ITask> AsteriskHandler(Asterisk asterisk) { return(PlaySound(asterisk.Body.Synchronous, asterisk.ResponsePort, SystemSounds.Asterisk)); }
void manager_OriginateResponse(object sender, Asterisk.NET.Manager.Event.OriginateResponseEvent e) { switch (e.Reason) { case 3: // Ringing but user didn't Answer PopulateLogs(String.Format("Caller 1 did not answer the call.")); break; case 4: // Asnwered PopulateLogs("Phone answered"); break; case 5: // Remote end is busy PopulateLogs("Remote End is Busy. "); break; case 8: // Circuits busy PopulateLogs("All circuits are Busy now please try your call again later."); break; default: break; } }
void manager_NewChannel(object sender, Asterisk.NET.Manager.Event.NewChannelEvent e) { // checking if channel containing caller 1's number if (e.Channel.Contains(this.Caller1.Text)) { // then caller1_channel is e.channel and unique_id data.channel_caller1 = e.Channel; data.uniqueid_caller1 = e.UniqueId; PopulateLogs(string.Format("Originating call to caller 1. extension: {0}", Caller1.Text)); } else if (e.Channel.Contains(this.Caller2.Text)) { // then caller2_channel is e.channel and unique_id data.channel_caller2 = e.Channel; data.uniqueid_caller2 = e.UniqueId; PopulateLogs(string.Format("Originating call to caller 2. extension: {0}", Caller2.Text)); } }
void manager_Hangup(object sender, Asterisk.NET.Manager.Event.HangupEvent e) { switch (e.Cause) { case 16: case 17: // normal clearing data = null; PopulateLogs("call is ended."); break; case 19: // no answer PopulateLogs("No answer.. hanging up."); break; default: break; } }
void manager_ExtensionStatus(object sender, Asterisk.NET.Manager.Event.ExtensionStatusEvent e) { if (e != null && !String.IsNullOrEmpty(e.Exten)) { if (e.Status == 1) { if (e.Exten.Contains(Caller1.Text)) PopulateLogs(String.Format("Caller 1 answer the call. phone number: {0}", Caller1.Text)); else if (e.Exten.Contains(Caller2.Text)) PopulateLogs(String.Format("Caller 2 answer the call. phone number: {0}", Caller2.Text)); } } }
void AsteriskManager_NewState(object sender, Asterisk.NET.Manager.Event.NewStateEvent e) { }
/// <summary> /// Listens for channel hangup, if the channel is associated with the incoming call dialog /// then it hides the incoming call dialog /// </summary> void AsteriskManager_Hangup(object sender, Asterisk.NET.Manager.Event.HangupEvent e) { if (monitoredChannels.Contains(e.Channel)) { monitoredChannels.Remove(e.Channel); HideIncomingCallDialog(); } }
void AsteriskManager_UnhandledEvent(object sender, Asterisk.NET.Manager.Event.ManagerEvent e) { log.Info("Event : " + e.GetType().Name); }
/// <summary> /// Listens for new channels, if a channel filter has been specified then it is /// compared against the new channel. With no filter or a filter match, then an /// attempt is made to fetch the correponding Contact and then display the incoming /// call dialog within MediaPortal /// </summary> void AsteriskManager_NewChannel(object sender, Asterisk.NET.Manager.Event.NewChannelEvent e) { log.Info("New Channel: " + e.Channel + ", Caller Number: " + e.CallerIdNum); //Setup defaults for unknown contacts and phone numbers Bitmap contactPhoto = (Bitmap)Contact.LargePhotoNone.Clone(); string contactNumber = e.CallerIdNum; string contactName = "Unknown"; using (ISession session = SessionFactory.OpenSession()) { string chanFilter = GetSetting(session, "channel_filter", ""); //if the channel filter is empty (dont filer) or the new channel starts //with the filter string the show the notification, otherwise ignore if (String.IsNullOrEmpty(chanFilter) || e.Channel.StartsWith(chanFilter, StringComparison.CurrentCultureIgnoreCase)) { //See if we can find a phone number within the database PhoneNumber phoneNumber = session.Get<PhoneNumber>(e.CallerIdNum); if (phoneNumber != null) { //We have found a phone number, so use the contacts name //and photo for the notification dialog log.Info("Found contact with name " + phoneNumber.Contact.FullName); contactName = phoneNumber.Contact.FullName; contactPhoto = (Bitmap)phoneNumber.Contact.PhotoLarge.Clone(); } //Show the dialog monitoredChannels.Add(e.Channel); ShowIncomingCallDialog(contactName, contactNumber, contactPhoto); } else { log.Debug("New channel ignored due to channel filter"); } } }