Пример #1
0
 public void ApplyTransactionForLambda(Action action)
 {
     FinallyGuarded.Apply(() =>
     {
         OpenSession();
         var session = _sessionFactory.GetCurrentSession();
         using (var transaction = session.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
         {
             action();
             transaction.Commit();
         }
     }, CloseSession);
 }
Пример #2
0
        public TResult ApplyTransactionForLambda <TResult>(Func <TResult> function) where TResult : new()
        {
            var result = new TResult();

            FinallyGuarded.Apply(() =>
            {
                OpenSession();
                var session = _sessionFactory.GetCurrentSession();

                using (var transaction = session.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
                {
                    result = function();
                    transaction.Commit();
                }
            }, CloseSession);
            return(result);
        }
Пример #3
0
        private void CheckHandlers()
        {
            if (HandlerTuples != null)
            {
                return;
            }

            HandlerTuples = new List <Tuple <Type, MethodInfo, Type> >();

            var eventTypes = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name.Contains("Lacjam"))
                             .SelectMany(assembly => assembly.GetExportedTypes())
                             .Where(type => !type.IsInterface)
                             .Where(x => typeof(IEvent).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
            ;

            foreach (var et in eventTypes)
            {
                var handlerTypes = typeof(IEventHandler <>).MakeGenericType(et);

                if (Handlers == null)
                {
                    Handlers = new ArrayList();
                }
                var arr = _container.ResolveAll(handlerTypes);
                foreach (var ar in arr)
                {
                    FinallyGuarded.Apply(() => Handlers.Add(ar),
                                         () => _logger.Warn(EventIds.Warn, "INVALID eventhandler - " + ar));
                }

                foreach (var handler in Handlers)
                {
                    var mis = handler.GetType().GetMethods(
                        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                              .Where(x => x.Name == "Handle" && x.GetParameters().Length > 0);

                    foreach (var mi in mis)
                    {
                        var eventType = mi.GetParameters()[0].ParameterType;
                        HandlerTuples.Add(new Tuple <Type, MethodInfo, Type>(handler.GetType(), mi, eventType));
                    }
                }
            }
        }
Пример #4
0
        public void HandleSequencedEvent(SequencedEvent sequencedEvent, bool?runImmediately = true)
        {
            if (!sequencedEvent.HasEvent())
            {
                return;
            }

            IDispatcherEventPublisher publisher = null;

            _transactor.ApplyTransactionForLambda(() =>
                                                  FinallyGuarded.Apply(() =>
            {
                publisher = DispatcherEventPublisher(sequencedEvent, runImmediately);
                AuditLogStatus(sequencedEvent);
            },
                                                                       () =>
            {
                if (publisher != null)
                {
                    _container.Release(publisher);
                }
            }));
        }
Пример #5
0
        /// <summary>
        /// Debug args --
        /// /d /b /u /c "Data Source=(local)\SQL2012;Database=Lacjam; Integrated Security=SSPI;"
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ShowHeader();

            var cleaned = new List <string>();

            if (args.Length == 0)
            {
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("No args passed to setup");
                Console.WriteLine("");
                Console.WriteLine("");
                ShowHelp();
                return;
            }

            // build script coming in from powershell was keeping the ,,,,,,,   so having to strip them
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Args received");
            Console.WriteLine("");


            foreach (string s in args)
            {
                Console.WriteLine(s);
                cleaned.Add(s.Replace(",", ""));
            }
            Console.WriteLine("");
            Console.WriteLine("");

            CommandArgs command = Configuration.Configure <CommandArgs>().CreateAndBind(cleaned);

            if (command == null)
            {
                Console.WriteLine("Error with args");
                Environment.Exit(1);
            }
            var database = string.IsNullOrEmpty(command.Connectionstring)
                ? new ApplicationDatabase()
                : new ApplicationDatabase().WithConnectionString(command.Connectionstring);

            if (command.Help)
            {
                ShowHelp();
                Pause();
            }

            if (command.DeleteTables)
            {
                FinallyGuarded.Apply(
                    () => DatabaseRunner.DeleteAllTables(database.ConnectionString),
                    ShowError,
                    Completed
                    );
            }

            if (command.BuildDatabase)
            {
                FinallyGuarded.Apply(
                    () => DatabaseRunner.CreateDatabase(database.ConnectionString),
                    ShowError,
                    Completed
                    );
            }

            if (command.UpdateDatabase)
            {
                FinallyGuarded.Apply(
                    () => DatabaseRunner.MigrateToLatest(database.ConnectionString),
                    ShowError,
                    Completed
                    );
            }

            #if DEBUG
            Pause();
            #endif
        }