Beispiel #1
0
        public JsonResult UpdateCommunicationMessage(string fileNameFullPath, WebApplication1.Models.Communication communication)
        {
            string errorMessage;

            WebApplication1.Models.Communication newCommunication;

            newCommunication = WebApplication1.Models.CommunicationUtility.UpdateCommunicationMessage(fileNameFullPath, communication, out errorMessage);

            if (errorMessage == null)
            {
                return(Json(newCommunication, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(errorMessage, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public static Communication UpdateCommunicationMessage(string fileNameFullPath, Communication communication, out string errorMessage)
        {
            string        start, end, serializedCommunication;
            Communication tmpCommunication;

            errorMessage = null;

            try
            {
                tmpCommunication = ReturnCommunication(fileNameFullPath, communication.MessageId, out start, out end, out errorMessage);

                if (errorMessage != null)
                {
                    return(null);
                }

                tmpCommunication.Sender  = communication.Sender;
                tmpCommunication.Message = communication.Message.Replace("\n", "-- New Row --");
                serializedCommunication  = SerializeCommunication(tmpCommunication);

                if (!string.IsNullOrEmpty(end))
                {
                    serializedCommunication += "\r\n";
                }

                Utility.CreateNewFile(fileNameFullPath, start + serializedCommunication + end);
            }
            catch (Exception e)
            {
                errorMessage = string.Format("ERROR!! An Exception occured in method UpdateCommunicationMessage! e.Message:\r\n{0}", e.Message);
                return(null);
            }

            return(DeserializeCommunication(serializedCommunication));
        }
Beispiel #3
0
 private static string SerializeCommunication(Communication communication)
 {
     return(string.Format("{0}-- New property --{1}-- New property --{2}-- New message --{3}", communication.MessageId, communication.Date, communication.Sender, communication.Message));
 }
Beispiel #4
0
        public static Communication InsertNewCommunicationMessage(string fileNameFullPath, Communication communication, out string errorMessage)
        {
            string        dimension, fileContents, date, messageId, serializedCommunication;
            int           s1, s2;
            DateTime      dateTimeNow;
            Communication newCommunication;

            errorMessage = null;

            try
            {
                dateTimeNow = DateTime.Now;

                fileContents = Utility.ReturnFileContents(fileNameFullPath);
                dimension    = fileContents.Substring(0, 12);
                fileContents = fileContents.Length > 12 ? fileContents.Substring(12) : "";

                date = dateTimeNow.ToString("yyMMdd");

                if (string.IsNullOrEmpty(fileContents))
                {
                    s1 = 1;
                    s2 = 1;
                }
                else
                {
                    messageId = fileContents.Substring(0, 18);

                    s1 = ReturnNextPrefixSequenceNumber(messageId);

                    date = dateTimeNow.ToString("yyMMdd");

                    if (date != ReturnLastDate(messageId))
                    {
                        s2 = 1;
                    }
                    else
                    {
                        s2 = 1 + ReturnLastSequenceNumber(messageId);
                    }
                }

                newCommunication        = new Communication(string.Format("N{0}D{1}L{2}", s1.ToString().PadLeft(6, '0'), date, s2.ToString().PadLeft(3, '0')), dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss"), communication.Sender, communication.Message.Replace("\n", "-- New Row --"));
                serializedCommunication = SerializeCommunication(newCommunication);

                if (string.IsNullOrEmpty(fileContents))
                {
                    Utility.CreateNewFile(fileNameFullPath, dimension + serializedCommunication);
                }
                else
                {
                    Utility.CreateNewFile(fileNameFullPath, dimension + serializedCommunication + "\r\n" + fileContents);
                }
            }
            catch (Exception e)
            {
                errorMessage = string.Format("ERROR!! An Exception occured in method InsertNewCommunicationMessage! e.Message:\r\n{0}", e.Message);
                return(null);
            }

            return(newCommunication);
        }