public void ConstructInstanceFactory()
        {
            // Setup
            var instance = new object();
            var instanceService = new InstanceService(typeof(object), instance);

            // Execute
            var factory = new InstanceFactory(instanceService);
        }
        public void CheckDependencyComplexity()
        {
            // Setup
            var instance = new object();
            var instanceService = new InstanceService(typeof(object), instance);
            var factory = new InstanceFactory(instanceService);

            // Assert
            Assert.AreEqual(0, factory.DependencyComplexity);
        }
        public void CheckCanCreate()
        {
            // Setup
            var instance = new object();
            var instanceService = new InstanceService(typeof(object), instance);
            var factory = new InstanceFactory(instanceService);

            // Assert
            Assert.IsTrue(factory.CanCreate);
        }
        public void CheckDependencies()
        {
            // Setup
            var instance = new object();
            var instanceService = new InstanceService(typeof(object), instance);
            var factory = new InstanceFactory(instanceService);

            // Assert
            Assert.IsNotNull(factory.Dependencies);
            Assert.AreEqual(0, factory.Dependencies.Length);
        }
        public void CreateServiceInstance()
        {
            // Setup
            var instance = new object();
            var instanceService = new InstanceService(typeof(object), instance);
            var factory = new InstanceFactory(instanceService);

            // Execute
            var result = factory.Create();

            // Assert
            Assert.AreSame(instance, result);
        }
Exemple #6
0
 private void CheckPlayers()
 {
     lock (Players)
     {
         for (int i = 0; i < Players.Count; i++)
         {
             if (Players[i].IsDisposed)
             {
                 Players.RemoveAt(i);
                 InstanceService.SavePlayerIDs(ZoneID + ":" + ID, Players);
             }
         }
     }
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_instanceServiceService">Instance.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_instanceServiceService"/> is null.</exception>
        public InstanceFactory(InstanceService a_instanceServiceService)
        {
            #region Argument Validation

            if (a_instanceServiceService == null)
                throw new ArgumentNullException(nameof(a_instanceServiceService));

            #endregion

            _instanceService = a_instanceServiceService;
            DependencyComplexity = 0;
            Dependencies = new Dependency[0];
            CanCreate = true;
        }
Exemple #8
0
        public async Task DescribeInstancesAsync_when_any_exist_should_describe_instances()
        {
            // Arrange
            var client = new EnvironmentVariables().CloudComputeClient();
            IInstanceService classUnderTest = new InstanceService(client);

            // Act
            var response = await classUnderTest.DescribeInstancesAsync();

            // Assert
            Assert.IsTrue(response.HttpStatusCode == System.Net.HttpStatusCode.OK);

            // Dump response
            new ResponseToJsonFile().Go("Instance_CreatedFromConsole", response);
        }
Exemple #9
0
        static void Main(string[] args)
        {
            //Task 2 - Get instances of Vehicle
            IEnumerable <Vehicle> vehicles = InstanceService.GetInstances <Vehicle>();

            Console.WriteLine("Vehicle names:");
            //Task 3.1 - Writing vehicle types sorted alphabetically
            foreach (var vehicle in vehicles.OrderBy(key => key.Name).Select(v => v))
            {
                Type vehicleType = vehicle.GetType();
                Console.WriteLine(vehicleType.Name);
            }
            //Task 3.2 - Search for types by specifying part of the name
            string partName = "CaR";

            Console.WriteLine("Method for searching types by part of name: {0}", partName);
            IEnumerable <Vehicle> startsWithBiVehicles = vehicles.SearchType(partName);

            foreach (var vehicle in startsWithBiVehicles)
            {
                Type vehicleType = vehicle.GetType();
                Console.WriteLine(vehicleType.Name);
            }
            //Task 3.3 - Save vehicles to disk
            vehicles.WriteInstancesToDisk();
            //Task 4.1 - ReverseString
            string str1 = "1234";

            Console.WriteLine("Reversed string {0}: {1}", str1, MyString.ReverseString(str1));
            Console.WriteLine("Reversed string (extension) {0}: {1}", str1, str1.ReverseString());
            //Task 4.2 - Using IsPalindrome
            str1 = "lol";
            Console.WriteLine("IsPalindrome {0}: {1}", str1, MyString.IsPalindrome(str1));
            Console.WriteLine("IsPalindrome (extension) {0}: {1}", str1, str1.IsPalindrome());
            //Task 4.3 - MissingElements
            int[] inputarr = new int[] { 1, 3, 4 };
            Console.Write("Missing elements for input: ");
            foreach (var item in inputarr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            foreach (var missing in MissingElems.MissingElements(inputarr))
            {
                Console.Write(missing + " ");
            }
            Console.ReadKey();
        }
Exemple #10
0
        public void SaveToJsonFile_ReadJsonString()
        {
            // Arrange
            var persistance = new PersistanceService();
            var service     = new InstanceService();
            var path        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Data.json");

            // Act
            var vehicles = service.GetInstances <IVehicle>();

            persistance.SaveToJson(path, vehicles);
            var expected = JsonConvert.SerializeObject(vehicles);
            var actual   = persistance.GetJsonStringFromFile(path);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public override string Start(string resourceXml)
        {
            Workflow workflow = XMLServiceFactory.Create(resourceXml);
            var      start    = workflow.Nodes.Where(n => n.NodeType == WorkflowNodeCategory.Start).FirstOrDefault();
            IList <Action <ISession, string> > commands = new List <Action <ISession, string> >();

            string callback(ISession session) => InstanceService.CreateInstance(start.ID, resourceXml, (entry) => session.Persist(entry));

            foreach (Node node in workflow.Nodes)
            {
                commands.Add((session, id) =>
                {
                    node.InstanceID = id;
                    base.NodeService.Persistent(node, (entry) => session.Persist(entry));
                });
            }

            return(DbFactory.Execute(DbFactory.OpenSession(), callback, commands));
        }
Exemple #12
0
        public void SearchForCycle_ReturnsBicycleAndMotorcycle()
        {
            // Arrange
            var service    = new InstanceService();
            var searchTerm = "Cycle";

            // Act
            var vehicles   = service.GetInstances <IVehicle>();
            var enumerable = vehicles.ToList();
            var expected   = enumerable.Select(x => x).Where(x => x.GetType().Name == nameof(Bicycle) || x.GetType().Name == nameof(Motorcycle)).ToList();
            var actual     = enumerable.FindElements(inputs =>
            {
                var output = inputs.Where(x => x.GetType().Name.ToLowerInvariant().Contains(searchTerm.ToLowerInvariant()))
                             .ToList();
                return(output);
            }).ToList();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #13
0
        public Instance(ushort zoneid, ushort id, byte realm, Instance_Lockouts lockouts)
        {
            Lockout = lockouts;
            ID      = id;
            ZoneID  = zoneid;
            Realm   = realm;
            Region  = new RegionMgr(zoneid, ZoneService.GetZoneRegion(zoneid), "", new ApocCommunications());
            InstanceService._InstanceInfo.TryGetValue(zoneid, out Info);
            LoadBossSpawns();
            LoadSpawns(); // todo get the saved progress from group
            _running      = true;
            _evtInterface = new EventInterface();
            closetime     = (TCPManager.GetTimeStamp() + 7200);

            // instancing stuff
            InstanceService.SaveLockoutInstanceID(ZoneID + ":" + ID, Lockout);

            new Thread(Update).Start();

            Log.Success("Opening Instance", "Instance ID " + ID + "  Map: " + Info.Name);
            // TOVL
            if (zoneid == 179)
            {
                foreach (var p in GameObjectService.GameObjectSpawns.Where(e => e.Value.ZoneId == 179))
                {
                    if (p.Value.Entry == 98908)
                    {
                        GameObject go = new GameObject(p.Value);

                        _Objects.Add(go);
                        Region.AddObject(go, zoneid, true);
                    }
                }

                if (Info != null && Info.Objects.Count > 0)
                {
                    LoadObjects();
                }
                _evtInterface.AddEvent(UpdatePendulums, 7000, 0);
            }
        }
Exemple #14
0
        public void AddPlayer(Player player, Zone_jump jump)
        {
            lock (Players)
            {
                if (!Players.Contains(player))
                {
                    Players.Add(player);
                }

                player.InstanceID = ZoneID + ":" + ID;

                if (jump != null)
                {
                    player.Teleport(Region, jump.ZoneID, jump.WorldX, jump.WorldY, jump.WorldZ, jump.WorldO);
                }
                else
                {
                    player.Teleport(Region, player._Value.ZoneId, (uint)player._Value.WorldX, (uint)player._Value.WorldY, (ushort)player._Value.WorldZ, (ushort)player._Value.WorldO);
                }

                Region.CheckZone(player);

                InstanceService.SavePlayerIDs(ZoneID + ":" + ID, Players);

                player.SendClientMessage("Instance ID: " + ID, SystemData.ChatLogFilters.CHATLOGFILTERS_TELL_RECEIVE);

                string players = string.Empty;
                foreach (Player plr in Players)
                {
                    players += plr.Name + ",";
                }
                if (players.EndsWith(","))
                {
                    players = players.Substring(0, players.Length - 1);
                }

                player.SendClientMessage("Registered players: " + players, SystemData.ChatLogFilters.CHATLOGFILTERS_TELL_RECEIVE);
                player.SendClientMessage("Note: Wait for your party leader to get into the instance if you find yourself in another instance ID.", SystemData.ChatLogFilters.CHATLOGFILTERS_TELL_RECEIVE);
            }
        }
Exemple #15
0
        public void ApplyLockout(List <Player> subGroup)
        {
            if (Lockout == null) // instance hasn't got any lockouts
            {
                Lockout = new Instance_Lockouts
                {
                    InstanceID   = "~" + ZoneID + ":" + (TCPManager.GetTimeStamp() + Info.LockoutTimer * 60),
                    Bosseskilled = CurrentBossId.ToString()
                };
                InstanceService._InstanceLockouts.Add(Lockout.InstanceID, Lockout);
                Lockout.Dirty = true;
                WorldMgr.Database.AddObject(Lockout);
                InstanceService.SaveLockoutInstanceID(ZoneID + ":" + ID, Lockout);
            }
            else             // instance has got already lockouts
            {
                List <string> bossList = Lockout.Bosseskilled.Split(':').Distinct().ToList();
                if (!bossList.Contains(CurrentBossId.ToString()))
                {
                    bossList.Add(CurrentBossId.ToString());
                }
                Lockout.Bosseskilled = string.Empty;
                foreach (string boss in bossList)
                {
                    Lockout.Bosseskilled += ":" + boss;
                }
                if (Lockout.Bosseskilled.StartsWith(":"))
                {
                    Lockout.Bosseskilled = Lockout.Bosseskilled.Substring(1);
                }
                Lockout.Dirty = true;
                WorldMgr.Database.SaveObject(Lockout);
            }

            foreach (Player pl in subGroup)
            {
                pl._Value.AddLockout(Lockout);
                pl.SendLockouts();
            }
        }
        private void LoadInstances()
        {
            this.Busy        = true;
            this.BusyContent = "Loading instances";

            try
            {
                var response = InstanceService.GetAllDbInstances();
                if (response != null)
                {
                    Instances = new ObservableCollection <string>(response);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error when loading instances. " + ex.Message, "Load instances", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                this.Busy = false;
            }
        }
        public async void ExecuteDeleteInstanceCommand(object parameter)
        {
            if (MessageBox.Show("Are you sure that you want to delete the instance " + SelectedInstance + Environment.NewLine + "This will remove all data in th instance and can not be undone.", "Delete instance", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                this.Busy        = true;
                this.BusyContent = "Deleting instanse " + SelectedInstance;

                try
                {
                    await Task.Factory.StartNew(() =>
                    {
                        if (InstanceService.DeleteInstance(SelectedInstance))
                        {
                            LoadInstances();
                        }
                    });
                }
                finally
                {
                    this.Busy = false;
                }
            }
        }
Exemple #18
0
        public void GetInstancesTest()
        {
            InstanceService <Vehicle> instanceService = new InstanceService <Vehicle>();
            var         instances = instanceService.GetInstances();
            List <Type> expected  = new List <Type>()
            {
                typeof(VehicleHotAirBalloon), typeof(VehicleSkateboard), typeof(VehicleTank), typeof(VehicleTeleporter)
            };

            if (instances.Count() != expected.Count)
            {
                Assert.IsFalse(true, "Incorrect number of results found");
                return;
            }
            foreach (Type item in instances)
            {
                if (!expected.Contains(item))
                {
                    Assert.IsFalse(true, "Found result not supposed to be there");
                    return;
                }
            }
            Assert.IsFalse(false, "All expected elements found");
        }
Exemple #19
0
        private static BootstrapData BootstrapApplication()
        {
            // If we're not on EC2, then we'll not even try bootstrapping the application.
            if (!IsEc2)
            {
                return(null);
            }

            // Uses ambient AWS credentials, probably from an IAM role.
            // This should be exactly the same as just creating the clients without passing the credentials.
            // It is left explicit to guarantee the same algorithm is used to get credentials here as it is
            // in Startup.Autofac.cs.
            AWSCredentials credentials = AmbientCredentials.GetCredentials();
            IAmazonEC2     ec2Client   = AWSClientFactory.CreateAmazonEC2Client(credentials);
            IAmazonS3      s3Client    = AWSClientFactory.CreateAmazonS3Client(credentials);

            var instanceService = new InstanceService(ec2Client);
            var storageService  = new StorageService(s3Client, new S3PathParser());
            var metadataService = new MetadataService();

            var bootstrapper = new ApplicationBootstrapper(instanceService, storageService, metadataService);

            return(bootstrapper.BootstrapApplication());
        }
Exemple #20
0
 /// <summary>
 /// 禁用申请单
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool ForbidInstance(ref Model.Instanceforbid model, out string errMsg)
 {
     return(InstanceService.ForbidInstance(ref model, out errMsg));
 }
Exemple #21
0
 /// <summary>
 /// 审核申请单
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool CheckInstance(ref Model.Instancecheck model, out string errMsg)
 {
     return(InstanceService.CheckInstance(ref model, out errMsg));
 }
Exemple #22
0
 /// <summary>
 /// 归档申请单
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool ArchiveInstance(ref Model.Instancearchive model, out string errMsg)
 {
     return(InstanceService.ArchiveInstance(ref model, out errMsg));
 }
Exemple #23
0
 /// <summary>
 /// 取回申请单
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool RecaptureTrace(ref Model.Tracerecapture model, out string errMsg)
 {
     return(InstanceService.RecaptureTrace(ref model, out errMsg));
 }
Exemple #24
0
 /// <summary>
 /// 新建申请单履历
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool AddTrace(ref Model.Tracenew model, out string errMsg)
 {
     return(InstanceService.AddTrace(ref model, out errMsg));
 }
        public void FulfillFuncFactory()
        {
            // Setup
            var instance = new object();
            var instanceService = new InstanceService(typeof(object), instance);
            var factory = new InstanceFactory(instanceService);
            var container = new Container();

            // Execute
            var result = factory.Fulfill(container);

            // Assert
            Assert.IsTrue(result);
        }
        private void WithService(Action<Mocks> mocksAction, Action<IInstanceService, MockLogger, Mocks> action)
        {
            Mocks mocks = new Mocks()
            {
                InstanceRepository = new Mock<IInstanceRepository>(),
                InstanceUserRepository = new Mock<IInstanceUserRepository>(),
                UserRepository = new Mock<IUserRepository>(),
                UserInstanceRepository = new Mock<IUserInstanceRepository>()
            };

            mocksAction(mocks);

            MockLogger logger = new MockLogger();

            IInstanceService service = new InstanceService(
                mocks.InstanceRepository.Object,
                mocks.InstanceUserRepository.Object,
                mocks.UserRepository.Object,
                mocks.UserInstanceRepository.Object,
                logger.Logger);

            action(service, logger, mocks);
        }
Exemple #27
0
 /// <summary>
 /// 获取车辆申请单
 /// </summary>
 /// <param name="car"></param>
 /// <param name="count"></param>
 /// <param name="lastId"></param>
 /// <param name="errMsg"></param>
 /// <returns></returns>
 public static IList <Model.Instance> GetInstancesByCar(int car, int count, int lastId, out string errMsg)
 {
     return(InstanceService.GetInstancesByCar(car, count, lastId, out errMsg));
 }
Exemple #28
0
        public static void F_INIT_PLAYER(BaseClient client, PacketIn packet)
        {
            GameClient cclient = (GameClient)client;

            Player Plr = cclient.Plr;

            if (Plr == null)
            {
                return;
            }

            // clear all lockouts if they are expired
            InstanceService.ClearLockouts(Plr);

            if (!Plr.IsInWorld()) // If the player is not on a map, then we add it to the map
            {
                ushort zoneId   = Plr.Info.Value.ZoneId;
                ushort regionId = (ushort)Plr.Info.Value.RegionId;

                Zone_Info info = ZoneService.GetZone_Info(zoneId);
                if (info?.Type == 0)
                {
                    RegionMgr region = WorldMgr.GetRegion(regionId, true);
                    if (region.AddObject(Plr, zoneId, true))
                    {
                        return;
                    }
                }
                else if (info?.Type == 4 || info?.Type == 5 || info?.Type == 6)  // login into a instance results in teleport outside
                {
                    if (InstanceService._InstanceInfo.TryGetValue(zoneId, out Instance_Info II))
                    {
                        Zone_jump ExitJump = null;
                        if (Plr.Realm == Realms.REALMS_REALM_ORDER)
                        {
                            ExitJump = ZoneService.GetZoneJump(II.OrderExitZoneJumpID);
                        }
                        else if (Plr.Realm == Realms.REALMS_REALM_DESTRUCTION)
                        {
                            ExitJump = ZoneService.GetZoneJump(II.DestrExitZoneJumpID);
                        }

                        if (ExitJump == null)
                        {
                            Log.Error("Exit Jump in Instance", " " + zoneId + " missing!");
                        }
                        else
                        {
                            Plr.Teleport(ExitJump.ZoneID, ExitJump.WorldX, ExitJump.WorldY, ExitJump.WorldZ, ExitJump.WorldO);
                        }
                    }
                    return;
                }

                // Warp a player to their bind point if they attempt to load into a scenario map.
                RallyPoint rallyPoint = RallyPointService.GetRallyPoint(Plr.Info.Value.RallyPoint);

                if (rallyPoint != null)
                {
                    Plr.Teleport(rallyPoint.ZoneID, rallyPoint.WorldX, rallyPoint.WorldY, rallyPoint.WorldZ, rallyPoint.WorldO);
                }
                else
                {
                    CharacterInfo cInfo = CharMgr.GetCharacterInfo(Plr.Info.Career);
                    Plr.Teleport(cInfo.ZoneId, (uint)cInfo.WorldX, (uint)cInfo.WorldY, (ushort)cInfo.WorldZ,
                                 (ushort)cInfo.WorldO);
                }
            }
            else
            {
                Plr.Loaded = false;
                Plr.StartInit();
            }
        }
 public void ExecuteCancelSpisInstanceSettingsCommand(object parameter)
 {
     SpisInstanceSettings = InstanceService.GetSpisInstanceSettings(SelectedInstance);
 }
Exemple #30
0
 /// <summary>
 /// 启用申请单
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool EnableInstance(ref Model.Instanceenable model, out string errMsg)
 {
     return(InstanceService.EnableInstance(ref model, out errMsg));
 }
Exemple #31
0
 /// <summary>
 /// 获取单个申请单
 /// </summary>
 /// <param name="id"></param>
 /// <param name="errMsg"></param>
 /// <returns></returns>
 public static Model.Instance GetInstanceById(int id, out string errMsg)
 {
     return(InstanceService.GetInstanceById(id, out errMsg));
 }
Exemple #32
0
 /// <summary>
 /// 中止申请单
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool AbortInstance(ref Model.Instanceabort model, out string errMsg)
 {
     return(InstanceService.AbortInstance(ref model, out errMsg));
 }
Exemple #33
0
 /// <summary>
 /// 一键优化
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool OneTouchOptimize(ref Model.Optimizer model, out string errMsg)
 {
     return(InstanceService.OneTouchOptimize(ref model, out errMsg));
 }
Exemple #34
0
        public override string Start(string resourceXml)
        {
            Workflow workflow = XMLServiceFactory.Create(resourceXml);
            var      start    = workflow.Nodes.Where(n => n.NodeType == WorkflowNodeCategory.Start).FirstOrDefault();

            IList <Action <IDbConnection, IDbTransaction, string> > commands = new List <Action <IDbConnection, IDbTransaction, string> >();
            Func <IDbConnection, IDbTransaction, string>            callback = (connection, transaction) => InstanceService.CreateInstance(start.ID, resourceXml, workflow.Mode, (command, entry) => connection.Execute(command, entry, transaction));

            foreach (Node node in workflow.Nodes)
            {
                commands.Add((connection, transaction, id) =>
                {
                    node.InstanceID = id;
                    base.NodeService.Persistent(node, (command, entry) => connection.Execute(command, entry, transaction));
                });
            }

            return(DbFactory.Execute(callback, commands));
        }
Exemple #35
0
        static void saveInstances(string filePath)
        {
            var instances = new InstanceService().GetInstances <Vehicle>().ToList();

            WriteToJsonFile(filePath, instances);
        }