forked from madelson/DistributedLock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (52 loc) · 1.8 KB
/
Program.cs
File metadata and controls
56 lines (52 loc) · 1.8 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
using Medallion.Threading;
using Medallion.Threading.Sql;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DistributedLockTaker.cs
{
class Program
{
private static readonly string ConnectionString = new SqlConnectionStringBuilder
{
DataSource = @".\SQLEXPRESS",
InitialCatalog = "master",
IntegratedSecurity = true
}
.ConnectionString;
static int Main(string[] args)
{
var type = args[0];
var name = args[1];
IDisposable handle = null;
switch (type)
{
case "SqlDistributedLock":
handle = new SqlDistributedLock(name, ConnectionString).Acquire();
break;
case "SqlReaderWriterLockDistributedLock":
handle = new SqlDistributedReaderWriterLock(name, ConnectionString).AcquireWriteLock();
break;
case "SqlSemaphoreDistributedLock":
handle = new SqlDistributedSemaphore(name, maxCount: 1, connectionString: ConnectionString).Acquire();
break;
case "SqlSemaphoreDistributedLock5":
handle = new SqlDistributedSemaphore(name, maxCount: 5, connectionString: ConnectionString).Acquire();
break;
case "SystemDistributedLock":
handle = new SystemDistributedLock(name).Acquire();
break;
default:
return 123;
}
if (Console.ReadLine() != "abandon")
{
handle.Dispose();
}
return 0;
}
}
}