Exemplo n.º 1
0
        private void App_DispatcherUnhandledException(object sender,
                                                      System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            Log.Error("An unhandled exception occurred. Showing view to user...", e.Exception);

            var exceptionView = new ExceptionView(e.Exception)
            {
                Owner = Application.Current != null ? Application.Current.MainWindow : null,
                WindowStartupLocation = Application.Current != null ? WindowStartupLocation.CenterOwner : WindowStartupLocation.CenterScreen,
            };

            exceptionView.ShowDialog();

            e.Handled = true;
        }
Exemplo n.º 2
0
        public Task InitializeAsync()
        {
            try
            {
                _logger.InfoFormat("Initializing Async");
                Container.RegisterInstance <Bootstrapper>(this);

                var sc = new SchedulerContext(
                    new SharedScheduler(TaskScheduler.FromCurrentSynchronizationContext(), DispatcherSchedulerEx.Current),
                    new SharedScheduler(TaskScheduler.Default, Scheduler.Default));
                Container.RegisterInstance <ISchedulerContext>(sc);
                ObservableObjectBase.DispatcherSynchronizationContext = SynchronizationContext.Current;
            }
            catch (Exception e)
            {
                _logger.Error("An error occurred in the initialization block: ", e);
                throw;
            }

            return(Task.Factory.StartNew(() =>
            {
                try
                {
                    _logger.InfoFormat("... 1of4 base.Initialize()");
                    base.Initialize();

                    // Do init async
                    // Bootstrap example definitions
                    _logger.InfoFormat("... 2of4 IModule.Initializer()");
                    Container.Resolve <IModule>().Initialize();

                    _logger.InfoFormat("... 3of4 Resolve IMainWindowViewModel");
                    var vm = ServiceLocator.Container.Resolve <IMainWindowViewModel>();

                    // Bootstrap D3D to save time on startup
                    _logger.InfoFormat("... 4of4 D3D11.Initialize()");
                    SciChart.Drawing.DirectX.Context.D3D11.Direct3D11RenderSurface.InitEngineAsync().Then(r =>
                    {
                        vm.InitReady = true;
                    });
                }
                catch (Exception e)
                {
                    _logger.Error("One or more errors occurred during initialization of the MainViewModel or DirectX11 engine", e);
                    throw;
                }
            }));
        }
Exemplo n.º 3
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (e.Args.Contains(_devMode))
            {
                DeveloperModManager.Manage.IsDeveloperMode = true;
            }

            try
            {
                Thread.CurrentThread.Name = "UI Thread";

                Log.Debug("--------------------------------------------------------------");
                Log.DebugFormat("SciChart.Examples.Demo: Session Started {0}",
                                DateTime.Now.ToString("dd MMM yyyy HH:mm:ss"));
                Log.Debug("--------------------------------------------------------------");

                var assembliesToSearch = new[]
                {
                    typeof(MainWindowViewModel).Assembly,
                };

                _bootStrapper = new Bootstrapper(ServiceLocator.Container, new AttributedTypeDiscoveryService(new ExplicitAssemblyDiscovery(assembliesToSearch)));
                _bootStrapper.InitializeAsync().Then(() =>
                {
                    //Syncing usages
                    var syncHelper = ServiceLocator.Container.Resolve <ISyncUsageHelper>();
                    syncHelper.LoadFromIsolatedStorage();

                    //Try sync with service
                    syncHelper.GetRatingsFromServer();
                    syncHelper.SendUsagesToServer();
                    syncHelper.SetUsageOnExamples();

                    _bootStrapper.OnInitComplete();
                }).Catch(ex =>
                {
                    Log.Error("Exception:\n\n{0}", ex);
                    MessageBox.Show("Exception occurred in SciChart.Examples.Demo Startup");
                });
            }
            catch (Exception caught)
            {
                Log.Error("Exception:\n\n{0}", caught);
                MessageBox.Show("Exception occurred in SciChart.Examples.Demo Startup");
            }
        }
Exemplo n.º 4
0
        public virtual void Initialize(DataMode dataMode = DataMode.Any)
        {
            try
            {
                var exportTypes = _attributedTypeDiscovery.DiscoverAttributedTypes <ExportTypeAttribute>();

                foreach (var tTo in exportTypes)
                {
                    foreach (var exportAttribute in tTo.GetCustomAttributes(true).OfType <ExportTypeAttribute>())
                    {
                        if (dataMode == DataMode.Any || exportAttribute.DataMode == DataMode.Any || exportAttribute.DataMode == dataMode)
                        {
                            if (exportAttribute.CreateAs == CreateAs.Singleton)
                            {
                                Log.DebugFormat("Registering Singleton: {0} as {1}", tTo.Name, exportAttribute.TFrom.Name);
                                _container.RegisterType(exportAttribute.TFrom, tTo, new ContainerControlledLifetimeManager());
                            }
                            else
                            {
                                Log.DebugFormat("Registering: {0} as {1}", tTo.Name, exportAttribute.TFrom.Name);
                                _container.RegisterType(exportAttribute.TFrom, tTo);
                            }
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                foreach (var lex in ex.LoaderExceptions)
                {
                    Log.Error(lex);
                }
                Log.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
        private void LogException(string message)
        {
            var exception = RouteData.Values["exception"] as Exception;

            if (exception != null)
            {
                _log.Error(new HttpExceptionWrapper(HttpContext, exception), message);
            }
            if (HttpContext.IsDebuggingEnabled)
            {
                _exception = exception;
            }
        }
Exemplo n.º 6
0
        public IEnumerable <Assembly> GetAssemblies()
        {
            if (_assemblies == null)
            {
                _assemblies = new List <Assembly>();
                var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                // Search the directory for assemblies. Exclude those in the exclude list
                var assemblyDlls = Directory.GetFiles(assemblyPath, "*.dll")
                                   .Where(asm => !_excludeList.Any(exl => asm.Contains(exl)));

                var exes = Directory.GetFiles(assemblyPath, "*.exe")
                           .Where(asm => !_excludeList.Any(exl => asm.Contains(exl)));

                var assemblyFiles = assemblyDlls.Concat(exes).ToArray();

                foreach (var assemblyFile in assemblyFiles)
                {
                    try
                    {
                        Log.InfoFormat(" ... Loading assembly {0}", assemblyFile);
                        var assembly = Assembly.Load(Path.GetFileNameWithoutExtension(assemblyFile));

                        if (!_assemblies.Contains(assembly))
                        {
                            _assemblies.Add(assembly);
                        }
                    }
                    catch (Exception caught)
                    {
                        Log.Error(caught);
                    }
                }
            }

            return(_assemblies);
        }
Exemplo n.º 7
0
        public virtual void Initialize(DataMode dataMode = DataMode.Any)
        {
            try
            {
                var exportTypes = _attributedTypeDiscovery.DiscoverAttributedTypes <ExportTypeAttribute>();

                foreach (var tTo in exportTypes)
                {
                    var  exportAttributes = tTo.GetCustomAttributes(true).OfType <ExportTypeAttribute>();
                    bool preRegistered    = false;
                    if (exportAttributes.Count() > 1 && exportAttributes.All(e => e.CreateAs == CreateAs.Singleton))
                    {
                        Log.DebugFormat("Registering Singleton: {0} in preparation for multiple mapping", tTo.Name);
                        _container.RegisterType(tTo, new ContainerControlledLifetimeManager());
                        preRegistered = true;
                    }
                    foreach (var exportAttribute in exportAttributes)
                    {
                        if (dataMode == DataMode.Any || exportAttribute.DataMode == DataMode.Any || exportAttribute.DataMode == dataMode)
                        {
                            if (exportAttribute.CreateAs == CreateAs.Singleton && !preRegistered)
                            {
                                if (string.IsNullOrEmpty(exportAttribute.Name))
                                {
                                    Log.DebugFormat("Registering Singleton: {0} as {1}", tTo.Name, exportAttribute.TFrom.Name);
                                    _container.RegisterType(exportAttribute.TFrom, tTo, new ContainerControlledLifetimeManager());
                                }
                                else
                                {
                                    Log.DebugFormat("Registering Singleton: {0} as {1} with name {2}", tTo.Name, exportAttribute.TFrom.Name, exportAttribute.Name);
                                    _container.RegisterType(exportAttribute.TFrom, tTo, exportAttribute.Name, new ContainerControlledLifetimeManager());
                                }
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(exportAttribute.Name))
                                {
                                    Log.DebugFormat("Registering: {0} as {1}", tTo.Name, exportAttribute.TFrom.Name);
                                    _container.RegisterType(exportAttribute.TFrom, tTo);
                                }
                                else
                                {
                                    Log.DebugFormat("Registering: {0} as {1} with name {2}", tTo.Name, exportAttribute.TFrom.Name, exportAttribute.Name);
                                    _container.RegisterType(exportAttribute.TFrom, tTo, exportAttribute.Name);
                                }
                            }
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                foreach (var lex in ex.LoaderExceptions)
                {
                    Log.Error(lex);
                }
                Log.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }