-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial draft of the project order management system
- Loading branch information
1 parent
012985d
commit c7da70b
Showing
19 changed files
with
868 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*bin | ||
*obj | ||
*.vs | ||
*.vscode | ||
C Sharp* | ||
App.config | ||
Settings.settings | ||
Settings.Designer.cs |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from faker import Faker | ||
import csv, json | ||
import random | ||
from datetime import datetime, timedelta | ||
|
||
fake = Faker() | ||
|
||
# Function to generate data for Categories table | ||
def generate_categories_data(): | ||
categories = [ | ||
{'category_id': i + 1, 'category_name': fake.word()} | ||
for i in range(10000) # Modify the range for the number of rows needed | ||
] | ||
return categories | ||
|
||
# Function to generate data for Products table | ||
def generate_products_data(): | ||
products = [ | ||
{ | ||
'product_id': i + 1, | ||
'product_name': fake.word(), | ||
'category_id': random.randint(1, 10000), # Assuming 10000 categories | ||
'price': round(random.uniform(10, 1000), 2), | ||
'description': fake.sentence(), | ||
'image_url': fake.image_url(), | ||
'date_added': (datetime.now() - timedelta(days=random.randint(1, 365))).strftime('%Y-%m-%d') | ||
} | ||
for i in range(1000000) # Modify the range for the number of rows needed | ||
] | ||
return products | ||
|
||
# Function to generate data for Orders table | ||
def generate_orders_data(): | ||
orders = [ | ||
{'order_id': i + 1, 'order_date': (datetime.now() - timedelta(days=random.randint(1, 365))).strftime('%Y-%m-%d'), 'customer_name': fake.name()} | ||
for i in range(50000) # Modify the range for the number of rows needed | ||
] | ||
return orders | ||
|
||
# Function to generate data for OrderProducts table | ||
def generate_order_products_data(): | ||
order_products = [ | ||
{'order_id': random.randint(1, 50000), 'product_id': random.randint(1, 1000000)} # Assuming 50000 orders and 1000000 products | ||
for _ in range(150000) # Modify the range for the number of rows needed | ||
] | ||
return order_products | ||
|
||
# Write data to CSV files | ||
def write_to_csv(data, filename): | ||
folderPath = "./generated_files/" | ||
with open(folderPath + filename, 'w', newline='', encoding='utf-8') as csvfile: | ||
writer = csv.DictWriter(csvfile, fieldnames=data[0].keys()) | ||
writer.writeheader() | ||
writer.writerows(data) | ||
|
||
# Write data to json files | ||
def write_to_json(data, filename): | ||
folderPath = "./generated_files/" | ||
with open(folderPath + filename, 'w') as file: | ||
json.dump(data, file, indent=2) | ||
|
||
# Generate data for each table | ||
categories_data = generate_categories_data() | ||
products_data = generate_products_data() | ||
orders_data = generate_orders_data() | ||
order_products_data = generate_order_products_data() | ||
|
||
|
||
# Write data to CSV files | ||
write_to_csv(categories_data, 'categories.csv') | ||
write_to_csv(products_data, 'products.csv') | ||
write_to_csv(orders_data, 'orders.csv') | ||
write_to_csv(order_products_data, 'order_products.csv') | ||
|
||
write_to_json(categories_data, 'categories.json') | ||
write_to_json(products_data, 'products.json') | ||
write_to_json(orders_data, 'orders.json') | ||
write_to_json(order_products_data, 'order_products.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34408.163 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmsCli", "OmsCli\OmsCli.csproj", "{7B679F98-6515-4429-B6AC-EDDC5811416F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{7B679F98-6515-4429-B6AC-EDDC5811416F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{7B679F98-6515-4429-B6AC-EDDC5811416F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{7B679F98-6515-4429-B6AC-EDDC5811416F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{7B679F98-6515-4429-B6AC-EDDC5811416F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {50D39080-D9F8-496E-ADE6-2ED9D61D7E8F} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using Azure; | ||
using Azure.Core; | ||
using Azure.Identity; | ||
using Azure.ResourceManager; | ||
using Azure.ResourceManager.DataFactory; | ||
using Azure.ResourceManager.DataFactory.Models; | ||
using Azure.ResourceManager.Resources; | ||
|
||
namespace OmsCli.AdfManager | ||
{ | ||
public static class AdfManager | ||
{ | ||
#region Azure parameters | ||
private static readonly Settings setting = new(); | ||
|
||
// Set variables | ||
private static readonly string tenantID = setting.TenantId; | ||
|
||
/// <summary> | ||
/// your application ID | ||
/// </summary> | ||
private static readonly string applicationId = setting.ApplicationId; | ||
/// <summary> | ||
/// authentication key for the application | ||
/// </summary> | ||
private static readonly string authenticationKey = setting.ApplicationSecret; | ||
|
||
/// <summary> | ||
/// your subscription ID where the data factory resides | ||
/// </summary> | ||
private static readonly string subscriptionId = setting.SubscriptionId; | ||
|
||
/// <summary> | ||
/// your resource group where the data factory resides | ||
/// </summary> | ||
private static readonly string resourceGroupName = setting.ResourceGroup; | ||
|
||
/// <summary> | ||
/// specify the name of data factory to create. It must be globally unique | ||
/// </summary> | ||
private static readonly string dataFactoryName = "omsadf-learning"; | ||
|
||
|
||
public const string PIPELINE = "RandomData"; | ||
|
||
#endregion | ||
|
||
public static Response<PipelineCreateRunResult> TriggerPipeline(string pipelineName, IDictionary<string, BinaryData>? parameters) | ||
{ | ||
Console.WriteLine($"Reading datafactory: {dataFactoryName}"); | ||
var dataFactoryResource = GetDataFactory(); | ||
|
||
// Create a pipeline run | ||
Console.WriteLine("Creating pipeline run..."); | ||
var pipelineResource = dataFactoryResource.GetDataFactoryPipeline(pipelineName); | ||
|
||
Console.WriteLine($"Starting pipeline run: {pipelineName}"); | ||
var runResponse = pipelineResource.Value.CreateRun(parameters); | ||
Console.WriteLine("Pipeline run ID: " + runResponse.Value.RunId); | ||
|
||
return runResponse; | ||
} | ||
|
||
public static void MonitorPipeline(string pipelineRunId, string pipelineName) | ||
{ | ||
Console.WriteLine($"Reading datafactory: {dataFactoryName}"); | ||
var dataFactoryResource = GetDataFactory(); | ||
|
||
|
||
// Monitor the pipeline run | ||
Console.WriteLine($"Checking pipeline ${pipelineName} run status..."); | ||
DataFactoryPipelineRunInfo pipelineRun; | ||
while (true) | ||
{ | ||
pipelineRun = dataFactoryResource.GetPipelineRun(pipelineRunId); | ||
Console.WriteLine($"Status: {pipelineRun.Status}"); | ||
if (pipelineRun.Status == "InProgress" || pipelineRun.Status == "Queued") | ||
{ | ||
Console.WriteLine($"Sleeping for 15 seconds, pipeline status {pipelineRun.Status}"); | ||
System.Threading.Thread.Sleep(15000); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Pipeline completed successfully. Status {pipelineRun.Status}"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private static ArmClient ObtainArmClient() | ||
{ | ||
ArmClient armClient = new( | ||
new ClientSecretCredential(tenantID, applicationId, authenticationKey, new TokenCredentialOptions | ||
{ | ||
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud | ||
}), | ||
subscriptionId, | ||
new ArmClientOptions { Environment = ArmEnvironment.AzurePublicCloud } | ||
); | ||
return armClient; | ||
} | ||
|
||
private static SubscriptionResource ObtainSubscriptionResource(ArmClient armClient) { | ||
ResourceIdentifier resourceIdentifier = SubscriptionResource.CreateResourceIdentifier(subscriptionId); | ||
SubscriptionResource subscriptionResource = armClient.GetSubscriptionResource(resourceIdentifier); | ||
return subscriptionResource; | ||
} | ||
|
||
private static ResourceGroupResource GetResource(SubscriptionResource subscriptionResource) { | ||
Console.WriteLine("Get an existing resource group " + resourceGroupName + "..."); | ||
var resourceGroupOperation = subscriptionResource.GetResourceGroup(resourceGroupName); | ||
|
||
return resourceGroupOperation.Value; | ||
} | ||
|
||
private static DataFactoryResource GetDataFactory() | ||
{ | ||
try | ||
{ | ||
ArmClient armClient = ObtainArmClient(); | ||
SubscriptionResource subscriptionResource = ObtainSubscriptionResource(armClient); | ||
var resourceGroupResource = GetResource(subscriptionResource); | ||
|
||
Console.WriteLine("Get Data Factory " + dataFactoryName + "..."); | ||
var dataFactoryOperation = resourceGroupResource.GetDataFactory(dataFactoryName); | ||
return dataFactoryOperation.Value; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
Console.Read(); | ||
throw; | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.