c # – data transfer task

You will receive several lines of messages containing data. you have
check the validity of the lines. A valid line must be in the
format: "" s: {sender}; r: {recipient}; m - "{message}"

  • sender – can contain any ASCII character except for ;
  • recipient – can contain any ASCII character except for ;
  • message – must contain only letters and spaces

Each valid message contains a hidden data transfer size. the
the size of the data transfer is calculated by the sum of all the digits of
the names of the sender and the recipient. After each valid message, print a
line in format: "{senderName} says" {currentMessage} "to
{recieverName} "
. Printed names must contain only letters and
the spaces.

Example: sender "P @ e $ 5sh # o Go ^ 4sh5ov" is valid and corresponds, but when
by printing his name, we only print "Pesho Goshov". At the end, print a
line in "Total transferred data: {totalData} MB" format.

using the system;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class program
{
MessageInfo class
{
public bool isOk = true;
public int messageSize;
chain sender;
chain receiver;
public channel Sender
{
get
{
return Regex.Replace (sender, @ " s +", "");
}
together
{
StringBuilder temp = new StringBuilder ();
foreach (var c in value)
{
if (Char.IsDigit (c))
{
messageSize + = (c - 0);
}
if (Char.IsLetter (c) || ​​Char.IsWhiteSpace (c))
{
temp.Append (c);
}
}
sender = temp.ToString ();
}
}
public channel Reciver
{
get
{
return Regex.Replace (reciver, @ " s +", "");
}
together
{
StringBuilder temp = new StringBuilder ();
foreach (var c in value)
{
if (Char.IsDigit (c))
{
messageSize + = (c - 0);
}
if (Char.IsLetter (c) || ​​Char.IsWhiteSpace (c))
{
temp.Append (c);
}
}
reciver = temp.ToString ();
}
}
public string Message {get; together; }

}
Static Empty Hand ()
{
int n = int.Parse (Console.ReadLine ());
int totalMessageSize = 0;
MessageInfo[] chatLog = new MessageInfo[n];
for (int i = 0; i <n; i ++)
{
string = Console.ReadLine ();
chatlog[i] = CoreAction (line);
if (chatLog[i].isOk)
{
totalMessageSize + = chatLog[i].messageSize;
}
}
for (int i = 0; i < chatLog.Length; i++)
        {
            if (chatLog[i].isOk)
            {
                Console.WriteLine("{0} says "{1}" to {2}", chatLog[i].Sender, chatLog[i].Message, chatLog[i].Reciver);
            }
        }
        Console.WriteLine("Total data transferred: {0}MB",totalMessageSize);
    }

    private static MessageInfo CoreAction(string line1)
    {
        MessageInfo a = new MessageInfo();
        int indexer = 0;
        StringBuilder sender = new StringBuilder();
        StringBuilder reciver = new StringBuilder();
        StringBuilder message = new StringBuilder();
        Regex matchLine = new Regex("^s:[^;]+;r:[^;]+;m--"[\w\s]+"$");
        if (matchLine.IsMatch(line1))
        {
            lineSplitter(line1, ref indexer, ref sender, ref reciver, ref message);
        }
        else
        {
            a.isOk = false;
        }
        a.Sender = sender.ToString();
        a.Reciver = reciver.ToString();
        a.Message = message.ToString();
        return a;
    }

    private static void lineSplitter(string line1, ref int indexer, ref StringBuilder sender, ref StringBuilder reciver, ref StringBuilder message)
    {
        while (true)
        {
            if (line1[indexer + 1] == ':')
            {
                if (line1[indexer] == 's')
                {
                    sender = stringFill(line1, ref indexer, 2, ';');
                }
                if (line1[indexer] == 'r')
                {
                    reciver = stringFill(line1, ref indexer, 2, ';');
                }
            }
            if (line1[indexer] == 'm' && line1[indexer + 1] == '-' &&
                line1[indexer + 2] == '-' && line1[indexer + 3] == '"')
            {
                message = stringFill(line1, ref indexer, 4, '"');
            }
            if (indexer >= line1.Length - 1)
{
Pause;
}
indexer ++;
}
}

static StringBuilder static stringFill (string line1, reference indexer, indexer, offSet, char chartreak)
{
StringBuilder temp = new StringBuilder ();
indexer + = offSet;
while (line1[indexer] ! = charBreak)
{
temp.Append (line1[indexer])
indexer ++;
}
return temp;
}
}