Ejemplo n.º 1
0
        private static void Init()
        {
            var player = map.Actors.Single(a => a is Player) as Player;

            var mapConsole     = new MapConsole(game, true, new AStarPathFinder());
            var logConsole     = new LogConsole();
            var messageConsole = new MessageConsole();
            var statusConsole  = new StatusConsole(player);
            var menuConsole    = new MenuConsole(Width, Height);

            var inventory = new InventoryConsole(player);

            var keyboardHandler = new KeyboardHandler(mapConsole, logConsole, messageConsole, player, inventory, menuConsole, game, () => StartGame(rnd));

            var mainConsole = new MainConsole(mapConsole, logConsole, messageConsole, statusConsole, keyboardHandler, inventory);

            mainConsole.Children.Add(mapConsole);
            mainConsole.Children.Add(logConsole);
            mainConsole.Children.Add(messageConsole);
            mainConsole.Children.Add(statusConsole);
            mainConsole.Children.Add(inventory);
            mainConsole.Children.Add(menuConsole);

            SadConsole.Game.Instance.Screen = mainConsole;
        }
Ejemplo n.º 2
0
        public void FillData(DataSet dataSet)
        {
            var curColumn = 0;
            var curRow    = 0;
            var showRoCo  = true;

            try {
                var owList    = new List <OverWork>();
                var dataTable = dataSet.Tables[0];
                for (; curRow < dataTable.Rows.Count; curRow++)
                {
                    curColumn = 0;
                    showRoCo  = true;
                    var number    = dataTable.Rows[curRow][curColumn++]?.ToString();
                    var epNo      = dataTable.Rows[curRow][curColumn++]?.ToString();
                    var epName    = dataTable.Rows[curRow][curColumn++]?.ToString();
                    var startTime = DateTime.Parse(dataTable.Rows[curRow][curColumn++]?.ToString());
                    var endTime   = DateTime.Parse(dataTable.Rows[curRow][curColumn++]?.ToString());
                    var applyTime = int.Parse(dataTable.Rows[curRow][curColumn++].ToString());
                    //var reduceTime = DateTime.Parse(dataTable.Rows[ro][curColumn++]?.ToString());
                    var typeOverWork = dataTable.Rows[curRow][curColumn++]?.ToString();
                    var IsOnduty     = int.Parse(dataTable.Rows[curRow][curColumn++].ToString());
                    var IsOffduty    = int.Parse(dataTable.Rows[curRow][curColumn++].ToString());
                    var description  = dataTable.Rows[curRow][curColumn++]?.ToString();
                    var creator      = dataTable.Rows[curRow][curColumn]?.ToString();
                    showRoCo = false;

                    var foundEp =
                        ModelSource.Employees.ToList()
                        .Find(ep => ep.EmployeeNO == epNo && ep.EmployeeBaseInfo.EmployName == epName);
                    if (foundEp == null)
                    {
                        throw new Exception($"未找到员工:{epNo}/{epName}");
                    }

                    var o = new OverWork {
                        Number        = number,
                        Employee      = foundEp,
                        BeginDateTime = startTime.ToString(CultureInfo.InvariantCulture),
                        EndDateTime   = endTime.ToString(CultureInfo.InvariantCulture),
                        ApplyTime     = applyTime.ToString(),
                        //ReduceTime = reduceTime.ToString(CultureInfo.InvariantCulture),
                        OverWorkType = typeOverWork,
                        IsOnDuty     = IsOnduty.ParseToBoolean(),
                        IsOffDuty    = IsOffduty.ParseToBoolean(),
                        Description  = description,
                        Creator      = creator
                    };
                    owList.Add(o);
                    ModelSource.OverWorks.AddWithoutEntity(o);
                    //Console.WriteLine(cellValue is DBNull ? "Empty" : cellValue);
                }
                (ModelSource.OverWorks.EntityCtrl as OverWorkControl)?.ImportData(owList);
            } catch (Exception exception) {
                //第一行为列名, 第二行开始; 代码从0开始, 显示从1开始;  计算列时catch之前已经被++,所以不用+1
                var failTip = showRoCo? $"(行:{curRow + 2} 列:{curColumn})" : string.Empty;
                MessageBox.Show($"{exception.Message}\r\n{failTip}", "加班单导入失败!");
                StatusConsole.WriteLine("加班单导入失败! " + failTip);
            }
        }
Ejemplo n.º 3
0
        private static bool ValidateSingleFcnt(uint?fCntStart, uint?fCntStartRep, uint?fCntResetCounter, uint?fCntResetCounterRep, string fCntStartType)
        {
            if (fCntStart == null)
            {
                // fCntStart not set. Nothing to do.
                return(true);
            }

            // fCntStartRep not null
            if (fCntStartRep == null || fCntStart > fCntStartRep)
            {
                StatusConsole.WriteLogLine(MessageType.Info, $"{fCntStartType} {fCntStart} will be set on gateway.");
                return(true);
            }

            // fCntStartRep not null, fCntStartRep not null, fCntStart <= fCntStartRep
            if (fCntResetCounter == null)
            {
                StatusConsole.WriteLogLine(MessageType.Warning, $"{fCntStartType} {fCntStart} will not be set on gateway. Reported {fCntStartType} {fCntStartRep} is larger or equal and FCntResetCounter is not set.");
                return(true);
            }

            // fCntStartRep not null, fCntStartRep not null, fCntStart <= fCntStartRep,
            // fCntResetCounter not null
            if (fCntResetCounterRep == null || fCntResetCounter > fCntResetCounterRep)
            {
                StatusConsole.WriteLogLine(MessageType.Info, $"{fCntStartType} {fCntStart} will be set on gateway.");
                return(true);
            }

            // fCntStartRep not null, fCntStartRep not null, fCntStart <= fCntStartRep,
            // fCntResetCounter not null, fCntResetCounterRep not null, fCntResetCounter <= fCntResetCounterRep
            StatusConsole.WriteLogLine(MessageType.Warning, $"{fCntStartType} {fCntStart} will not be set on gateway. Reported {fCntStartType} {fCntStartRep} is larger or equal and FCntResetCounter {fCntResetCounter} is not larger than reported FCntResetCounter {fCntResetCounterRep}.");
            return(true);
        }
Ejemplo n.º 4
0
 private void TurnToHRPage(Control v, ViewModelBase vm)
 {
     v.DataContext       = vm;
     IsHRTabItemSelected = true;
     Content             = v;
     StatusConsole.WriteReady();
 }
Ejemplo n.º 5
0
 private void OnMainWindowLoaded()
 {
     ShowExpireTip();
     CurUserName = ModelSource.CurrentUser.UserName;
     CurUserType = ModelSource.CurrentUser.SystemRole.Name;
     StatusConsole.WriteLine(CurUserName + "已登录, 欢迎使用!");
 }
        public static bool ValidateSensorDecoder(string sensorDecoder)
        {
            var isValid   = true;
            var isWarning = false;

            if (sensorDecoder == null)
            {
                StatusConsole.WriteLine(MessageType.Error, "SensorDecoder is missing.");
                return(false);
            }

            if (sensorDecoder == string.Empty)
            {
                StatusConsole.WriteLine(MessageType.Info, "SensorDecoder is empty. No decoder will be used.");
                return(true);
            }

            if (sensorDecoder.StartsWith("http", StringComparison.OrdinalIgnoreCase) || sensorDecoder.Contains('/'))
            {
                if (!Uri.TryCreate(sensorDecoder, UriKind.Absolute, out Uri validatedUri))
                {
                    StatusConsole.WriteLine(MessageType.Error, "SensorDecoder has an invalid URL.");
                    isValid = false;
                }

                // if (validatedUri.Host.Any(char.IsUpper))
                if (!sensorDecoder.StartsWith(validatedUri.Scheme, StringComparison.OrdinalIgnoreCase) ||
                    sensorDecoder.IndexOf(validatedUri.Host) != validatedUri.Scheme.Length + 3)
                {
                    StatusConsole.WriteLine(MessageType.Error, "SensorDecoder Hostname must be all lowercase.");
                    isValid = false;
                }

                if (validatedUri.AbsolutePath.IndexOf("/api/") < 0)
                {
                    StatusConsole.WriteLine(MessageType.Warning, "SensorDecoder is missing \"api\" keyword.");
                    isWarning = true;
                }
            }

            if (!isValid || isWarning)
            {
                StatusConsole.WriteLine(MessageType.Info, "Make sure the URI based SensorDecoder Twin desired property looks like \"http://containername/api/decodername\".");
            }
            else
            {
                StatusConsole.WriteLine(MessageType.Info, $"SensorDecoder {sensorDecoder} is valid.");
            }

            return(isValid);
        }
Ejemplo n.º 7
0
 public bool UpDataEntity()
 {
     try
     {
         var effect = Factory.Update();
         ParaList.Add(effect.ToString());
         WriteLog("更新成功,更新记录");
         StatusConsole.WriteLine("已更新记录");
         return(true);
     }
     catch (Exception e)
     {
         WriteLogFalse("更新失败", e);
         StatusConsole.WriteLine("更新失败");
         return(false);
     }
 }
Ejemplo n.º 8
0
 public virtual bool AddEntity(T t)
 {
     InitLogNeed(t);
     try
     {
         Factory.Add(t);
         WriteLog("添加成功");
         StatusConsole.WriteLine("添加成功");
         return(true);
     }
     catch (Exception e)
     {
         WriteLogFalse("添加失败", e);
         StatusConsole.WriteLine("添加失败");
         return(false);
     }
 }
Ejemplo n.º 9
0
        public MainViewModel()
        {
            StatusConsole.Initialize(this);
            EmployeeManageCommand      = new RelayCommand(ShowEmployeeManageUI);
            DepartmentManageCommand    = new RelayCommand(ShowDepartmentManageUI);
            OperatingPostManageCommand = new RelayCommand(ShowOperatingPostManagerUI);
            OnJobManageCommand         = new RelayCommand(ShowOnJobManageUI);
            OffJobManageCommand        = new RelayCommand(ShowOffJobManageUI);
            DormitoryManageCommand     = new RelayCommand(ShowDormitoryManageUI);
            PostTransferManageCommand  = new RelayCommand(ShowPostTransferManageUI);
            SalarySetCommand           = new RelayCommand(SalarySet);

            VaccationSolutionCommand      = new RelayCommand(ShowVaccationSolutionUI);
            VaccationSolutionAsignCommand = new RelayCommand(ShowVaccationSolutionAsignUI);
            AskLeaveManageCommand         = new RelayCommand(ShowAskLeaveManageUI);
            BusinessTripManageCommand     = new RelayCommand(ShowBusinessTripManageUI);
            ReSignInManageCommand         = new RelayCommand(ShowReSignInManageUI);
            OverWorkManageCommand         = new RelayCommand(ShowOverWorkManageUI);
            DefWorkArrangeCommand         = new RelayCommand(ShowWkarDefineUI);
            AsignWorkArrangeCommand       = new RelayCommand(ShowWkarAsignUI);
            CardFillRecordManageCommand   = new RelayCommand(CardFillRecordManage);
            AttendanceManageCommand       = new RelayCommand(AttendanceManage);
            TiaoXiuManageCommand          = new RelayCommand(TiaoXiuManage);
            AttendanceAnalysisCommand     = new RelayCommand(ShowAttendanceAnalysis);
            SalaryDetailCommand           = new RelayCommand(ShowSalaryDetail);

            SysArgsManageCommand    = new RelayCommand(ShowSysArgsManageUI);
            SysUserManageCommand    = new RelayCommand(SysUserManage);
            SysRoleManageCommand    = new RelayCommand(SysRoleManage);
            AttArgManageCommand     = new RelayCommand(AttArgManage);
            BaseSalaryManageCommand = new RelayCommand(BaseSalaryManage);
            TaxManageCommand        = new RelayCommand(TaxManage);

            MainWindowLoadedCommand = new RelayCommand(OnMainWindowLoaded);

            ReportEmployeeProfileCommand  = new RelayCommand(ReportEmployeeProfile);
            ReportEmployeeTransferCommand = new RelayCommand(ReportEmployeeTransfer);
            ReportEmployeeDayAttCommand   = new RelayCommand(ReportEmployeeDayAtt);
            ReportEmployeeMonthAttCommand = new RelayCommand(ReportEmployeeMonthAttendence);
            ReportDepartmentSalaryCommand = new RelayCommand(ReportDepartmentSalary);
            ReportEmployeeSalaryCommand   = new RelayCommand(ReportEmployeeSalary);

            IsMainPageTabItemSelected = true;

            RegistReceiverSlot(AttendeceAnalysisViewModel.ToVacationPlanPageToken, ShowVaccationSolutionUI);
        }
Ejemplo n.º 10
0
 public bool DeleteEntity(T t)
 {
     InitLogNeed(t);
     if (!DeleteProtected(t))
     {
         WriteDeleteProtectedLog("删除失败");
         StatusConsole.WriteLine("删除失败! (对象受删除保护)");
         return(false);
     }
     try
     {
         Factory.Delete(t);
         WriteLog("删除成功");
         StatusConsole.WriteLine("删除成功");
         return(true);
     }
     catch (Exception e)
     {
         WriteLogFalse("删除失败", e);
         StatusConsole.WriteLine("删除失败");
         return(false);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Engine.Initialize(_graphics, "IBM.font", 100, 34);
            Engine.UseMouse    = true;
            Engine.UseKeyboard = true;

            _map = new MapConsole(this, 80, 34);
            _map.PlayerTeleportEvent += PlayerTeleportEvent;
            _map.PlayerMoveEvent     += PlayerMoveEvent;
            _map.NewGameEvent        += NewGameEvent;

            _status          = new StatusConsole(20, 34);
            _status.Position = new Point(80, 0);

            Engine.ConsoleRenderStack = new SadConsole.Consoles.ConsoleList {
                _map, _status
            };
            Engine.ActiveConsole = Engine.ConsoleRenderStack[0];

            NextLevel();

            base.Initialize();
        }
        public bool ReadConfig(string[] args)
        {
            string iotHubConnectionString, netId, storageConnectionString;

            Console.WriteLine("Reading configuration from command line and \"appsettings.json\" file...");

            // Read configuration file appsettings.json
            try
            {
                var configurationBuilder = new ConfigurationBuilder()
                                           .SetBasePath(Directory.GetCurrentDirectory())
                                           .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
                                           .AddJsonFile("appsettings.local.json", optional: true, reloadOnChange: false)
                                           .AddCommandLine(args)
                                           .Build();

                iotHubConnectionString  = configurationBuilder["iothub-connection-string"];
                storageConnectionString = configurationBuilder["storage-connection-string"];
                netId = configurationBuilder["NetId"];

                if (iotHubConnectionString is null || netId is null)
                {
                    StatusConsole.WriteLogLine(MessageType.Error, "IoT Hub connection string and NetId are required.");
                    return(false);
                }
            }
            catch (FileNotFoundException)
            {
                StatusConsole.WriteLogLine(MessageType.Error, "Configuration file 'appsettings.json' was not found.");
                return(false);
            }

            // Validate connection setting
            if (string.IsNullOrEmpty(iotHubConnectionString))
            {
                StatusConsole.WriteLogLine(MessageType.Error, "IoT Hub connection string may not be empty.");
                return(false);
            }
            else
            {
                // Just show IoT Hub Hostname
                if (GetHostFromConnectionString(iotHubConnectionString, out var hostName))
                {
                    StatusConsole.WriteLogLine(MessageType.Info, $"Using IoT Hub: {hostName}");
                }
                else
                {
                    StatusConsole.WriteLogLine(MessageType.Error, "Invalid connection string in appsettings.json. Can not find \"HostName=\". The file should have the following structure: { \"IoTHubConnectionString\" : \"HostName=xxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxx\" }.");
                    return(false);
                }
            }

            // Validate NetId setting
            if (string.IsNullOrEmpty(netId))
            {
                netId = ValidationHelper.CleanNetId(Constants.DefaultNetId.ToString(CultureInfo.InvariantCulture));
                StatusConsole.WriteLogLine(MessageType.Info, $"NetId is not set in settings file. Using default {netId}.");
            }
            else
            {
                netId = ValidationHelper.CleanNetId(netId);

                if (ValidationHelper.ValidateHexStringTwinProperty(netId, 3, out var customError))
                {
                    StatusConsole.WriteLogLine(MessageType.Info, $"Using NetId {netId} from settings file.");
                }
                else
                {
                    var netIdBad = netId;
                    netId = ValidationHelper.CleanNetId(Constants.DefaultNetId.ToString(CultureInfo.InvariantCulture));
                    StatusConsole.WriteLogLine(MessageType.Warning, $"NetId {netIdBad} in settings file is invalid. {customError}.");
                    StatusConsole.WriteLogLine(MessageType.Warning, $"Using default NetId {netId} instead.");
                }
            }

            StatusConsole.WriteLogLine(MessageType.Info, $"To override, use --netid parameter.");

            NetId = netId;

            // Create Registry Manager using connection string
            try
            {
                RegistryManager = RegistryManager.CreateFromConnectionString(iotHubConnectionString);
            }
            catch (Exception ex) when(ex is ArgumentNullException
                                      or FormatException
                                      or ArgumentException)
            {
                StatusConsole.WriteLogLine(MessageType.Error, $"Failed to create Registry Manager from connection string: {ex.Message}.");
                return(false);
            }

            if (storageConnectionString != null)
            {
                try
                {
                    CertificateStorageContainerClient = new BlobContainerClient(storageConnectionString, CredentialsStorageContainerName);
                    FirmwareStorageContainerClient    = new BlobContainerClient(storageConnectionString, FirmwareStorageContainerName);
                }
                catch (FormatException)
                {
                    StatusConsole.WriteLogLine(MessageType.Info, "Storage account is incorrectly configured.");
                }
            }

            Console.WriteLine("done.");
            return(true);
        }
        public bool ReadConfig()
        {
            string connectionString, netId;

            Console.WriteLine("Reading configuration file \"appsettings.json\"...");

            // Read configuration file appsettings.json
            try
            {
                var configurationBuilder = new ConfigurationBuilder()
                                           .SetBasePath(Directory.GetCurrentDirectory())
                                           .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
                                           .AddJsonFile("appsettings.local.json", optional: true, reloadOnChange: false)
                                           .Build();

                connectionString = configurationBuilder["IoTHubConnectionString"];
                netId            = configurationBuilder["NetId"];
            }
            catch (Exception ex)
            {
                StatusConsole.WriteLogLine(MessageType.Error, $"{ex.Message}");
                StatusConsole.WriteLogLine(MessageType.Info, "The file should have the following structure: { \"IoTHubConnectionString\" : \"HostName=xxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxx\" }");
                return(false);
            }

            // Validate connection setting
            if (string.IsNullOrEmpty(connectionString))
            {
                StatusConsole.WriteLogLine(MessageType.Error, "Connection string not found in settings file. The format should be: { \"IoTHubConnectionString\" : \"HostName=xxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxx\" }.");
                return(false);
            }
            else
            {
                // Just show IoT Hub Hostname
                if (this.GetHostFromConnectionString(connectionString, out string hostName))
                {
                    StatusConsole.WriteLogLine(MessageType.Info, $"Using IoT Hub: {hostName}");
                }
                else
                {
                    StatusConsole.WriteLogLine(MessageType.Error, "Invalid connection string in appsettings.json. Can not find \"HostName=\". The file should have the following structure: { \"IoTHubConnectionString\" : \"HostName=xxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxx\" }.");
                    return(false);
                }
            }

            // Validate NetId setting
            if (string.IsNullOrEmpty(netId))
            {
                netId = ValidationHelper.CleanNetId(Constants.DefaultNetId.ToString());
                StatusConsole.WriteLogLine(MessageType.Info, $"NetId is not set in settings file. Using default {netId}.");
            }
            else
            {
                netId = ValidationHelper.CleanNetId(netId);

                if (ValidationHelper.ValidateHexStringTwinProperty(netId, 3, out string customError))
                {
                    StatusConsole.WriteLogLine(MessageType.Info, $"Using NetId {netId} from settings file.");
                }
                else
                {
                    var netIdBad = netId;
                    netId = ValidationHelper.CleanNetId(Constants.DefaultNetId.ToString());
                    StatusConsole.WriteLogLine(MessageType.Warning, $"NetId {netIdBad} in settings file is invalid. {customError}.");
                    StatusConsole.WriteLogLine(MessageType.Warning, $"Using default NetId {netId} instead.");
                }
            }

            StatusConsole.WriteLogLine(MessageType.Info, $"To override, use --netid parameter.");

            this.NetId = netId;

            // Create Registry Manager using connection string
            try
            {
                this.RegistryManager = RegistryManager.CreateFromConnectionString(connectionString);
            }
            catch (Exception ex)
            {
                StatusConsole.WriteLogLine(MessageType.Error, $"Can not connect to IoT Hub (possible error in connection string): {ex.Message}.");
                return(false);
            }

            Console.WriteLine("done.");
            return(true);
        }