Пример #1
0
 public void Start()
 {
     _startup = ResourceStartupPhase.Starting;
     Parallel.ForEach(Graph.GetAll(), resourceWrapper =>
     {
         try
         {
             resourceWrapper.Start();
         }
         catch (Exception e)
         {
             resourceWrapper.ErrorOccured();
             Logger.LogException(LogLevel.Warning, e, "Failed to start resource {0}-{1}", resourceWrapper.Target.Id, resourceWrapper.Target.Name);
         }
     });
     _startup = ResourceStartupPhase.Started;
 }
Пример #2
0
        public void Stop()
        {
            _startup = ResourceStartupPhase.Stopping;

            Parallel.ForEach(Graph.GetAll(), resourceWrapper =>
            {
                try
                {
                    resourceWrapper.Stop();
                    UnregisterEvents(resourceWrapper.Target);
                }
                catch (Exception e)
                {
                    Logger.LogException(LogLevel.Warning, e, "Failed to stop resource {0}-{1}", resourceWrapper.Target.Id, resourceWrapper.Target.Name);
                }
            });

            _startup = ResourceStartupPhase.Stopped;
        }
Пример #3
0
        public void Initialize()
        {
            // Set delegates on graph
            Graph.SaveDelegate    = Save;
            Graph.DestroyDelegate = Destroy;

            _startup = ResourceStartupPhase.LoadResources;
            using (var uow = UowFactory.Create(ContextMode.AllOff))
            {
                // Create all objects
                var allResources = ResourceEntityAccessor.FetchResourceTemplates(uow);
                if (allResources.Count > 0)
                {
                    LoadResources(allResources);
                }
                else
                {
                    Logger.Log(LogLevel.Warning, "The ResourceManager initialized without a resource." +
                               "Execute a resource initializer to add resources with \"exec ResourceManager initialize\"");
                }
            }

            _startup = ResourceStartupPhase.Initializing;
            // Boot resources
            Parallel.ForEach(Graph.GetAll(), resourceWrapper =>
            {
                try
                {
                    resourceWrapper.Initialize();
                }
                catch (Exception e)
                {
                    resourceWrapper.ErrorOccured();
                    Logger.LogException(LogLevel.Warning, e, "Failed to initialize resource {0}-{1}", resourceWrapper.Target.Id, resourceWrapper.Target.Name);
                }
            });
            _startup = ResourceStartupPhase.Initialized;
        }