Ejemplo n.º 1
0
        public void SaveRevisionGuidTest()
        {
            var repo = new SqlTransactionRepository(
                Dsn,
                new SpecificationFinder(),
                "NM1,N1,N3,N4,N9,REF,PER".Split(','),
                typeof(Guid),
                "X12");

            var segments = repo.GetTransactionSegments(Guid.Parse("DC737E4D-33D3-487D-9C36-00C93759B8C4"), int.MaxValue);

            var subsriberSeg = segments.First(s => s.SpecLoopId == "2010BA");

            subsriberSeg.Segment.SetElement(5, "MID");

            var claimSeg = segments.First(s => s.SpecLoopId == "2300");

            claimSeg.Segment.SetElement(1, "ABC26403774");

            var tooSeg = segments.First(s => s.PositionInInterchange == 30);

            tooSeg.Deleted = true;

            long revId = repo.SaveRevision(segments, "Testing the revision feature", Environment.UserName);

            Trace.WriteLine(revId);

            Assert.IsTrue(revId > 0);
        }
Ejemplo n.º 2
0
        public void LoadAllTestFiles()
        {
            var repo = new SqlTransactionRepository <long>("Data Source=127.0.0.1;Initial Catalog=X12;Integrated Security=True", new SpecificationFinder(),
                                                           new string[] { "AMT",
                                                                          "BHT",
                                                                          "CAS",
                                                                          "CL1",
                                                                          "CLM",
                                                                          "CN1",
                                                                          "DMG",
                                                                          "DN1",
                                                                          "DTP",
                                                                          "HCP",
                                                                          "HI",
                                                                          "HL",
                                                                          "K3",
                                                                          "LX",
                                                                          "MEA",
                                                                          "N3",
                                                                          "N4",
                                                                          "NM1",
                                                                          "NTE",
                                                                          "OI",
                                                                          "PAT",
                                                                          "PER",
                                                                          "PRV",
                                                                          "PWK",
                                                                          "QTY",
                                                                          "REF",
                                                                          "SBR",
                                                                          "SV1",
                                                                          "SV2",
                                                                          "SV3",
                                                                          "SVD",
                                                                          "TOO", }, "Inbound");

            var parser = new X12Parser();

            foreach (var resource in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if (resource.StartsWith("OopFactory.X12.Tests.Unit.Parsing._SampleEdiFiles") && !resource.EndsWith(".xml"))
                {
                    var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);

                    try
                    {
                        var interchanges = parser.ParseMultiple(stream);
                        foreach (var interchange in interchanges)
                        {
                            repo.Save(interchange, resource, "dstrubhar");
                        }
                    }
                    catch (Exception exc)
                    {
                        Trace.WriteLine(resource);
                        Trace.WriteLine(exc.Message);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void SaveRevisionTest()
        {
            var repo = new SqlTransactionRepository <long>("Data Source=127.0.0.1;Initial Catalog=X12;Integrated Security=True",
                                                           new SpecificationFinder(),
                                                           "NM1,N1,N3,N4,N9,REF,PER".Split(','), "Test", "dbo");

            var segments = repo.GetTransactionSegments(3293, Int32.MaxValue, false);

            var subsriberSeg = segments.First(s => s.SpecLoopId == "2010BA");

            subsriberSeg.Segment.SetElement(5, "MID");

            var claimSeg = segments.First(s => s.SpecLoopId == "2300");

            claimSeg.Segment.SetElement(1, "ABC26403774");

            var tooSeg = segments.First(s => s.PositionInInterchange == 30);

            tooSeg.Deleted = true;

            long revId = repo.SaveRevision(segments, "Testing the revision feature", Environment.UserName);

            Trace.WriteLine(revId);

            Assert.IsTrue(revId > 0);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string dsn = ConfigurationManager.ConnectionStrings["X12"].ConnectionString;

            bool throwExceptionOnSyntaxErrors = ConfigurationManager.AppSettings["ThrowExceptionOnSyntaxErrors"] == "true";

            string[] segments           = ConfigurationManager.AppSettings["IndexedSegments"].Split(',');
            string   parseDirectory     = ConfigurationManager.AppSettings["ParseDirectory"];
            string   parseSearchPattern = ConfigurationManager.AppSettings["ParseSearchPattern"];
            string   archiveDirectory   = ConfigurationManager.AppSettings["ArchiveDirectory"];
            string   failureDirectory   = ConfigurationManager.AppSettings["FailureDirectory"];
            string   sqlDateType        = ConfigurationManager.AppSettings["SqlDateType"];
            int      segmentBatchSize   = Convert.ToInt32(ConfigurationManager.AppSettings["SqlSegmentBatchSize"]);

            var specFinder = new SpecificationFinder();
            var parser     = new X12Parser(throwExceptionOnSyntaxErrors);

            parser.ParserWarning += new X12Parser.X12ParserWarningEventHandler(parser_ParserWarning);
            var repo = new SqlTransactionRepository <int>(dsn, specFinder, segments, ConfigurationManager.AppSettings["schema"], ConfigurationManager.AppSettings["containerSchema"], segmentBatchSize, sqlDateType);

            foreach (var filename in Directory.GetFiles(parseDirectory, parseSearchPattern, SearchOption.AllDirectories))
            {
                byte[] header = new byte[6];
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    // peak at first 6 characters to determine if this is a unicode file
                    fs.Read(header, 0, 6);
                    fs.Close();
                }
                Encoding encoding = (header[1] == 0 && header[3] == 0 && header[5] == 0) ? Encoding.Unicode : Encoding.UTF8;


                var fi = new FileInfo(filename);
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    try
                    {
                        var interchanges = parser.ParseMultiple(fs, encoding);

                        foreach (var interchange in interchanges)
                        {
                            repo.Save(interchange, filename, Environment.UserName);
                        }
                        if (!string.IsNullOrWhiteSpace(archiveDirectory))
                        {
                            MoveTo(fi, parseDirectory, archiveDirectory);
                        }
                    }
                    catch (Exception exc)
                    {
                        Trace.TraceError("Error parsing {0}: {1}\n{2}", fi.FullName, exc.Message, exc.StackTrace);
                        if (!string.IsNullOrEmpty(failureDirectory))
                        {
                            MoveTo(fi, parseDirectory, failureDirectory);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void TestGetTransactionSegments([Values(831, 821)] int loopId)
        {
            // arrange
            var repo = new SqlTransactionRepository("Data Source=localhost;Initial Catalog=X12;Integrated Security=True", "Test", typeof(long));

            // act - assert
            var segments = repo.GetTransactionSegments(loopId, 99, true);
        }
Ejemplo n.º 6
0
        public void TestMethod2()
        {
            var repo = new SqlTransactionRepository <long>("Data Source=127.0.0.1;Initial Catalog=X12;Integrated Security=True", "Test");

            var segments = repo.GetTransactionSetSegments(821, 99, true);

            foreach (var seg in segments)
            {
                Trace.WriteLine(seg.Segment.SegmentString);
            }
        }
Ejemplo n.º 7
0
        public void ReadLoops()
        {
            // arrange
            var repo = new SqlTransactionRepository("Data Source=127.0.0.1;Initial Catalog=X12;Integrated Security=True", "Test", typeof(long));

            // act
            var list = repo.GetLoops(new RepoLoopSearchCriteria {
                TransactionSetCode = "837", SpecLoopId = "2300"
            });

            // assert
            Assert.IsTrue(list.Count > 0);
        }
Ejemplo n.º 8
0
        public void ReadLoops()
        {
            var repo = new SqlTransactionRepository <long>("Data Source=127.0.0.1;Initial Catalog=X12;Integrated Security=True", "Test");
            var list = repo.GetLoops(new RepoLoopSearchCriteria <long> {
                TransactionSetCode = "837", SpecLoopId = "2300"
            });

            Assert.IsTrue(list.Count > 0);
            foreach (var claim in list)
            {
                Trace.TraceInformation("{0}{1}", claim.Segment.SegmentString, claim.Segment.Delimiters.SegmentTerminator);
            }
        }
Ejemplo n.º 9
0
        public void ReadTransactions()
        {
            // arrange
            var repo = new SqlTransactionRepository("Data Source=(local);Initial Catalog=X12;Integrated Security=True", "Test", typeof(long));

            // act
            var list = repo.GetTransactionSets(new RepoTransactionSetSearchCriteria
            {
                SenderId           = "580977458",
                InterchangeMinDate = DateTime.Parse("2011-01-01")
            });

            // assert
            Assert.IsTrue(list.Count > 0);
        }
Ejemplo n.º 10
0
        public void ReadTransactions()
        {
            var repo = new SqlTransactionRepository <long>("Data Source=(local);Initial Catalog=X12;Integrated Security=True", "Test");
            var list = repo.GetTransactionSets(new RepoTransactionSetSearchCriteria <long>
            {
                SenderId           = "580977458",
                InterchangeMinDate = DateTime.Parse("2011-01-01")
            });

            foreach (var set in list)
            {
                Trace.TraceInformation("Date: {0}, Transaction Set: {1}, Control Number: {2} ", set.InterchangeDate, set.TransactionSetCode, set.ControlNumber);
            }

            Assert.IsTrue(list.Count > 0);
        }
        public void LoadAllTestFiles()
        {
            var indexedSegments = new[]
            {
                "AMT",
                "BHT",
                "CAS",
                "CL1",
                "CLM",
                "CN1",
                "DMG",
                "DN1",
                "DTP",
                "HCP",
                "HI",
                "HL",
                "K3",
                "LX",
                "MEA",
                "N3",
                "N4",
                "NM1",
                "NTE",
                "OI",
                "PAT",
                "PER",
                "PRV",
                "PWK",
                "QTY",
                "REF",
                "SBR",
                "SV1",
                "SV2",
                "SV3",
                "SVD",
                "TOO"
            };

            var repo = new SqlTransactionRepository(
                "Data Source=localhost;Initial Catalog=X12;Integrated Security=True",
                new SpecificationFinder(),
                indexedSegments,
                typeof(long),
                "Inbound");

            var parser = new X12Parser();

            foreach (var resource in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if (resource.StartsWith("X12.Tests.Unit.Parsing._SampleEdiFiles") && !resource.EndsWith(".xml"))
                {
                    var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);

                    var interchanges = parser.ParseMultiple(stream);
                    foreach (var interchange in interchanges)
                    {
                        repo.Save(interchange, resource, "dstrubhar");
                    }
                }
            }
        }