예제 #1
0
        public async Task StartAsync()
        {
            if (IsStarted)
            {
                return;
            }

            Log.Information("Starting service...");
            await DoWork(async() =>
            {
                var hardwareConfig = m_ConfigService.LoadHardwareConfig("hardware.xml");
                if (await m_Automation.FindDevicesAsync(hardwareConfig))
                {
                    m_ConfigService.SaveHardwareConfig("hardware.xml", hardwareConfig);
                    Log.Information("Hardware configuration updated");
                }

                var deviceInfo = m_Automation.GetDeviceInfo();
                Log.Information("Found devices: {Count}", deviceInfo.Count);
                foreach (var info in deviceInfo)
                {
                    Log.Information("{Name} - {Device}", info.Name, info.Device);
                }

                var automationConfig = m_ConfigService.LoadAutomationConfig("automation.xml");
                m_Automation.Start(automationConfig);
                IsStarted = true;

                m_HomeConfig = m_ConfigService.LoadHomeConfig("home.xml");
            });

            Log.Information("Service has started");
        }
예제 #2
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            HomeConfig config = await this.configService.GetConfigAsync <HomeConfig>();

            this.ViewData["_SiteFooter"] = config.SiteFooter;
            return(View());
        }
예제 #3
0
 public void Init()
 {
     ctx  = EFContext.CreateContext();
     repo = new HomeConfigRepository(ctx);
     using (UserManager <Client, int> manager = new ClientUserManager(new CustomUserStore(ctx)))
     {
         entity = new HomeConfig()
         {
             Home = new Home()
             {
                 Title             = "LaCorderieTest",
                 EstablishmentType = EEstablishmentType.BB,
                 Client            = manager.FindByEmail("*****@*****.**"),
             },
             AutoSendSatisfactionEmail = false,
             DepositNotifEnabled       = false,
             Devise                  = "$",
             EnableDinner            = false,
             EnableDisplayActivities = false,
             EnableDisplayMeals      = false,
             EnableDisplayProducts   = false,
             EnableDisplayRooms      = false,
             EnableReferencing       = false,
             FollowStockEnable       = false,
             HourFormat24            = true
         };
     }
     repo.Add(entity);
     repo.Save();
 }
예제 #4
0
        public bool AddHome(IPlayer player, Home home)
        {
            var    uuid       = player.Uuid;
            var    name       = uuid.ToString().Replace("-", "");
            var    homeLoc    = Globals.Files.PlayerHome(uuid);
            string logMessage = null;

            try
            {
                Globals.Logger.Log($"§7[Config]{ChatColor.Reset} Creating home named §9{name.ToLower()}{ChatColor.Reset}...");
                if (!Globals.FileWriter.FileExists(homeLoc))
                {
                    logMessage = $"§7[Config]{ChatColor.Reset} Warp named {ChatColor.BrightGreen}{name.ToLower()}{ChatColor.Reset} successfully created";
#if DEBUG || SNAPSHOT
                    logMessage += $" on location {ChatColor.BrightGreen}{homeLoc}";
#endif
                    logMessage += ".";
                    var homes = new HomeConfig
                    {
                        home
                    };
                    PlayerHomes.Add(uuid, homes);
                    Globals.FileWriter.WriteAllText(homeLoc, JsonSerializer.Serialize(PlayerHomes[uuid], Globals.JsonSerializerOptions));
                    Globals.Logger.Log(logMessage);
                }
                else //if (executor.HasPermission("essentials.who.knows.what.the.perm.for.it"))
                {
                    logMessage = $"§7[Config]{ChatColor.Reset} Warp named {ChatColor.BrightGreen}{name.ToLower()}{ChatColor.Reset} successfully overwritten by {ChatColor.BrightGreen}{player.Username}{ChatColor.Reset}.";
#if DEBUG || SNAPSHOT
                    logMessage += $" home location: {ChatColor.BrightGreen}{homeLoc}{ChatColor.Reset}";
#endif
                    Globals.Logger.Log(logMessage);
#if DEBUG || SNAPSHOT
                    logMessage = $"{ChatColor.BrightGreen}{player.Username}{ChatColor.Reset}'s home list previously had §b{PlayerHomes[uuid].Count}{ChatColor.Reset} home{(PlayerHomes[uuid].Count > 1 ? "s" : "")}, ";
#endif
                    PlayerHomes[uuid].Add(home);
                    Globals.FileWriter.WriteAllText(homeLoc, JsonSerializer.Serialize(PlayerHomes[uuid], Globals.JsonSerializerOptions));
#if DEBUG || SNAPSHOT
                    logMessage += $"now it has §e{PlayerHomes[uuid].Count}{ChatColor.Reset}.";
                    Globals.Logger.LogDebug(logMessage);
#endif
                }
            }
            catch (Exception ex)
            {
                logMessage = $"§7[Config]{ChatColor.Reset} Creating warp named {ChatColor.Red}{name.ToLower()}{ChatColor.Reset}";
#if DEBUG || SNAPSHOT
                logMessage += $", location: {ChatColor.Red}{homeLoc}{ChatColor.Reset}";
#endif
                logMessage += $" thrown an unexpected exception during execution. The exception is the following:\r\n{ChatColor.Red}{ex}";

                Globals.Logger.LogError(logMessage);

                return(false);
            }
            return(true);
        }
예제 #5
0
 /// <summary>
 /// 设置首页选项
 /// </summary>
 public async Task <int> SetHomeConfigAsync(HomeConfig config)
 {
     if (config == null)
     {
         throw new ArgumentNullException(nameof(config));
     }
     using (var work = this.DbFactory.StartWork())
     {
         return(await work.Config.SetHomeConfigAsync(config));
     }
 }
예제 #6
0
        public void ConfigTest2ValuesEqualsOnOtherSide()
        {
            var    conf     = new HomeConfig();
            string filename = "test.json";

            conf.AppFoldername = "HomeConfigLibraryTests";
            string[] paramList = { "--config", $"={filename}" };
            var      result    = conf.ExtractParams(paramList);

            Assert.AreEqual(filename, conf.ParamConfigFile);
            Assert.AreEqual(0, result.Length);
        }
예제 #7
0
        public void ConfigTest1ValueExtraArgs()
        {
            var    conf     = new HomeConfig();
            string filename = "test.json";

            conf.AppFoldername = "HomeConfigLibraryTests";
            string[] paramList = { "arg0", $"--config={filename}", "arg1" };
            var      result    = conf.ExtractParams(paramList);

            Assert.AreEqual(filename, conf.ParamConfigFile);
            Assert.AreEqual(2, result.Length);
            Assert.AreEqual("arg0", result[0]);
            Assert.AreEqual("arg1", result[1]);
        }
예제 #8
0
        public OverlayForm(HomeForm parent)
        {
            //get home screen object
            HOMEFORM = parent;
            //set current form as object
            OVERLAYFORM = this;

            InitializeComponent();

            HomeConfig temp = HOMEFORM.CONFIG_FILE.homeButtonConfig;

            //set home button image
            HomeButton.Image  = Image.FromFile(Path.Combine(HOMEFORM.CONFIG_FILE.resourceFolder, temp.backgroundImageName));
            HomeButton.Click += HomeButton_Click;
            HomeButton.Paint += ButtonText_Paint;

            //set button size
            OVERLAYFORM.Size = new Size(temp.buttonWidth, temp.buttonHeight);

            HomeButton.Size = new Size(temp.buttonWidth, temp.buttonHeight);
            //move home button to position
            Rectangle workingArea = Screen.GetWorkingArea(OVERLAYFORM);

            if (temp.buttonPosition == "TOPRIGHT")
            {
                OVERLAYFORM.Location = new Point(workingArea.Right - temp.buttonWidth - temp.buttonPaddingHorizontal, workingArea.Top + temp.buttonPaddingVertical);
            }
            else if (temp.buttonPosition == "TOPLEFT")
            {
                OVERLAYFORM.Location = new Point(workingArea.Left + temp.buttonPaddingHorizontal, workingArea.Top + temp.buttonPaddingVertical);
            }
            else if (temp.buttonPosition == "BOTTOMRIGHT")
            {
                OVERLAYFORM.Location = new Point(workingArea.Right - temp.buttonWidth - temp.buttonPaddingHorizontal, workingArea.Bottom - temp.buttonHeight - temp.buttonPaddingVertical);
            }
            else if (temp.buttonPosition == "BOTTOMLEFT")
            {
                OVERLAYFORM.Location = new Point(workingArea.Left + temp.buttonPaddingHorizontal, workingArea.Bottom - temp.buttonHeight - temp.buttonPaddingVertical);
            }

            //timeout config
            TIMEOUT = HOMEFORM.CONFIG_FILE.timeoutTime;
            MAXIDLE = HOMEFORM.CONFIG_FILE.idleTimeout / IDLEINTERVAL;

            //set idle check hooks
            _proc       = HookCallback;
            kh.KeyDown += Kh_KeyDown;
            _hookID     = SetHook(_proc);
        }
예제 #9
0
 public NeonConfig()
 {
     Database           = new DatabaseConfig();
     Scripts            = new ScriptConfig();
     Mqtt               = new MqttConfig();
     Plugins            = new PluginConfig();
     Tasks              = new TaskConfig();
     FileSystem         = new FileSystemConfig();
     Components         = new ComponentConfig();
     EventsDatabase     = new EventDatabaseConfig();
     IoT                = new IoTConfig();
     JwtToken           = "password";
     AutoLoadComponents = true;
     Home               = new HomeConfig();
 }
예제 #10
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            HomeConfig config = await this.configService.GetHomeConfigAsync();

            string url = this.HttpContext.Request.GetEncodedUrl();
            OpenGraphComponentModel model = new OpenGraphComponentModel()
            {
                SiteName        = config.SiteName,
                Url             = url,
                IsHome          = this.HttpContext.Request.Path == "/",
                HomeDescription = config.SeoDescription
            };

            return(View(model));
        }
예제 #11
0
        public virtual MailLog MailSteps(Client currentClient, MailBookingModel model, object param)
        {
            ValidateNull <MailBookingModel>(model);

            MailLog         log             = new MailLog();
            HomeConfig      hc              = null;
            Document        body            = null;
            List <Document> listAttachments = null;

            BookingStepBookingRepository.includes.Add("CurrentStep");
            BookingStepBookingRepository.includes.Add("CurrentStep.Documents");
            BookingStepBookingRepository.includes.Add("CurrentStep.MailTemplate");
            BookingStepBookingRepository.includes.Add("Booking");
            BookingStepBookingRepository.includes.Add("Booking.People");
            BookingStepBooking b = BookingStepBookingRepository.GetBookingStepBookingById(model.BookingId, currentClient.Id);

            if (b == null)
            {
                validationDictionnary.AddModelError(TypeOfName.GetNameFromType <Booking>(), GenericError.FORBIDDEN_RESOURCE_OR_DOES_NO_EXIST);
                throw new ManahostValidationException(validationDictionnary);
            }
            HomeConfigRepository.includes.Add("DefaultMailConfig");
            hc = HomeConfigRepository.GetHomeConfigById(b.HomeId, currentClient.Id);
            if (!((BookingStepBookingValidation)validation).MailStepValidation(validationDictionnary, currentClient, hc, b, model, param))
            {
                throw new ManahostValidationException(validationDictionnary);
            }
            if (b.CurrentStep.MailTemplate == null)
            {
                validationDictionnary.AddModelError("CurrentStep.MailTemplate", GenericError.CANNOT_BE_NULL_OR_EMPTY);
                throw new ManahostValidationException(validationDictionnary);
            }
            body            = DocumentRepository.GetDocumentById(b.CurrentStep.MailTemplate.Id, currentClient.Id);
            listAttachments = b.CurrentStep.Documents;
            if (hc.DefaultMailConfig != null)
            {
                SendMailUsingCustomMailAccount(hc.DefaultMailConfig, b, log, model.Password,
                                               GetMailBody(body, b.Home), MailUtils.GetAttachments(listAttachments, b.Home));
            }
            else
            {
                SendMailUsingManahostMailAccount(b, log, GetMailBody(body, b.Home), MailUtils.GetAttachments(listAttachments, b.Home));
            }
            repo.Add <MailLog>(log);
            repo.Update(b);
            repo.Save();
            return(log);
        }
예제 #12
0
        private void ButtonText_Paint(object sender, PaintEventArgs e)
        {
            StringFormat format = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Center,
                Trimming      = StringTrimming.Character
            };

            HomeConfig temp = HOMEFORM.CONFIG_FILE.homeButtonConfig;

            using (Font myFont = new Font("Arial", temp.fontSize))
            {
                e.Graphics.DrawString(temp.buttonText, myFont, new SolidBrush(Color.FromName(temp.textColor)), new Point(temp.buttonWidth / 2, temp.buttonHeight / 2), format);
            }

            //set black border for button
            ControlPaint.DrawBorder(e.Graphics, (sender as PictureBox).ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
        }
예제 #13
0
 public ConfigurationData()
 {
     themeColour       = def_themeColour;
     resourceFolder    = def_resourceFolder;
     numOfButtons      = def_numOfButtons;
     buttonWidth       = def_buttonWidth;
     buttonHeight      = def_buttonHeight;
     mainRows          = def_mainRows;
     mainPaddingTop    = def_mainPaddingTop;
     mainPaddingRight  = def_mainPaddingRight;
     mainPaddingBottom = def_mainPaddingBottom;
     mainPaddingLeft   = def_mainPaddingLeft;
     idleTimeout       = def_idleTimeout;
     timeoutTime       = def_timeoutTime;
     timeoutText       = def_timeoutText;
     timeoutWidth      = def_timeoutWidth;
     timeoutHeight     = def_timeoutHeight;
     timeoutFontSize   = def_timeoutFontSize;
     appButtonsConfig  = def_appButtonsConfig;
     homeButtonConfig  = def_homeButtonConfig;
 }
예제 #14
0
        public async Task <IActionResult> HomeConfig(HomeConfig model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                try
                {
                    await this.configService.SetHomeConfigAsync(model);

                    this.SetTempMessage("操作成功");
                    return(this.RedirectToAction("HomeConfig", "Config", new { Area = "Admin" }));
                }
                catch (Exception e)
                {
                    this.SetTempMessage(e.Message);
                    return(this.View(model));
                }
            }
        }
예제 #15
0
 public virtual bool MailStepValidation(System.Web.Http.ModelBinding.ModelStateDictionary validationDictionary, Client currentClient, HomeConfig hc, BookingStepBooking entity, MailBookingModel model, object param, params object[] additionalObjects)
 {
     if (hc == null)
     {
         validationDictionary.AddModelError("HomeConfig", GenericError.CANNOT_BE_NULL_OR_EMPTY);
         return(false);
     }
     if (hc.DefaultMailConfig != null && String.IsNullOrEmpty(model.Password))
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <MailBookingModel>(), "Password"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     try
     {
         if (hc.DefaultMailConfig != null && !String.IsNullOrEmpty(model.Password))
         {
             model.Password = Encoding.UTF8.GetString(Convert.FromBase64String(model.Password));
         }
     }
     catch (Exception e)
     {
         if (e is FormatException || e is ArgumentNullException)
         {
             validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <MailBookingModel>(), "Password"), GenericError.INVALID_GIVEN_PARAMETER);
         }
         else
         {
             throw;
         }
     }
     if (hc.DefaultMailConfig == null && entity.MailSent == MAX_SENT)
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Booking>(), "MailSent"), GenericError.DOES_NOT_MEET_REQUIREMENTS);
     }
     if (entity.CurrentStep == null)
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Booking>(), "CurrentStep"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     if (entity.CurrentStep != null && entity.CurrentStep.MailTemplate == null)
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Booking>(), "MailTemplate"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     if (entity.Booking.People == null)
     {
         validationDictionary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Booking>(), "People"), GenericError.CANNOT_BE_NULL_OR_EMPTY);
     }
     return(validationDictionary.IsValid);
 }
예제 #16
0
 public HomeConfig LoadHomeConfig(string fileName) => LoadConfig(fileName, element => HomeConfig.FromXml(element));
예제 #17
0
 /// <summary>
 /// 设置首页配置
 /// </summary>
 public async Task <int> SetHomeConfigAsync(HomeConfig homeConfig, DbTransaction transaction = null)
 {
     return(await this.SetConfigAsync <HomeConfig>(homeConfig, transaction));
 }
예제 #18
0
        //TODO BookingDocument

        protected override Booking DoPostPutDto(Client currentClient, BookingDTO dto, Booking entity, string path, object param)
        {
            if (entity == null)
            {
                entity = new Booking();
            }
            GetMapper.Map <BookingDTO, Booking>(dto, entity);

            HomeConfig hc = HomeConfigRepository.GetHomeConfigById(entity.HomeId, currentClient.Id);

            if (hc != null)
            {
                if (hc.DefaultHourCheckIn != null)
                {
                    entity.DateArrival = ((DateTime)entity.DateArrival).Date.Add(hc.DefaultHourCheckInToTimeSpan);
                }
                if (hc.DefaultHourCheckOut != null)
                {
                    entity.DateDeparture = ((DateTime)entity.DateDeparture).Date.Add(hc.DefaultHourCheckOutToTimeSpan);
                }
            }
            if (dto.People != null)
            {
                entity.People = PeopleService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.People, currentClient, path);
            }
            if (dto.AdditionalBookings != null)
            {
                AdditionalBookingRepository.DeleteRange(entity.AdditionalBookings.Where(d => !dto.AdditionalBookings.Any(x => x.Id == d.Id)));
                dto.AdditionalBookings.ForEach(additionalBooking =>
                {
                    if (entity.AdditionalBookings.Count != 0 && additionalBooking.Id != 0 &&
                        entity.AdditionalBookings.Find(p => p.Id == additionalBooking.Id) != null)
                    {
                        return;
                    }
                    AdditionalBooking toAdd = AdditionalBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, additionalBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.AdditionalBookings.Add(toAdd);
                    }
                });
            }
            if (dto.BookingStepBooking != null)
            {
                entity.BookingStepBooking = BookingStepBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BookingStepBooking, currentClient, path);
            }
            if (dto.Deposits != null)
            {
                DepositRepository.DeleteRange(entity.Deposits.Where(d => !dto.Deposits.Any(x => x.Id == d.Id)));
                dto.Deposits.ForEach(deposit =>
                {
                    if (entity.Deposits.Count != 0 && deposit.Id != 0 &&
                        entity.Deposits.Find(p => p.Id == deposit.Id) != null)
                    {
                        return;
                    }
                    Deposit toAdd = DepositService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, deposit, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.Deposits.Add(toAdd);
                    }
                });
            }
            if (dto.DinnerBookings != null)
            {
                DinnerBookingRepository.DeleteRange(entity.DinnerBookings.Where(d => !dto.DinnerBookings.Any(x => x.Id == d.Id)));
                dto.DinnerBookings.ForEach(dinnerBooking =>
                {
                    if (entity.DinnerBookings.Count != 0 && dinnerBooking.Id != 0 &&
                        entity.DinnerBookings.Find(p => p.Id == dinnerBooking.Id) != null)
                    {
                        return;
                    }
                    DinnerBooking toAdd = DinnerBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dinnerBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.DinnerBookings.Add(toAdd);
                    }
                });
            }
            if (dto.ProductBookings != null)
            {
                ProductBookingRepository.DeleteRange(entity.ProductBookings.Where(d => !dto.ProductBookings.Any(x => x.Id == d.Id)));
                dto.ProductBookings.ForEach(productBooking =>
                {
                    if (entity.ProductBookings.Count != 0 && productBooking.Id != 0 &&
                        entity.ProductBookings.Find(p => p.Id == productBooking.Id) != null)
                    {
                        return;
                    }
                    ProductBooking toAdd = ProductBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, productBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.ProductBookings.Add(toAdd);
                    }
                });
            }
            if (dto.RoomBookings != null)
            {
                RoomBokingRepository.DeleteRange(entity.RoomBookings.Where(d => !dto.RoomBookings.Any(x => x.Id == d.Id)));
                dto.RoomBookings.ForEach(roomBooking =>
                {
                    if (entity.RoomBookings.Count != 0 && roomBooking.Id != 0 &&
                        entity.RoomBookings.Find(p => p.Id == roomBooking.Id) != null)
                    {
                        return;
                    }
                    RoomBooking toAdd = RoomBookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, roomBooking, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.RoomBookings.Add(toAdd);
                    }
                });
            }
            entity.DateCreation = DateTime.UtcNow;
            return(entity);
        }
예제 #19
0
        public async Task <IActionResult> HomeConfig()
        {
            HomeConfig homeConfig = await configService.GetHomeConfigAsync();

            return(View(homeConfig));
        }
예제 #20
0
 public DarkSkyComponent(ILoggerFactory loggerFactory, IIoTService ioTService, NeonConfig neonConfig, IComponentsService componentsService) : base(loggerFactory, ioTService, componentsService)
 {
     _homeConfig = neonConfig.HomeConfig;
 }
예제 #21
0
 public SunComponent(ILoggerFactory loggerFactory, IIoTService ioTService, NeonConfig neonConfig, IComponentsService componentsService, IHttpClientFactory httpClientFactory) : base(loggerFactory, ioTService, componentsService)
 {
     _homeConfig = neonConfig.HomeConfig;
     _httpClient = httpClientFactory.CreateClient();
 }