Пример #1
0
        public State RegisterHost(Host host)
        {
            //bool exist = false;

            HostRepository hostRepo = new HostRepository();
            //var hosts = hostRepo.GetAll();

            //foreach(var h in hosts)
            //{
            //    if (h.Ip == host.Ip && h.Port == host.Port)
            //    {
            //        exist = true;
            //    }
            //}

            //if (exist)
            //{
            //    return new State() {IsError = true, Message = "Host is already registred!" };
            //}

            //string id = Guid.NewGuid().ToString();
            HostEntity entity = new HostEntity {
                HostId = host.Id, Ip = host.Ip, Port = host.Port, IsBusy = host.IsBusy
            };

            hostRepo.Create(entity);
            //hostRepo.Save();

            return(new State()
            {
                IsError = false, Message = "id"
            });
        }
Пример #2
0
        private void SaveHostImages(OrganizationRoleUser organizationRoleUser)
        {
            var hostImagesToSave = new List <HostImage>();

            int counter = 1;

            counter = UploadHostImage(HostImageUploader1, counter, hostImagesToSave);
            counter = UploadHostImage(HostImageUploader2, counter, hostImagesToSave);
            counter = UploadHostImage(HostImageUploader3, counter, hostImagesToSave);
            counter = UploadHostImage(HostImageUploader4, counter, hostImagesToSave);
            counter = UploadHostImage(HostImageUploader5, counter, hostImagesToSave);

            hostImagesToSave.ForEach(hostImage =>
            {
                hostImage.UploadedBy = organizationRoleUser;
                hostImage.UploadedOn = DateTime.Now;
            });

            IHostRepository hostRepository = new HostRepository();

            if (hostImagesToSave.Count > 0)
            {
                hostRepository.SaveHostImages(HostId, hostImagesToSave);
            }
        }
Пример #3
0
        /// <summary>
        /// 删除用户已获取的主机列表中的数据
        /// </summary>
        /// <param name="cachePageId">当前用户获取的主机列表缓存页主键</param>
        /// <param name="Ids">准备被删除的主键集合</param>
        /// <returns></returns>
        public OperationResult DeleteHosts(Guid[] cachePageId, params Guid[] Ids)
        {
            int count = 0;

            HostRepository.UnitOfWork.BeginTransaction();
            foreach (var i in Ids)
            {
                if (!cachePageId.Contains(i))
                {
                    throw new Exception($"id:主机{i}不存在或你未获取过该数据!");
                }

                count += HostRepository.DeleteDirect(i);

                // 删除关联该主机的分组信息
                var ditem1 = DataItemDetailRepository.Entities.FirstOrDefault(m => m.QueryCoding == "GroupType" && m.Index == 0);
                var grous  = GroupControlRepository.TrackEntities.Where(m => m.DataItemDetail_Id == ditem1.Id && m.ObjectId == i).ToList();
                GroupControlRepository.Delete(grous);

                // 删除主机关联的能耗信息
                var ditem2 = DataItemDetailRepository.Entities.FirstOrDefault(m => m.QueryCoding == "ECType" && m.Index == 0);
                var ect    = AnnualElectricityRepository.TrackEntities.Where(m => m.DataItemDetail_Id == ditem2.Id && m.ObjectId == i).ToList();
                AnnualElectricityRepository.Delete(ect);
            }
            HostRepository.UnitOfWork.Commit();
            if (count > 0)
            {
                return(new OperationResult(OperationResultType.Success, $"{count}条数据被删除"));
            }
            else
            {
                return(new OperationResult(OperationResultType.NoChanged, "请求被取消"));
            }
        }
Пример #4
0
 /// <summary>
 /// 添加新的主机信息
 /// </summary>
 /// <param name="cache">当前登录用户的缓存</param>
 /// <param name="belongOrganizeId">当前用户所管理的组织机构ID</param>
 /// <param name="dtos">输入主机信息实体</param>
 /// <returns></returns>
 public OperationResult AddHosts(CacheUser cache, Guid[] belongOrganizeId, params HostInputDto[] dtos) => HostRepository.Insert(dtos,
                                                                                                                                checkAction: m =>
 {
     if (!cache.IsAdministrator)
     {
         if (!belongOrganizeId.Contains(m.Organize_Id))
         {
             throw new Exception($"id:主机{m.FullName}&{m.RegPackage}归属组织机构错误!");
         }
     }
     if (HostRepository.CheckExists(a => a.RegPackage == m.RegPackage))
     {
         throw new Exception($"id:主机{m.RegPackage}已经存在");
     }
 },
                                                                                                                                updateFunc: (dto, entity) =>
 {
     entity.CreatedTime = DateTime.Now;
     entity.HostRealTimeDataMany.Add(new HostRealTimeData
     {
         //在主机实时数据表添加数据
         HostOne    = entity,
         UpdateTime = DateTime.Now,
     });
     return(entity);
 });
Пример #5
0
        public async Task <ApiResponse <List <Module> > > GetRolesPermissions(string[] id, Guid tenantId)
        {
            var modules = await HostRepository.GetAsync <Module>(
                m => m.Pages.SelectMany(p => p.Actions).SelectMany(a => a.AppRoleActions)
                .Any(ar => id.Contains(ar.ApplicationRole.Name) && ar.ApplicationRole.TenantId == tenantId),
                includeProperties : "Pages.Actions.AppRoleActions.ApplicationRole");

            return(ApiResponse <List <Module> > .Success(modules.ToList()));
        }
Пример #6
0
        public MainViewModel()
        {
            repository = new HostRepository();
            Hosts      = repository.GetAll().ToList();

            EditItemCommand   = new RelayCommand <Host>(EditItem);
            AddItemCommand    = new RelayCommand(AddItem);
            RemoveItemCommand = new RelayCommand <Host>(RemoveItem);
            StopItemCommand   = new RelayCommand <Host>(StopItem);
        }
Пример #7
0
        public virtual void SetUp()
        {
            ServiceLocatorInitializer.Init();

            string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
            _configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
                                                    "../../../../app/wrms.Web/NHibernate.config");

            _HostRepository = new HostRepository();
            //_requestRepository = new RequestRepository();
            //_wrmsSystemRepository = new WrmsSystemRepository();
        }
Пример #8
0
        public State PushResult(TaskResult result)
        {
            ResultRepository resultRepo = new ResultRepository();
            HostRepository   hostRepo   = new HostRepository();
            TaskRepository   taskRepo   = new TaskRepository();

            if (resultRepo.Get(result.HostId, result.TaskId, result.PartId) != null)
            {
                return(new State()
                {
                    IsError = true, Message = "Result was already pushed!"
                });
            }
            if (hostRepo.Get(result.HostId) == null)
            {
                return(new State()
                {
                    IsError = true, Message = "There is no any host with this id!"
                });
            }
            if (taskRepo.Get(result.HostId, result.TaskId) == null)
            {
                return(new State()
                {
                    IsError = true, Message = "There is no any task with this id for this host!"
                });
            }

            resultRepo.Create(new TaskResultEntity
            {
                HostId = result.HostId,
                TaskId = result.TaskId,
                PartId = result.PartId,
                //Array = result.Data.Array,
                Height   = result.Data.Height,
                Width    = result.Data.Width,
                StepFrom = result.StepFrom,
                StepTo   = result.StepTo
            });
            resultRepo.Save();

            return(new State()
            {
                IsError = false, Message = "Push was succesed complete!"
            });
        }
Пример #9
0
        public void AttemptLeap(Leaper leaper)
        {
            Event randomEvent;
            Host  randomHost;

            while (true)
            {
                randomEvent = new EventRepository().GetRandom();

                randomHost = new HostRepository().GetRandom();

                bool compareHostAndEventWithLastLeap = isLeapIdentical(randomEvent, randomHost);
                if (!compareHostAndEventWithLastLeap)
                {
                    break;
                }
            }

            var currentDate = CurrentEventDate();

            int eventsDateDifference = DateDistance(currentDate, randomEvent);

            int dailyCostOfTravel = 1000 * eventsDateDifference;

            if (dailyCostOfTravel > _budget)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Not enough funds to leap to that spot in time.\n");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"Your current budget is only ${_budget}. The cost of that leap is {dailyCostOfTravel}.\n");
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                Leap leap = new Leap(randomEvent.Id, leaper.Id, randomHost.Id);
                SubtractFunds(dailyCostOfTravel);
                LeapRepository makeLeap = new LeapRepository();
                makeLeap.Add(leap);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Congrats {leaper.Name}, you have leaped into {randomHost.Name}. You are at {randomEvent.Location} in the year {randomEvent.HistoricalDate.Year}\n");
                Console.ForegroundColor = ConsoleColor.White;

                ButterflyEffect(randomEvent);
            }
        }
Пример #10
0
        public State UnRegisterHost(string id)
        {
            HostRepository hostRepo = new HostRepository();
            var            host     = hostRepo.Get(id);

            if (host != null)
            {
                hostRepo.Delete(id);
                hostRepo.Save();
                return(new State()
                {
                    IsError = false, Message = "Host is disconnected!"
                });
            }
            return(new State()
            {
                IsError = true, Message = "There is no any host with this id!"
            });
        }
Пример #11
0
        public State SaveTask(Task task)
        {
            HostRepository hostRepo = new HostRepository();
            TaskRepository taskRepo = new TaskRepository();

            var host = hostRepo.Get(task.HostId);

            if (host == null)
            {
                return new State {
                           IsError = true, Message = "There is no any host with this id!"
                }
            }
            ;
            if (host.IsBusy)
            {
                return new State {
                           IsError = true, Message = "This host is already busy!"
                }
            }
            ;

            taskRepo.Create(new TaskEntity
            {
                HostId = task.HostId,
                TaskId = task.TaskId,
                //Array = task.Data.Array,
                Height     = task.Data.Height,
                Width      = task.Data.Width,
                StepsCount = task.StepsCount
            });
            taskRepo.Save();

            host.IsBusy = !(host.IsBusy);
            hostRepo.Update(host);
            hostRepo.Save();

            return(new State {
                IsError = false, Message = "Task was saved succesfully!"
            });
        }
    }
}
Пример #12
0
        public HostMutation(HostRepository hostRepo)
        {
            Name = "HostMutation";

            Field <HostGraphType>("modifyStats",
                                  arguments: new QueryArguments(
                                      new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "hostId", Description = "host id"
            },
                                      new QueryArgument <ListGraphType <StatsInputGraphType> > {
                Name = "stats", Description = "stats"
            }
                                      ),
                                  resolve: context => {
                var hostId = context.GetArgument <int>("hostId");
                var stats  = context.GetArgument <List <Domain.Stats> >("stats");
                var host   = hostRepo.ModifyStats(hostId, stats);
                return(host);
            })
            .AddQAPermissions();
        }
Пример #13
0
        public HostQuery(HostRepository hostRepo, IUsersIdentityService accountService)
        {
            Name = "HostQuery";

            Field <ListGraphType <HostGraphType> >("all",
                                                   arguments: ConscienceArguments.PaginationsAndSortingArgument,
                                                   resolve: context => hostRepo.GetAllHosts(accountService.CurrentUser)
                                                   .ApplyPaginationAndOrderBy(context)
                                                   .AvoidLazyLoad(context, h => h.Account, h => h.Notifications, h => h.Characters, h => h.CoreMemory1, h => h.CoreMemory2, h => h.CoreMemory3, h => h.Account, h => h.Account.Device)
                                                   .ToList().Where(h => !accountService.CurrentUser.UserName.Contains("-") || h.Account.UserName.StartsWith(accountService.CurrentUser.UserName.Split('-').First())) //TODO: Remove this line, only to send both runs pre game
                                                   )
            .AddBehaviourAndPlotPermissions();

            Field <HostGraphType>("byId",
                                  arguments: new QueryArguments(
                                      new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id", Description = "host id"
            }
                                      ),
                                  resolve: context => hostRepo.GetById(accountService.CurrentUser, context.GetArgument <int>("id")))
            .AddBehaviourAndPlotPermissions();
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "End of Day Listing";
            if (!IsPostBack)
            {
                IHostRepository hostRepository = new HostRepository();
                var             host           = hostRepository.GetHostForEvent(EventId);

                HostId   = host.Id;
                HostName = host.OrganizationName + ", " + host.Address.State;

                MarkedLaterForHostRanking = false;
                ScreenForHostRanking      = false;
                if (Request.QueryString["HostRanking"] != null)
                {
                    this.Title = "Update Host Ranking";
                    _divSignoffCompleted.Style[HtmlTextWriterStyle.Display] = "none";
                    ScreenForHostRanking = true;
                    LinksEodDiv.Style[HtmlTextWriterStyle.Display] = "none";
                    OpenHostRankingInputBox();
                }
                //else if (Request.QueryString["EventID"] != null)
                //{
                //    FetchList(EventId);

                //    if (Request.QueryString["EventName"] == null)
                //    {
                //        MasterDAL masterDal = new MasterDAL();
                //        EEvent objEvent = masterDal.GetEvent(Request.QueryString["EventID"], "2").FirstOrDefault<EEvent>();
                //        spEventName.InnerHtml = HttpUtility.HtmlEncode(objEvent.Name);
                //    }
                //    else
                //        spEventName.InnerHtml = HttpUtility.HtmlEncode(Request.QueryString["EventName"]);
                //}
            }
        }
Пример #15
0
        public List <HostImage> GetHostImages(long hostId)
        {
            IHostRepository hostRepository = new HostRepository();

            return(hostRepository.GetHostImages(hostId));
        }
Пример #16
0
 public HostService(HostRepository hostRepo)
 {
     _hostRepo = hostRepo;
 }
Пример #17
0
 public HostViewModel(Host model = null)
 {
     repository  = new HostRepository();
     Model       = model;
     SaveCommand = new RelayCommand(Save);
 }
Пример #18
0
 public HostController(HostRepository repository)
 {
     this.repository = repository;
 }
Пример #19
0
        static void Main(string[] args)
        {
            var budget = new Budget();

            var eventRepository = new EventRepository();

            eventRepository.PopulateEvents();

            var hostRepository = new HostRepository();

            hostRepository.CreateSeedDataHosts();

            var currentLeaper = new Leaper("Zack Taylor");

            var leapRepository = new LeapRepository();

            var action = "";

            do
            {
                Console.WriteLine("What do you want to do? [leap/fund/get history/exit]");
                action = Console.ReadLine();
                // leap
                if (action == "leap")
                {
                    if (budget.CheckBudget())
                    {
                        leapRepository.TakeALeap(currentLeaper, hostRepository, eventRepository);
                        var newLeapComplete = leapRepository.ReturnLastLeap();
                        Console.WriteLine($"Leap complete. You were hosted by " +
                                          $"{newLeapComplete.Host.Name} and you went to {newLeapComplete.Event.Location}.");
                    }
                    else
                    {
                        Console.WriteLine($"You need to add funds.");
                    }
                }

                // fund
                if (action == "fund")
                {
                    budget.AddFunds();
                    Console.WriteLine("You added $5000 to your budget");
                }

                // get history
                if (action == "get history")
                {
                    var leapHistory = leapRepository.GetLeapHistory(currentLeaper);
                    int leapCounter = 1;

                    foreach (var leap in leapHistory)
                    {
                        Console.WriteLine(leapCounter);
                        Console.WriteLine($"Location: {leap.Event.Location}");
                        Console.WriteLine($"Date: {leap.Event.Date.ToString("MM/dd/yyyy")}");
                        Console.WriteLine($"Leaper: {leap.Leaper.Name}");
                        Console.WriteLine($"Host: {leap.Host.Name}");
                        Console.WriteLine("");

                        leapCounter++;
                    }
                }
            } while (action != "exit");
        }
Пример #20
0
 public HostController(HostRepository repo)
 {
     _repo = repo;
 }
Пример #21
0
 /// <summary>
 /// 修改主机基本信
 /// </summary>
 /// <param name="cachePageId">当前用户获取的主机列表缓存页主键</param>
 /// <param name="dtos">输入信息实体模型</param>
 /// <returns></returns>
 public OperationResult EditHosts(Guid[] cachePageId, params HostInputDto[] dtos) => HostRepository.Update(dtos,
                                                                                                           checkAction: (dto, entity) =>
 {
     if (!(cachePageId.Contains(dto.Id)))
     {
         throw new Exception($"id:主机{dto.FullName}&{dto.RegPackage}不存在或你未获取过该数据!");
     }
 },
                                                                                                           updateFunc: (dto, entity) =>
 {
     //var value = dto.MapTo<Host>();
     //value.CreatedTime = entity.CreatedTime;
     return(entity);
 });
Пример #22
0
 public PlayerController(HostRepository repo)
 {
     _repo = repo;
 }