private bool getSavedMessageData(string saveLocation = null) { if (saveLocation == null) { saveLocation = AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\data.json"; } if (File.Exists(saveLocation)) { string savedData = File.ReadAllText(saveLocation); string valuetemp = ""; int c = 0; int m = 0; TextMessage item = new TextMessage(); JsonTextReader reader = new JsonTextReader(new StringReader(savedData)); string phone_name = ""; while (reader.Read()) { if (reader.Value != null) { if (valuetemp == "SMS") { item = new TextMessage(); valuetemp = ""; } if (valuetemp == "CONTACT") { phone_name = ""; valuetemp = ""; } if (valuetemp == "Name") { phone_name = reader.Value.ToString(); valuetemp = ""; } if (valuetemp == "ID") { item.ID = reader.Value.ToString(); valuetemp = ""; } if (valuetemp == "Timestamp") { item.Timestamp = reader.Value.ToString(); valuetemp = ""; } if (valuetemp == "Type") { item.Type = reader.Value.ToString(); valuetemp = ""; } if (valuetemp == "DID") { item.DID = reader.Value.ToString(); valuetemp = ""; } if (valuetemp == "ContactNumber") { item.ContactNumber = reader.Value.ToString(); valuetemp = ""; } if (valuetemp == "Unread") { item.Unread = (bool)item.Unread; valuetemp = ""; } if (valuetemp == "Message") { item.Message = reader.Value.ToString(); messageData.Add(item); m++; valuetemp = ""; } if (valuetemp == "Number") { contactData.Add(reader.Value.ToString(), phone_name); c++; valuetemp = ""; } if (reader.TokenType.ToString() == "PropertyName") { valuetemp = reader.Value.ToString(); } } } Console.WriteLine("Loaded " + m + " message(s) and " + c + " contacts"); return(true); } return(false); }
public static object sendSMS(string username, string password, string did, string destination, string smsContent) { //minimum required information otherwise fail if (username == "" || password == "" || did == "" || destination == "" || smsContent == "") { Console.WriteLine("sendSMS Failed. Cannot have empty values."); return("failed_emptyvalues"); } if (!utilities.isNumber(did) || !utilities.isNumber(destination)) { Console.WriteLine("sendSMS Failed. DID or Destination must be numeric values"); return("failed_notnumeric"); } ms.voip.VoIPms_Service soap = new ms.voip.VoIPms_Service(); ms.voip.sendSMSInput input = new ms.voip.sendSMSInput(); input.api_username = username; input.api_password = password; input.did = did; input.dst = destination; XmlNode[] output = null; XmlElement result_status = null; XmlElement result_id = null; //used to update messageData List <TextMessage> smsUpdateList = new List <TextMessage>(); TextMessage insertMessage = new TextMessage(); insertMessage.Type = "0"; // 0 Sent / 1 Received insertMessage.ContactNumber = destination; insertMessage.DID = did; insertMessage.Unread = false; string[] smsDataArray = utilities.str_SplitChunk(smsContent, 160); // text messages must be split into 160 character chunks to be valid. voip.ms will return error if sent without splitting foreach (string smsString in smsDataArray) { input.message = smsString; insertMessage.Message = smsString; //try and send the message output = (XmlNode[])soap.sendSMS(input); result_status = (XmlElement)output.GetValue(1); if (result_status.ChildNodes[1].InnerText == "success") { // voip.ms generated sms ID result_id = (XmlElement)output.GetValue(2); insertMessage.ID = result_id.ChildNodes[1].InnerText; // Set voip.ms ID insertMessage.Timestamp = utilities.getNewDateStr(); // Get the } else { //failed messages need to still be added. They need to be either resent later or deleted. insertMessage.ID = result_id.ChildNodes[1].InnerText; // Set to failure message right now insertMessage.Timestamp = result_id.ChildNodes[1].InnerText; // Set to failure message right now } smsUpdateList.Add(insertMessage); } smsUpdateList.Reverse(); // Messages need to be last sent at the top return(smsUpdateList); }
public bool updateMessageData(XmlElement xmlData = null, List <TextMessage> textData = null) { List <TextMessage> newMessages = new List <TextMessage>(); if (xmlData != null) { int count = 0; bool canAdd = true; for (int i = 0; i <= xmlData.ChildNodes.Count - 1; i++) { XmlElement message = (XmlElement)xmlData.ChildNodes[i]; TextMessage testData = new TextMessage(); testData.ID = message.ChildNodes[0].ChildNodes[1].InnerText; testData.Timestamp = message.ChildNodes[1].ChildNodes[1].InnerText; testData.Type = message.ChildNodes[2].ChildNodes[1].InnerText; testData.DID = message.ChildNodes[3].ChildNodes[1].InnerText; testData.ContactNumber = message.ChildNodes[4].ChildNodes[1].InnerText; testData.Message = message.ChildNodes[5].ChildNodes[1].InnerText; testData.Unread = true; for (int j = 0; j <= messageData.Count - 1; j++) { if (messageData[j].ID == testData.ID) { canAdd = false; } } if (canAdd == true) { count++; Console.WriteLine("Adding new text..."); newMessages.Add(testData); } } Console.WriteLine("Total texts parsed: " + xmlData.ChildNodes.Count); Console.WriteLine("Total texts added: " + count); if (count > 0) { // Notification sound and tray icon NotifyIcon.BalloonTipText = count + " New Message"; if (count > 1) { NotifyIcon.BalloonTipText += "s"; } NotifyIcon.BalloonTipTitle = "New Messages"; NotifyIcon.ShowBalloonTip(7000); System.Media.SoundPlayer player = new System.Media.SoundPlayer(); player.Stream = Properties.Resources.notification; player.Play(); } } if (textData != null) { newMessages = textData; //newMessages.Add(textData); } for (int j = 0; j <= messageData.Count - 1; j++) { newMessages.Add(messageData[j]); } messageData.Clear(); messageData = newMessages; return(true); }