Created
September 19, 2013 03:43
-
-
Save RhysC/6618849 to your computer and use it in GitHub Desktop.
Turn external response codes into an enum - we are suing this for SMS central (see page 28 for an example http://www.smscentral.com.au/wp-content/uploads/SMS-Central-API-Reference-May-2013.pdf)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
//turn response codes into enum values | |
var things = GetData().Select (x =>{ | |
var id = GetNumberFromStart(x); | |
var name = ConvertToVariable(x.Replace(id.ToString(),string.Empty)); | |
return string.Format("{0} = {1},",id,name); | |
} ); | |
things.Dump(); | |
} | |
// Define other methods and classes here | |
public static int GetNumberFromStart(string stringWithLeadingDigits) | |
{ | |
var str = stringWithLeadingDigits.TrimStart(); | |
string digits = string.Empty; | |
for (int i=0; i< str.Length; i++) | |
{ | |
if (Char.IsDigit(str[i])) | |
digits += str[i]; | |
else break; | |
} | |
if (digits.Length>0) | |
return int.Parse(digits); | |
return 0; | |
} | |
public static string ConvertToVariable(string stringAsSentence) | |
{ | |
var str = stringAsSentence.Trim(); | |
string newStr = new string(str.Take(1).ToArray()).ToUpper(); | |
for (int i = 1; i < str.Length; i++) { | |
if (str[i] == ' ') { | |
i++; | |
while(!char.IsLetterOrDigit(str[i])){ | |
i++; | |
} | |
newStr = newStr + new string(new[]{str[i]}).ToUpper(); | |
} | |
else | |
{ | |
if(char.IsLetterOrDigit(str[i])) | |
newStr = newStr + new string(new[]{str[i]}); | |
} | |
} | |
return newStr; | |
} | |
public string[] GetData() | |
{ | |
return new []{ | |
"0 Message is Ok (so far)", | |
"1 Message has been acknowledged by the receiving handset", | |
"500 Generic failure", | |
"501 Failed to deliver to the network", | |
"502 Failed to find a route internally to the system", | |
"503 The message has expired past its timeout within the carrier", | |
"504 The message has expired past its timeout within the gateway", | |
"506 The gateway misunderstood what you wanted. Check your XML.", | |
"511 Your username or password is incorrect", | |
"512 Your username or password is incorrect in a reply message", | |
"513 It appears that this message has been seen before. Check ", | |
"refererences.", | |
"514 We don’t seem to have anybody to send the message to", | |
"515 Generic failure to send the message out of the queues", | |
"516 The queue was stopped and the message was killed", | |
"517 We tried and tried but couldn’t get the message out to the networks", | |
"518 Its never a good idea to send message to the sender", | |
"519 The destination number has been blacklisted from this service", | |
"520 The filter attached to that destination rejected the message", | |
"521 Searching for your reference found no matching message", | |
"522 We got no positive or negative response from the carriers so cannot ", | |
"resend", | |
"523 The recipient had insufficient credit in their prepaid SIM", | |
"524 Failed to connect to the upstream gateway", | |
"526 No longer used", | |
"527 This message has been manually resent", | |
"528 No more trying, we give up.", | |
"529 The gateway server rejected the message permanently", | |
"530 The MMS message you are sending is too large", | |
"531 You have to deliver something. You cannot send an empty message.", | |
"533 Oops, something went wrong internally to the SRS.", | |
"550 Message accepted but not delivered to the handset.", | |
"536 Message has been temporarily delayed.", | |
"534 Credit limited exceeded. Message delivery failed.", | |
"535 Source address (ORIGINATOR) is not valid." | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment