Skip to content

Commit

Permalink
Change all C# files to use file scoped namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhg committed Aug 30, 2024
1 parent 32172ec commit 1368836
Show file tree
Hide file tree
Showing 1,127 changed files with 137,063 additions and 138,175 deletions.
139 changes: 69 additions & 70 deletions sample/BenchmarkServer/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <copyright file="ProductsController.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
Expand All @@ -11,92 +11,91 @@
using Microsoft.AspNetCore.OData.Routing.Controllers;
using ODataPerformanceProfile.Models;

namespace ODataPerformanceProfile.Controllers
namespace ODataPerformanceProfile.Controllers;

public class ProductsController : ODataController
{
public class ProductsController : ODataController
{
private ProductsContext _context;
private IList<Product> products;
private ProductsContext _context;
private IList<Product> products;

public ProductsController(ProductsContext context)
{
_context = context;
products = new List<Product>();
public ProductsController(ProductsContext context)
{
_context = context;
products = new List<Product>();

for (int i = 1; i < 3000; i++)
for (int i = 1; i < 3000; i++)
{
var prod = new Product()
{
var prod = new Product()
Id = i,
Category = "Goods" + i,
Color = Color.Red,
Others = new List<string> {"Others1", "Others2", "Others3"},
CreatedDate = new DateTimeOffset(2001, 4, 15, 16, 24, 8, TimeSpan.FromHours(-8)),
UpdatedDate = new DateTimeOffset(2011, 2, 15, 16, 24, 8, TimeSpan.FromHours(-8)),
Detail = new ProductDetail { Id = "Id" + i, Info = "Info" + i },
ProductOrders = new List<Order> {
new Order
{
Id = i,
OrderNo = "Order"+i
}
},
ProductSuppliers = new List<Supplier>
{
Id = i,
Category = "Goods" + i,
Color = Color.Red,
Others = new List<string> {"Others1", "Others2", "Others3"},
CreatedDate = new DateTimeOffset(2001, 4, 15, 16, 24, 8, TimeSpan.FromHours(-8)),
UpdatedDate = new DateTimeOffset(2011, 2, 15, 16, 24, 8, TimeSpan.FromHours(-8)),
Detail = new ProductDetail { Id = "Id" + i, Info = "Info" + i },
ProductOrders = new List<Order> {
new Order
{
Id = i,
OrderNo = "Order"+i
}
},
ProductSuppliers = new List<Supplier>
new Supplier
{
new Supplier
Id = i,
Name = "Supplier"+i,
Description = "SupplierDesc"+i,
SupplierAddress = new Location
{
Id = i,
Name = "Supplier"+i,
Description = "SupplierDesc"+i,
SupplierAddress = new Location
{
City = "SupCity"+i,
Address = "SupAddre"+i
}
City = "SupCity"+i,
Address = "SupAddre"+i
}
},
Properties = new Dictionary<string, object>
{
{ "Prop1", new DateTimeOffset(2014, 7, 3, 0, 0, 0, 0, new TimeSpan(0))},
{ "Prop2", new [] { "Leonard G. Lobel", "Eric D. Boyd" }},
{ "Prop3", "Others"}
}
};
},
Properties = new Dictionary<string, object>
{
{ "Prop1", new DateTimeOffset(2014, 7, 3, 0, 0, 0, 0, new TimeSpan(0))},
{ "Prop2", new [] { "Leonard G. Lobel", "Eric D. Boyd" }},
{ "Prop3", "Others"}
}
};

products.Add(prod);
}
products.Add(prod);
}
}

[HttpGet]
[EnableQuery(PageSize = 3000)]
public IActionResult Get()
{
return Ok(products);
}
[HttpGet]
[EnableQuery(PageSize = 3000)]
public IActionResult Get()
{
return Ok(products);
}

[HttpGet("odata/Products/mostRecent()")]
public IActionResult MostRecent()
{
var maxProductId = products.Max(x => x.Id);
return Ok(maxProductId);
}
[HttpGet("odata/Products/mostRecent()")]
public IActionResult MostRecent()
{
var maxProductId = products.Max(x => x.Id);
return Ok(maxProductId);
}

[HttpPost("odata/Products({key})/Rate")]
public IActionResult Rate([FromODataUri] string key, ODataActionParameters parameters)
[HttpPost("odata/Products({key})/Rate")]
public IActionResult Rate([FromODataUri] string key, ODataActionParameters parameters)
{
if (!ModelState.IsValid)
{
if (!ModelState.IsValid)
{
return BadRequest();
}

int rating = (int)parameters["rating"];
return BadRequest();
}

if (rating < 0)
{
return BadRequest();
}
int rating = (int)parameters["rating"];

return Ok(new ProductRating() { Id = key, Rating = rating });
if (rating < 0)
{
return BadRequest();
}

return Ok(new ProductRating() { Id = key, Rating = rating });
}
}
37 changes: 18 additions & 19 deletions sample/BenchmarkServer/EdmModelBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <copyright file="EdmModelBuilder.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
Expand All @@ -9,29 +9,28 @@
using Microsoft.OData.ModelBuilder;
using ODataPerformanceProfile.Models;

namespace ODataPerformanceProfile
namespace ODataPerformanceProfile;

public static class EdmModelBuilder
{
public static class EdmModelBuilder
public static IEdmModel GetEdmModel()
{
public static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
builder.EntitySet<Supplier>("Suppliers");
builder.EntitySet<Order>("Orders");
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
builder.EntitySet<Supplier>("Suppliers");
builder.EntitySet<Order>("Orders");

builder.EntityType<Product>().Collection
.Function("mostRecent")
.Returns<string>();
builder.EntityType<Product>().Collection
.Function("mostRecent")
.Returns<string>();

builder.EntityType<Product>()
.Action("rate")
.Parameter<int>("rating");
builder.EntityType<Product>()
.Action("rate")
.Parameter<int>("rating");

var model = builder.GetEdmModel();
model.MarkAsImmutable();
var model = builder.GetEdmModel();
model.MarkAsImmutable();

return model;
}
return model;
}
}
97 changes: 48 additions & 49 deletions sample/BenchmarkServer/Models/Product.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <copyright file="Product.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
Expand All @@ -7,60 +7,59 @@

using System.ComponentModel.DataAnnotations;

namespace ODataPerformanceProfile.Models
namespace ODataPerformanceProfile.Models;

public class Product
{
public class Product
{
public int Id { get; set; }
public string Category { get; set; }
public Color Color { get; set; }
public IList<string> Others { get; set; }
public DateTimeOffset CreatedDate { get; set; }
public int Id { get; set; }
public string Category { get; set; }
public Color Color { get; set; }
public IList<string> Others { get; set; }
public DateTimeOffset CreatedDate { get; set; }

[ConcurrencyCheck]
public DateTimeOffset? UpdatedDate { get; set; }
public virtual ProductDetail Detail { get; set; }
public virtual ICollection<Supplier> ProductSuppliers { get; set; }
public virtual ICollection<Order> ProductOrders { get; set; }
public IDictionary<string, object> Properties { get; set; }
}
[ConcurrencyCheck]
public DateTimeOffset? UpdatedDate { get; set; }
public virtual ProductDetail Detail { get; set; }
public virtual ICollection<Supplier> ProductSuppliers { get; set; }
public virtual ICollection<Order> ProductOrders { get; set; }
public IDictionary<string, object> Properties { get; set; }
}

public class ProductDetail
{
public string Id { get; set; }
public string Info { get; set; }
}
public class ProductDetail
{
public string Id { get; set; }
public string Info { get; set; }
}

public class Supplier
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Location SupplierAddress { get; set; }
}
public class Supplier
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Location SupplierAddress { get; set; }
}

public enum Color
{
Red,
Green,
Blue
}
public enum Color
{
Red,
Green,
Blue
}

public class Location
{
public string City { get; set; }
public string Address { get; set; }
}
public class Location
{
public string City { get; set; }
public string Address { get; set; }
}

public class Order
{
public int Id { get; set; }
public string OrderNo { get; set; }
}
public class Order
{
public int Id { get; set; }
public string OrderNo { get; set; }
}

public class ProductRating
{
public string Id { get; set; }
public int Rating { get; set; }
}
public class ProductRating
{
public string Id { get; set; }
public int Rating { get; set; }
}
31 changes: 15 additions & 16 deletions sample/BenchmarkServer/Models/ProductsContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <copyright file="ProductsContext.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
Expand All @@ -7,23 +7,22 @@

using Microsoft.EntityFrameworkCore;

namespace ODataPerformanceProfile.Models
namespace ODataPerformanceProfile.Models;

public class ProductsContext : DbContext
{
public class ProductsContext : DbContext
public ProductsContext(DbContextOptions<ProductsContext> options)
: base(options)
{
public ProductsContext(DbContextOptions<ProductsContext> options)
: base(options)
{
}
}

public DbSet<Product> Products { get; set; }
public DbSet<Supplier> Suppliers { get; set; }
public DbSet<Order> Orders { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Product>().HasMany(a => a.ProductSuppliers);
modelBuilder.Entity<Product>().HasMany(a => a.ProductOrders);
modelBuilder.Entity<Supplier>().OwnsOne(c => c.SupplierAddress).WithOwner();
}
public DbSet<Product> Products { get; set; }
public DbSet<Supplier> Suppliers { get; set; }
public DbSet<Order> Orders { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Product>().HasMany(a => a.ProductSuppliers);
modelBuilder.Entity<Product>().HasMany(a => a.ProductOrders);
modelBuilder.Entity<Supplier>().OwnsOne(c => c.SupplierAddress).WithOwner();
}
}
Loading

0 comments on commit 1368836

Please sign in to comment.