示例#1
0
        public void GetInstance_InstanceNotRegistered_GetUnregisteredException <TStruct> (TStruct hackForGeneric)
            where TStruct : IStructure
        {
            var fact = new StructureFactory();

            fact.GetInstance <TStruct>();
        }
示例#2
0
        public void RegisterInstance_DoesNotThrow <TStruct> (TStruct structure)
            where TStruct : IStructure, new()
        {
            var fact = new StructureFactory();

            Assert.That(() => fact.RegisterInstance <TStruct>(structure), Throws.Nothing);
        }
示例#3
0
        /// <summary>
        /// Create configuration object, which implements given Structure.
        /// Structure properties are parsed from input stream.
        /// </summary>
        /// <param name="parser">Parser which is used for input/output.</param>
        /// <param name="readFromParser">Determine that values can be read from parser.</param>
        /// <typeparam name="Structure">Interface which describes structure of configuration file.</typeparam>
        /// <returns>Configuration object.</returns>
        private static Structure createConfig <Structure>(ConfigParser parser, bool readFromParser = true)
            where Structure : IConfiguration
        {
            var structureType = typeof(Structure);

            //throws exception for invalid structureType
            StructureValidation.ThrowOnInvalid(structureType);

            var structureInfo = StructureFactory.CreateStructureInfo(structureType);
            var optionValues  = readFromParser ? parser.GetOptionValues(structureInfo) : getDefaults(structureInfo);

            if (!readFromParser)
            {
                //parser has to now about structure
                parser.RegisterStructure(structureInfo);
            }


            var configRoot = ConfigFactory.CreateConfigRoot(structureInfo);

            configRoot.AssociateParser(parser);
            //fill config with option values
            foreach (var value in optionValues)
            {
                configRoot.SetOption(value);
                if (!readFromParser)
                {
                    //parser doesn't know about default values - notify it
                    var info = configRoot.GetOptionInfo(value.Name);
                    parser.SetOption(info, value);
                }
            }

            return((Structure)(object)configRoot);
        }
示例#4
0
 public void MakeIfConstructed()
 {
     //this turns the blueprint into a real structure. removes nodes, deletes itself, and activates structure.
     if (IsConstructed())
     {
         GameObject          realStructure       = StructureFactory.MakeStructure(thing.thingType, false);
         StructureController structureController = realStructure.GetComponent <StructureController> ();
         realStructure.transform.position = blueprintStructure.transform.position;
         realStructure.transform.rotation = blueprintStructure.transform.rotation;
         Destroy(gameObject);
     }
 }
示例#5
0
        public object CreateContainer(Type containerType, IEnumerable <object> elements)
        {
            var container   = Activator.CreateInstance(containerType);
            var elementType = StructureFactory.GetElementType(containerType);

            foreach (var el in elements)
            {
                ReflectionUtils.CollectionAdd(elementType, container, el);
            }

            return(container);
        }
示例#6
0
        public static void Init(TestContext context)
        {
            SpecificationProvider provider = SpecificationProvider.CreateOffline(new FileArtifactSource("TestData"));
            SpecificationBuilder  builder  = new SpecificationBuilder(provider);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add("http://disk/Profile/lipid.profile.xml#lipidPanel");
            builder.Expand();

            spec = builder.ToSpecification();
        }
示例#7
0
 public void StartBlueprint(Thing thing)
 {
     if (blueprintStructure != null)
     {
         Destroy(blueprintStructure);
     }
     blueprintMode      = BlueprintModes.expanding;
     expandTimer        = 0;
     this.thing         = thing;
     blueprintStructure = StructureFactory.MakeStructure(thing.thingType, true);
     blueprintStructure.transform.parent = gameObject.transform;
 }
示例#8
0
        private SpecificationWorkspace getSpecification(Uri uri, bool expand)
        {
            SpecificationProvider provider = new SpecificationProvider(Source);
            SpecificationBuilder  builder  = new SpecificationBuilder(provider);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(uri);
            if (expand)
            {
                builder.Expand();
            }

            return(builder.ToSpecification());
        }
示例#9
0
        public static Specification GetProfileSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            if (expand)
            {
                builder.Expand();
            }

            return(builder.ToSpecification());
        }
示例#10
0
        public static Specification GetExtendedPatientSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.LoadXmlFile("TestData\\patient.extended.profile.xml");
            builder.LoadXmlFile("TestData\\type-Extension.profile.xml");
            if (expand)
            {
                builder.Expand();
            }
            return(builder.ToSpecification());
        }
示例#11
0
        public SpecificationWorkspace Spec(string fileuri, string structure)
        {
            FhirFile.ExpandProfileFile("TestData\\" + fileuri + ".xml", "TestData\\testprofile.xml");
            Uri uri = new Uri("http://disk/testdata/testprofile.xml#" + structure);

            SpecificationProvider provider = SpecificationProvider.CreateOffline(new FileArtifactSource("TestData"));
            SpecificationBuilder  builder  = new SpecificationBuilder(provider);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add(uri);
            builder.Expand();

            return(builder.ToSpecification());
        }
示例#12
0
        protected override Profile LoadProfile()
        {
            ProfileBuilder builder = new ProfileBuilder();

            //profile.Add(ProfileFactory.MetaTypesProfile());
            //profile.Add(ProfileFactory.DataTypesProfile());
            builder.Add(StructureFactory.PrimitiveTypes());
            //profile.LoadXMLValueSets("Data\\valuesets.xml");
            //profile.LoadXmlFile("Data\\type-HumanName.profile.xml");
            //profile.LoadXmlFile("Data\\type-Identifier.profile.xml");
            builder.LoadXmlFile("Data\\type-ResourceReference.profile.xml");

            builder.LoadXmlFile("Data\\profile.profile.xml");
            return(builder.ToProfile());
        }
示例#13
0
文件: Set.cs 项目: Thaina/Towel
 /// <summary>This constructor is for cloning purposes.</summary>
 /// <param name="set">The set to clone.</param>
 /// <param name="clone">A delegate for cloning the structures.</param>
 /// <runtime>O(n)</runtime>
 internal Set(Set <Structure, T> set, StructureClone clone)
 {
     _factory = set._factory;
     _equate  = set._equate;
     _hash    = set._hash;
     _table   = new Structure[set._table.Length];
     for (int i = 0; i < _table.Length; i++)
     {
         if (!(set._table[i] is null))
         {
             _table[i] = clone(set._table[i]);
         }
     }
     _count = set._count;
 }
示例#14
0
        public static SpecificationWorkspace GetExtendedPatientSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add("http://here.there/patient.extended.profile.xml");
            builder.Add("http://here.there/type-Extension.profile.xml");
            if (expand)
            {
                builder.Expand();
            }
            return(builder.ToSpecification());
        }
示例#15
0
        public static SpecificationWorkspace GetSpecification(Uri uri, bool expand)
        {
            SpecificationProvider provider = GetSpecificationResolver();
            SpecificationBuilder  builder  = new SpecificationBuilder(provider);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add(uri);
            if (expand)
            {
                builder.Expand();
            }

            return(builder.ToSpecification());
        }
示例#16
0
        public static SpecificationWorkspace GetLipidSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add("http://here.there/TestData/valueset.profile.xml");
            builder.Add("http://here.there/TestData/lipid.profile.xml");
            if (expand)
            {
                builder.Expand();
            }

            return(builder.ToSpecification());
        }
示例#17
0
        protected override Profile LoadProfile()
        {
            ProfileBuilder builder = new ProfileBuilder();

            //profile.Add(ProfileFactory.MetaTypesProfile());
            //profile.Add(ProfileFactory.DataTypesProfile());
            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.LoadXMLValueSets("Data\\valuesets.xml");
            builder.LoadXmlFile("Data\\type-Extension.profile.xml");
            builder.LoadXmlFile("Data\\type-HumanName.profile.xml");
            builder.LoadXmlFile("Data\\type-Identifier.profile.xml");
            builder.LoadXmlFile("Data\\type-Narrative.profile.xml");
            builder.LoadXmlFile("Data\\patient.profile.xml");

            return(builder.ToProfile());
        }
示例#18
0
 private Stage()
 {
     MATRIX                       = new Case[MATRIX_SIZE, MATRIX_SIZE];
     caseFactory                  = new CaseFactory();
     structureFactory             = new StructureFactory();
     itemFactory                  = new ItemFactory();
     studentEnemyFactory          = new StudentEnemyFactory();
     player                       = new Player(0, 0);
     debugOutput                  = new List <string>();
     facingInteractionOutput      = new List <string>();
     closeInteractionsOutput      = new List <string>();
     interactionTriggeredOutput   = new List <string>();
     questOutput                  = new List <string>();
     inCombatOuput                = new List <string>();
     availableCombatOptionsOutput = new List <string>();
     currentLevel                 = 0;
 }
示例#19
0
        public static SpecificationWorkspace GetPatientSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.MetaTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add("http://hl7.org/fhir/Profile/Patient");

            if (expand)
            {
                builder.Expand();
            }

            return(builder.ToSpecification());
        }
示例#20
0
        public MinimalMockServer(GalacticProperties gp, IDatabaseManager databaseManager, IDbIdIoService dbIdIoService)
        {
            Logger.Initialize();

            DatabaseManager = databaseManager;
            DbIdIoService   = dbIdIoService;

            //Minimal initializations
            GalaxyIDManager  = new LocalIDManager(null, IDTypes.GalaxyID);
            TeamIDManager    = new LocalIDManager(null, IDTypes.TeamID);
            accountIDManager = new LocalIDManager(null, IDTypes.AccountID);

            InitializeIdData(gp);

            globalGalaxyIDManager = new GlobalGalaxyIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalGalaxyIDManager, GalaxyIDManager, gp.IdProperties[IDTypes.GalaxyID].LastIDAdded);

            globalTeamIDManager = new GlobalTeamIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalTeamIDManager, TeamIDManager, gp.IdProperties[IDTypes.TeamID].LastIDAdded);

            globalAccountIDManager = new GlobalAccountIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalAccountIDManager, accountIDManager, gp.IdProperties[IDTypes.AccountID].LastIDAdded);

            _redisServer = new RedisServer(Logger.LogRedisError, Logger.LogRedisInfo, new RedisConfig().Address);


            TeamManager        = new GlobalTeamManager(TeamIDManager, null, null, null, DatabaseManager);
            PlayerManager      = new PlayerManager(DatabaseManager, null, _redisServer, GalaxyIDManager, null);
            GalaxyManager      = new GalaxyManager(gp.SolID, TeamManager);
            shipManager        = new ShipManager(null, GalaxyManager, null, null, DatabaseManager);
            CollisionManager   = new CollisionManager(GalaxyManager, null, null, null);
            GalaxyGenerator    = new DebugGalaxyGenerator(PlayerManager, GalaxyManager, shipManager);
            AccountManager     = new AccountManager_MasterServer(accountIDManager, DatabaseManager, false);
            CargoSynchronizer  = new Server.Managers.CargoSynchronizer();
            StructureManager   = new StructureManager(DatabaseManager, GalaxyManager, GalaxyIDManager, CargoSynchronizer);
            RegistrationManger = new GalaxyRegistrationManager(GalaxyManager, shipManager, CollisionManager, GalaxyIDManager, PlayerManager, null, CargoSynchronizer, StructureManager);
            ColonyFactory.Initialize(GalaxyIDManager, RegistrationManger);
            StructureFactory.Initialize(GalaxyIDManager, RegistrationManger);
            LocatorService = new LocatorService(RegistrationManger, PlayerManager, GalaxyManager, shipManager, AccountManager, TeamManager, TeamManager, null, StructureManager, null);

            WarpManager = new WarpManager(GalaxyManager, null, null, _redisServer, AccountManager, null);

            CargoSynchronizer.Start(10, 4);
        }
示例#21
0
 public bool Build()
 {
     Debug.Log("Building Set");
     if (CanAffordSet())
     {
         foreach (dStructurePlacement spd in _set)
         {
             HomelandsStructure newStructure = StructureFactory.Make(spd.location._game, spd);
             spd.location._structure = newStructure;
             _player._resources.Pay(spd.data.cost);
             _player._game._locations[spd.location._pos]._structure = newStructure;
             _player._buildQueue._queue.Remove(spd);
         }
         return(true);
     }
     else
     {
         Debug.Log(_player._name + " can't afford the set!");
         return(false);
     }
 }
示例#22
0
        private void addToggleHandler(Toggle toggle, StructureFactory factory)
        {
            toggle.onValueChanged.AddListener((isOn) =>
            {
                if (isOn)
                {
                    CurrentFactory = factory;
                }
                else
                {
                    CurrentFactory = null;
                }
            });
            var trigger    = toggle.gameObject.AddComponent <EventTrigger>();
            var enterEntry = new EventTrigger.Entry();

            enterEntry.eventID = EventTriggerType.PointerEnter;
            enterEntry.callback.AddListener((data) => infoBox.SetInfo(factory));
            var exitEntry = new EventTrigger.Entry();

            exitEntry.eventID = EventTriggerType.PointerExit;
            exitEntry.callback.AddListener((data) => infoBox.SetInfo(currentFactory));
            var clickEntry = new EventTrigger.Entry();

            clickEntry.eventID = EventTriggerType.PointerClick;
            clickEntry.callback.AddListener((data) =>
            {
                if (!factory.CanBuild(out string reason))
                {
                    ShowPopupInfo(reason);
                }
            });
            trigger.triggers.Add(enterEntry);
            trigger.triggers.Add(exitEntry);
            trigger.triggers.Add(clickEntry);
        }
示例#23
0
文件: Set.cs 项目: Thaina/Towel
 /// <summary>Constructs a hashed set.</summary>
 /// <param name="factory">The factory delegate.</param>
 /// <param name="equate">The equate delegate.</param>
 /// <param name="hash">The hashing function.</param>
 /// <param name="expectedCount">The expected count of the set.</param>
 /// <runtime>O(1)</runtime>
 public Set(
     StructureFactory factory,
     Equate <T> equate = null,
     Hash <T> hash     = null,
     int?expectedCount = null)
 {
     if (expectedCount.HasValue && expectedCount.Value > 0)
     {
         int tableSize = (int)(expectedCount.Value * (1 / _maxLoadFactor));
         while (!IsPrime(tableSize))
         {
             tableSize++;
         }
         _table = new Structure[tableSize];
     }
     else
     {
         _table = new Structure[2];
     }
     _factory = factory;
     _equate  = equate ?? Towel.Equate.Default;
     _hash    = hash ?? Towel.Hash.Default;
     _count   = 0;
 }
示例#24
0
 public StructureFacade(byte[] buff)
 {
     _buff = buff;
     _imageDosHeaderFactory = new StructureFactory <IMAGE_DOS_HEADER>(buff, 0);
 }
示例#25
0
        private void LoadSolarSystem()
        {
            _sun = new Sun();

            var mercury = new Mercury();
            var venus   = new Venus();
            var earth   = new Earth();
            var moon    = new Moon(earth.Position, earth.Velocity);
            var mars    = new Mars();
            var jupiter = new Jupiter();
            var europa  = new Europa(jupiter.Position, jupiter.Velocity);
            var saturn  = new Saturn();

            _massiveBodies = new List <IMassiveBody>
            {
                _sun, mercury, venus, earth, moon, mars, jupiter, europa, saturn
            };

            ResolveMassiveBodyParents();

            _spaceCrafts = new List <ISpaceCraft>();
            _structures  = new List <StructureBase>();

            MissionConfig primaryMission = MissionConfig.Load(ProfilePaths[0]);

            _originTime = primaryMission.GetLaunchDate();

            OrbitHelper.SimulateToTime(_massiveBodies, _originTime, 300);

            // Load missions
            for (int i = 0; i < ProfilePaths.Count; i++)
            {
                MissionConfig missionConfig = MissionConfig.Load(ProfilePaths[i]);

                IMassiveBody targetPlanet = LocatePlanet(missionConfig.ParentPlanet);

                double launchAngle = targetPlanet.GetSurfaceAngle(_originTime, _sun);

                _spaceCrafts.AddRange(SpacecraftFactory.BuildSpaceCraft(targetPlanet, launchAngle, missionConfig, ProfilePaths[i]));

                _structures.AddRange(StructureFactory.Load(targetPlanet, launchAngle, ProfilePaths[i]));
            }

            // Initialize the spacecraft controllers
            foreach (ISpaceCraft spaceCraft in _spaceCrafts)
            {
                spaceCraft.InitializeController(_eventManager);
            }

            _gravitationalBodies = new List <IGravitationalBody>
            {
                _sun, mercury, venus, earth, moon, mars, jupiter, europa, saturn
            };

            foreach (ISpaceCraft spaceCraft in _spaceCrafts)
            {
                _gravitationalBodies.Add(spaceCraft);
            }

            // Target the spacecraft
            _targetIndex = _gravitationalBodies.IndexOf(_spaceCrafts.FirstOrDefault());

            ResolveSpaceCraftParents();
        }
示例#26
0
 public StructureFacade(byte[] buff)
 {
     _buff = buff;
     _imageDosHeaderFactory = new StructureFactory<IMAGE_DOS_HEADER>(buff, 0);
 }
示例#27
0
        /// <summary>
        /// Returns created NPCPlayers
        /// </summary>
        /// <param name="galaxyManager"></param>
        /// <param name="IDManager"></param>
        /// <param name="rm"></param>
        /// <param name="pm"></param>
        /// <param name="npcShips"></param>
        /// <returns></returns>
        async Task <IEnumerable <NPCPlayer> > CreateNPCs(GalaxyManager galaxyManager, LocalIDManager IDManager, GalaxyRegistrationManager rm, PlayerManager pm, LocatorService locatorService, CargoSynchronizer cargoSynchronizer, GlobalTeamManager teamManager, LocalIDManager galaxyIDManager)
        {
            Random r = new Random(666);


            var players = new List <NPCPlayer>();


            var systems  = galaxyManager.Systems;
            int npcCount = 0;

            foreach (PSystem s in systems)
            {
                List <Player> team1 = new List <Player>();
                List <Player> team2 = new List <Player>();
                List <Player> team3 = new List <Player>();
                for (int i = 0; i < _config.NumNPCsPerSystem; i++)
                {
                    List <WeaponTypes> weapons = new List <WeaponTypes>();

                    ShipTypes shipType = ShipTypes.Barge;
                    switch (npcCount % 3)
                    {
                    case 0:
                        shipType = ShipTypes.Penguin;
                        break;

                    case 1:
                        shipType = ShipTypes.Barge;
                        break;

                    case 2:
                        shipType = ShipTypes.Reaper;
                        break;
                    }

                    if (shipType == ShipTypes.Reaper)
                    {
                        weapons.Add(WeaponTypes.LaserWave);
                        weapons.Add(WeaponTypes.PlasmaCannon);
                    }
                    else
                    {
                        weapons.Add(WeaponTypes.AltLaser);
                        weapons.Add(WeaponTypes.LaserWave);
                    }

                    ShipCreationProperties props = new ShipCreationProperties(r.Next(-20, 20), r.Next(-20, 20), (int)galaxyManager.SolAreaID, PilotTypes.NPC, shipType, weapons);
                    IShip tempShip = _dbFillerUtils.ShipFactory.CreateShip(props);
                    tempShip.ShipStats.ShieldType = ShieldTypes.QuickRegen;

                    NPCPlayer p = pm.CreateNPCPlayer(locatorService);
                    pm.RegisterPlayer(p);
                    players.Add(p);

                    tempShip.SetPlayer(p);
                    p.SetActiveShip(tempShip, MockServer.WarpManager);


                    TransactionAddStatelessCargo tr = new TransactionAddStatelessCargo(tempShip,
                                                                                       StatelessCargoTypes.AmbassadorMissile, 666666, true);
                    cargoSynchronizer.RequestTransaction(tr);
                    await tr.ResultTask;

                    tr = new TransactionAddStatelessCargo(tempShip, StatelessCargoTypes.Biodome, 666666, true);
                    cargoSynchronizer.RequestTransaction(tr);
                    await tr.ResultTask;

                    Helpers.DebugWarp(s, p, tempShip);

                    ships.Add(tempShip);

                    //Random team assignment
                    switch (npcCount % 2)
                    {
                    case 0:
                        team1.Add(p);
                        break;

                    case 1:
                        team2.Add(p);
                        break;

                    case 2:
                        team3.Add(p);
                        break;
                    }


                    //Give the guy some turrets
                    for (int j = 0; j < _config.NumTurretsPerNPC; j++)
                    {
                        var t = StructureFactory.CreateStructure(StructureTypes.LaserTurret, r.Next(-20, 20),
                                                                 r.Next(-20, 20), p, null, (int)p.CurrentAreaID, locatorService.PlayerLocator, true, dbm);

                        p.GetArea().AddStructure(t);
                    }

                    AddModulesToShip(tempShip, 5, cargoSynchronizer, galaxyIDManager);

                    npcCount++;
                }

                foreach (Planet pl in s.GetPlanets())
                {
                    npcCount = 0;
                    for (int i = 0; i < _config.NumNpcsPerPlanet; i++)
                    {
                        ShipTypes shipType = ShipTypes.Barge;
                        switch (npcCount % 3)
                        {
                        case 0:
                            shipType = ShipTypes.Penguin;
                            break;

                        case 1:
                            shipType = ShipTypes.Barge;
                            break;

                        case 2:
                            shipType = ShipTypes.Reaper;
                            break;
                        }

                        NPCPlayer p = pm.CreateNPCPlayer(locatorService);
                        pm.RegisterPlayer(p);
                        players.Add(p);
                        IShip tempShip = new NPCShip(ShipStatManager.TypeToStats[shipType], locatorService);
                        tempShip.ShipStats.ShieldType = ShieldTypes.QuickRegen;
                        tempShip.Id = IDManager.PopFreeID();
                        rm.RegisterObject(tempShip);
                        p.SetActiveShip(tempShip, MockServer.WarpManager);


                        tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.MissileLauncher));


                        if (shipType == ShipTypes.Reaper)
                        {
                            tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.LaserWave));
                            tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.PlasmaCannon));
                        }
                        else
                        {
                            tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.AltLaser));
                            tempShip.SetWeapon(WeaponManager.GetNewWeapon(WeaponTypes.LaserWave));
                        }



                        TransactionAddStatelessCargo tr = new TransactionAddStatelessCargo(tempShip,
                                                                                           StatelessCargoTypes.AmbassadorMissile, 666666, true);
                        cargoSynchronizer.RequestTransaction(tr);
                        await tr.ResultTask;

                        tr = new TransactionAddStatelessCargo(tempShip, StatelessCargoTypes.Biodome, 666666, true);
                        cargoSynchronizer.RequestTransaction(tr);
                        await tr.ResultTask;

                        tempShip.PosX = r.Next(-20, 20);
                        tempShip.PosY = r.Next(-20, 20);

                        Helpers.DebugWarp(pl, p, tempShip);


                        ships.Add(tempShip);

                        //Random team assignment
                        switch (npcCount % 2)
                        {
                        case 0:
                            team1.Add(p);
                            break;

                        case 1:
                            team2.Add(p);
                            break;

                        case 2:
                            team3.Add(p);
                            break;
                        }



                        AddModulesToShip(tempShip, 5, cargoSynchronizer, galaxyIDManager);

                        npcCount++;
                    }


                    teamManager.DebugCreateNewTeam(team1);
                    teamManager.DebugCreateNewTeam(team2);
                    teamManager.DebugCreateNewTeam(team3);
                }
            }

            return(players);
        }
示例#28
0
        private void LoadSolarSystem()
        {
            _sun = new Sun();

            var mercury = new Mercury();
            var venus   = new Venus();

            var earth = new Earth();
            var moon  = new Moon(earth.Position, earth.Velocity);

            var mars = new Mars();

            var jupiter  = new Jupiter();
            var callisto = new Callisto(jupiter.Position, jupiter.Velocity);
            var europa   = new Europa(jupiter.Position, jupiter.Velocity);
            var ganymede = new Ganymede(jupiter.Position, jupiter.Velocity);
            var io       = new Io(jupiter.Position, jupiter.Velocity);

            var saturn = new Saturn();

            _massiveBodies = new List <IMassiveBody>
            {
                _sun, mercury, venus, earth, moon, mars, jupiter, callisto, europa, ganymede, io, saturn
            };

            ResolveMassiveBodyParents();

            _gravitationalBodies = new List <IGravitationalBody>
            {
                _sun, mercury, venus, earth, moon, mars, jupiter, callisto, europa, ganymede, io, saturn
            };

            _spaceCraftManager = new SpaceCraftManager(_gravitationalBodies);
            _structures        = new List <StructureBase>();

            MissionConfig primaryMission = MissionConfig.Load(ProfilePaths[0]);

            _originTime = primaryMission.GetLaunchDate();

            UpdateLoadingPercentage(20);

            OrbitHelper.SimulateToTime(_massiveBodies, _originTime, 300, UpdateLoadingPercentage);

            UpdateLoadingPercentage(80);

            // Load missions
            for (int i = 0; i < ProfilePaths.Count; i++)
            {
                MissionConfig missionConfig = MissionConfig.Load(ProfilePaths[i]);

                if (missionConfig.ClockDelay > _clockDelay)
                {
                    _clockDelay = missionConfig.ClockDelay;
                }

                IMassiveBody targetPlanet = LocatePlanet(missionConfig.ParentPlanet);

                // Get the launch angle relative to the sun for the given time at the origin
                // and offset each vehicle by a certain amount on the surface
                double launchAngle = targetPlanet.GetSurfaceAngle(_originTime, _sun) + i * 0.00002;

                _spaceCraftManager.Add(SpacecraftFactory.BuildSpaceCraft(targetPlanet, launchAngle, missionConfig, ProfilePaths[i]));

                _structures.AddRange(StructureFactory.Load(targetPlanet, launchAngle, ProfilePaths[i]));
            }

            _spaceCraftManager.Initialize(_eventManager, _clockDelay);

            // Target the spacecraft
            _targetIndex = _gravitationalBodies.IndexOf(_spaceCraftManager.First);

            _spaceCraftManager.ResolveGravitionalParents(_massiveBodies);

            UpdateLoadingPercentage(90);
        }
示例#29
0
        public static OperationOutcome ValidateEntry(ResourceEntry entry)
        {
            OperationOutcome result = new OperationOutcome();

            result.Issue = new List <OperationOutcome.OperationOutcomeIssueComponent>();

            ICollection <ValidationResult> vresults = new List <ValidationResult>();


            // Phase 1, validate against low-level rules built into the FHIR datatypes

            // todo: The API no longer seems to have the FhirValidator class.

            /*
             * (!FhirValidator.TryValidate(entry.Resource, vresults, recurse: true))
             * {
             *  foreach (var vresult in vresults)
             *      result.Issue.Add(createValidationResult("[.NET validation] " + vresult.ErrorMessage, vresult.MemberNames));
             * }
             */

            // Phase 2, validate against the XML schema
            var xml = FhirSerializer.SerializeResourceToXml(entry.Resource);
            var doc = XDocument.Parse(xml);

            doc.Validate(SchemaCollection.ValidationSchemaSet, (source, args) => result.Issue.Add(createValidationResult("[XSD validation] " + args.Message, null)));


            // Phase 3, validate against a profile, if present
            var profileTags = entry.GetAssertedProfiles();

            if (profileTags.Count() == 0)
            {
                // If there's no profile specified, at least compare it to the "base" profile
                string baseProfile = CoreZipArtifactSource.CORE_SPEC_PROFILE_URI_PREFIX + entry.Resource.GetCollectionName();
                profileTags = new Uri[] { new Uri(baseProfile, UriKind.Absolute) };
            }

            var artifactSource = ArtifactResolver.CreateOffline();
            var specProvider   = new SpecificationProvider(artifactSource);

            foreach (var profileTag in profileTags)
            {
                var specBuilder = new SpecificationBuilder(specProvider);
                specBuilder.Add(StructureFactory.PrimitiveTypes());
                specBuilder.Add(StructureFactory.MetaTypes());
                specBuilder.Add(StructureFactory.NonFhirNamespaces());
                specBuilder.Add(profileTag.ToString());
                specBuilder.Expand();

                string path = Directory.GetCurrentDirectory();

                var spec = specBuilder.ToSpecification();
                var nav  = doc.CreateNavigator();
                nav.MoveToFirstChild();

                Report report = spec.Validate(nav);
                var    errors = report.Errors;
                foreach (var error in errors)
                {
                    result.Issue.Add(createValidationResult("[Profile validator] " + error.Message, null));
                }
            }

            if (result.Issue.Count == 0)
            {
                return(null);
            }
            else
            {
                return(result);
            }
        }
示例#30
0
        /// <summary>
        /// Initializes the entire server
        /// </summary>
        private void Initialize()
        {
            for (int i = 0; i < 20; i++)
            {
                msgAvgQue.Enqueue(0);
            }

            var rand = new Random(3);

            // Logging Enabled
            Logger.Initialize();

            _synchronizers = new List <ISynchronizer>();


            //Load configs
            ConnectionManagerConfig connectionManagerConfig = new ConnectionManagerConfig(new CoreNetworkConfig());
            GalacticProperties      galacticProperties      = new GalacticProperties();

            _consoleManager = new ConsoleManager();

            _projectileManager = new ProjectileManager();

            ConsoleManager.WriteLine("Starting database...", ConsoleMessageType.Startup);
            _databaseManager = new MongoDatabaseManager();

            ShipStatManager.ReadShipsFromDBSList(_databaseManager.GetStatsFromDBAsync().Result);
            ConsoleManager.WriteLine("Ship types loaded.", ConsoleMessageType.Startup);

            RedisConfig rc = new RedisConfig();

            _redisServer = new RedisServer(LogRedisError, LogRedisInfo, rc.Address);

            var slaveId = SlaveServerConfigService.GetFreeSlaveID(_redisServer).Result;

            _slaveServerConfigService = new SlaveServerConfigService(_redisServer, slaveId);

            _masterServerManager = new MasterServerManager(new MasterServerConfig(), new GalacticProperties(), _databaseManager, _databaseManager, _redisServer, _slaveServerConfigService);

            _cargoSynchronizer = new CargoSynchronizer();
            _synchronizers.Add(_cargoSynchronizer);

            connectionManagerConfig.MyConfig.Port = ConnectionManager.GetFreePort(28002, 28010);
            _connectionManager = new ConnectionManager();
            _connectionManager.Initialize(connectionManagerConfig);

            //Poll to listen to Lidgren until it is ready
            //LidgrenMessagePoller_Init initializationPoller = new LidgrenMessagePoller_Init(_connectionManager.Server, this);
            //initializationPoller.Poll();

            _galaxyIDManager      = new LocalIDManager(_masterServerManager, IDTypes.GalaxyID);
            _teamIDManager        = new LocalIDManager(_masterServerManager, IDTypes.TeamID);
            _accountIDManager     = new LocalIDManager(_masterServerManager, IDTypes.AccountID);
            _transactionIDManager = new LocalIDManager(_masterServerManager, IDTypes.TransactionID);

            _accountManager = new AccountManager(_accountIDManager, _databaseManager);

            _messageManager = new MessageManager(_connectionManager);

            _clientUpdateManager = new ClientUpdateManager(_playerManager);

            _playerManager = new PlayerManager(_databaseManager, _connectionManager, _redisServer, _galaxyIDManager, _clientUpdateManager);

            var chatCommands = new List <IChatCommand>()
            {
                new HelpCommand(),
                new ShoutCommand(_redisServer),
                new RadioCommand(),
                new TellCommand(_playerManager)
            };

            var asyncChatCommands = new List <IAsyncChatCommand>()
            {
                new AdminWarpCommand(_databaseManager, _redisServer, new Random())
            };

            _teamManager = new GlobalTeamManager(_teamIDManager, _connectionManager, _redisServer, _playerManager, _databaseManager);

            _galaxyManager = new GalaxyManager(galacticProperties.SolID, _teamManager);

            _chatManager = new ChatManager(chatCommands, asyncChatCommands, _playerManager, _messageManager, _redisServer);

            _warpManager = new WarpManager(_galaxyManager, _messageManager, _chatManager, _redisServer, _accountManager, _databaseManager);

            _shipManager = new ShipManager(_messageManager, _galaxyManager, _warpManager, _connectionManager, _databaseManager);

            _structureManager = new StructureManager(_databaseManager, _galaxyManager, _galaxyIDManager, _cargoSynchronizer);

            loginManager = new LoginManager(_accountManager, _playerManager, _connectionManager, _redisServer);

            // Todo: Convert everything over to ServerNetworkMessage to propogate full request context.
            _simulatorManager = new SimulatorManager(new SimulatorConfig(), _redisServer, (sender, container) => ProcessMessage(sender, new ServerNetworkMessage(container, null)));

            StructureStatManager.Initialize();

            ConsoleManager.WriteLine("Completed Initialization", ConsoleMessageType.Startup);

            _economyManager      = new EconomyManager(_transactionIDManager, _playerManager, _galaxyManager, _cargoSynchronizer, _shipManager, _databaseManager, _masterServerManager);
            _killManager         = new KillManager(_cargoSynchronizer, _playerManager, _galaxyManager, _messageManager, _connectionManager, _warpManager, _chatManager, _economyManager);
            _collisionManager    = new CollisionManager(_galaxyManager, _messageManager, _killManager, _projectileManager);
            _registrationManager = new GalaxyRegistrationManager(_galaxyManager, _shipManager, _collisionManager, _galaxyIDManager, _playerManager, _accountManager, _cargoSynchronizer, _structureManager);
            _warpManager.SetRegistrationManager(_registrationManager);//Gross, I know.
            _locatorService   = new LocatorService(_registrationManager, _playerManager, _galaxyManager, _shipManager, _accountManager, _teamManager, _teamManager, _messageManager, _structureManager, _masterServerManager);
            _msMessageHandler = new MasterServerMessageHandler((int)_masterServerManager.SlaveID, _redisServer, _connectionManager, _locatorService, _accountManager, _accountIDManager, _databaseManager, _galaxyManager, _galaxyIDManager, _playerManager, _shipManager, _registrationManager, _teamIDManager, _messageManager, _teamManager, _warpManager, _transactionIDManager, ProcessRoutedMessage);

            StructureFactory.Initialize(_galaxyIDManager, _registrationManager);
            ColonyFactory.Initialize(_galaxyIDManager, _registrationManager);

            dbSyncer = new DBSyncer(_databaseManager, _galaxyManager, _shipManager, _playerManager, _accountManager, _structureManager);

#if DEBUG
            _typesToExcludeIgnore.Add(MessageTypes.PositionUpdateData);
            _typesToExcludeIgnore.Add(MessageTypes.ShipFireRequest);
            _typesToExcludeIgnore.Add(MessageTypes.ProjectileCollisionReport);
            _typesToExcludeIgnore.Add(MessageTypes.StructureFireRequest);
            _typesToExcludeIgnore.Add(MessageTypes.ObjectPickupRequest);
#endif
        }
示例#31
0
        public void Ctor_CreateInstance_IsNotNull()
        {
            var obj = new StructureFactory();

            Assert.That(obj, Is.Not.Null);
        }