blob: 6ba2785110123524a56338ad6d327e5ac45c45f0 (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tango.BL;
using Tango.Core;
using Tango.PPC.Common.UpdatePackages;
using Tango.PPC.Shared.Updates;
namespace Tango.PPC.Packages.Auth2
{
[PPCPackage(PackageType.Pre, "Applying Auth2 Patch", false)]
public class Auth2 : ExtendedObject, IPPCPackage
{
public Task Run(PackageContext context)
{
return Task.Factory.StartNew(() =>
{
LogManager.Log("Starting Auth2 package procedure...");
using (ObservablesContext db = ObservablesContext.CreateDefault())
{
using (var transaction = db.Database.BeginTransaction())
{
LogManager.Log("Setting all jobs users to null...");
context.ReportProgress("Modifying jobs...");
db.Database.ExecuteSqlCommand("ALTER TABLE JOBS ALTER COLUMN USER_GUID VARCHAR(36) NULL");
db.Database.ExecuteSqlCommand("UPDATE JOBS SET USER_GUID = NULL");
Thread.Sleep(1000);
LogManager.Log("Setting all job runs users to null...");
context.ReportProgress("Modifying job runs...");
db.Database.ExecuteSqlCommand("UPDATE JOB_RUNS SET USER_GUID = NULL");
Thread.Sleep(1000);
LogManager.Log("Setting all events users to null...");
context.ReportProgress("Modifying events...");
db.Database.ExecuteSqlCommand("UPDATE MACHINES_EVENTS SET USER_GUID = NULL");
Thread.Sleep(1000);
LogManager.Log("Removing all users...");
context.ReportProgress("Modifying users...");
db.Database.ExecuteSqlCommand("DELETE FROM USERS");
Thread.Sleep(1000);
LogManager.Log("Removing redundant addresses...");
context.ReportProgress("Modifying addresses...");
db.Database.ExecuteSqlCommand(@"
DELETE ADDRESSES FROM ADDRESSES
FULL JOIN ORGANIZATIONS ON ORGANIZATIONS.ADDRESS_GUID = ADDRESSES.GUID
WHERE ORGANIZATIONS.ADDRESS_GUID IS NULL");
Thread.Sleep(1000);
LogManager.Log("Removing redundant contacts...");
context.ReportProgress("Modifying contacts...");
db.Database.ExecuteSqlCommand(@"
DELETE CONTACTS FROM CONTACTS
FULL JOIN ORGANIZATIONS ON ORGANIZATIONS.CONTACT_GUID = CONTACTS.GUID
WHERE ORGANIZATIONS.CONTACT_GUID IS NULL");
Thread.Sleep(1000);
LogManager.Log("Committing transaction...");
context.ReportProgress("Committing transaction...");
transaction.Commit();
}
}
});
}
}
}
|