private (Guid id, IClientEntity client) OpenConnection(string objectName, ServiceBusEntityType entityType)
        {
            var           connectionId = Guid.NewGuid();
            IClientEntity client       = null;

            switch (entityType)
            {
            case ServiceBusEntityType.Queue:
                client = new QueueClient(ConnectionChannel.ConnectionString, objectName);
                break;

            case ServiceBusEntityType.Topic:
                client = new TopicClient(ConnectionChannel.ConnectionString, objectName);
                break;

            case ServiceBusEntityType.Subscription:
                var names = objectName.Split('/');
                client = new SubscriptionClient(ConnectionChannel.ConnectionString, names[0], names[1]);
                break;
            }
            client.OperationTimeout = new TimeSpan(0, 0, ConnectionChannel.OperationTimeoutSeconds);
            if (client != null)
            {
                openConnections.TryAdd(connectionId, client);
            }
            else
            {
                throw new InvalidEntityTypeException();
            }
            return(connectionId, client);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Register custom Logging Service
 /// </summary>
 /// <param name="client">Client connection to register the plugin</param>
 /// <param name="loggingService">New logging Service to user</param>
 public static void RegisterloggingService(this IClientEntity client, ILoggingService loggingService)
 {
     client.RegisteredPlugins.Add(new LoggingPlugin(configurations =>
     {
         configurations.CustomLoggingService = loggingService;
     }));
 }
Ejemplo n.º 3
0
        public static IRestClient GetRestClient(this IClientEntity entity)
        {
            Guard.IsNotNull(entity);
            Guard.IsAssignableToType <IRestClient>(entity.Client);

            return(entity.Client as IRestClient);
        }
Ejemplo n.º 4
0
            public void Notify(IClientEntity entity)
            {
                var e = (SpaceShipClientBase)entity;

                e.Data = Data;
                e.OnSnapshot(Snapshot);
            }
        /// <summary>Instantiate plugin with the required configuration.</summary>
        /// <param name="client"><see cref="IClientEntity"/>, <see cref="SubscriptionClient"/>, <see cref="QueueClient"/>, <see cref="MessageSender"/>, <see cref="MessageReceiver"/>, or <see cref="SessionClient"/> to register plugin with.</param>
        /// <param name="configuration"><see cref="AzureStorageAttachmentConfiguration"/> object.</param>
        /// <returns>Registered plugin as <see cref="ServiceBusPlugin"/>.</returns>
        public static ServiceBusPlugin RegisterAzureStorageAttachmentPlugin(this IClientEntity client, AzureStorageAttachmentConfiguration configuration)
        {
            var plugin = new AzureStorageAttachment(configuration);

            client.RegisterPlugin(plugin);

            return(plugin);
        }
Ejemplo n.º 6
0
        public static IClientEntity EnableRijndaelManagedEncryption(this IClientEntity clientEntity, string cryptoKey, string initVectorKey)
        {
            ICryptographyProvider provider = new RijndaelManagedCryptographyProvider(cryptoKey, initVectorKey);

            clientEntity.RegisterPlugin(new MessagePayloadEncryptionPlugin(provider));

            return(clientEntity);
        }
        internal static DiscordClientBase GetDiscordClient(this IClientEntity entity)
        {
            Guard.IsNotNull(entity);

            if (entity.Client is not DiscordClientBase client)
            {
                throw new InvalidOperationException("This entity's client is not a Discord client implementation.");
            }

            return(client);
        }
Ejemplo n.º 8
0
            public void Notify(IClientEntity entity)
            {
                var e = (SpaceShipClientBase)entity;

                if (DataTracker != null)
                {
                    e.OnTrackableDataChanging(0, DataTracker);
                    DataTracker.ApplyTo(e.Data);
                    e.OnTrackableDataChanged(0, DataTracker);
                }
            }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(o =>
            {
                if (o.Read && o.Write)
                {
                    Console.WriteLine("Please use read or write argument. Not both.");
                    return;
                }

                if (!o.Read && !o.Write)
                {
                    Console.WriteLine("Please use read or write argument.");
                    return;
                }

                if (string.IsNullOrEmpty(o.Queue) && string.IsNullOrEmpty(o.Topic))
                {
                    Console.WriteLine("Please provide queue or topic name");
                    return;
                }

                if (!string.IsNullOrEmpty(o.Queue) && !string.IsNullOrEmpty(o.Topic))
                {
                    Console.WriteLine("Please provide queue or topic name. Not both.");
                    return;
                }

                if (o.Verbose)
                {
                    Verbose = true;
                }

                client = GetClient(o.ServiceBusConnString, o.Queue, o.Topic, o.Subscription, o.Peek);

                if (o.Read)
                {
                    Read((IReceiverClient)client, o.Peek, o.NumberOfMessages, o.TimeToWait);
                }
                else
                {
                    Task.Run(async() =>
                    {
                        var message = CreateSBMessage(o.Message, o.UserProperties);

                        await Write((ISenderClient)client, message);
                    }).GetAwaiter().GetResult();
                }
            });
        }
Ejemplo n.º 10
0
        public static ICollection <IClientEntity> GetImmidiateChildrenAndClear(IClientEntity clientEntity)
        {
            var childList = new List <IClientEntity>();

            Type objectType = clientEntity.GetType();

            PropertyInfo[] properties = objectType.GetProperties();

            foreach (PropertyInfo propertyInfo in properties)
            {
                try
                {
                    Object value = propertyInfo.GetValue(clientEntity, null);
                    if (value != null)
                    {
                        if (value is IList)
                        {
                            var enumerable = (IList)value;
                            foreach (Object o in enumerable)
                            {
                                if (o is IClientEntity)
                                {
                                    childList.Add((IClientEntity)o);
                                }
                            }
                            enumerable.Clear();
                        }
                        else if (value is IClientEntity)
                        {
                            childList.Add((IClientEntity)value);
                            propertyInfo.SetValue(clientEntity, null, null);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogManager.GetLogger(typeof(StatusManager)).Fatal(
                        "Exception occured while trying to retrieve child objects", e);
                }
            }

            return(childList);
        }
Ejemplo n.º 11
0
        public static void SetStatus(IClientEntity clientEntity, EntityStatus status)
        {
            if (clientEntity == null)
            {
                return;
            }

            clientEntity.Status = status;

            Type objectType = clientEntity.GetType();

            PropertyInfo[] properties = objectType.GetProperties();
            foreach (PropertyInfo propertyInfo in properties)
            {
                try
                {
                    Object value = propertyInfo.GetValue(clientEntity, null);
                    if (value != null)
                    {
                        if (value is ICollection)
                        {
                            var enumerable = (ICollection)value;
                            foreach (Object o in enumerable)
                            {
                                if (o is IClientEntity)
                                {
                                    SetStatus((IClientEntity)o, status);
                                }
                            }
                        }
                        else if (value is IClientEntity)
                        {
                            SetStatus((IClientEntity)value, status);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogManager.GetLogger(typeof(StatusManager)).Fatal(
                        "Exception occured while trying to update status", e);
                }
            }
        }
Ejemplo n.º 12
0
        public void Spawn_ServerOnlyEntity_WhenSpawn_ClientCannotSee()
        {
            // Arrange

            var s = TestZoneBuilder.Build();

            // Act

            IServerEntity so = null;

            s.ServerZone.RunAction(z => so = z.Spawn(typeof(IMonitor), 0));
            Assert.NotNull(so);
            Assert.IsType <ServerMonitor>(so);

            // Assert

            foreach (var clientZone in s.ClientZones)
            {
                IClientEntity co = clientZone.GetEntity(so.Id);
                Assert.Null(co);
            }
        }
Ejemplo n.º 13
0
        public void Spawn_SyncedToClient()
        {
            // Arrange

            var s = TestZoneBuilder.Build();

            // Act

            IServerEntity so = null;

            s.ServerZone.RunAction(z => so = z.Spawn(typeof(IBullet), 1));
            Assert.NotNull(so);
            Assert.IsType <ServerBullet>(so);

            // Assert

            foreach (var clientZone in s.ClientZones)
            {
                IClientEntity co = clientZone.GetEntity(so.Id);
                Assert.NotNull(co);
                Assert.IsType <ClientBullet>(co);
            }
        }
Ejemplo n.º 14
0
 public static void VerifyAgainstServerEntity(this IClientEntity <Guid> clientEntity, IServerEntity serverEntity)
 {
     Assert.That(clientEntity.Id, Is.EqualTo(serverEntity.Id));
     Assert.That(clientEntity.EntityState, Is.EqualTo(serverEntity.EntityState));
     Assert.That(clientEntity.ModifiedAtTicks, Is.EqualTo(serverEntity.ModifiedAt.Ticks));
 }
Ejemplo n.º 15
0
 public void Save(IClientEntity clientEntity)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 void IClientEntityFactory.Delete(IClientEntity entity)
 {
 }
Ejemplo n.º 17
0
 void IClientEntityFactory.Delete(IClientEntity entity)
 {
     var enb = ((EntityNetworkBehaviour)entity);
     UnityEngine.Object.Destroy(enb.gameObject);
 }
Ejemplo n.º 18
0
 private void OnDespawn(IClientEntity entity)
 {
     Logs.Add(Tuple.Create(entity.Id, "Despawn"));
 }
Ejemplo n.º 19
0
 public override void AddClientSideEntity(IClientEntity entity)
 {
     entity.LoadContent(_contentManager);
     clientSide.Add(entity);
 }
        /// <summary>Initiate plugin for Receive-Only mode to retrieve attachments using SAS URI. </summary>
        /// <param name="client"><see cref="IClientEntity"/>, <see cref="SubscriptionClient"/>, <see cref="QueueClient"/>, <see cref="MessageSender"/>, <see cref="MessageReceiver"/>, or <see cref="SessionClient"/> to register plugin with.</param>
        /// <param name="messagePropertyToIdentifySasUri">Message property name to be used to retrieve message SAS UI.</param>
        /// <returns>Registered plugin as <see cref="ServiceBusPlugin"/>.</returns>
        public static ServiceBusPlugin RegisterAzureStorageAttachmentPluginForReceivingOnly(this IClientEntity client, string messagePropertyToIdentifySasUri = AzureStorageAttachmentConfigurationExtensions.DefaultMessagePropertyToIdentitySasUri)
        {
            var plugin = new ReceiveOnlyAzureStorageAttachment(messagePropertyToIdentifySasUri);

            client.RegisterPlugin(plugin);

            return(plugin);
        }
 public static bool IsNewerThan <T>(this IClientEntity <T> entity, long modifiedAtTicks)
 {
     return(modifiedAtTicks == 0 || entity.ModifiedAtTicks > modifiedAtTicks);
 }
Ejemplo n.º 22
0
 public virtual void AddClientSideEntity(IClientEntity entity)
 {
 }