示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Startup...");
            int waitDuration = 10;
            int maxThreads = Convert.ToInt32(ConfigurationManager.AppSettings["MaxThreads"]); ;
            bool loopThru = true;
            bool isSingleTransaction = false;

            //Create job to update exchange rate (daily)

            if (args.Length == 0)
            {
                ISchedulerFactory schedFact = new StdSchedulerFactory();
                sched = schedFact.GetScheduler();
                sched.Start();
                CreateScheduledJob();
            }

            while (loopThru)
            {
                try
                {
                    Console.WriteLine("Waiting...");
                    Thread.Sleep(TimeSpan.FromSeconds(waitDuration));
                    int offeringId = 2;
                    Console.WriteLine("Initializing Iptv2Context service...");
                    using (var context = new IPTV2Entities())
                    {
                        var offering = context.Offerings.Find(offeringId);
                        Console.WriteLine("Initializing GomsTfcTv service...");
                        var service = new GomsTfcTv();
                        Console.WriteLine("Process start.");
                        // Update Forex
                        Console.WriteLine("Updating FOREX...");
                        service.GetExchangeRates(context, "USD");
                        Console.WriteLine("Finished FOREX...");


                        // Process Single transactionsint check;                        
                        if (args.Length > 0)
                        {
                            try
                            {
                                // Process Single transactions
                                service.ProcessSinglePendingTransactionInGoms(context, offering, Convert.ToInt32(args[0]));
                                isSingleTransaction = true;
                            }
                            catch (Exception)
                            {
                                loopThru = false;
                            }
                        }
                        else
                            DoProcessByIncrement(offeringId, maxThreads);
                    }
                    Console.WriteLine("Process finish.");
                    if (isSingleTransaction)
                        Environment.Exit(0);
                    //DoProcess(offeringId, maxThreads);
                    //DoProcessByIncrement(offeringId, maxThreads);
                    // Process Transactions
                    // service.ProcessAllPendingTransactionsInGoms(context, offering);
                    // Process Single transactions
                    // service.ProcessSinglePendingTransactionInGoms(context, offering, Convert.ToInt32(args[0]));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("error: " + ex.Message);
                    Trace.TraceError("fail in Run", ex);
                }
            }
        }