Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="server"></param>
        /// <param name="serverInstance"></param>
        public ServerContext(Game game, string gameId, int port, IServerInstance serverInstance)
        {
            this.game           = game;
            this.serverInstance = serverInstance;

            var netConfig = new NetPeerConfiguration(gameId);

            netConfig.Port = port;
            netConfig.MaximumConnections      = 32;
            netConfig.UnreliableSizeBehaviour = NetUnreliableSizeBehaviour.NormalFragmentation;

            if (Debugger.IsAttached)
            {
                netConfig.ConnectionTimeout = float.MaxValue;
                Log.Message("SV: Debugger is attached: ConnectionTimeout = {0} sec", netConfig.ConnectionTimeout);
            }

            netConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            netConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            netConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
            netConfig.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);

            notifications = new Queue <string>();

            netServer = new NetServer(netConfig);
            netServer.Start();
        }
        public void GetCatalogsByInstanceId(int id, out FetDatasetIdentify[] dsIds, out FetClassIdentify[] fetclassIds)
        {
            dsIds       = null;
            fetclassIds = null;
            IServerInstance instance = GetServerInstanceById(id);

            if (instance == null)
            {
                throw new Exception(string.Format(HttpCommands.cstErrorInstanceIsNotExisted, id));
            }
            try
            {
                ICatalogProvider prd = instance.CatalogProvider;
                if (prd == null)
                {
                    throw new Exception(string.Format(HttpCommands.cstErrorCatalogProviderNotExistdOfInstance, id));
                }
                dsIds       = prd.GetFetDatasetIdentify();
                fetclassIds = prd.GetFetClassIdentify();
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format(HttpCommands.cstErrorCatalogProviderNotExistdOfInstance + "," + ex.Message, id));
            }
        }
Exemple #3
0
        protected override Dictionary <string, object> UpdateObject <T>(IServerInstance instance, T @new, T old)
        {
            var command = instance.Connection.CreateCommand();

            var update = "UPDATE " + base.Table <T>() + " SET ";


            var count = 0;

            var changedPairs = CompareAndChange <T>(@new, old);

            if (changedPairs.Count == 0)
            {
                return(null);
            }
            foreach (var changedPair in changedPairs)
            {
                string paramName = string.Empty;


                paramName = "@" + changedPair.Key;

                if (changedPairs.Count - 1 == count)
                {
                    update += changedPair.Key + "=@" + changedPair.Key;
                }
                else
                {
                    update += changedPair.Key + "=@" + changedPair.Key + ",";
                }


                count++;

                IDbDataParameter parameter = command.CreateParameter();
                parameter.ParameterName = paramName;
                parameter.Value         = changedPair.Value;
                command.Parameters.Add(parameter);


                //command.Parameters.AddWithValue("@" + changedPair.Key, changedPair.Value);
            }
            string where = ""; // = " WHERE " + Key + "=@Key";
            IDbDataParameter whereParam = command.CreateParameter();


            where = " WHERE " + Key <T>() + "=@Key";
            whereParam.ParameterName = "@Key";


            whereParam.Value    = @new.GetType().GetProperty(Key <T>()).GetValue(@new);
            command.CommandText = update + where;
            command.Parameters.Add(whereParam);

            command.ExecuteNonQuery();
            return(changedPairs);
        }
 public UpdateProviderLocal(IServerInstance serverInstance,
                            UpdateProviderLocalConfiguration specificConfiguration,
                            ILogger <UpdateProviderLocal> logger,
                            IConfiguration configuration)
 {
     _serverInstance        = serverInstance;
     _specificConfiguration = specificConfiguration;
     _logger        = logger;
     _configuration = configuration;
 }
        public Feature[] ReadFeatures(int instanceId, string fetclassId, Envelope evp)
        {
            IServerInstance instance = GetServerInstanceById(instanceId);

            if (instance == null)
            {
                throw new Exception(string.Format(HttpCommands.cstErrorInstanceIsNotExisted, instanceId));
            }
            using (IFeaturesReaderService reader = instance.GetFeaturesReaderService(fetclassId))
            {
                return(reader.Read(evp));
            }
        }
        public FetClassProperty GetFetClassProperty(int instanceId, string fetclassId)
        {
            IServerInstance instance = GetServerInstanceById(instanceId);

            if (instance == null)
            {
                throw new Exception(string.Format(HttpCommands.cstErrorInstanceIsNotExisted, instanceId));
            }
            ICatalogProvider prd = instance.CatalogProvider;

            if (prd == null)
            {
                throw new Exception(string.Format(HttpCommands.cstErrorCatalogProviderNotExistdOfInstance, fetclassId));
            }
            return(prd.GetFetClassProperty(fetclassId));
        }
Exemple #7
0
        public void Arrange()
        {
            var serverMock = new Mock <IServerInstance>();

            serverMock.Setup(s => s.GetServerInstance()).Returns("New Server For Tests");

            _server = serverMock.Object;

            var serverComponentMock = new Mock <ServerComponent>(_server)
            {
                CallBase = true
            };

            serverComponentMock.Setup(s => s.Execute(It.IsAny <int>()));

            _serverComponent = serverComponentMock.Object;
        }
Exemple #8
0
        /*
         * <VectorServerInstances>
         *     <Instance name="北京1:5000万基础矢量服务" descrption="" args =""/>
         *     <Instance name="世界1:5000万基础矢量服务" descrption="" args =""/>
         * </VectorServerInstances>
         */
        public static IServerInstance[] Parse(string cnfgfile)
        {
            XDocument doc  = XDocument.Load(cnfgfile);
            XElement  root = doc.Element("VectorServerInstances");
            var       eles = root.Elements("Instance");

            if (eles == null)
            {
                return(null);
            }
            List <IServerInstance> defs = new List <IServerInstance>();

            foreach (XElement ele in eles)
            {
                int              id    = int.Parse(ele.Attribute("id").Value);
                string           name  = ele.Attribute("name").Value;
                string           desc  = ele.Attribute("description").Value;
                string           args  = ele.Attribute("args").Value;
                InstanceIdentify idobj = new InstanceIdentify(id, name, desc);
                IServerInstance  def   = ServerInstanceFactory.GetServerInstance(idobj, args);
                defs.Add(def);
            }
            return(defs.Count > 0 ? defs.ToArray() : null);
        }
Exemple #9
0
 public override void bootLoader(IServerInstance ist)
 {
 }
Exemple #10
0
 /// <summary>
 /// Questo è il primo modulo che viene caricato
 /// Diversamente da Wildfly lo standalone.xml come refernce al primo modulo
 /// caricato. Questo significa che , se è standalone faccio partire un modulo diverso da quello
 /// per il dominio.
 /// </summary>
 /// <param name="ist"></param>
 public abstract void bootLoader(IServerInstance ist);
Exemple #11
0
 public override void bootLoader(IServerInstance ist)
 {
     // Implementare in questo punto
     throw new NotImplementedException();
 }
Exemple #12
0
        protected override void InsertObject <T>(IServerInstance instance, T obj)
        {
            var command = instance.Connection.CreateCommand();

            command.CommandText = "INSERT INTO " + Table <T>() + " ";

            string columns = "(", values = " VALUES (";

            var infos = obj.GetType().GetProperties();

            for (var i = 0; i < infos.Length; i++)
            {
                IEnumerable <Identity> fields = infos[i].GetCustomAttributes(false).OfType <Identity>();

                bool ignore = fields.Any(f => f.IgnoreField);

                if (ignore)
                {
                    continue;
                }

                var o = infos[i].GetValue(obj);

                if (o == null)
                {
                    continue;
                }

                if (o is DateTime && (DateTime)o == DateTime.MinValue)
                {
                    continue;
                }


                string paramName = "?";

                if (i == infos.Length - 1)
                {
                    columns += infos[i].Name + ")";
                    values  += "?)";
                }
                else
                {
                    columns += infos[i].Name + ",";
                    values  += "?,";
                }



                IDbDataParameter parameter = command.CreateParameter();
                parameter.ParameterName = paramName;
                parameter.Value         = o;

                command.Parameters.Add(parameter);
            }

            columns = ReplaceTrailingComma(columns);
            values  = ReplaceTrailingComma(values);


            command.CommandText += columns + values;

            command.ExecuteNonQuery();
        }
Exemple #13
0
 public ServerComponent(IServerInstance server)
 {
     _server = server;
 }
Exemple #14
0
        public override void bootLoader(IServerInstance ist){

        }
Exemple #15
0
 public PsqlDbContext(IServerInstance instance)
 {
     _instance = instance;
 }
Exemple #16
0
 private static void CheckExtensions(IServerInstance server)
 {
     Console.WriteLine(server.LoadHulkExtension());
     Console.WriteLine(server.LoadWidowExtension());
 }
Exemple #17
0
 public IExtensionsBase GetWidowExtension(IServerInstance server)
 {
     return(new WidowExtension(server));
 }
Exemple #18
0
        protected virtual void CreateMappings <T>(T item, object linkProperty, object context, string andQuery,
                                                  object value, string fieldTo, PropertyInfo info, IServerInstance instance)
        {
            if (linkProperty.GetType().Name.Contains("List"))
            {
                Type argument = linkProperty.GetType().GetGenericArguments()[0];



                object objReturned = null;



                object[] parameters;

                Type[] types = null;

                if (andQuery == null)
                {
                    if (value is int)
                    {
                        types = new[] { typeof(int), typeof(string) };
                    }
                    else
                    {
                        types = new[] { typeof(string), typeof(string) };
                    }

                    parameters = new[] { value, fieldTo };
                }
                else
                {
                    if (value is int)
                    {
                        types = new[] { typeof(int), typeof(string), typeof(string) };
                    }
                    else
                    {
                        types = new[] { typeof(string), typeof(string), typeof(string) };
                    }
                    parameters = new[] { value, fieldTo, andQuery };
                }



                if (value is int)
                {
                    objReturned =
                        context.GetType().GetMethod("GetAll", types).MakeGenericMethod(argument)
                        .Invoke(context, parameters);
                }
                if (value is string)
                {
                    var genericMethod = context.GetType()
                                        .GetMethod("GetAll", types).MakeGenericMethod(argument);

                    objReturned =
                        genericMethod
                        .Invoke(context, parameters);
                }

                info.SetValue(item, objReturned);
            }
            else
            {
                object objReturned = null;

                if (value is int)
                {
                    objReturned = context.GetType()
                                  .GetMethod("GetById", new[] { typeof(int) }).MakeGenericMethod(linkProperty.GetType())
                                  .Invoke(context, new[] { value });
                }
                if (value is string)
                {
                    objReturned = context.GetType()
                                  .GetMethod("GetById", new[] { typeof(string) }).MakeGenericMethod(linkProperty.GetType())
                                  .Invoke(context, new[] { value });
                }

                info.SetValue(item, objReturned);
            }
        }
Exemple #19
0
 public WidowExtension(IServerInstance server) : base(server, "Widow")
 {
 }
Exemple #20
0
 public OleDbContext(IServerInstance instance)
 {
     _instance = instance;
 }
Exemple #21
0
 /// <summary>
 /// Inserts a object to a database
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="obj"></param>
 protected abstract void InsertObject <T>(IServerInstance instance, T obj);
Exemple #22
0
 Dictionary <string, object> UpdateObject <T>(IServerInstance instance, T @new, T old);
Exemple #23
0
 public HulkExtension(IServerInstance server) : base(server, "Hulk")
 {
 }
Exemple #24
0
 public IExtensionsBase GetHulkExtension(IServerInstance server)
 {
     return(new HulkExtension(server));
 }
Exemple #25
0
 /// <summary>
 /// Questo è il primo modulo che viene caricato
 /// Diversamente da Wildfly lo standalone.xml come refernce al primo modulo 
 /// caricato. Questo significa che , se è standalone faccio partire un modulo diverso da quello 
 /// per il dominio. 
 /// </summary>
 /// <param name="ist"></param>
 public abstract void bootLoader(IServerInstance ist);
Exemple #26
0
 IExtensionsBase IExtensionsFactory.GetExtension <T>(IServerInstance server)
 {
     return(Activator.CreateInstance(typeof(T), server) as IExtensionsBase);
 }
Exemple #27
0
 public ExtensionsBase(IServerInstance server, string extensionName)
 {
     _server         = server;
     _extenstionName = extensionName;
 }
Exemple #28
0
 public override void bootLoader(IServerInstance ist)
 {
     // Implementare in questo punto 
     throw new NotImplementedException();
 }