public bool isOk(string username) { // get servers random string from database: UnitOfWork uow = new UnitOfWork(); RandomModel randomModel = new RandomModel(); randomModel = Mapper.Map <RandomModel>(uow.RandomRepository.Get().Where(u => u.Username == username).FirstOrDefault()); string randomS = randomModel.RandomString; Guid modelGuid = randomModel.Id; string input = this.randomClient + this.passwordHash + randomS; // generate hash string hash = ""; SHA512 alg = SHA512.Create(); byte[] data = alg.ComputeHash(Encoding.Default.GetBytes(input)); string hex = BitConverter.ToString(data); hash = hex.Replace("-", "").ToLower(); //compare hash with big hash if (hash == this.bigHash) { uow.RandomRepository.Delete(modelGuid); uow.Save(); return(true); } else { uow.RandomRepository.Delete(modelGuid); uow.Save(); return(false); } }
public RandomPage(int tournamentId) { InitializeComponent(); _model = new RandomModel(Navigation, tournamentId); BindingContext = _model; var frames = _model.GetRandomDraw(); foreach (var frame in frames) { StackLayout.HeightRequest += 180; FrameLayout.HeightRequest += 150; FrameLayout.Children.Add(frame); } _model.RedrawPlayers += (sender, args) => { FrameLayout.Children.Clear(); FrameLayout.HeightRequest = 0; foreach (var frame in _model.GetRandomDraw()) { FrameLayout.HeightRequest += 150; FrameLayout.Children.Add(frame); } }; }
public static string GetRandom(int length, RandomModel randomModel = RandomModel.Number) { string str = string.Empty; switch (randomModel) { case RandomModel.CharacterNumber: str = "ABCDEFGHJKMNPQRSTUVWXYZ0123456789"; break; case RandomModel.Character: str = "ABCDEFGHJKMNPQRSTUVWXYZ"; break; default: str = "0123456789"; break; } var sb = new StringBuilder(); for (int i = 0; i < length; i++) { sb.Append(str[new Random(Guid.NewGuid().GetHashCode()).Next(0, str.Length - 1)]); } return(sb.ToString()); }
private void btnStartTurntable_Click(object sender, RoutedEventArgs e) { try { logic.isSengxia(); var windo = new Input(result); windo.Owner = Application.Current.MainWindow; if (windo.ShowDialog() == true) { polt = logic.Next(result.bayNumber, result.orderNumber, result.price); btnStartTurntable.IsEnabled = false; var t = polt.id - 2; if (t < 0) { t = 8 + t; } _Index = t; Storyboard sb = (Storyboard)this.FindResource("zhuandong"); sb.Completed -= this.sb_Completed; sb.Completed += new EventHandler(sb_Completed); ((SplineDoubleKeyFrame)((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[0]).Value = _OldAngle; ((SplineDoubleKeyFrame)((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[3]).Value = _ListAngle[_Index]; sb.Begin(); } } catch (Exception eex) { return; } }
public string GenerateRandomString(string username) { DeleteOldStrings(username); string rndStr = ""; System.Random random = new System.Random((int)DateTime.Now.Ticks); StringBuilder builder = new StringBuilder(); char ch; for (int i = 0; i < strLength; i++) { ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); builder.Append(ch); } rndStr = builder.ToString(); // save random string and username into database RandomModel randomModel = new RandomModel(); randomModel.Id = Guid.NewGuid(); randomModel.Username = username; randomModel.RandomString = rndStr; var rnd = Mapper.Map <RepairmenModel.Random>(randomModel); UnitOfWork uow = new UnitOfWork(); uow.RandomRepository.Insert(rnd); uow.Save(); return(rndStr); }
private void Turntable_AwardProcess(RandomModel award, inputReuslt input) { StringBuilder sb = new StringBuilder(); sb.AppendLine("用户单号:" + input.orderNumber); sb.AppendLine("中了:" + award.name); MessageBox.Show(sb.ToString(), "恭喜", MessageBoxButton.OK, MessageBoxImage.Information); }
public IActionResult Submit(RandomModel model) { // var dataStore = new CsvDataStore(); // var moves = dataStore.GenerateCombo(); // model = new RandomModel { Moves = moves }; return(RedirectToAction("Index", model)); }
public IActionResult Index() { var dataStore = new CsvDataStore(); var moves = dataStore.GetAllMoves(); var model = new RandomModel { Moves = moves }; return(View(model)); }
public ActionResult NewRandomNumber() { RandomModel.AddNumber(); var sessionId = RandomModel.GetSize(); return(new JsonResult() { Data = sessionId }); }
private List <byte> GetBytesFromRandomModel(RandomModel randomModel) { List <byte> bytList = new List <byte>(); bytList.Add((byte)randomModel.Data1); bytList.Add((byte)randomModel.Data2); bytList.Add((byte)randomModel.ModelType); return(bytList); }
public ActionResult Index() { RandomModelContext randomModelContext = new RandomModelContext(); RandomModel randomModel = new RandomModel() { Integer = 1, Character = '1', ID = 1, String = "1" }; for (int i = 0; i < 3; i++) { randomModelContext.RandomModels.Add(randomModel); } randomModelContext.SaveChanges(); return(View()); }
public ActionResult VerifyGuess(int input, int sessionId) { var hint = "Please enter a number between 1 and 100"; var randomNumber = RandomModel.GetNumber(sessionId); if (input < 101 && input > 0) { hint = (input > randomNumber) ? "Lower" : (input < randomNumber) ? "Higher" : "Equal"; } return(new JsonResult() { Data = hint }); }
public RandomModel GetRandomQuote() { CategoriesController controller = new CategoriesController(); var categories = controller.GetAllCategories(); var randomCategory = categories.ElementAt(new Random().Next(0, categories.Count())); var quotes = controller.GetCategoryByName(randomCategory.Title, randomCategory.Url); var foundQuote = quotes.Quotes.ElementAt(new Random().Next(0, quotes.Quotes.Count)); var randomQuote = new RandomModel() { Quote = foundQuote.Key, Author = foundQuote.Value }; return(randomQuote); }
public RandomViewModel() { SelectedRandomModel = new RandomModel() { //Rnd one, two & three kan vara en Rnd, Men då behöver man sätta .next i varje AddToList innan man lägger det i listan. Se exempel nedan. RndNumber = new Random(), RndOne = new int(), RndTwo = new int(), RndThree = new int(), ListOne = new ObservableCollection <int>(), ListTwo = new ObservableCollection <int>(), ListThree = new ObservableCollection <int>(), }; SelectedListModel = new ListModel(); RandomizeNumber = new DelegateCommand(RandomizeNumberExecuted, RandomizeNumberCanExecute); AddRandomCmd = new DelegateCommand(AddRandomCmdExecuted, AddRandomCmdCanExecute); ClearRandomCmd = new DelegateCommand(ClearRandomCmdExecuted, ClearRandomCmdCanExecute); FillListsWithData(); }
static async System.Threading.Tasks.Task Main(string[] args) { int count = 10; var key = string.Empty; List <string> topics = new List <string>(); topics.Add("test"); topics.Add("test2"); var config = new ProducerConfig { BootstrapServers = "localhost:9092", ClientId = Dns.GetHostName() }; //Create a topic with 3 partions with a replication factor of 1 //var createTopic = TopicHelper.CreateTopic(config, topic, 3, 1); using (var producer = new ProducerBuilder <string, string>(config).Build()) { try { topics.ForEach(async topic => { for (var i = 0; i <= count; i++) { if (i % 2 == 0) { key = "ev"; } else { key = "od"; } var randomModel = new RandomModel { Key = key, Message = $"Message with count: {i}", RandomNumber = new Random().Next() }; await producer.ProduceAsync(topic, new Message <string, string> { Key = key, Value = JsonConvert.SerializeObject(randomModel) }); Console.WriteLine($"{count} messages were produced to on topic {topic}"); } ; producer.Flush(TimeSpan.FromSeconds(35)); }); } catch (Exception e) { Console.WriteLine($"Error has occurred: {e.Message}"); } Console.Read(); } }
public MenuViewModel(MainModel mainModel, RandomModel model) { this._mainModel = mainModel; this._model = model; OpenUsersCommand = new RelayCommand(OpenUsers, CanOpenUsers); }
/// <summary> /// 发送数据 /// </summary> /// <param name="obj"></param> public List <byte> Send(byte orderCode, object obj) { List <byte> checkList = new List <byte>(); switch (orderCode) { case 0x01: //设置单板时间 if (obj is SystemDT) { SystemDT systemDT = (SystemDT)obj; //数据长度 checkList.Add(0x0A); checkList.Add(0x00); //命令 checkList.Add(orderCode); //数据 checkList.AddRange(GetBytesFromSystemDT(systemDT)); } break; case 0x02: //查询单板时间 case 0x03: //查询单板版本信息 case 0x05: //查询系统参数 case 0x07: //查询CH1参数 case 0x09: //查询CH2参数 case 0x0B: //查询CH3参数 case 0x0C: //保存参数 case 0x10: //显示通道信号强度 case 0x11: //关闭信号强度显示 case 0x14: //退出上传通道信号 case 0x20: //上传单板报警记录 case 0x68: //查询效验码 case 0x6E: case 0x69: case 0x6A: case 0x6B: case 0x6C: case 0x6D: case 0x0E: //数据长度 checkList.Add(0x03); checkList.Add(0x00); //命令 checkList.Add(orderCode); break; case 0x04: //系统参数设置 if (obj is SystemParam) { SystemParam systemParam = (SystemParam)obj; //数据长度 checkList.Add(0x10); checkList.Add(0x00); //命令 checkList.Add(orderCode); //数据 checkList.AddRange(GetBytesFromSystemParam(systemParam)); } break; case 0x06: //设置CH1参数 case 0x08: //设置CH2参数 case 0x0A: //设置CH3参数 if (obj is ChannelParam) { ChannelParam channelParam = (ChannelParam)obj; //数据长度 checkList.Add(0x07); checkList.Add(0x00); //命令 checkList.Add(orderCode); //数据 checkList.AddRange(GetBytesFromChannelParam(channelParam)); } break; case 0x12: //检测周围相位 case 0x13: //上传通道信号 //数据长度 checkList.Add(0x04); checkList.Add(0x00); //命令 checkList.Add(orderCode); //数据 checkList.Add(byte.Parse(obj.ToString())); break; case 0x15: //设置调试相位 //数据长度 checkList.Add(0x08); checkList.Add(0x00); //命令 checkList.Add(orderCode); //数据 float f = float.Parse(obj.ToString()); checkList.AddRange(BitConverter.GetBytes(f)); checkList.Add((byte)FrmMain.phaseIndex); break; case 0x60: //设置随机数 //数据长度 checkList.Add(0x06); checkList.Add(0x00); //命令 checkList.Add(orderCode); //数据 RandomModel randomModel = (RandomModel)obj; checkList.AddRange(GetBytesFromRandomModel(randomModel)); break; case 0x61: //设置发射密度 case 0x62: //设置同步 case 0x63: //设置噪声抑制 case 0x64: //设置信号抑制 case 0x65: //设置可调间隔 case 0x0D: //设置信号抑制 //数据长度 checkList.Add(0x04); checkList.Add(0x00); //命令 checkList.Add(orderCode); //数据 checkList.Add(byte.Parse(obj.ToString())); break; } byte[] bytCheck = GetDataCheck(checkList); List <byte> sendList = new List <byte>(); sendList.Add(0x10); sendList.Add(0xFF); sendList.Add(0xFE); sendList.AddRange(checkList); sendList.AddRange(bytCheck); isNormalFrame = false; serialPortHelper.Write(sendList.ToArray(), 0, sendList.Count); return(sendList); }
/// <summary> /// 返回记录数据 /// </summary> /// <param name="lstDataDomain">数据域数组</param> /// <returns></returns> //public object GetDataValue(List<byte> lstDataDomain) public object GetDataValue(List <byte> lstReciveByte) { //如果返回不是正常应答帧 返回空 //if (!serialPortHelper.IsNormalFrame) //{ // return null; //} //lstClone.AddRange(lstDataDomain); //isNormalFrame = false; returnType = 0; lstDataDomain.Clear(); lstRead.Clear(); int revLength = lstReciveByte.Count; if (revLength >= 8) { if (lstReciveByte[0] == 0x10 && lstReciveByte[1] == 0xFF && lstReciveByte[2] == 0xFE) //识别帧 { int dataLength = lstReciveByte[4] * 256 + lstReciveByte[3]; int frameLen = dataLength + 5; if (revLength >= frameLen) { List <byte> checkList = lstReciveByte.GetRange(3, dataLength); byte[] bytCheck = GetDataCheck(checkList); if (bytCheck[1] == lstReciveByte[frameLen - 1] && bytCheck[0] == lstReciveByte[frameLen - 2]) //校验和 { lstRead.AddRange(lstReciveByte.GetRange(0, frameLen)); lstDataDomain.AddRange(lstReciveByte.GetRange(5, dataLength - 2)); returnType = lstDataDomain[0]; isNormalFrame = true; Application.DoEvents(); //System.Threading.Thread.Sleep(50); //lstReciveByte.Clear(); } //else //{ // byte a = lstReciveByte[frameLen - 1]; // byte b = lstReciveByte[frameLen - 2]; // isNormalFrame = true; // returnType = 0x20; // lstDataDomain.AddRange(lstReciveByte.GetRange(5, dataLength - 2)); // lstRead.AddRange(lstReciveByte.GetRange(0, frameLen)); //} lstReciveByte.RemoveRange(0, frameLen); } } } if (!isNormalFrame) { return(null); } //创建一个新集合 克隆数据域数据 List <byte> lstClone = new List <byte>(); lstClone.AddRange(lstDataDomain); object obj = null; if (lstClone.Count > 1) { switch (lstClone[0]) { case 0x01: //设置单板时间 case 0x04: //系统参数设置 case 0x06: //设置CH1参数 case 0x08: //设置CH2参数 case 0x0A: //设置CH3参数 case 0x0C: //保存参数 case 0x11: //关闭信号强度显示 case 0x14: //退出上传通道信号 case 0x15: //设置调试相位 case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x0D: if (lstClone[1] == 0) { obj = "操作成功"; // MessageBox.Show("操作成功"); } else if (lstClone[1] == 1) { obj = "参数错误"; //MessageBox.Show("参数错误"); } else { obj = "无效"; //MessageBox.Show("无效"); } break; case 0x68: if (lstClone.Count == 5) { CheckCode checkCode = new CheckCode(); checkCode.Data1 = lstClone[1]; checkCode.Data2 = lstClone[2]; checkCode.Data3 = lstClone[3]; checkCode.Data4 = lstClone[4]; obj = checkCode; } break; case 0x6E: if (lstClone.Count == 2) { RandomModel randomModel = new RandomModel(); randomModel.ModelType = lstClone[1]; obj = randomModel; } break; case 0x69: if (lstClone.Count == 2) { MiduParam param = new MiduParam(); param.Data = lstClone[1]; obj = param; } break; case 0x6A: if (lstClone.Count == 2) { TongbuParam param = new TongbuParam(); param.Data = lstClone[1]; obj = param; } break; case 0x6B: if (lstClone.Count == 2) { NoiseParam param = new NoiseParam(); param.Data = lstClone[1]; obj = param; } break; case 0x6C: if (lstClone.Count == 2) { XinhaoParam param = new XinhaoParam(); param.Data = lstClone[1]; obj = param; } break; case 0x6D: if (lstClone.Count == 2) { InterverParam param = new InterverParam(); param.Data = lstClone[1]; obj = param; } break; case 0x0E: if (lstClone.Count == 2) { GongpinParam param = new GongpinParam(); param.Data = lstClone[1]; obj = param; } break; case 0x02: //查询单板时间 if (lstClone.Count == 8) { SystemDT systemDT = new SystemDT(); systemDT.Year = lstClone[2] * 256 + lstClone[1]; systemDT.Month = lstClone[3]; systemDT.Day = lstClone[4]; systemDT.Hour = lstClone[5]; systemDT.Minute = lstClone[6]; systemDT.Second = lstClone[7]; obj = systemDT; } break; case 0x03: //查询单板版本信息 if (lstClone.Count == 12) { VersionInfo versionInfo = new VersionInfo(); versionInfo.SoftVersion = lstClone[1] + "." + lstClone[2] + "." + lstClone[3] + "." + lstClone[4]; versionInfo.CompileDT = new SystemDT(); versionInfo.CompileDT.Year = lstClone[6] * 256 + lstClone[5]; versionInfo.CompileDT.Month = lstClone[7]; versionInfo.CompileDT.Day = lstClone[8]; versionInfo.CompileDT.Hour = lstClone[9]; versionInfo.CompileDT.Minute = lstClone[10]; versionInfo.CompileDT.Second = lstClone[11]; obj = versionInfo; } break; case 0x05: //查询系统参数 if (lstClone.Count == 14) { SystemParam systemParam = new SystemParam(); //byte[] phase = lstClone.GetRange(1, 4).ToArray(); //phase = phase.Reverse().ToArray(); systemParam.Phase = lstClone[2] * 256 + lstClone[1]; systemParam.Frequency = lstClone[3]; systemParam.SendInterval = lstClone[4]; systemParam.SendStrength = lstClone[5]; systemParam.RevDelay = lstClone[6]; systemParam.ChannelMode = lstClone[7]; systemParam.InterferenceDetection = lstClone[8]; systemParam.SignDetection = lstClone[9]; systemParam.DecodingFilterA = lstClone[10]; systemParam.DecodingFilterB = lstClone[11]; systemParam.DecodingFilterC = lstClone[12]; systemParam.DecodingFilterD = lstClone[13]; obj = systemParam; } break; case 0x07: //查询CH1参数 case 0x09: //查询CH2参数 case 0x0B: //查询CH3参数 if (lstClone.Count == 5) { ChannelParam channelParam = new ChannelParam(); channelParam.AlarmThreshold = lstClone[1]; //channelParam.Sign1 = lstClone[2] & 0x01; //channelParam.Sign2 = (lstClone[2] >> 1) & 0x01; //channelParam.Sign3 = (lstClone[2] >> 2) & 0x01; channelParam.TX = lstClone[2] & 0x01; channelParam.RX = (lstClone[2] >> 1) & 0x01; channelParam.Buzzer = lstClone[3]; channelParam.ChannelGain = lstClone[4]; obj = channelParam; } break; case 0x10: //显示通道信号强度 if (lstClone.Count == 7) { ChannelSignStrength channelSignStrength = new ChannelSignStrength(); channelSignStrength.Ch1Noise = lstClone[1]; channelSignStrength.Ch1Sign = lstClone[2]; channelSignStrength.Ch2Noise = lstClone[3]; channelSignStrength.Ch2Sign = lstClone[4]; channelSignStrength.Ch3Noise = lstClone[5]; channelSignStrength.Ch3Sign = lstClone[6]; obj = channelSignStrength; } break; case 0x12: //检测周围相位 if (lstClone.Count == 33) { List <string> phaseList = new List <string>(); for (int i = 0; i < 16; i++) { int temp = lstClone[i * 2 + 2] * 256 + lstClone[i * 2 + 1]; if (temp == 65535) { phaseList.Add("无"); } else { double fTemp = temp * 0.1; phaseList.Add(fTemp.ToString("0.0")); } } obj = phaseList; } break; case 0x13: //上传通道信号 //if (lstClone.Count == 601) { int number = (lstClone.Count - 1) / 2; UploadChannelSign ucs = new UploadChannelSign(); ucs.Bit15List = new List <int>(); ucs.Bit0_14List = new List <int>(); for (int i = 0; i < number; i++) { if ((lstClone[i * 2 + 2] >> 7) == 1) { ucs.Bit15List.Add(1600); } else { ucs.Bit15List.Add(0); } // ucs.Bit15List.Add((lstClone[i * 2 + 2] >> 15) & 0x80); ucs.Bit0_14List.Add((lstClone[i * 2 + 2] & 0x7F) * 256 + lstClone[i * 2 + 1]); } obj = ucs; } break; case 0x20: //上传单板报警记录 List <AlarmRecord> arList = new List <AlarmRecord>(); int count = (lstClone.Count - 1) / 16; for (int i = 0; i < count; i++) { AlarmRecord ar = new AlarmRecord(); ar.index = i + 1; ar.Number = lstClone[i * 16 + 1]; ar.Code = lstClone[i * 16 + 2]; ar.RecordDT = new SystemDT(); ar.RecordDT.Year = 2000 + lstClone[i * 16 + 3]; ar.RecordDT.Month = lstClone[i * 16 + 4]; ar.RecordDT.Day = lstClone[i * 16 + 5]; ar.RecordDT.Hour = lstClone[i * 16 + 6]; ar.RecordDT.Minute = lstClone[i * 16 + 7]; ar.RecordDT.Second = lstClone[i * 16 + 8]; StringBuilder sb = new StringBuilder(); for (int j = 9; j <= 16; j++) { if (sb.Length > 0) { sb.Append(" "); } sb.Append(lstClone[i * 16 + j].ToString("X2")); } ar.Data = sb.ToString(); arList.Add(ar); } obj = arList; break; } } return(obj); }
/** * <summary> Training algorithm for random classifier.</summary> * * <param name="trainSet"> Training data given to the algorithm.</param> * <param name="parameters">-</param> */ public override void Train(InstanceList.InstanceList trainSet, Parameter.Parameter parameters) { model = new RandomModel(new List <String>(trainSet.ClassDistribution().Keys), parameters.GetSeed()); }