-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
134 lines (117 loc) · 4.63 KB
/
Program.cs
File metadata and controls
134 lines (117 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Threading.Tasks;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.SampleConsole.Constants;
using Contentstack.SampleConsole.Services;
namespace Contentstack.SampleConsole;
/// <summary>
/// Main entry point for the Contentstack Sample Console Application.
/// This application demonstrates various features of the Contentstack .NET SDK
/// through an interactive menu-driven console interface.
/// </summary>
static class Program
{
/// <summary>
/// Main entry point of the application.
/// </summary>
/// <param name="args">Command-line arguments (not used).</param>
static async Task Main(string[] args)
{
// Initialize configuration service
var configService = new ConfigurationService();
// Get and validate Contentstack configuration
var missing = configService.GetContentstackConfiguration(
out string? apiKey,
out string? deliveryToken,
out string? environment,
out string? host);
if (missing.Count > 0)
{
Console.WriteLine("Missing required configuration: " + string.Join(", ", missing));
Console.WriteLine("Set values in App.config or environment variables, then run again.");
Environment.Exit(1);
return;
}
// Initialize Contentstack service
var contentstackService = new ContentstackService(apiKey!, deliveryToken!, environment!, host);
var menuService = new MenuService();
// Initialize menu services
var contentTypesMenuService = new ContentTypesMenuService(contentstackService, menuService);
var entriesMenuService = new EntriesMenuService(contentstackService, menuService);
var syncMenuService = new SyncMenuService(contentstackService.Client, menuService);
var assetsMenuService = new AssetsMenuService(contentstackService.Client, menuService);
var taxonomyMenuService = new TaxonomyMenuService(
contentstackService.Client,
menuService,
entriesMenuService);
// Main application loop
await RunMainLoopAsync(
menuService,
contentTypesMenuService,
entriesMenuService,
syncMenuService,
assetsMenuService,
taxonomyMenuService);
}
/// <summary>
/// Runs the main application loop, displaying the menu and handling user input.
/// </summary>
private static async Task RunMainLoopAsync(
MenuService menuService,
ContentTypesMenuService contentTypesMenuService,
EntriesMenuService entriesMenuService,
SyncMenuService syncMenuService,
AssetsMenuService assetsMenuService,
TaxonomyMenuService taxonomyMenuService)
{
while (true)
{
menuService.ShowMainMenu();
var input = menuService.ReadInput();
if (string.IsNullOrEmpty(input))
{
Console.WriteLine("Please enter a number (1-7).\n");
continue;
}
try
{
switch (input)
{
case MenuOptions.ListContentTypes:
await contentTypesMenuService.HandleListContentTypesAsync();
break;
case MenuOptions.QueryEntries:
await entriesMenuService.HandleQueryEntriesAsync();
break;
case MenuOptions.FetchSingleEntry:
await entriesMenuService.HandleFetchSingleEntryAsync();
break;
case MenuOptions.SyncMenu:
await syncMenuService.HandleSyncMenuAsync();
break;
case MenuOptions.AssetsMenu:
await assetsMenuService.HandleAssetsMenuAsync();
break;
case MenuOptions.TaxonomyMenu:
await taxonomyMenuService.HandleTaxonomyMenuAsync();
break;
case MenuOptions.Exit:
Console.WriteLine("Goodbye.");
return;
default:
Console.WriteLine("Invalid option. Enter 1-7.\n");
break;
}
}
catch (ContentstackException ex)
{
Console.WriteLine($"Contentstack error: {ex.Message}\n");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}\n");
}
}
}
}