Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                ConfigurationModel configurationModel = null;
                var message = Configuration.GetConfiguration(out configurationModel);
                if (!message.Success)
                {
                    PrintMessage(message);
                }
                else
                {
                    var txtParser = new TxtParser(configurationModel);
                    var msg       = txtParser.ParseFromFile(out ICollection <Group> groups, out ICollection <MessageParser> parseErrs);
                    Cache.GetInstance().AddGroups(groups);
                    Cache.GetInstance().AddParserErrors(parseErrs);
                }

                CommandLineInterface.StartMessage();
                string command = Commands.none.ToString();
                while (!String.IsNullOrEmpty(command))
                {
                    command = Console.ReadLine();
                    CommandLineInterface.ProccesCommand(command, configurationModel);
                }
            }
            catch (Exception ex)
            {
                PrintExceptions(ex);
                Console.ReadKey();
            }
        }
        public Document Parse(string file, Document document)
        {
            using (var reader = new StreamReader(file, Encoding.GetEncoding(1251))) {
                var header    = reader.ReadLine();
                var txtParser = new TxtParser(header, '|');
                reader.ReadLine();
                while (txtParser.ReadLine(reader))
                {
                    document.ProviderDocumentId = txtParser.ProviderDocumentId;
                    document.DocumentDate       = txtParser.DocumentDate;

                    var line = document.NewLine();
                    line.Code                   = txtParser.Code;
                    line.Product                = txtParser.Product;
                    line.Producer               = txtParser.Producer;
                    line.SerialNumber           = txtParser.SerialNumber;
                    line.Country                = txtParser.Country;
                    line.Quantity               = txtParser.Quantity;
                    line.ProducerCostWithoutNDS = txtParser.ProducerCost;
                    line.SupplierCost           = txtParser.SupplierCost;
                    line.Nds = txtParser.Nds;
                    line.SupplierCostWithoutNDS = txtParser.SupplierCostWithoutNds;
                    line.Period       = txtParser.Period;
                    line.RegistryCost = txtParser.RegistryCost;
                    line.Certificates = txtParser.Certificates;
                    var vi = txtParser.VitallyImportantChar;
                    line.VitallyImportant = (vi == null) ? false : vi.Equals("*");
                }
            }
            return(document);
        }
Esempio n. 3
0
        public void Fail_WhenFileNotExist()
        {
            var parser   = new TxtParser();
            var fileName = "thisfiledoesnotexist.txt";

            parser.ParseFile(fileName).IsSuccess.Should().BeFalse();
        }
Esempio n. 4
0
 public static Phase[] phaseInfo = new Phase[100]; //페이즈별 정보
 public static void LoadData()
 {
     for (int i = 0; i < phaseInfo.Length; i++)
     {
         phaseInfo[i] = new Phase();
     }
     TxtParser.LoadData("data");
 }
Esempio n. 5
0
        public void TxtParser()
        {
            byte[] msg       = GetMessageRaw(@"STMMessageSamples\textMessage with area-1.xml");
            var    msgString = Serialization.ByteArrayToString(msg);

            var validator = new StmSchemaValidator();

            validator.ValidateTextMessageXML(msgString);

            var parser = new TxtParser(msgString);
            var id     = parser.TextMessageId;
        }
Esempio n. 6
0
        public string ParseFile(string path)
        {
            var parser  = new TxtParser();
            var content = parser.ParseFile(path);

            if (content == null)
            {
                return(string.Empty);
            }

            var       concordance = new Concordanse();
            const int count       = 50;

            concordance.CreateConcordanse(content, count);
            var pathOutput = path;
            //var output = new TxtOutput();
            //output.Output(concordance.GetConcordanseResult(), pathOutput);
            var output = new XmlOutput();

            return(output.Output(concordance, path));
        }
        public virtual ResponseObj UploadTextMessage([FromBody] string textMessageObject, [FromUri] string deliveryAckEndPoint = null)
        {
            log.Info("Incoming request to " + GetCurrentMethod());

            var messageType = _messageTypeService.Get(x => x.Name.ToLower() == "txt").First();

            var parser = new TxtParser(textMessageObject);
            var dataId = parser.TextMessageId;

            var paramList = new List <KeyValuePair <string, string> >();
            var param     = new KeyValuePair <string, string>("deliveryAckEndPoint", deliveryAckEndPoint);

            paramList.Add(param);

            var errorMsgResponse = string.Empty;
            var request          = Request;
            var headers          = request.Headers;

            if (string.IsNullOrEmpty(textMessageObject))
            {
                log.Debug("TextMessage is empty");
                errorMsgResponse += "Required parameter TextMessage is missing." + Environment.NewLine;

                throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required parameter TextMessage is missing.");
            }

            try
            {
                if (string.IsNullOrEmpty(InstanceContext.CallerOrgId))
                {
                    log.Debug("Calling organization identity missing in header.");
                    errorMsgResponse += "Calling organization identity missing in header." + Environment.NewLine;

                    throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required header incomingOrganizationId is missing.");
                }

                //Write to log table
                _logEventService.LogInfo(EventNumber.VIS_uploadTextMessage_request, EventDataType.TXT,
                                         paramList, textMessageObject);
                // Get identity ether from internal id talbe or from id registry
                var identity = _identityService.GetCallerIdentity();

                var result = new UploadedMessage();
                result.AckDelivered        = false;
                result.DeliveryAckEndpoint = deliveryAckEndPoint;
                result.DeliveryAckReqested = string.IsNullOrEmpty(deliveryAckEndPoint) ? false : true;
                result.FetchedByShip       = false;
                result.FetchTime           = null;
                result.FromOrg             = identity;
                result.FromServiceId       = InstanceContext.CallerServiceId;
                result.Message             = Serialization.StrToByteArray(textMessageObject);
                result.MessageType         = _messageTypeService.Get(x => x.Name.ToLower() == "txt").First();
                result.Notified            = false;
                result.ReceiveTime         = DateTime.UtcNow;
                result.MessageID           = dataId;

                _uploadedMessageService.InsertTXT(result);

                //Notify STM module
                var notification = new Common.Services.Internal.Interfaces.Notification();
                notification.FromOrgName        = identity.Name;
                notification.FromOrgId          = identity.UID;
                notification.FromServiceId      = InstanceContext.CallerServiceId;
                notification.NotificationType   = EnumNotificationType.MESSAGE_WAITING;
                notification.Subject            = "New Text message uploaded.";
                notification.NotificationSource = EnumNotificationSource.VIS;

                var notified = _notificationService.Notify(notification);

                if (notified)
                {
                    result.Notified = true;
                    _uploadedMessageService.Update(result);
                }

                var responsObj = new ResponseObj("Success store message");

                //Save to DB
                _context.SaveChanges();

                _logEventService.LogSuccess(EventNumber.VIS_uploadTextMessage_response, EventDataType.Other, paramList,
                                            JsonConvert.SerializeObject(responsObj, Formatting.Indented));

                return(responsObj);
            }

            catch (HttpResponseException ex)
            {
                log.Error(ex.Message, ex);
                _logEventService.LogError(EventNumber.VIS_uploadTextMessage_request, EventType.Error_internal,
                                          paramList,
                                          JsonConvert.SerializeObject(ex.Response, Formatting.Indented));

                throw;
            }
            catch (DbEntityValidationException dbEx)
            {
                var           response = request.CreateResponse(HttpStatusCode.InternalServerError);
                StringBuilder sb       = new StringBuilder();
                foreach (var item in dbEx.EntityValidationErrors)
                {
                    sb.Append(item + " errors: ");
                    foreach (var i in item.ValidationErrors)
                    {
                        sb.Append(i.PropertyName + " : " + i.ErrorMessage);
                    }
                    sb.Append(Environment.NewLine);
                }
                string msg = "VIS internal server error. " + dbEx.Message;

                _logEventService.LogError(EventNumber.VIS_uploadTextMessage_request, EventType.Error_internal,
                                          paramList, msg);
                log.ErrorFormat("Validation errors: {0}", sb.ToString());

                throw CreateHttpResponseException(HttpStatusCode.InternalServerError, sb.ToString());
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                _logEventService.LogError(EventNumber.VIS_uploadTextMessage_request, EventType.Error_internal,
                                          paramList, ex.Message);

                string msg = "VIS internal server error. " + ex.Message;
                throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg);
            }
        }