Skip to content

Commit 356959b

Browse files
committed
Added missing models
1 parent 51d1a2a commit 356959b

File tree

4 files changed

+156
-1
lines changed

4 files changed

+156
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
3+
4+
namespace Web.AnalyticsWeb.Models
5+
{
6+
public class AuthTeamRequest
7+
{
8+
9+
[JsonProperty("teamIdsToAuth")]
10+
public List<string> TeamIdsToAuth { get; set; }
11+
12+
[JsonProperty("teamIdsToDeauth")]
13+
public List<string> TeamIdsToDeauth { get; set; }
14+
15+
[JsonProperty("token")]
16+
public string Token { get; set; }
17+
}
18+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using App.ControlPanel.Engine;
2+
using Azure.Messaging.ServiceBus;
3+
using Common.Entities;
4+
using Common.Entities.Config;
5+
using Common.Entities.Redis;
6+
using Newtonsoft.Json;
7+
using System.Data.Entity;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
11+
namespace Web.AnalyticsWeb.Models
12+
{
13+
public class SystemStatus
14+
{
15+
#region Constructors
16+
17+
public SystemStatus(string json)
18+
{
19+
if (!string.IsNullOrEmpty(json))
20+
{
21+
try
22+
{
23+
this.Config = JsonConvert.DeserializeObject<SolutionInstallConfig>(json);
24+
}
25+
catch (JsonReaderException)
26+
{
27+
// Nothing. Show no config object
28+
}
29+
}
30+
31+
this.ConfigJson = json;
32+
}
33+
protected SystemStatus() { }
34+
35+
#endregion
36+
37+
#region Props
38+
39+
public SolutionInstallConfig Config { get; set; }
40+
41+
public string ConfigJson { get; set; }
42+
43+
public int HitCount { get; set; }
44+
public int ActivityCount { get; set; }
45+
46+
public int TeamsCount { get; set; }
47+
public int TeamsBeingTrackedCount { get; set; }
48+
49+
public string BuildLabel { get; set; }
50+
51+
public bool HasValidConfig
52+
{
53+
get { return this.Config != null; }
54+
}
55+
56+
public string WebAppConfigSQL { get; set; }
57+
public string WebAppConfigRedis { get; set; }
58+
public string WebAppConfigServiceBus { get; set; }
59+
public string WebAppConfigCognitive { get; set; }
60+
public bool CognitiveServiceEnabled { get; set; }
61+
public string WebAppBaseURL { get; set; }
62+
public bool YammerAuth { get; set; }
63+
64+
#endregion
65+
66+
internal async static Task<SystemStatus> LoadFrom(AnalyticsEntitiesContext db, CacheConnectionManager cache)
67+
{
68+
SystemStatus status = null;
69+
70+
71+
// Load config
72+
var latestConfig = await db.ConfigStates.OrderByDescending(s => s.DateApplied).Take(1).ToListAsync();
73+
if (latestConfig.Count == 1 && !string.IsNullOrEmpty(latestConfig[0].ConfigJson))
74+
{
75+
try
76+
{
77+
status = new SystemStatus(latestConfig[0].ConfigJson);
78+
}
79+
catch (JsonReaderException)
80+
{
81+
status = new UnknownConfigSystemStatus();
82+
}
83+
}
84+
else
85+
{
86+
status = new UnknownConfigSystemStatus();
87+
}
88+
89+
status.BuildLabel = System.Configuration.ConfigurationManager.AppSettings["BuildLabel"];
90+
91+
// DB counts
92+
status.HitCount = await db.hits.CountAsync();
93+
status.ActivityCount = await db.AuditEventsCommon.CountAsync();
94+
status.TeamsCount = await db.Teams.CountAsync();
95+
status.TeamsBeingTrackedCount = await db.Teams.Where(t => t.HasRefreshToken).CountAsync();
96+
97+
// Config
98+
var config = new AppConfig();
99+
status.WebAppConfigCognitive = config.CognitiveEndpoint;
100+
status.WebAppConfigRedis = StackExchange.Redis.ConfigurationOptions.Parse(config.ConnectionStrings.RedisConnectionString).SslHost;
101+
status.WebAppConfigSQL = new System.Data.SqlClient.SqlConnectionStringBuilder(config.ConnectionStrings.DatabaseConnectionString).DataSource;
102+
status.WebAppConfigServiceBus = ServiceBusConnectionStringProperties.Parse(config.ConnectionStrings.ServiceBusConnectionString).Endpoint.ToString();
103+
status.CognitiveServiceEnabled = config.IsValidCognitiveConfig;
104+
status.WebAppBaseURL = config.WebAppURL;
105+
return status;
106+
}
107+
}
108+
109+
public class UnknownConfigSystemStatus : SystemStatus
110+
{
111+
public UnknownConfigSystemStatus() : this(string.Empty)
112+
{
113+
}
114+
public UnknownConfigSystemStatus(string json) : base(json)
115+
{
116+
base.Config = SolutionInstallConfig.NewConfig();
117+
}
118+
}
119+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Web.AnalyticsWeb.Models
4+
{
5+
/// <summary>
6+
/// Used to list access tokens for Teams
7+
/// </summary>
8+
public class TeamAuthStatusResponse
9+
{
10+
[JsonProperty("teamId")]
11+
public string TeamId { get; set; }
12+
13+
[JsonProperty("hasAuthToken")]
14+
public bool HasAuthToken { get; set; }
15+
}
16+
}

src/AnalyticsEngine/Web/Web.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@
204204
<Compile Include="Global.asax.cs">
205205
<DependentUpon>Global.asax</DependentUpon>
206206
</Compile>
207+
<Compile Include="Models\AuthTeamRequest.cs" />
208+
<Compile Include="Models\SystemStatus.cs" />
209+
<Compile Include="Models\TeamAuthStatusResponse.cs" />
207210
<Compile Include="Properties\AssemblyInfo.cs" />
208211
<Compile Include="Startup.cs" />
209212
</ItemGroup>
@@ -230,7 +233,6 @@
230233
</ItemGroup>
231234
<ItemGroup>
232235
<Folder Include="App_Data\" />
233-
<Folder Include="Models\" />
234236
<Folder Include="Scripts\teams-permission-grant\build\static\" />
235237
</ItemGroup>
236238
<ItemGroup>

0 commit comments

Comments
 (0)