public ActionResult Create(BookingModel model) { TravelaEntities db = new TravelaEntities(); var customer = new CustomerT() { customerid = model.customerid, customername = model.customername, customersurname = model.customersurname, birthdate = model.birthdate, phone = model.phone, email = model.email, address = model.address }; var reservation = new ReservationT() { customerid = model.customerid, hotelid = model.hotelid, tourid = model.tourid, status = model.status = false, reservationnumber = model.reservationnumber = RandomGen2.Next() }; db.CustomerT.Add(customer); db.ReservationT.Add(reservation); db.SaveChanges(); return(Redirect("~/Web/Index")); }
public async Task Initialize() { Bars.Clear(); Cars = new Car[NumberOfCars]; int teemoNum = RandomGen2.Next() % (NumberOfCars - 1) + 1; MainGrid.RowDefinitions.Add(new RowDefinition()); for (int i = 0; i < NumberOfCars; i++) { MainGrid.RowDefinitions.Add(new RowDefinition()); // Add CarRaceBar in mainGrid CarRaceBar bar = new CarRaceBar() { Maximum = (double)Distance, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; MainGrid.Children.Add(bar); Grid.SetColumn(bar, 1); Grid.SetRow(bar, i + 1); // Set color of car. if (i == 0) { await bar.SetColor(PlayerColor); } else { await bar.SetColor(Color.FromArgb(255, (byte)(RandomGen2.Next() % 255), (byte)(RandomGen2.Next() % 255), (byte)(RandomGen2.Next() % 255))); } Bars.Add(bar); // Make text TextBlock description = new TextBlock() { Name = $"Text{i}", Foreground = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0xff, 0xff)), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center }; MainGrid.Children.Add(description); Grid.SetColumn(description, 2); Grid.SetRow(description, i + 1); Image placeImage = new Image(); placeImage.Source = new BitmapImage(new Uri(@"appx:///Assets/0.png")); placeImage.HorizontalAlignment = HorizontalAlignment.Center; placeImage.VerticalAlignment = VerticalAlignment.Center; MainGrid.Children.Add(placeImage); Grid.SetColumn(placeImage, 0); Grid.SetRow(placeImage, i + 1); if (i == 0) { Cars[i] = Car.NapraviAuto(Account.CurrentAccount.Nickname, bar, description); } else if (i == teemoNum) { Cars[i] = Car.NapraviAuto("Teemo", bar, description); } else { NamesCollection names = NamesCollection.GetInstance(); await names.ReadNamesAsync(); Cars[i] = Car.NapraviAuto(names[RandomGen2.Next() % names.Names.Count], bar, description); } } MainGrid.RowDefinitions.Add(new RowDefinition()); MainGrid.Children.Add(BackButton); ButtonStyle(BackButton, "BACK", 0, NumberOfCars + 1); ButtonStyle(StartRaceButton, "START RACE", 1, NumberOfCars + 1); }
public IActionResult Index() { ViewData["Message"] = RandomGen2.Next(); return(View()); }
public async Task Initialize() { Bars.Clear(); Cars = new Car[NumberOfCars]; int teemoNum = RandomGen2.Next() % (NumberOfCars - 1) + 1; for (int i = 0; i < NumberOfCars; i++) { CarRaceBar bar = new CarRaceBar() { Name = "Progress" + i, Maximum = (double)Distance, Margin = new Thickness(50, 160 * i, 0, 0), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Width = 1200, Height = 80, }; if (i == 0) { await bar.SetColor(PlayerColor); } else { await bar.SetColor(Color.FromArgb(255, (byte)(RandomGen2.Next() % 255), (byte)(RandomGen2.Next() % 255), (byte)(RandomGen2.Next() % 255))); } Bars.Add(bar); Grid grid = new Grid() { Name = "Text" + i, Margin = new Thickness(50, 80 * (2 * i + 1), 0, 0), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, Width = 900, Height = 80, }; grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(25, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(25, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(25, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(25, GridUnitType.Star) }); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30, GridUnitType.Pixel) }); grid.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); var textBlocks = new[] { new TextBlock { Text = "" }, new TextBlock { Text = "" }, new TextBlock { Text = "" }, new TextBlock { Text = "" } }; int index = 0; foreach (var textBlock in textBlocks) { grid.Children.Add(textBlock); textBlock.TextAlignment = TextAlignment.Center; textBlock.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); Grid.SetColumn(textBlock, index++); } TextBlock text = new TextBlock() { Name = "Text" + i, IsColorFontEnabled = true, Foreground = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0xff, 0xff)), Margin = new Thickness(50, 160 * i, 0, 0), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Width = 400, Height = 80 }; Grid.Children.Add(bar); Grid.Children.Add(grid); Grid.Children.Add(text); StackPanel.Height += 80; if (i == 0) { Cars[i] = Car.NapraviAuto(Account.CurrentAccount.Nickname, bar, textBlocks); } else if (i == teemoNum) { Cars[i] = Car.NapraviAuto("Teemo", bar, textBlocks); } else { NamesCollection names = NamesCollection.GetInstance(); await names.ReadNamesAsync(); Cars[i] = Car.NapraviAuto(names[RandomGen2.Next() % names.Names.Count], bar, textBlocks); } } Button.Margin = new Thickness(0, 160 * NumberOfCars, 0, 0); Button.HorizontalAlignment = HorizontalAlignment.Center; Button.VerticalAlignment = VerticalAlignment.Top; Button.Width = 100; Button.Height = 40; }
static void Main(string[] args) { Debug.WriteLine("main thread id " + Thread.CurrentThread.ManagedThreadId); List <int> lstNumbersToIterate = new List <int>(); for (int i = 0; i < 1000000; i++) { lstNumbersToIterate.Add(i); } ParallelOptions paralelOp = new ParallelOptions(); paralelOp.MaxDegreeOfParallelism = 10; //since we have 1m items and maximum 8 threads, the .net has split our list into 8 parts starting from 0, 125k, 250k, 375k, 500k, .. //Parallel.ForEach(lstNumbersToIterate, paralelOp, number => { // //Debug.WriteLine("each iteration inside parallel foreach scope thread id " + Thread.CurrentThread.ManagedThreadId); each one runs in a task not in the main thread // Console.WriteLine(number); //}); Random rand = new Random(); Parallel.For(0, 1000000, (i, loop) => { if (rand.Next() == 0) { loop.Stop(); } }); while (true) { Console.WriteLine(rand.Next()); Console.ReadLine(); } //int lastNumber = 1, count = 0; //Parallel.For(0, 1000000, (i, loop) => //{ // // Get the next number // int curNumber = new Random().Next(); // // If it’s the same as the previous number, // // note the increased count // if (curNumber == lastNumber) count++; // // Otherwise, we have a different number than // // the previous. Write out the previous number // // and its count, then start // // over with the new number. // else // { // if (count > 0) // Console.WriteLine( // count + ": " + lastNumber); // lastNumber = curNumber; // } //}); Stopwatch sw; const int NUM = 100000; StreamWriter swWrite = new StreamWriter("classic non locking random generator.txt"); swWrite.AutoFlush = true; paralelOp.MaxDegreeOfParallelism = 100; List <int> lstGeneratedNumbers = new List <int>(); while (true) { sw = Stopwatch.StartNew(); Parallel.For(0, NUM, paralelOp, i => { lstGeneratedNumbers.Add(RandomGen0.Next()); }); Console.WriteLine(sw.Elapsed); File.WriteAllLines("0 static non locking random generator.txt", lstGeneratedNumbers.Select(p => p.ToString())); lstGeneratedNumbers = new List <int>(); sw = Stopwatch.StartNew(); var vrResult = Parallel.For(0, NUM, paralelOp, i => { lstGeneratedNumbers.Add(RandomGen1.Next()); }); Console.WriteLine(sw.Elapsed); File.WriteAllLines("1 thread static random generator.txt", lstGeneratedNumbers.Select(p => p.ToString())); lstGeneratedNumbers = new List <int>(); sw = Stopwatch.StartNew(); Parallel.For(0, NUM, paralelOp, i => { lstGeneratedNumbers.Add(RandomGen2.Next()); }); Console.WriteLine(sw.Elapsed); File.WriteAllLines("2 thread static and RNGCryptoServiceProvider random generator.txt", lstGeneratedNumbers.Select(p => p.ToString())); lstGeneratedNumbers = new List <int>(); sw = Stopwatch.StartNew(); Parallel.For(0, NUM, paralelOp, i => { lstGeneratedNumbers.Add(RandomGen3.Next()); }); Console.WriteLine(sw.Elapsed); File.WriteAllLines("3 thread local and RNGCryptoServiceProvider random generator.txt", lstGeneratedNumbers.Select(p => p.ToString())); lstGeneratedNumbers = new List <int>(); sw = Stopwatch.StartNew(); Parallel.For(0, NUM, paralelOp, i => { lstGeneratedNumbers.Add(RandomGen4.Next()); }); Console.WriteLine(sw.Elapsed); lstGeneratedNumbers = new List <int>(); sw = Stopwatch.StartNew(); Parallel.For(0, NUM, paralelOp, i => { lstGeneratedNumbers.Add(threadSafeRandomWithCrypto(0, Int32.MaxValue)); }); Console.WriteLine(sw.Elapsed); File.WriteAllLines("5 thread safe random generator.txt", lstGeneratedNumbers.Select(p => p.ToString())); swWrite.Flush(); Console.ReadLine(); } }
public async Task <ActionResult> OnPostAsync() { // check if input file was uploaded if (Upload_input != null) { var file_input = Path.Combine("C:\\Users\\matthodg\\source\\repos\\ExtRamp_ASP.Net\\ExtRamp_ASP.Net\\ExtRamp\\ExtRamp\\Uploads\\", Upload_input.FileName); using (var fileStream = new FileStream(file_input, FileMode.Create)) { await Upload_input.CopyToAsync(fileStream); } input_file = Upload_input.FileName; } else { //var file_input = Path.Combine("C:\\Users\\matthodg\\source\\repos\\ExtRamp_ASP.Net\\ExtRamp_ASP.Net\\ExtRamp\\ExtRamp\\Uploads\\", "example_input.fasta"); input_file = "example_input.fasta"; } bool tAI = false; bool rscu = false; if (Upload_tAI != null) { var file_tAI = Path.Combine(_environment.ContentRootPath, "Uploads", Upload_tAI.FileName); using (var fileStream = new FileStream(file_tAI, FileMode.Create)) { await Upload_input.CopyToAsync(fileStream); } tAI = true; tAI_file = Upload_tAI.FileName; } if (Upload_rscu != null) { var file_rscu = Path.Combine(_environment.ContentRootPath, "Uploads", Upload_rscu.FileName); using (var fileStream = new FileStream(file_rscu, FileMode.Create)) { await Upload_input.CopyToAsync(fileStream); } rscu = true; rscu_file = Upload_rscu.FileName; } string lines = GeneSequence; System.IO.File.WriteAllText("C:\\Users\\matthodg\\source\\repos\\ExtRamp_ASP.Net\\ExtRamp_ASP.Net\\ExtRamp\\ExtRamp\\Uploads\\from_text_box.fasta", lines); if (GeneSequence != null) { input_file = "from_text_box.fasta"; } var rand = RandomGen2.Next(); Rand = rand; RunExtRamp(rand, tAI, rscu); // download file // check if only one bool is true bool[] outputFiles = { Vals, Speeds, NoRamps, RemovedSequences, AfterRamp, Standard }; int numTrue = 0; foreach (bool outputFile in outputFiles) { if (outputFile == true) { numTrue += 1; } } if (numTrue == 0 || numTrue == 1) { return(DownloadSingleFile(rand, input_file, tAI_file, rscu_file)); } else { return(DownloadFile(rand, input_file, tAI_file, rscu_file)); } }