예제 #1
1
        private static void RunAsyncConstructor(Encoding enc, params string[] pathElements)
        {
            var asyncEngine = new FileHelperAsyncEngine<CustomersVerticalBar>(enc);
            Assert.AreEqual(enc, asyncEngine.Encoding);

            CoreRunAsync(asyncEngine, pathElements);
        }
예제 #2
0
        public void AsyncFieldIndex1()
        {
            var engine = new FileHelperAsyncEngine(typeof (SampleType));

            var sw = new StringWriter();
            engine.BeginWriteStream(sw);

            engine[0] = new DateTime(2003, 2, 1);
            engine[1] = "B";
            engine[2] = 18;

            engine.WriteNextValues();

            engine.Close();

            engine.BeginReadString(sw.GetStringBuilder().ToString());
            engine.ReadNext();

            Assert.AreEqual(new DateTime(2003, 2, 1), engine[0]);
            Assert.AreEqual("B", engine[1]);
            Assert.AreEqual(18, engine[2]);

            Assert.AreEqual(new DateTime(2003, 2, 1), engine.LastRecordValues[0]);
            Assert.AreEqual("B", engine.LastRecordValues[1]);
            Assert.AreEqual(18, engine.LastRecordValues[2]);

            engine.ReadNext();

            Assert.IsNull(engine.LastRecord);
            Assert.IsNull(engine.LastRecordValues);
        }
예제 #3
0
        public void AsyncFieldIndexBad2()
        {
            var engine = new FileHelperAsyncEngine(typeof (SampleType));

            Assert.Throws<BadUsageException>(()
                => engine.WriteNextValues());
        }
예제 #4
0
		private void RunAsyncConstructor(string fileName, Encoding enc)
		{
			asyncEngine = new FileHelperAsyncEngine(typeof (CustomersVerticalBar), enc);
			Assert.AreEqual(enc, asyncEngine.Encoding);

			CoreRunAsync(fileName);
		}
예제 #5
0
        public void WriteEvents()
        {
            before = 0;
            after = 0;

            engine = new FileHelperAsyncEngine<SampleType>();

            engine.BeforeWriteRecord += new BeforeWriteHandler<SampleType>(engine_BeforeWriteRecord);
            engine.AfterWriteRecord += new AfterWriteHandler<SampleType>(engine_AfterWriteRecord);

            var res = new SampleType[2];

            res[0] = new SampleType();
            res[1] = new SampleType();

            res[0].Field1 = DateTime.Now.AddDays(1);
            res[0].Field2 = "je";
            res[0].Field3 = 0;

            res[1].Field1 = DateTime.Now;
            res[1].Field2 = "ho";
            res[1].Field3 = 2;

            engine.BeginWriteFile("tempEvent.txt");
            engine.WriteNexts(res);
            engine.Close();

            File.Delete("tempEvent.txt");
            Assert.AreEqual(2, engine.TotalRecords);
            Assert.AreEqual(2, before);
            Assert.AreEqual(2, after);
        }
예제 #6
0
		public void AsyncRead()
		{
			asyncEngine = new FileHelperAsyncEngine(typeof (SampleType));

			SampleType rec1, rec2;

			Common.BeginReadTest(asyncEngine, @"Good\test1.txt");

			rec1 = (SampleType) asyncEngine.ReadNext();
			Assert.IsNotNull(rec1);
			rec2 = (SampleType) asyncEngine.ReadNext();
			Assert.IsNotNull(rec1);

			Assert.IsTrue(rec1 != rec2);

			rec1 = (SampleType) asyncEngine.ReadNext();
			Assert.IsNotNull(rec2);
			rec1 = (SampleType) asyncEngine.ReadNext();
			Assert.IsNotNull(rec2);

			Assert.IsTrue(rec1 != rec2);

			Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

			asyncEngine.Close();
		}
        //-> /File
        //->  Instantiate a FileHelperAsyncEngine and read or write files:
        public override void Run()
        {
            //-> File:Example.cs
            var engine = new FileHelperAsyncEngine<Customer>();

            // Read
            using(engine.BeginReadFile("Input.txt"))
            {
                // The engine is IEnumerable
                foreach(Customer cust in engine)
                {
                    // your code here
                    Console.WriteLine(cust.Name);
                }
            }

            // Write

            var arrayCustomers = new Customer[] {
                new Customer { CustId = 1732, Name = "Juan Perez", Balance = 435.00m,
                               AddedDate = new DateTime (2020, 5, 11) },
                new Customer { CustId = 554, Name = "Pedro Gomez", Balance = 12342.30m,
                               AddedDate = new DateTime (2004, 2, 6) },
            };

            using(engine.BeginWriteFile("TestOut.txt"))
            {
                foreach(Customer cust in arrayCustomers)
                {
                    engine.WriteNext(cust);
                }
            }

            //-> /File
        }
예제 #8
0
        /// <summary>
        /// Process the delimited file twice,
        /// once with the simple engine, once with Async
        /// </summary>
        /// <remarks>
        /// This is a simple sample of using the Normal engine and the Async engine
        /// </remarks>
        public void ReadWrite()
        {
            var engine = new FileHelperEngine<Orders>();

            // to Read use:
            Orders[] res = engine.ReadFile(@"C:\TestIn.txt");

            // to Write use:
            engine.WriteFile(@"C:\TestOut.txt", res);

            foreach (Orders order in res) {
                Console.WriteLine("Order Info:");
                Console.WriteLine(order.CustomerID + " - " +
                                  order.OrderDate.ToString("dd/MM/yy"));
            }

            var asyncEngine = new FileHelperAsyncEngine<Orders>();

            asyncEngine.BeginReadFile(@"C:\TestIn.txt");

            Orders ord;

            while (asyncEngine.ReadNext() != null) {
                ord = asyncEngine.LastRecord;
                // your code here
                Console.WriteLine(ord.CustomerID);
            }
        }
예제 #9
0
        public void ExportApprovalList(string fileName, CancellationToken token)
        {
            using (DatabaseContext context = GetContext())
            {
                // init engine
                FileHelperAsyncEngine<CsvApprovalItem> engine = new FileHelperAsyncEngine<CsvApprovalItem>() { HeaderText = CsvApprovalItem.HeaderLine };
                engine.BeginWriteFile(fileName);

                // look for approval items
                var query = context.ViewApprovalLists.Where("it.Status=@st", new ObjectParameter("st", APPROVAL_STATUS_NEW));
                foreach (ViewApprovalList item in query)
                {
                    if (token.IsCancellationRequested) break;
                    engine.WriteNext(new CsvApprovalItem()
                    {
                        ItemID = item.Id,
                        EngineName = item.EngineName,
                        ProductName = item.SearchName,
                        FoundName = item.Name,
                        URL = item.Url,
                        Price = item.Price,
                        Command = APPROVAL_COMMAND_UNDEFINED
                    });
                }
                engine.Close();
            }
        }
        public void ImportGeonamesFrom(string fileName)
        {
            var geoNames = new FileHelperAsyncEngine(typeof(Geoname));
            geoNames.BeginReadFile(fileName);

            _geoDataStore.DeleteAll();

            long cnt = 0;
            foreach (Geoname geoName in geoNames)
            {
                //Store the name in a format suitable for case-insensitive searching:
                geoName.Name = geoName.Name.ToUpper();

                if (geoName.FeatureClass == "P")
                {
                    SaveCity(geoName, cnt);
                }

                // Parks: http://127.0.0.1:28017/local/geonames/?filter_FeatureClass=L&filter_FeatureCode=PRK
                if(geoName.FeatureClass.Equals("L") && geoName.FeatureCode.Equals("PRK"))
                {
                    SavePark(geoName);
                }

                cnt++;
            }

            _geoDataStore.DoIndexing();

            geoNames.Close();
        }
예제 #11
0
        public void AsyncRead()
        {
            var asyncEngine = new FileHelperAsyncEngine<SampleType>();

            SampleType rec1, rec2;
            asyncEngine.BeginReadFile(FileTest.Good.Test1.Path);

            rec1 = asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);
            rec2 = asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);

            Assert.IsTrue(rec1 != rec2);

            rec1 = asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);
            rec1 = asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);

            Assert.IsTrue(rec1 != rec2);

            Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

            asyncEngine.Close();
        }
예제 #12
0
        internal void Import()
        {
            var repo = new AddressRepository();
            using (var engine = new FileHelperAsyncEngine<REDPostalAddressImport>())
            {
                engine.BeginReadFile(_fileName);

                var swWrite = Stopwatch.StartNew();
                var processed = 0L;

                var postalAddresses = new List<PostalAddress>();
                foreach (REDPostalAddressImport postalAddress in engine)
                {
                    postalAddresses.Add(Convert(postalAddress));
                    if (postalAddresses.Count == 100000)
                    {
                        processed += postalAddresses.Count;

                        repo.Write(postalAddresses);
                        postalAddresses.Clear();

                        Console.WriteLine("Processed {0} in {1}", processed, swWrite.Elapsed);
                        swWrite.Restart();
                    }
                }
                if (postalAddresses.Count > 0)
                {
                    repo.Write(postalAddresses);
                    processed += postalAddresses.Count;
                    Console.WriteLine("Processed {0} in {1}", processed, swWrite.Elapsed);
                }
            }
        }
예제 #13
0
		public void WriteNullAsync()
		{
			asyncEngine = new FileHelperAsyncEngine(typeof (SampleType));

			asyncEngine.BeginWriteFile("tempNull.txt");

			asyncEngine.WriteNext(new SampleType());
			asyncEngine.WriteNext(new SampleType());
			asyncEngine.WriteNext(new SampleType());

			asyncEngine.Close();

			asyncEngine.BeginReadFile("tempNull.txt");
			SampleType[] res = (SampleType[]) asyncEngine.ReadNexts(5000);
			asyncEngine.Close();

			Assert.AreEqual(3, res.Length);
			Assert.AreEqual(3, asyncEngine.TotalRecords);
			Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

			Assert.AreEqual(DateTime.MinValue, res[0].Field1);
			Assert.AreEqual("", res[0].Field2);
			Assert.AreEqual(0, res[0].Field3);

			if (File.Exists("tempNull.txt")) File.Delete("tempNull.txt");
		}
예제 #14
0
		public void AsyncRead()
		{

            FileHelperAsyncEngine<SampleType> asyncEngine = new FileHelperAsyncEngine<SampleType>();

			SampleType rec1, rec2;
            asyncEngine.BeginReadFile(Common.TestPath(@"Good\test1.txt"));

			rec1 = asyncEngine.ReadNext();
			Assert.IsNotNull(rec1);
			rec2 = asyncEngine.ReadNext();
			Assert.IsNotNull(rec1);

			Assert.IsTrue(rec1 != rec2);

			rec1 = asyncEngine.ReadNext();
			Assert.IsNotNull(rec2);
			rec1 = asyncEngine.ReadNext();
			Assert.IsNotNull(rec2);

			Assert.IsTrue(rec1 != rec2);

			Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);

            asyncEngine.Close();

		}
예제 #15
0
        public void AsyncRead()
        {
            asyncEngine = new FileHelperAsyncEngine(typeof (SampleType));

            SampleType rec1, rec2;

            Assert.AreEqual(0, asyncEngine.LineNumber);
            TestCommon.BeginReadTest(asyncEngine, "Good", "Test1.txt");

            rec1 = (SampleType) asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);
            Assert.AreEqual(1, asyncEngine.LineNumber);

            rec2 = (SampleType) asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);
            Assert.AreEqual(2, asyncEngine.LineNumber);

            Assert.IsTrue(rec1 != rec2);

            rec1 = (SampleType) asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);
            Assert.AreEqual(3, asyncEngine.LineNumber);
            rec1 = (SampleType) asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);
            Assert.AreEqual(4, asyncEngine.LineNumber);

            Assert.IsTrue(rec1 != rec2);

            Assert.AreEqual(4, asyncEngine.TotalRecords);
            Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);
        }
예제 #16
0
        private void RunAsyncConstructor(Encoding enc, params string[] pathElements)
        {
            asyncEngine = new FileHelperAsyncEngine<CustomersVerticalBar>(enc);
            Check.That(enc).IsEqualTo(asyncEngine.Encoding);

            CoreRunAsync(pathElements);
        }
예제 #17
0
        public void IgnoreComment1Async()
        {
            var asyncEngine = new FileHelperAsyncEngine<IgnoreCommentsType>();
            var res = TestCommon.ReadAllAsync<IgnoreCommentsType>(asyncEngine, "Good", "IgnoreComments1.txt");

            Assert.AreEqual(4, res.Count);
            Assert.AreEqual(7, asyncEngine.LineNumber);
        }
예제 #18
0
        public void IgnoreComment1Async()
        {
            asyncEngine = new FileHelperAsyncEngine(typeof (IgnoreCommentsType));
            object[] res = TestCommon.ReadAllAsync(asyncEngine, "Good", "IgnoreComments1.txt");

            Assert.AreEqual(4, res.Length);
            Assert.AreEqual(7, asyncEngine.LineNumber);
        }
예제 #19
0
        public void NullRecords2()
        {
            engine2 = new FileHelperAsyncEngine(typeof (SampleType));
            engine2.BeginWriteStream(new StringWriter(new StringBuilder()));

            Assert.Throws<ArgumentNullException>(()
                => engine2.WriteNexts(null));
        }
예제 #20
0
        public void AsyncFieldIndexBad3()
        {
            var engine = new FileHelperAsyncEngine(typeof (SampleType));
            var sw = new StringWriter();
            engine.BeginWriteStream(sw);

            Assert.Throws<BadUsageException>(()
                => engine.WriteNextValues());
        }
예제 #21
0
		public void IgnoreEmpty3Async()
		{
			asyncEngine = new FileHelperAsyncEngine(typeof (IgnoreEmptyType1));

			object[] res = Common.ReadAllAsync(asyncEngine, @"Good\IgnoreEmpty3.txt");

			Assert.AreEqual(4, res.Length);
			Assert.AreEqual(7, asyncEngine.LineNumber);
		}
        public void BeginWriteWhileReading()
        {
            FileHelperAsyncEngine eng = new FileHelperAsyncEngine(typeof(SampleType));
            eng.BeginReadString("jejjeje");

            var filename = TestCommon.GetTempFile("TempWrite.txt");
            Assert.Throws<BadUsageException>(()
                => eng.BeginWriteFile(filename));
        }
예제 #23
0
        public static object[] ReadAllAsync(FileHelperAsyncEngine engine, string fileName)
        {
            ArrayList arr = new ArrayList();
            engine.BeginReadFile(@"..\..\data\" + fileName);
            while(engine.ReadNext() != null)
                arr.Add(engine.LastRecord);
            engine.Close();

            return arr.ToArray();
        }
예제 #24
0
        public void LoadFromXML()
        {
            ClassBuilder cb = ClassBuilder.LoadFromXml(TestCommon.GetPath("Dynamic", "VendorImport.xml"));
            Type t = cb.CreateRecordClass(); // this line generates an error in the FH library 

            using (var engine = new FileHelperAsyncEngine(t)) {
                engine.BeginReadString("");

                while (engine.ReadNext() != null) {}
            }
        }
예제 #25
0
		public void DiscardFirst6()
		{
			asyncEngine = new FileHelperAsyncEngine(typeof (DiscardType2));

			Common.BeginReadTest(asyncEngine, @"Good\DiscardFirst2.txt");

			Assert.AreEqual("you can get this lines\r\nwith the FileHelperEngine.HeaderText property\r\n", asyncEngine.HeaderText);

			DiscardType2 res = (DiscardType2) asyncEngine.ReadNext();

			Assert.AreEqual(new DateTime(1314, 12, 11), res.Field1);
		}
예제 #26
0
        public static object[] ReadAllAsync(FileHelperAsyncEngine engine, params string[] pathElements)
        {
            ArrayList arr = new ArrayList();

            using (engine.BeginReadFile(GetPath(pathElements)))
            {
                while (engine.ReadNext() != null)
                    arr.Add(engine.LastRecord);
            }

            return arr.ToArray();
        }
예제 #27
0
        public void AsyncFieldIndexBad1()
        {
            var engine = new FileHelperAsyncEngine(typeof (SampleType));
            engine.BeginReadString(data);

            while (engine.ReadNext() != null) {
                Assert.Throws<IndexOutOfRangeException>(()
                    => { object val = engine[10]; });
            }

            engine.Close();
        }
예제 #28
0
 public void MoreCallsToMoveNext1()
 {
     var engine = new FileHelperAsyncEngine<Record>();
     string src = "first,line\nabc,JohnDoe";
     using (engine.BeginReadString(src))
     {
         var enumerator = (engine as IEnumerable<Record>).GetEnumerator();
         enumerator.MoveNext();
         enumerator.MoveNext();
         enumerator.MoveNext();
         enumerator.MoveNext();
     }
 }
예제 #29
0
        public void AsyncFieldIndex3()
        {
            var engine = new FileHelperAsyncEngine(typeof (SampleType));
            engine.BeginReadString(data);

            while (engine.ReadNext() != null) {
                Assert.AreEqual(engine["Field1"], engine.LastRecordValues[0]);
                Assert.AreEqual(engine["Field2"], engine.LastRecordValues[1]);
                Assert.AreEqual(engine["Field3"], engine.LastRecordValues[2]);
            }

            engine.Close();
        }
예제 #30
0
		static void Main(string[] args)
		{
			FileHelperAsyncEngine engine = new FileHelperAsyncEngine (typeof(TestRecord));

			engine.BeginReadFile(@"E:\_SVN\FileHelpers\test2.csv");
			//string s;
			
			while(engine.ReadNext() != null)
			{
				
			}
			
			engine.Close();
		}
예제 #31
0
        public void ReadAsyncFieldIndex()
        {
            string data = "11121314901234\n" +
                          "10111314012345\n" +
                          "11101314123456\n" +
                          "10101314234567\n";

            asyncEngine = new FileHelperAsyncEngine(typeof(SampleType));
            asyncEngine.BeginReadString(data);

            foreach (SampleType rec in asyncEngine)
            {
                Assert.AreEqual(rec.Field1, asyncEngine[0]);
                Assert.AreEqual(rec.Field2, asyncEngine[1]);
                Assert.AreEqual(rec.Field3, asyncEngine[2]);

                Assert.AreEqual(rec.Field1, asyncEngine["Field1"]);
                Assert.AreEqual(rec.Field2, asyncEngine["Field2"]);
                Assert.AreEqual(rec.Field3, asyncEngine["Field3"]);
            }

            asyncEngine.Close();
        }
예제 #32
0
 public static void ProcessSim <Qop>(QCTraceSimulator sim, string comment = "", bool full_depth = false, string suffix = "")
 {
     if (!full_depth)
     {
         DisplayCSV.CSV(sim.ToCSV(), typeof(Qop).FullName, false, comment, false, suffix);
     }
     else
     {
         // full depth only
         var depthEngine = new FileHelperAsyncEngine <DepthCounterCSV>();
         using (depthEngine.BeginReadString(sim.ToCSV()[MetricsCountersNames.depthCounter]))
         {
             // The engine is IEnumerable
             foreach (DepthCounterCSV cust in depthEngine)
             {
                 if (cust.Name == typeof(Qop).FullName)
                 {
                     Console.Write($"{cust.DepthAverage}");
                 }
             }
         }
     }
 }
예제 #33
0
        private static void CoreRunAsync(FileHelperAsyncEngine <CustomersVerticalBar> asyncEngine, params string[] pathElements)
        {
            var arr = new List <CustomersVerticalBar>();

            TestCommon.BeginReadTest(asyncEngine, pathElements);

            foreach (var record in asyncEngine)
            {
                arr.Add(record);
            }

            CustomersVerticalBar[] res = arr.ToArray();
            Check.That(ExpectedRecords).IsEqualTo(res.Length);
            Check.That(ExpectedRecords).IsEqualTo(asyncEngine.TotalRecords);

            Assert.AreEqual(ExpectedTextWithNTilde, res[1].CompanyName);
            Assert.AreEqual(ExpectedTextWithEGrave, res[6].CompanyName);
            Assert.AreEqual(ExpectedTextWithEAcute1, res[6].ContactName);

            Assert.AreEqual(ExpectedTextWithEAcute2, res[6].Address);
            Assert.AreEqual(ExpectedTextWithADiaeresis, res[4].Address);
            Assert.AreEqual(ExpectedTextWithARing, res[4].City);
        }
예제 #34
0
        /// <summary>
        /// Processes results and writes them to local file.
        /// </summary>
        /// <param name="results">Results to save.</param>
        /// <param name="filename">Filename to write.</param>
        /// <returns><c>true</c> if no exception occured, <c>false</c> otherwise.</returns>
        private static bool WriteFile(List <List <RatingDataContainer> > results, string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(false);
            }

            var engine = new FileHelperAsyncEngine <COuputFileData>
            {
                HeaderText = typeof(COuputFileData).GetCsvHeader()
            };

            using (engine.BeginWriteFile(filename))
            {
                Dictionary <string, List <double> > converted = ConvertResultsToDict(results);
                engine.WriteNexts(converted.Select(result => new COuputFileData
                {
                    thingName   = $"\"{result.Key}\"", // Escape Thing names.
                    ratingValue = result.Value
                }));
            }
            return(true);
        }
예제 #35
0
        public void ReadEvents()
        {
            before = 0;
            after  = 0;

            engine = new FileHelperAsyncEngine <SampleType>();
            engine.BeforeReadRecord += new BeforeReadHandler <SampleType>(BeforeEvent);
            engine.AfterReadRecord  += new AfterReadHandler <SampleType>(AfterEvent);

            engine.BeginReadFile(FileTest.Good.Test1.Path);

            int count = 0;

            foreach (var t in engine)
            {
                count++;
            }

            Assert.AreEqual(4, count);
            Assert.AreEqual(4, engine.TotalRecords);
            Assert.AreEqual(4, before);
            Assert.AreEqual(4, after);
        }
예제 #36
0
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            using (var engine = new FileHelperAsyncEngine <CustomerInput>())
            {
                engine.HeaderText = engine.GetFileHeader();

                using (StreamWriter errorsFile = new StreamWriter(ErrorsFilePath))
                    using (engine.BeginWriteFile(RejectedRecordsFilePath))
                    {
                        foreach (Row row in rows)
                        {
                            if (!row.IsValid())
                            {
                                errorCount++;

                                // write rejected record
                                var record = row.ToObject <CustomerInput>();
                                engine.WriteNext(record);

                                // write validation errors
                                errorsFile.WriteLine($"Record Id: {record.Id}");
                                foreach (var err in row.GetErrors().Split('|'))
                                {
                                    errorsFile.WriteLine($"  {err}");
                                }

                                continue;
                            }
                            else
                            {
                                validRecordCount++;
                                yield return(row);
                            }
                        }
                    }
            }
        }
예제 #37
0
        public void DiscardWriteRead2()
        {
            engine = new FileHelperEngine(typeof(DiscardLastType1));

            DiscardLastType1[] res = (DiscardLastType1[])TestCommon.ReadTest(engine, @"Good\DiscardLast1.txt");


            asyncEngine = new FileHelperAsyncEngine(typeof(DiscardLastType1));

            asyncEngine.FooterText = "This is a new Footer....";

            asyncEngine.BeginWriteFile("temp.txt");
            asyncEngine.WriteNexts(res);
            asyncEngine.EndsWrite();

            asyncEngine.FooterText = "none none";

            asyncEngine.BeginReadFile("temp.txt");

            while (asyncEngine.ReadNext() != null)
            {
            }

            Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
            Assert.AreEqual("This is a new Footer....\r\n", asyncEngine.FooterText);

            asyncEngine.EndsRead();

            Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
            Assert.AreEqual("This is a new Footer....\r\n", asyncEngine.FooterText);

            if (File.Exists("tempo.txt"))
            {
                File.Delete("tempo.txt");
            }
        }
예제 #38
0
        public void ReadAsyncFieldIndex()
        {
            string data = "11121314901234" + Environment.NewLine +
                          "10111314012345" + Environment.NewLine +
                          "11101314123456" + Environment.NewLine +
                          "10101314234567" + Environment.NewLine;

            var asyncEngine = new FileHelperAsyncEngine <SampleType>();

            asyncEngine.BeginReadString(data);

            foreach (var rec in asyncEngine)
            {
                Assert.AreEqual(rec.Field1, asyncEngine[0]);
                Assert.AreEqual(rec.Field2, asyncEngine[1]);
                Assert.AreEqual(rec.Field3, asyncEngine[2]);

                Assert.AreEqual(rec.Field1, asyncEngine["Field1"]);
                Assert.AreEqual(rec.Field2, asyncEngine["Field2"]);
                Assert.AreEqual(rec.Field3, asyncEngine["Field3"]);
            }

            asyncEngine.Close();
        }
예제 #39
0
 static GrimoireHandler()
 {
     //first, check for compiled grimoire file
     if (File.Exists("grimoire.cgm"))
     {
         FileInfo        grimoireLoad = new FileInfo("grimoire.cgm");
         BinaryFormatter b            = new BinaryFormatter();
         Stream          s            = grimoireLoad.OpenRead();
         grimoire = (List <GrimoireAbility>)b.Deserialize(s);
         s.Close();
     }
     else if (File.Exists("grimoire.csv"))
     {
         //compiled grimoire does not exist, recompile!
         FileHelperAsyncEngine <GrimoireLine> reader = new FileHelperAsyncEngine <GrimoireLine>();
         reader.BeginReadFile("grimoire.csv");
         foreach (GrimoireLine line in reader)
         {
             if (line.AllowInMCS)
             {
                 grimoire.Add(new GrimoireAbility(line));
             }
         }
         reader.Close();
         //compile the grimoire to grimoire.cgm
         FileInfo        compileTarget = new FileInfo("grimoire.cgm");
         BinaryFormatter b             = new BinaryFormatter();
         Stream          s             = compileTarget.Open(FileMode.Create, FileAccess.Write);
         b.Serialize(s, grimoire);
         s.Close();
     }
     else
     {
         MessageBox.Show("No grimoire.csv or grimoire.cgm detected. Unable to load in predefined character abilities. Please check the MCS Helper page for the most recent version of the grimoire.", "Can't find grimoire!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
     }
 }
예제 #40
0
        private static void CreateTempFile(int sizeOfFile, string fileName, bool ascending)
        {
            var size   = 0;
            var engine = new FileHelperAsyncEngine <OrdersTab>();

            engine.AfterWriteRecord += (sender, e) => size += e.RecordLine.Length;

            using (engine.BeginWriteFile(fileName))
            {
                var i = 1;
                while (size < sizeOfFile)
                {
                    var order = new OrdersTab
                    {
                        CustomerID = "sdads",
                        EmployeeID = 123,
                        Freight    = 123,
                        OrderDate  = new DateTime(2009, 10, 23)
                    };
                    if (ascending)
                    {
                        order.OrderID = 1000000 + i;
                    }
                    else
                    {
                        order.OrderID = 1000000 - i;
                    }
                    order.RequiredDate = new DateTime(2009, 10, 20);
                    order.ShippedDate  = new DateTime(2009, 10, 21);
                    order.ShipVia      = 123;

                    engine.WriteNext(order);
                    i++;
                }
            }
        }
예제 #41
0
        public void DiscardWriteRead2()
        {
            var engine = new FileHelperEngine <DiscardLastType1>();

            DiscardLastType1[] res = TestCommon.ReadTest <DiscardLastType1>(engine, "Good", "DiscardLast1.txt");


            var asyncEngine = new FileHelperAsyncEngine <DiscardLastType1>();

            asyncEngine.FooterText = "This is a new Footer....";

            asyncEngine.BeginWriteFile("temp.txt");
            asyncEngine.WriteNexts(res);
            asyncEngine.Close();

            asyncEngine.FooterText = "none none";

            asyncEngine.BeginReadFile("temp.txt");

            while (asyncEngine.ReadNext() != null)
            {
            }

            Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
            Assert.AreEqual(expectedShortFooterText, asyncEngine.FooterText);

            asyncEngine.Close();

            Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
            Assert.AreEqual(expectedShortFooterText, asyncEngine.FooterText);

            if (File.Exists("tempo.txt"))
            {
                File.Delete("tempo.txt");
            }
        }
예제 #42
0
        public void AsyncRead()
        {
            asyncEngine = new FileHelperAsyncEngine(typeof(SampleType));

            SampleType rec1, rec2;

            TestCommon.BeginReadTest(asyncEngine, @"Good\test1.txt");

            rec1 = (SampleType)asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);
            rec2 = (SampleType)asyncEngine.ReadNext();
            Assert.IsNotNull(rec1);

            Assert.IsTrue(rec1 != rec2);

            rec1 = (SampleType)asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);
            rec1 = (SampleType)asyncEngine.ReadNext();
            Assert.IsNotNull(rec2);

            Assert.IsTrue(rec1 != rec2);

            Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount);
        }
예제 #43
0
        public void BeginReadWhileWriting()
        {
            var eng = new FileHelperAsyncEngine(typeof(SampleType));

            var filename = TestCommon.GetTempFile("TempWrite.txt");

            Assert.Throws <BadUsageException>(()
                                              =>
            {
                try
                {
                    eng.BeginWriteFile(filename);
                    eng.BeginReadString("jejjeje");
                }
                finally
                {
                    eng.Close();
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                }
            });
        }
        private void CreateTempFileHeaderFooter(int sizeOfFile, string fileName, bool ascending)
        {
            int size   = 0;
            var engine = new FileHelperAsyncEngine <OrdersTabHeaderFooter>();

            engine.AfterWriteRecord += (sender, e) => size += e.RecordLine.Length;

            engine.HeaderText = "Test Header, Test Header \r\nAnotherLine";
            engine.FooterText = "Footer Text";
            using (engine.BeginWriteFile(fileName))
            {
                var i = 1;
                while (size < sizeOfFile)
                {
                    var order = new OrdersTabHeaderFooter();
                    order.CustomerID = "sdads";
                    order.EmployeeID = 123;
                    order.Freight    = 123;
                    order.OrderDate  = new DateTime(2009, 10, 23);
                    if (ascending)
                    {
                        order.OrderID = 1000000 + i;
                    }
                    else
                    {
                        order.OrderID = 1000000 - i;
                    }
                    order.RequiredDate = new DateTime(2009, 10, 20);
                    order.ShippedDate  = new DateTime(2009, 10, 21);
                    order.ShipVia      = 123;

                    engine.WriteNext(order);
                    i++;
                }
            }
        }
예제 #45
0
 public DataObject(FileHelperAsyncEngine <TSource> engine, FileInfo dataFile)
 {
     _engine   = engine.ThrowIfNull(nameof(engine));
     _dataFile = dataFile.ThrowIfNull(nameof(dataFile));
 }
예제 #46
0
 /// <summary>
 /// Use an engine to read the first part of the file
 /// </summary>
 /// <param name="engine">Engine to read the data</param>
 /// <param name="pathElements">List of directories and a filename in Data area</param>
 public static void BeginReadTest <T>(FileHelperAsyncEngine <T> engine, params string[] pathElements)
     where T : class
 {
     engine.BeginReadFile(GetPath(pathElements));
 }
예제 #47
0
 /// <summary>
 /// Use an engine to read the first part of the file
 /// </summary>
 /// <param name="engine">Engine to read the data</param>
 /// <param name="pathElements">List of directories and a filename in Data area</param>
 public static void BeginReadTest(FileHelperAsyncEngine engine, params string[] pathElements)
 {
     engine.BeginReadFile(GetPath(pathElements));
 }
예제 #48
0
        public void ImportDBProcess()
        {
            string tableName = "";
            //string root = Android.OS.Environment.DirectoryDownloads;
            var enggine = new FileHelperAsyncEngine <FileHelperModel>();

            //System.IO.DirectoryNotFoundException: 'Could not find a part of the path "/content:/com.android.providers.downloads.documents/document/21"

            //using (enggine.BeginReadFile(fileData.FilePath))
            //using (enggine.BeginReadFile(DependencyService.Get<IFileHelper>().GetLocalDownloadPath(fileData.FileName)))
            //using (enggine.BeginReadFile(System.IO.Path.Combine(FileSystem.AppDataDirectory, "DataImport.csv")))
            //using (enggine.BeginReadFile(DependencyService.Get<IFileHelper>().GetLocalFilePath("DataImport.csv")))
            using (enggine.BeginReadFile(filePath.Text))
            {
                List <TblInventory>    tblInventory    = new List <TblInventory>();
                List <TblDISCNT_ITEM>  tblDISCNT_ITEM  = new List <TblDISCNT_ITEM>();
                List <TblBill>         tblBill         = new List <TblBill>();
                List <TblSold_Item>    tblSold_Item    = new List <TblSold_Item>();
                List <TblStok_History> tblStok_History = new List <TblStok_History>();

                foreach (FileHelperModel fileHlp in enggine)
                {
                    if (fileHlp.ID_BRG.StartsWith("#TABLE:"))
                    {
                        if (tableName == "")
                        {
                            tableName = fileHlp.ID_BRG.Replace("#TABLE:", "");
                        }
                        else
                        {
                            if (tableName == "INVENTORY")
                            {
                                App.arPosRepo.InsertInvAllSync(tblInventory);
                            }
                            if (tableName == "DISCNT_ITEM")
                            {
                                App.arPosRepo.InsertInvAllSync(tblDISCNT_ITEM);
                            }
                            if (tableName == "BILL")
                            {
                                App.arPosRepo.InsertInvAllSync(tblBill);
                            }
                            if (tableName == "SOLD_ITEM")
                            {
                                App.arPosRepo.InsertInvAllSync(tblSold_Item);
                            }
                            if (tableName == "STOK_HISTORY")
                            {
                                App.arPosRepo.InsertInvAllSync(tblStok_History);
                            }
                            tableName = fileHlp.ID_BRG.Replace("#TABLE:", "");
                        }
                    }
                    else
                    {
                        if (tableName == "INVENTORY")
                        {
                            TblInventory barTblInventory = new TblInventory();
                            barTblInventory.ID_BRG   = fileHlp.ID_BRG;
                            barTblInventory.NM_BRG   = fileHlp.NM_BRG;
                            barTblInventory.STOK_MIN = fileHlp.STOK_MIN;
                            if (fileHlp.EXP_TGL.ToString() != "")
                            {
                                barTblInventory.EXP_TGL = DateTime.Parse(fileHlp.EXP_TGL.ToString());
                            }

                            barTblInventory.SATUAN = fileHlp.SATUAN;
                            if (fileHlp.SATUAN_JUAL.ToString() != "")
                            {
                                barTblInventory.SATUAN_JUAL = int.Parse(fileHlp.SATUAN_JUAL.ToString());
                            }
                            if (fileHlp.HRG_MODAL.ToString() != "")
                            {
                                barTblInventory.HRG_MODAL = int.Parse(fileHlp.HRG_MODAL.ToString());
                            }
                            if (fileHlp.HRG_JUAL.ToString() != "")
                            {
                                barTblInventory.HRG_JUAL = int.Parse(fileHlp.HRG_JUAL.ToString());
                            }
                            if (fileHlp.STOK.ToString() != "")
                            {
                                barTblInventory.STOK = int.Parse(fileHlp.STOK.ToString());
                            }

                            barTblInventory.OWNER = fileHlp.OWNER;
                            if (fileHlp.LAST_TRN.ToString() != "")
                            {
                                barTblInventory.LAST_TRN = DateTime.Parse(fileHlp.LAST_TRN.ToString());
                            }


                            tblInventory.Add(barTblInventory);
                        }
                        else if (tableName == "DISCNT_ITEM")
                        {
                            TblDISCNT_ITEM barTblDIS = new TblDISCNT_ITEM();
                            barTblDIS.ID_BRG     = fileHlp.ID_BRG;
                            barTblDIS.KETERANGAN = fileHlp.NM_BRG;
                            barTblDIS.QTY        = fileHlp.STOK_MIN;

                            if (fileHlp.HRG_MODAL.ToString() != "")
                            {
                                barTblDIS.HRG_DIS_SATUAN = int.Parse(fileHlp.HRG_MODAL.ToString());
                            }

                            tblDISCNT_ITEM.Add(barTblDIS);
                        }
                        else if (tableName == "BILL")
                        {
                            TblBill barTblBil = new TblBill();
                            barTblBil.BIL_NO      = Convert.ToInt32(fileHlp.ID_BRG);
                            barTblBil.NM_PEL      = fileHlp.NM_BRG;
                            barTblBil.UANG_TERIMA = fileHlp.STOK_MIN;
                            if (fileHlp.EXP_TGL.ToString() != "")
                            {
                                barTblBil.BIL_TGL = DateTime.Parse(fileHlp.EXP_TGL.ToString());
                            }

                            barTblBil.JENIS_BAYAR = fileHlp.SATUAN;
                            if (fileHlp.SATUAN_JUAL.ToString() != "")
                            {
                                barTblBil.SPCL_DISC = int.Parse(fileHlp.SATUAN_JUAL.ToString());
                            }
                            if (fileHlp.HRG_MODAL.ToString() != "")
                            {
                                barTblBil.UANG_KEMBALI = int.Parse(fileHlp.HRG_MODAL.ToString());
                            }
                            if (fileHlp.HRG_JUAL.ToString() != "")
                            {
                                barTblBil.BAYAR_LAIN = int.Parse(fileHlp.HRG_JUAL.ToString());
                            }
                            barTblBil.OPRBY = fileHlp.OWNER;
                            if (fileHlp.LAST_TRN.ToString() != "")
                            {
                                barTblBil.KAS_TGL = DateTime.Parse(fileHlp.LAST_TRN.ToString());
                            }

                            tblBill.Add(barTblBil);
                        }
                        else if (tableName == "SOLD_ITEM")
                        {
                            TblSold_Item barTblSold = new TblSold_Item();
                            barTblSold.BIL_NO = Convert.ToInt32(fileHlp.ID_BRG);
                            barTblSold.ID_BRG = fileHlp.NM_BRG;
                            barTblSold.QTY    = fileHlp.STOK_MIN;

                            barTblSold.NM_BRG = fileHlp.SATUAN;
                            if (fileHlp.SATUAN_JUAL.ToString() != "")
                            {
                                barTblSold.HRG_SATUAN = int.Parse(fileHlp.SATUAN_JUAL.ToString());
                            }
                            if (fileHlp.HRG_MODAL.ToString() != "")
                            {
                                barTblSold.HRG_TOTAL = int.Parse(fileHlp.HRG_MODAL.ToString());
                            }
                            if (fileHlp.HRG_JUAL.ToString() != "")
                            {
                                barTblSold.DISCOUNT = int.Parse(fileHlp.HRG_JUAL.ToString());
                            }
                            if (fileHlp.STOK.ToString() != "")
                            {
                                barTblSold.HRG_MODAL = int.Parse(fileHlp.STOK.ToString());
                            }
                            barTblSold.UNIT     = fileHlp.OWNER;
                            barTblSold.DISC_KET = fileHlp.DISC_KET;
                            if (fileHlp.PROFIT.ToString() != "")
                            {
                                barTblSold.PROFIT = int.Parse(fileHlp.PROFIT.ToString());
                            }
                            if (fileHlp.PEMBULATAN.ToString() != "")
                            {
                                barTblSold.PEMBULATAN = int.Parse(fileHlp.PEMBULATAN.ToString());
                            }

                            tblSold_Item.Add(barTblSold);
                        }
                        else if (tableName == "STOK_HISTORY")
                        {
                            TblStok_History barTblSHis = new TblStok_History();
                            barTblSHis.ID_BRG    = fileHlp.ID_BRG;
                            barTblSHis.KET       = fileHlp.NM_BRG;
                            barTblSHis.STOK_AWAL = fileHlp.STOK_MIN;
                            if (fileHlp.EXP_TGL.ToString() != "")
                            {
                                barTblSHis.TGL = DateTime.Parse(fileHlp.EXP_TGL.ToString());
                            }
                            if (fileHlp.SATUAN_JUAL.ToString() != "")
                            {
                                barTblSHis.STOK_ADD = int.Parse(fileHlp.SATUAN_JUAL.ToString());
                            }
                            if (fileHlp.HRG_MODAL.ToString() != "")
                            {
                                barTblSHis.STOK_AKHIR = int.Parse(fileHlp.HRG_MODAL.ToString());
                            }
                            barTblSHis.OPRBY = fileHlp.OWNER;

                            tblStok_History.Add(barTblSHis);
                        }
                    }
                }

                //Insert untuk jika habis
                if (tableName == "INVENTORY")
                {
                    App.arPosRepo.InsertInvAllSync(tblInventory);
                }
                if (tableName == "DISCNT_ITEM")
                {
                    App.arPosRepo.InsertInvAllSync(tblDISCNT_ITEM);
                }
                if (tableName == "BILL")
                {
                    App.arPosRepo.InsertInvAllSync(tblBill);
                }
                if (tableName == "SOLD_ITEM")
                {
                    App.arPosRepo.InsertInvAllSync(tblSold_Item);
                }
                if (tableName == "STOK_HISTORY")
                {
                    App.arPosRepo.InsertInvAllSync(tblStok_History);
                }
            }
        }
 public void Setup()
 {
     engine = new FileHelperAsyncEngine(typeof(SampleType));
 }
예제 #50
0
        public void NullString2()
        {
            var engine2 = new FileHelperAsyncEngine <SampleType>();

            engine2.BeginReadString(null);
        }
예제 #51
0
        private void OnPostWatchlist()
        {
            string userId = ClaimChecker.UserId(User.Identity);

            int existingCount = 0;
            int newCount      = 0;

            LastImportErrors.Clear();

            string connectionString = configuration.GetConnectionString("FxMoviesDb");

            using (var db = FxMoviesDbContextFactory.Create(connectionString))
                foreach (var file in Request.Form.Files)
                {
                    try
                    {
                        var engine = new FileHelperAsyncEngine <ImdbUserWatchlistRecord>();

                        var movieIdsInFile = new SortedSet <string>();

                        using (var reader = new StreamReader(file.OpenReadStream()))
                            using (engine.BeginReadStream(reader))
                                foreach (var record in engine)
                                {
                                    try
                                    {
                                        string _const = record.Const;
                                        movieIdsInFile.Add(_const);

                                        DateTime date = DateTime.ParseExact(record.Created,
                                                                            new string[] { "yyyy-MM-dd", "ddd MMM d HH:mm:ss yyyy", "ddd MMM dd HH:mm:ss yyyy" },
                                                                            CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);

                                        // Watchlist
                                        // Position,Const,Created,Modified,Description,Title,URL,Title Type,IMDb Rating,Runtime (mins),Year,Genres,Num Votes,Release Date,Directors
                                        var userWatchList = db.UserWatchLists.Find(userId, _const);
                                        if (userWatchList == null)
                                        {
                                            userWatchList             = new UserWatchListItem();
                                            userWatchList.UserId      = userId;
                                            userWatchList.ImdbMovieId = _const;
                                            db.UserWatchLists.Add(userWatchList);
                                            newCount++;
                                        }
                                        else
                                        {
                                            existingCount++;
                                        }
                                        userWatchList.AddedDate = date;
                                    }
                                    catch (Exception x)
                                    {
                                        LastImportErrors.Add(
                                            Tuple.Create(
                                                $"Lijn {engine.LineNumber - 1} uit het watchlist bestand '{file.FileName}' kon niet verwerkt worden. "
                                                + "De meest voorkomende reden is een aanpassing aan het bestandsformaat door IMDb.",
                                                x.ToString(),
                                                "danger"));
                                    }
                                }

                        List <UserWatchListItem> itemsToRemove =
                            db.UserWatchLists
                            .Where(ur => ur.UserId == userId && !movieIdsInFile.Contains(ur.ImdbMovieId))
                            .ToList();

                        db.UserWatchLists.RemoveRange(itemsToRemove);

                        LastImportErrors.Add(
                            Tuple.Create(
                                $"Het watchlist bestand '{file.FileName}' werd ingelezen. "
                                + $"{newCount} nieuwe en {existingCount} bestaande films.  {itemsToRemove.Count} films verwijderd.",
                                (string)null,
                                "success"));
                    }
                    catch (Exception x)
                    {
                        LastImportErrors.Add(
                            Tuple.Create(
                                $"Het watchlist bestand '{file.FileName}' kon niet ingelezen worden.\n"
                                + "De meest voorkomende reden is het omwisselen van Ratings en Watchlist bestanden, of een aanpassing aan "
                                + "het bestandsformaat door IMDb.",
                                x.ToString(),
                                "danger"));
                    }

                    db.SaveChanges();
                }
        }
예제 #52
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileEngine"/> class.
 /// </summary>
 /// <param name="engine">The engine.</param>
 public FileEngine(FileHelperAsyncEngine engine)
 {
     this.engine = engine;
 }
예제 #53
0
        public static void Parse <T1, T2>(
            BackgroundWorker worker,
            string[] filePaths,
            string name,
            FilterRowAndGetProductName <T1, T2> FilterRowAndGetProductName,
            FilterRows <T1, T2> FilterRows,
            out string productName,
            out List <T2> records)
            where T1 : class
        {
            productName = null;
            records     = new List <T2>();

            worker.ReportProgress(0);

            for (int i = 0; i < filePaths.Length; i++)
            {
                if (worker.CancellationPending)
                {
                    productName = null;
                    records     = null;
                    return;
                }

                try
                {
                    using (TextReader textReader = new StreamReader(filePaths[i]))
                    {
                        var engine = new FileHelperAsyncEngine <T1>();

                        using (engine.BeginReadStream(textReader))
                        {
                            // Parse the first row from input CSV file
                            T1 csvRow = engine.ReadNext();

                            if (csvRow == null)
                            {
                                // There is no data rows in this CSV file -- just skip it
                                continue;
                            }

                            // Remove extra columns and get the product name
                            string thisProductName;
                            T2     filteredRow = FilterRowAndGetProductName(csvRow, out thisProductName);

                            // Check the product name consistency
                            if (productName != null && thisProductName != productName)
                            {
                                string msg = string.Format(
                                    "The selected {0} CSV File(s) do not conform to each other by \"ProductName\" column.",
                                    name);

                                MessageBox.Show(
                                    msg,
                                    formText,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                                productName = null;
                                records     = null;
                                return;
                            }

                            // Save the first row data
                            productName = thisProductName;
                            records.Add(filteredRow);

                            // Parse all other rows from the CSV file lazily
                            IEnumerable <T1> csvRows = engine.AsEnumerable <T1>();

                            // Remove extra columns lazily
                            IEnumerable <T2> filteredRows = FilterRows(csvRows);

                            // Add new rows to the common list
                            records.AddRange(filteredRows);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        ex.Message,
                        formText,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    productName = null;
                    records     = null;
                    return;
                }

                worker.ReportProgress(i + 1);
            }
        }
예제 #54
0
 public void Setup()
 {
     engine      = new FileHelperEngine(typeof(CustomersQuotedType));
     engineAsync = new FileHelperAsyncEngine(typeof(CustomersQuotedType));
 }
예제 #55
0
 public void NullString2()
 {
     engine2 = new FileHelperAsyncEngine(typeof(SampleType));
     engine2.BeginReadString(null);
 }
예제 #56
0
 public void NullWriter2()
 {
     engine2 = new FileHelperAsyncEngine(typeof(SampleType));
     engine2.BeginWriteStream(null);
 }
예제 #57
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FluentFile"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 public FluentFile(Type type)
 {
     engine = new FileHelperAsyncEngine(type);
 }
예제 #58
0
 public void FileNotFound3()
 {
     engine2 = new FileHelperAsyncEngine(typeof(SampleType));
     engine2.BeginAppendToFile(null);
 }
예제 #59
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            DirectoryInfo pickupDir = new DirectoryInfo(DSConfig.PickupDir);

            //read csv and place it in memory

            foreach (var file in pickupDir.GetFiles())
            {
                if (file.Extension.Equals(".pdf"))
                {
                    Log.Info("Attempt to Convert the following PDF :: " + file.Name);
                    convertPDFDoc(file.DirectoryName, file.Name, file.Extension);
                    Log.Info("The following PDF was Converted Successfully:: " + file.Name);
                }
                else if (file.Extension.Equals(".docx"))
                {
                    //     c.convertWordDoc1("","");
                }
                else
                {
                    //do nothing
                }
            }
            try
            {
                var           apiClient = new ApiClient();
                DocuSignProps props     = new DocuSignProps(apiClient);

                //read
                var Readengine = new FileHelperAsyncEngine <Record>(); //read document goes line by line

                Readengine.BeginReadFile(DSConfig.DsTags);

                using (Readengine)
                {
                    foreach (Record r in Readengine)
                    {
                        string anchor = r.DocusignTag;

                        anchor = anchor.Substring(1, anchor.Length - 3);

                        switch (anchor)
                        {
                        case "s":
                            props.CreateCustomTabsFromCSV("SignHere", "SDKSigner", "SDKSignerToolTip", "/s{r}/");
                            Log.Info("Document Property of Type - SignHere - Was Created.");
                            break;

                        case "i":
                            props.CreateCustomTabsFromCSV("InitialHere", "SDKInitial", "SDKInitalToolTip", "/i{r}/");
                            Log.Info("Document Property of Type - InitialHere - Was Created.");
                            break;

                        case "oi":
                            props.CreateCustomTabsFromCSV("InitialHereOptional", "SDKInitialOptional", "SDKInitialOptionalToolTip", "/oi{r}/");
                            Log.Info("Document Property of Type - InitialHereOptional - Was Created.");
                            break;

                        case "n":
                            props.CreateCustomTabsFromCSV("FullName", "SDKName", "SDKNameToolTip", "/n{r}/");
                            Log.Info("Document Property of Type - FullName - Was Created.");
                            break;

                        case "co":
                            props.CreateCustomTabsFromCSV("Company", "SDKCompany", "SDKCompanyip", "/co{r}/");
                            Log.Info("Document Property of Type - Company - Was Created.");
                            break;

                        case "t":
                            props.CreateCustomTabsFromCSV("Title", "SDKTime", "SDKSignerTimeTip", "/t{r}/");
                            Log.Info("Document Property of Type - Title - Was Created.");
                            break;

                        case "d":
                            props.CreateCustomTabsFromCSV("Date", "SDKDate", "SDKDateToolTip", "//d{r}//");
                            Log.Info("Document Property of Type - Date - Was Created.");
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (ApiException e)
            {
                Log.Error("\nDocuSign Exception!");

                // Special handling for consent_required
                String message = e.Message;
                if (!String.IsNullOrWhiteSpace(message) && message.Contains("consent_required"))
                {
                    String consent_url = String.Format("\n    {0}/oauth/auth?response_type=code&scope={1}&client_id={2}&redirect_uri={3}",
                                                       DSConfig.AuthenticationURL, DSConfig.PermissionScopes, DSConfig.ClientID, DSConfig.OAuthRedirectURI);

                    Log.Error("C O N S E N T   R E Q U I R E D");
                    Log.Error("Ask the user who will be impersonated to run the following url: ");
                    Log.Error(consent_url);
                }
                else
                {
                    Log.Error("Error Reponse: {0}", e.ErrorContent);
                }
            }

            catch (DirectoryNotFoundException dirEx)
            {
                Log.Error("Directory not found: " + dirEx.Message);
            }
            catch (IOException IOEx)
            {
                Log.Error("File not found or could not be Moved / Deleted: " + IOEx.Message);
            }
        }
예제 #60
0
 public void FileNotFound2()
 {
     engine2 = new FileHelperAsyncEngine(typeof(SampleType));
     engine2.BeginReadFile("No fouffffnd this file.txt");
 }