Beispiel #1
0
 public Settings(LogDispatcher.LogDispatcher log)
 {
     _log = log;
     InitializeComponent();
     comboBackendSelector.SelectedIndex = Properties.Settings.Default.DBType;
     panelCleanupBackup.Enabled = (Properties.Settings.Default.CleanupBackup && (Properties.Settings.Default.DBType == 0));
 }
 public static Character GetCharacter(this Metadata md, string pathToAccDir,LogDispatcher.LogDispatcher log)
 {
     var acc = AccountRetriever.GetAccount(Path.Combine(pathToAccDir, md.CharPath + ".fl"),log);
     //TODO: fix against FOS
     if (acc == null) return null;
     acc.IsBanned = File.Exists(Path.Combine(pathToAccDir, md.CharPath + "banned"));
     return acc;
 }
        public MainWindow()
        {
            var logDispatcher = new LogDispatcher(this.Dispatcher,
                                                  delegate(LoggerItem item)
            {
                ShowMessage(item.Message, item.Level);
            });

            LoggerFactory.Writer = logDispatcher;

            InitializeComponent();

            loggerGrid.ItemsSource = logDispatcher.Items;

            Logger = LoggerFactory.CreateLogger("MainWindow");

            Logger.Print("The application has started.");

            SampleData.Instance.Targets.CurrentChanged += Targets_CurrentChanged;

            //PresentationTraceSources.SetTraceLevel(targetsView.ItemContainerGenerator, PresentationTraceLevel.High);
        }
            public void OnAddComponent(AddComponentOp <global::Improbable.Gdk.Tests.NestedComponent> op)
            {
                Unity.Entities.Entity entity;
                if (!view.TryGetEntity(op.EntityId.Id, out entity))
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent("Entity not found during OnAddComponent.")
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField(MutableView.Component, "SpatialOSNestedComponent"));
                    return;
                }
                var data = op.Data.Get().Value;

                var spatialOSNestedComponent = new SpatialOSNestedComponent();

                spatialOSNestedComponent.NestedType = global::Generated.Improbable.Gdk.Tests.TypeName.ToNative(data.nestedType);
                spatialOSNestedComponent.DirtyBit   = false;

                view.AddComponent(entity, spatialOSNestedComponent);
                view.AddComponent(entity, new NotAuthoritative <SpatialOSNestedComponent>());

                if (view.HasComponent <ComponentRemoved <SpatialOSNestedComponent> >(entity))
                {
                    view.RemoveComponent <ComponentRemoved <SpatialOSNestedComponent> >(entity);
                }
                else if (!view.HasComponent <ComponentAdded <SpatialOSNestedComponent> >(entity))
                {
                    view.AddComponent(entity, new ComponentAdded <SpatialOSNestedComponent>());
                }
                else
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(
                                                "Received ComponentAdded but have already received one for this entity.")
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField(MutableView.Component, "SpatialOSNestedComponent"));
                }
            }
Beispiel #5
0
 public void Connect()
 {
     try
     {
         switcher?.Connect();
     }
     catch (Switcher.CouldNotConnectException ex)
     {
         string errorMessage = string.Format("Couldn't connect to a BlackMagic Design mixer/switcher (ID: {0}) with IP {1}. Exception message: [{2}]",
                                             ID,
                                             IpAddress,
                                             ex.Message);
         LogDispatcher.E(LOG_TAG, errorMessage);
     }
     catch (Switcher.AlreadyConnectedException ex)
     {
         string errorMessage = string.Format("Tried to connect to a BlackMagic Design mixer/switcher (ID: {0}) with IP {1}, but was already connected. Exception message: [{2}]",
                                             ID,
                                             IpAddress,
                                             ex.Message);
         LogDispatcher.W(LOG_TAG, errorMessage);
     }
 }
Beispiel #6
0
 private void doHttpRequest()
 {
     try
     {
         string         url     = string.Format(API_URL, videoId, ApiKeySetting.Value);
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
         request.ContentType = "application/json; charset=utf-8";
         HttpWebResponse response = request.GetResponse() as HttpWebResponse;
         using (System.IO.Stream responseStream = response.GetResponseStream())
         {
             StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
             processResponse(reader.ReadToEnd());
         }
     }
     catch (Exception ex)
     {
         State = StreamState.Unknown;
         string logMessage = string.Format("Error occurred while trying to get state of a stream (ID: {0}) using YouTube API. Exception message: [{1}]",
                                           videoId,
                                           ex.Message);
         LogDispatcher.E(LOG_TAG, logMessage);
     }
 }
            public override void OnRemoveComponent(RemoveComponentOp op)
            {
                var entity = TryGetEntityFromEntityId(op.EntityId);

                entityManager.RemoveComponent <Improbable.Gdk.Tests.ComponentsWithNoFields.ComponentWithNoFieldsWithEvents.Component>(entity);

                if (entityManager.HasComponent <ComponentAdded <Improbable.Gdk.Tests.ComponentsWithNoFields.ComponentWithNoFieldsWithEvents.Component> >(entity))
                {
                    entityManager.RemoveComponent <ComponentAdded <Improbable.Gdk.Tests.ComponentsWithNoFields.ComponentWithNoFieldsWithEvents.Component> >(entity);
                }
                else if (!entityManager.HasComponent <ComponentRemoved <Improbable.Gdk.Tests.ComponentsWithNoFields.ComponentWithNoFieldsWithEvents.Component> >(entity))
                {
                    entityManager.AddComponent(entity, ComponentType.Create <ComponentRemoved <Improbable.Gdk.Tests.ComponentsWithNoFields.ComponentWithNoFieldsWithEvents.Component> >());
                }
                else
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(ReceivedDuplicateComponentRemoved)
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField("Component", "Improbable.Gdk.Tests.ComponentsWithNoFields.ComponentWithNoFieldsWithEvents")
                                            );
                }
            }
Beispiel #8
0
        GetImpl(
            object caller,
            string callerTypeName,
            string callerMemberName,
            LogType logType,
            LogCategory logCategory,
            int callerLineNumber,
            string callerFilePath
            )
        {
            if (LogDispatcher == null)
            {
                return(null, LogImpl);
            }

            return(LogDispatcher
                   .GetDispatcher(
                       caller,
                       callerTypeName,
                       callerMemberName,
                       logType,
                       logCategory
                       ), LogImpl);
        }
            public void OnComponentUpdate(ComponentUpdateOp <global::Improbable.Gdk.Tests.ExhaustiveOptional> op)
            {
                Unity.Entities.Entity entity;
                if (!view.TryGetEntity(op.EntityId.Id, out entity))
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent("Entity not found during OnComponentUpdate.")
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField(MutableView.Component, "SpatialOSExhaustiveOptional"));
                    return;
                }

                var componentData = view.GetComponentObject <SpatialOSExhaustiveOptional>(entity);
                var update        = op.Update.Get();

                if (view.HasComponent <NotAuthoritative <SpatialOSExhaustiveOptional> >(entity))
                {
                    if (update.field2.HasValue)
                    {
                        componentData.Field2 = update.field2.Value.HasValue ? new global::System.Nullable <float>(update.field2.Value.Value) : new global::System.Nullable <float>();
                    }
                    if (update.field4.HasValue)
                    {
                        componentData.Field4 = update.field4.Value.HasValue ? new global::System.Nullable <int>(update.field4.Value.Value) : new global::System.Nullable <int>();
                    }
                    if (update.field5.HasValue)
                    {
                        componentData.Field5 = update.field5.Value.HasValue ? new global::System.Nullable <long>(update.field5.Value.Value) : new global::System.Nullable <long>();
                    }
                    if (update.field6.HasValue)
                    {
                        componentData.Field6 = update.field6.Value.HasValue ? new global::System.Nullable <double>(update.field6.Value.Value) : new global::System.Nullable <double>();
                    }
                    if (update.field8.HasValue)
                    {
                        componentData.Field8 = update.field8.Value.HasValue ? new global::System.Nullable <uint>(update.field8.Value.Value) : new global::System.Nullable <uint>();
                    }
                    if (update.field9.HasValue)
                    {
                        componentData.Field9 = update.field9.Value.HasValue ? new global::System.Nullable <ulong>(update.field9.Value.Value) : new global::System.Nullable <ulong>();
                    }
                    if (update.field10.HasValue)
                    {
                        componentData.Field10 = update.field10.Value.HasValue ? new global::System.Nullable <int>(update.field10.Value.Value) : new global::System.Nullable <int>();
                    }
                    if (update.field11.HasValue)
                    {
                        componentData.Field11 = update.field11.Value.HasValue ? new global::System.Nullable <long>(update.field11.Value.Value) : new global::System.Nullable <long>();
                    }
                    if (update.field12.HasValue)
                    {
                        componentData.Field12 = update.field12.Value.HasValue ? new global::System.Nullable <uint>(update.field12.Value.Value) : new global::System.Nullable <uint>();
                    }
                    if (update.field13.HasValue)
                    {
                        componentData.Field13 = update.field13.Value.HasValue ? new global::System.Nullable <ulong>(update.field13.Value.Value) : new global::System.Nullable <ulong>();
                    }
                    if (update.field14.HasValue)
                    {
                        componentData.Field14 = update.field14.Value.HasValue ? new global::System.Nullable <int>(update.field14.Value.Value) : new global::System.Nullable <int>();
                    }
                    if (update.field15.HasValue)
                    {
                        componentData.Field15 = update.field15.Value.HasValue ? new global::System.Nullable <long>(update.field15.Value.Value) : new global::System.Nullable <long>();
                    }
                    if (update.field16.HasValue)
                    {
                        componentData.Field16 = update.field16.Value.HasValue ? new global::System.Nullable <long>(update.field16.Value.Value.Id) : new global::System.Nullable <long>();
                    }
                    if (update.field17.HasValue)
                    {
                        componentData.Field17 = update.field17.Value.HasValue ? new global::System.Nullable <global::Generated.Improbable.Gdk.Tests.SomeType>(global::Generated.Improbable.Gdk.Tests.SomeType.ToNative(update.field17.Value.Value)) : new global::System.Nullable <global::Generated.Improbable.Gdk.Tests.SomeType>();
                    }
                }

                componentData.DirtyBit = false;

                view.SetComponentObject(entity, componentData);

                var componentFieldsUpdated = false;
                var gdkUpdate = new SpatialOSExhaustiveOptional.Update();

                if (update.field2.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field2       = new Option <global::System.Nullable <float> >(update.field2.Value.HasValue ? new global::System.Nullable <float>(update.field2.Value.Value) : new global::System.Nullable <float>());
                }
                if (update.field4.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field4       = new Option <global::System.Nullable <int> >(update.field4.Value.HasValue ? new global::System.Nullable <int>(update.field4.Value.Value) : new global::System.Nullable <int>());
                }
                if (update.field5.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field5       = new Option <global::System.Nullable <long> >(update.field5.Value.HasValue ? new global::System.Nullable <long>(update.field5.Value.Value) : new global::System.Nullable <long>());
                }
                if (update.field6.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field6       = new Option <global::System.Nullable <double> >(update.field6.Value.HasValue ? new global::System.Nullable <double>(update.field6.Value.Value) : new global::System.Nullable <double>());
                }
                if (update.field8.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field8       = new Option <global::System.Nullable <uint> >(update.field8.Value.HasValue ? new global::System.Nullable <uint>(update.field8.Value.Value) : new global::System.Nullable <uint>());
                }
                if (update.field9.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field9       = new Option <global::System.Nullable <ulong> >(update.field9.Value.HasValue ? new global::System.Nullable <ulong>(update.field9.Value.Value) : new global::System.Nullable <ulong>());
                }
                if (update.field10.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field10      = new Option <global::System.Nullable <int> >(update.field10.Value.HasValue ? new global::System.Nullable <int>(update.field10.Value.Value) : new global::System.Nullable <int>());
                }
                if (update.field11.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field11      = new Option <global::System.Nullable <long> >(update.field11.Value.HasValue ? new global::System.Nullable <long>(update.field11.Value.Value) : new global::System.Nullable <long>());
                }
                if (update.field12.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field12      = new Option <global::System.Nullable <uint> >(update.field12.Value.HasValue ? new global::System.Nullable <uint>(update.field12.Value.Value) : new global::System.Nullable <uint>());
                }
                if (update.field13.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field13      = new Option <global::System.Nullable <ulong> >(update.field13.Value.HasValue ? new global::System.Nullable <ulong>(update.field13.Value.Value) : new global::System.Nullable <ulong>());
                }
                if (update.field14.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field14      = new Option <global::System.Nullable <int> >(update.field14.Value.HasValue ? new global::System.Nullable <int>(update.field14.Value.Value) : new global::System.Nullable <int>());
                }
                if (update.field15.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field15      = new Option <global::System.Nullable <long> >(update.field15.Value.HasValue ? new global::System.Nullable <long>(update.field15.Value.Value) : new global::System.Nullable <long>());
                }
                if (update.field16.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field16      = new Option <global::System.Nullable <long> >(update.field16.Value.HasValue ? new global::System.Nullable <long>(update.field16.Value.Value.Id) : new global::System.Nullable <long>());
                }
                if (update.field17.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.Field17      = new Option <global::System.Nullable <global::Generated.Improbable.Gdk.Tests.SomeType> >(update.field17.Value.HasValue ? new global::System.Nullable <global::Generated.Improbable.Gdk.Tests.SomeType>(global::Generated.Improbable.Gdk.Tests.SomeType.ToNative(update.field17.Value.Value)) : new global::System.Nullable <global::Generated.Improbable.Gdk.Tests.SomeType>());
                }

                if (componentFieldsUpdated)
                {
                    view.AddComponentsUpdated(entity, gdkUpdate, UpdatesPool);
                }
            }
 public static bool SaveCharacter(this Character ch, string pathToAccDir, LogDispatcher.LogDispatcher log)
 {
     return AccountRetriever.SaveCharacter(ch,Path.Combine(pathToAccDir, ch.CharPath + ".fl"));
 }
Beispiel #11
0
 private void SplashScreen_Load(object sender, EventArgs e)
 {
     LogDispatcher.Subscribe(this, LogMessageType.Info);
 }
Beispiel #12
0
 private static void log(string message) => LogDispatcher.I(LOG_TAG, message);
            public override void OnAddComponent(AddComponentOp op)
            {
                if (!IsValidEntityId(op.EntityId, "AddComponentOp", out var entity))
                {
                    return;
                }

                var data = Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Serialization.Deserialize(op.Data.SchemaData.Value.GetFields(), World);

                data.DirtyBit = false;
                entityManager.AddComponentData(entity, data);
                entityManager.AddComponentData(entity, new NotAuthoritative <Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component>());

                var update = new Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Update
                {
                    Field1  = data.Field1,
                    Field2  = data.Field2,
                    Field4  = data.Field4,
                    Field5  = data.Field5,
                    Field6  = data.Field6,
                    Field8  = data.Field8,
                    Field9  = data.Field9,
                    Field10 = data.Field10,
                    Field11 = data.Field11,
                    Field12 = data.Field12,
                    Field13 = data.Field13,
                    Field14 = data.Field14,
                    Field15 = data.Field15,
                    Field16 = data.Field16,
                    Field17 = data.Field17,
                };

                var updates = new List <Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Update>
                {
                    update
                };

                var updatesComponent = new Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.ReceivedUpdates
                {
                    handle = ReferenceTypeProviders.UpdatesProvider.Allocate(World)
                };

                ReferenceTypeProviders.UpdatesProvider.Set(updatesComponent.handle, updates);
                entityManager.AddComponentData(entity, updatesComponent);

                if (entityManager.HasComponent <ComponentRemoved <Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component> >(entity))
                {
                    entityManager.RemoveComponent <ComponentRemoved <Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component> >(entity);
                }
                else if (!entityManager.HasComponent <ComponentAdded <Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component> >(entity))
                {
                    entityManager.AddComponentData(entity, new ComponentAdded <Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component>());
                }
                else
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(ReceivedDuplicateComponentAdded)
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField("Component", "Generated.Improbable.Gdk.Tests.ExhaustiveBlittableSingular")
                                            );
                }
            }
            public void OnComponentUpdate(ComponentUpdateOp <global::Improbable.Gdk.Tests.BlittableTypes.BlittableComponent> op)
            {
                Unity.Entities.Entity entity;
                if (!view.TryGetEntity(op.EntityId.Id, out entity))
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent("Entity not found during OnComponentUpdate.")
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField(MutableView.Component, "SpatialOSBlittableComponent"));
                    return;
                }

                var componentData = view.GetComponent <SpatialOSBlittableComponent>(entity);
                var update        = op.Update.Get();

                if (view.HasComponent <NotAuthoritative <SpatialOSBlittableComponent> >(entity))
                {
                    if (update.boolField.HasValue)
                    {
                        componentData.BoolField = update.boolField.Value;
                    }
                    if (update.intField.HasValue)
                    {
                        componentData.IntField = update.intField.Value;
                    }
                    if (update.longField.HasValue)
                    {
                        componentData.LongField = update.longField.Value;
                    }
                    if (update.floatField.HasValue)
                    {
                        componentData.FloatField = update.floatField.Value;
                    }
                    if (update.doubleField.HasValue)
                    {
                        componentData.DoubleField = update.doubleField.Value;
                    }
                }

                var firstEventEvents = update.firstEvent;

                foreach (var spatialEvent in firstEventEvents)
                {
                    var nativeEvent = new FirstEventEvent
                    {
                        Payload = global::Generated.Improbable.Gdk.Tests.BlittableTypes.FirstEventPayload.ToNative(spatialEvent)
                    };

                    view.AddEventReceived(entity, nativeEvent, FirstEventEventPool);
                }
                var secondEventEvents = update.secondEvent;

                foreach (var spatialEvent in secondEventEvents)
                {
                    var nativeEvent = new SecondEventEvent
                    {
                        Payload = global::Generated.Improbable.Gdk.Tests.BlittableTypes.SecondEventPayload.ToNative(spatialEvent)
                    };

                    view.AddEventReceived(entity, nativeEvent, SecondEventEventPool);
                }
                componentData.DirtyBit = false;

                view.SetComponentData(entity, componentData);

                var componentFieldsUpdated = false;
                var gdkUpdate = new SpatialOSBlittableComponent.Update();

                if (update.boolField.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.BoolField    = new Option <BlittableBool>(update.boolField.Value);
                }
                if (update.intField.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.IntField     = new Option <int>(update.intField.Value);
                }
                if (update.longField.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.LongField    = new Option <long>(update.longField.Value);
                }
                if (update.floatField.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.FloatField   = new Option <float>(update.floatField.Value);
                }
                if (update.doubleField.HasValue)
                {
                    componentFieldsUpdated = true;
                    gdkUpdate.DoubleField  = new Option <double>(update.doubleField.Value);
                }

                if (componentFieldsUpdated)
                {
                    view.AddComponentsUpdated(entity, gdkUpdate, UpdatesPool);
                }
            }
Beispiel #15
0
        //Init ======================= Init:
        private async Task <ConfigureUtil> init(Action <ConfigureUtil> configure)
        {
            this.runtimeLog = new LogDispatcher(this.Clock);
            lock (lockRunning) {
                if (__running__)
                {
                    return(null);
                }
                __running__ = true;
            }
            this.AddSingletonDependency(this, typeof(ICreateInstanceActorForScene));

            //Get configuration from the user:
            var config = new ConfigureUtil();

            configure(config);
            config.Sanitize();

            //Add this director to the static list of running directors:
            lockDirectors.EnterWriteLock();
            try {
                if (directors.ContainsKey(config.DirectorName))
                {
                    throw new ApplicationException($"There is already a running director with the name '{config.DirectorName}'");
                }
                directors[config.DirectorName] = this;
            }
            finally {
                lockDirectors.ExitWriteLock();
            }

            //Get an instance of the start up log, or throw an exception:
            var   log = new LogDispatcherForActor(new LogDispatcher(this.Clock), "Before Start");
            Actor startUpLogAsActor;

            {
                var startUpLogInstantiator = new ActinInstantiator(config.StartUpLogType);
                if (!startUpLogInstantiator.Build((t) => {
                    throw new ApplicationException($"{config.StartUpLogType.Name} is being used as the 'StartUp' Log, and must not have any dependencies.");
                }))
                {
                    throw new ApplicationException($"{config.StartUpLogType.Name} is being used as the 'StartUp' Log, and must not have any dependencies.");
                }
                lock (lockInstantiators) {
                    instantiators[config.StartUpLogType] = startUpLogInstantiator;
                }
                var startUpLog = startUpLogInstantiator.GetSingletonInstance(this) as IActinLogger;
                if (startUpLog == null)
                {
                    throw new ApplicationException("The 'StartUp' Log must implement IActinLogger.");
                }
                startUpLogAsActor = startUpLog as Actor;
                log.AddDestination(startUpLog);

                if (startUpLog is ActinStandardLogger && !string.IsNullOrWhiteSpace(config.StandardLogOutputFolder))
                {
                    var standardLogger = startUpLog as ActinStandardLogger;
                    standardLogger.SetClock(this.Clock);
                    standardLogger.SetLogFolderPath(config.StandardLogOutputFolder);
                }
            }

            try {
                //Do manual user start up:
                log.Info("Director Initializing");
                await config.RunBeforeStart(new ActorUtil(null, this.Clock) {
                    Log = log,
                });

                //Do automated DI startup:
                foreach (var a in config.AssembliesToCheckForDI)
                {
                    try {
                        foreach (var t in a.GetTypes())
                        {
                            if (t.HasAttribute <SingletonAttribute>() || t.HasAttribute <InstanceAttribute>())
                            {
                                lock (lockInstantiators) {
                                    if (!instantiators.ContainsKey(t))
                                    {
                                        //If it's already contained, then it was manually added as a Singleton dependency.
                                        //We can't add it again, as when manually added, a singleton instance was provided.
                                        instantiators[t] = new ActinInstantiator(t);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex) {
                        var msg = $"Actin Failed in assembly {a.FullName}. Inner Exception: {ex.Message}";
                        log.Error(msg, ex);
                        await runStartUpLog();

                        throw new Exception(msg, ex);
                    }
                }

                lock (lockInstantiators) {
                    //At this point, we should only have manually added singletons, and attribute marked Singleton or Instance classes.
                    var rootableInstantiators = instantiators.Values.ToList();
                    rootableInstantiators = rootableInstantiators.Where(config.RootActorFilter).ToList();
                    var skipped = new List <ActinInstantiator>();
                    foreach (var instantiator in rootableInstantiators)
                    {
                        try {
                            var skippedBecauseConcreteLineageRequired = !instantiator.Build(t => {
                                if (!this.instantiators.TryGetValue(t, out var dependencyInstantiator))
                                {
                                    dependencyInstantiator = new ActinInstantiator(t);
                                    this.instantiators[t]  = dependencyInstantiator;
                                }
                                return(dependencyInstantiator);
                            });
                            if (skippedBecauseConcreteLineageRequired)
                            {
                                skipped.Add(instantiator);
                            }
                        }
                        catch (Exception ex) {
                            throw new ApplicationException($"Failed to build rootable type {instantiator.Type.Name}: {ex.Message}", ex);
                        }
                    }

                    var skippedAndNeverBuilt = skipped.Where(x => !x.WasBuilt).ToList();
                    if (skippedAndNeverBuilt.Any())
                    {
                        throw new AggregateException(skippedAndNeverBuilt.Select(
                                                         x => new ApplicationException($"{x.Type.Name} has a concrete [Parent] or [Sibling], but its parent was not found in the dependency chain."
                                                                                       + "Most likely you forgot to mark the parent class with a [Singleton] or [Instance] attribute."
                                                                                       + "If the Parent is a Scene, or not always available, then you must instead use [FlexibleParent] or [FlexibleSibling]."
                                                                                       + "Note that the flexible attributes do not do type checking on start-up.")));
                    }

                    foreach (var singletonInstantiator in rootableInstantiators.Where(x => x.IsRootSingleton))
                    {
                        var singleton = singletonInstantiator.GetSingletonInstance(this);
                    }
                }

                if (!TryGetSingleton(config.RuntimeLogType, out var rtLog))
                {
                    throw new ApplicationException($"Actin failed to get a singleton instance of the 'Runtime' log. Ensure you've marked {config.RuntimeLogType.Name} with the Singleton attribute, or manually added it to the Director as a singleton.");
                }
                var rtLogAsIActinLogger = rtLog as IActinLogger;
                if (rtLogAsIActinLogger == null)
                {
                    throw new ApplicationException($"{config.RuntimeLogType} must implement IActinLogger, as it is being used as the 'Runtime' Log.");
                }

                runtimeLog.AddDestination(rtLogAsIActinLogger);
                await config.RunAfterStart(new ActorUtil(null, this.Clock) {
                    Log = new LogDispatcherForActor(runtimeLog, "After Start"),
                });

                return(config);
            }
            catch (Exception ex) when(logFailedStartup(ex))
            {
                //Exception is always unhandled, this is a nicer way to ensure logging before the exception propagates.
                return(null);
            }

            bool logFailedStartup(Exception ex)
            {
                log.Log(new ActinLog {
                    Time        = Clock.Now,
                    Location    = "StartUp",
                    UserMessage = "Actin failed to start.",
                    Details     = ex?.ToString(),
                    Type        = LogType.Error,
                });
                runStartUpLog().Wait();
                return(false);
            }

            async Task runStartUpLog()
            {
                try {
                    if (startUpLogAsActor != null)
                    {
                        var disposeHandle = await startUpLogAsActor.Init(() => new DispatchData {
                            MainLog = new ConsoleLogger(),
                        });

                        if (disposeHandle != null)
                        {
                            lock (lockDisposeHandles) {
                                disposeHandles.Add(disposeHandle);
                            }
                        }
                        await startUpLogAsActor.Run(() => new DispatchData {
                            MainLog = new ConsoleLogger(),
                        });
                    }
                }
                catch {
                    //Nowhere to put this if the log is failing.
                }
            }
        }
            public override void OnAddComponent(AddComponentOp op)
            {
                var entity = TryGetEntityFromEntityId(op.EntityId);

                var data = Improbable.Gdk.Tests.ExhaustiveOptional.Serialization.Deserialize(op.Data.SchemaData.Value.GetFields(), World);

                data.DirtyBit = false;
                entityManager.AddComponentData(entity, data);
                entityManager.AddComponent(entity, ComponentType.Create <NotAuthoritative <Improbable.Gdk.Tests.ExhaustiveOptional.Component> >());

                var update = new Improbable.Gdk.Tests.ExhaustiveOptional.Update
                {
                    Field1  = data.Field1,
                    Field2  = data.Field2,
                    Field3  = data.Field3,
                    Field4  = data.Field4,
                    Field5  = data.Field5,
                    Field6  = data.Field6,
                    Field7  = data.Field7,
                    Field8  = data.Field8,
                    Field9  = data.Field9,
                    Field10 = data.Field10,
                    Field11 = data.Field11,
                    Field12 = data.Field12,
                    Field13 = data.Field13,
                    Field14 = data.Field14,
                    Field15 = data.Field15,
                    Field16 = data.Field16,
                    Field17 = data.Field17,
                };

                var updates = new List <Improbable.Gdk.Tests.ExhaustiveOptional.Update>
                {
                    update
                };

                var updatesComponent = new Improbable.Gdk.Tests.ExhaustiveOptional.ReceivedUpdates
                {
                    handle = ReferenceTypeProviders.UpdatesProvider.Allocate(World)
                };

                ReferenceTypeProviders.UpdatesProvider.Set(updatesComponent.handle, updates);
                entityManager.AddComponentData(entity, updatesComponent);

                if (entityManager.HasComponent <ComponentRemoved <Improbable.Gdk.Tests.ExhaustiveOptional.Component> >(entity))
                {
                    entityManager.RemoveComponent <ComponentRemoved <Improbable.Gdk.Tests.ExhaustiveOptional.Component> >(entity);
                }
                else if (!entityManager.HasComponent <ComponentAdded <Improbable.Gdk.Tests.ExhaustiveOptional.Component> >(entity))
                {
                    entityManager.AddComponent(entity, ComponentType.Create <ComponentAdded <Improbable.Gdk.Tests.ExhaustiveOptional.Component> >());
                }
                else
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(ReceivedDuplicateComponentAdded)
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField("Component", "Improbable.Gdk.Tests.ExhaustiveOptional")
                                            );
                }
            }
Beispiel #17
0
 private static void mainFormOpenedHandler(object sender, EventArgs e)
 {
     LogDispatcher.I(LOG_TAG, "Main form opened.");
     splashScreen.Close();
 }