namespace WindowsFormsApp1
{
partial class UserControl1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(142, 67);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(346, 47);
this.button1.TabIndex = 0;
this.button1.Text = "Eat me!";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// UserControl1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.button1);
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(710, 150);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
}
}
namespace ConsoleApp39
{
class Program
{
static void Main(string[] args)
{
Student[] students = new Student[3];
for (int i = 0; i < students.Length; i++) students[i].SetInfo();
Student.GetInfo(students);
}
}
struct Student
{
string LastName;
string FirstName;
int GroupNumber;
int[] scores;
public void SetInfo()
{
Console.WriteLine("Last name: ");
LastName = Console.ReadLine();
Console.WriteLine("Name: ");
FirstName = Console.ReadLine();
Console.WriteLine("Number: ");
while (!int.TryParse(Console.ReadLine(), out GroupNumber)) {
Console.WriteLine("Only number allowed");
};
Console.WriteLine("Scores: ");
scores = new int[5];
int inp;
for (int i = 0; i < scores.Length; i++)
{
while (!int.TryParse(Console.ReadLine(), out inp))
{
Console.WriteLine("Only number allowed");
};
scores[i] = inp;
}
}
public static void GetInfo(Student[] students)
{
foreach (var student in students)
{
for (int i = 0; i < student.scores.Length; i++)
{
if (student.scores[i] <= 2)
{
Console.WriteLine($"Last name: {student.LastName}\n name: {student.FirstName}\n Group: {student.GroupNumber}");
}
}
}
}
}
}
using System;
using System.Runtime.InteropServices;
public class Program
{
// Import user32.dll (containing the function we need) and define
// the method corresponding to the native function.
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType);
public static void Main(string[] args)
{
// Invoke the function as a regular managed method.
MessageBox(IntPtr.Zero, "Command-line message box", "Attention!", 0);
}
}
Host.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureLogging(loggerFactory => loggerFactory.AddEventLog())
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ServiceTelemetry>();
})
.ConfigureWebHostDefaults(webBuilder =>
{
var fileName = Process.GetCurrentProcess().MainModule.FileName;
var procDirectory = Directory.GetParent(fileName).FullName;
var appSettings = Path.Combine(procDirectory, "appsettings.json");
var config = new ConfigurationBuilder()
.SetBasePath(procDirectory)
.AddEnvironmentVariables()
.AddJsonFile(appSettings)
.AddCommandLine(args)
.Build();
webBuilder
.UseConfiguration(config)
.UseStartup<Startup>();
});
public void ConfigureServices(IServiceCollection services)
{
var con = _configuration.GetConnectionString("telemetry");
services.AddDbContext<TelemetryContext>(options => options.UseSqlServer(con));
}
[ApiController]
[Route("api/[controller]")]
public class TelemetryController : ControllerBase
{
private const int Interval = 15;
private readonly TelemetryContext _ctx;
public TelemetryController(TelemetryContext context)
{
_ctx = context;
}
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> Post(TelemetryModel model)
{
if (ModelState.IsValid)
{
public class User
{
[Key]
public int Id { get; set; }
public int Age { get; set; }
[MaxLength(60)]
public string Name { get; set; }
[MaxLength(20)]
public string Status { get; set; }
public override string ToString() => $"id: {Id} Name: {Name} Age: {Age} Status: {Status}";
}
public class UserContext : DbContext
{
public static readonly ILoggerFactory LoggerFactory
= new LoggerFactory(new[] {
new ConsoleLoggerProvider((category, level) =>
category == DbLoggerCategory.Database.Command.Name &&
level == LogLevel.Information, true)
});
public UserContext() : base()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseLoggerFactory(LoggerFactory) // для отключения логгирования закоменнтировать строку
.EnableSensitiveDataLogging() // для отключения логгирования закоменнтировать строку
.UseSqlServer(@"Server=.;Database=UserTestDB;Trusted_Connection=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.HasIndex(b => b.Status)
.HasName("IX_Status");
modelBuilder.Entity<User>()
.HasIndex(b => b.Age)
.HasName("IX_Age");
modelBuilder.Entity<User>()
.HasIndex(b => b.Name)
.HasName("IX_Name");
}
public DbSet<User> Users { get; set; }
}