Created
April 19, 2016 15:04
-
-
Save jungrok5/c373fb6de646b08d5ba259b8b84f82ad to your computer and use it in GitHub Desktop.
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
<script> | |
$(document).ready(function () { | |
if (g_ServerListIntervalID == 0) { | |
g_ServerListIntervalID = setInterval(function () { | |
$('#serverList').load('/Server/ServerList'); | |
}, 3000); | |
} | |
}); | |
</script> | |
$(document).ready(function () { | |
$('#serverList').load('/Server/ServerList'); | |
}); |
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
using System.Runtime.InteropServices; | |
namespace GMTool.Sources.Util | |
{ | |
// 서비스 컨트롤 할때 원격에 있는 경우 아래 기능이 필요하다. 또는 원격에 있는 네트워크 드라이브 연결할때도 사용하면됨 | |
// http://www.pinvoke.net/default.aspx/mpr.wnetaddconnection2 | |
public class NetworkDrive | |
{ | |
public enum ResourceScope | |
{ | |
RESOURCE_CONNECTED = 1, | |
RESOURCE_GLOBALNET, | |
RESOURCE_REMEMBERED, | |
RESOURCE_RECENT, | |
RESOURCE_CONTEXT | |
} | |
public enum ResourceType | |
{ | |
RESOURCETYPE_ANY, | |
RESOURCETYPE_DISK, | |
RESOURCETYPE_PRINT, | |
RESOURCETYPE_RESERVED | |
} | |
public enum ResourceUsage | |
{ | |
RESOURCEUSAGE_CONNECTABLE = 0x00000001, | |
RESOURCEUSAGE_CONTAINER = 0x00000002, | |
RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004, | |
RESOURCEUSAGE_SIBLING = 0x00000008, | |
RESOURCEUSAGE_ATTACHED = 0x00000010, | |
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED), | |
} | |
public enum ResourceDisplayType | |
{ | |
RESOURCEDISPLAYTYPE_GENERIC, | |
RESOURCEDISPLAYTYPE_DOMAIN, | |
RESOURCEDISPLAYTYPE_SERVER, | |
RESOURCEDISPLAYTYPE_SHARE, | |
RESOURCEDISPLAYTYPE_FILE, | |
RESOURCEDISPLAYTYPE_GROUP, | |
RESOURCEDISPLAYTYPE_NETWORK, | |
RESOURCEDISPLAYTYPE_ROOT, | |
RESOURCEDISPLAYTYPE_SHAREADMIN, | |
RESOURCEDISPLAYTYPE_DIRECTORY, | |
RESOURCEDISPLAYTYPE_TREE, | |
RESOURCEDISPLAYTYPE_NDSCONTAINER | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
private class NETRESOURCE | |
{ | |
public ResourceScope dwScope = 0; | |
public ResourceType dwType = 0; | |
public ResourceDisplayType dwDisplayType = 0; | |
public ResourceUsage dwUsage = 0; | |
public string lpLocalName = null; | |
public string lpRemoteName = null; | |
public string lpComment = null; | |
public string lpProvider = null; | |
} | |
public enum WNetAddConnectionFlag | |
{ | |
CONNECT_UPDATE_PROFILE = 0x00000001, | |
} | |
[DllImport("mpr.dll")] | |
private static extern int WNetAddConnection2(NETRESOURCE lpNetResource, string lpPassword, string lpUsername, int dwFlags); | |
public int MapNetworkDrive(string unc, string drive, string user, string password) | |
{ | |
NETRESOURCE myNetResource = new NETRESOURCE(); | |
myNetResource.dwScope = ResourceScope.RESOURCE_GLOBALNET; | |
myNetResource.dwType = ResourceType.RESOURCETYPE_ANY; | |
myNetResource.dwDisplayType = ResourceDisplayType.RESOURCEDISPLAYTYPE_DOMAIN; | |
myNetResource.dwUsage = ResourceUsage.RESOURCEUSAGE_CONNECTABLE; | |
myNetResource.lpLocalName = drive; | |
myNetResource.lpRemoteName = unc; | |
myNetResource.lpProvider = null; | |
// 흐음???? password, user 순서를 바꿔입력해야되나? | |
int result = WNetAddConnection2(myNetResource, password, user, (int)WNetAddConnectionFlag.CONNECT_UPDATE_PROFILE); | |
return result; | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Newtonsoft.Json; | |
// 스레드에 안전한 Dictionary | |
// 이미 닷넷에 ConcurrentXXXX 시리즈 함수가 존재하긴 하는데 | |
// 잘못사용하는 경우에 문제가 있다. 사용방식에 있어서 통일하기 위함 Concurrent함수가 좋다면 이 클래스만 바꾸면됨 | |
namespace GMTool.Sources.Util | |
{ | |
public class ThreadSafeDictionary<TKey, TValue> : IDisposable | |
{ | |
[JsonIgnore] | |
private object LockObject = new object(); | |
private Dictionary<TKey, TValue> data { get; set; } | |
[JsonIgnore] | |
private Random random = new Random(); | |
public ThreadSafeDictionary() | |
{ | |
data = new Dictionary<TKey, TValue>(); | |
} | |
public void Add(TKey key, TValue value) | |
{ | |
lock (LockObject) | |
{ | |
data.Add(key, value); | |
} | |
} | |
// 기존에 키 값이 있고 없고를 떠나서 무조건 add가 되도록 하는경우 사용 | |
public void AddIfExistRemove(TKey key, TValue value) | |
{ | |
lock (LockObject) | |
{ | |
data.Remove(key); | |
data.Add(key, value); | |
} | |
} | |
public bool Remove(TKey key) | |
{ | |
lock (LockObject) | |
{ | |
return data.Remove(key); | |
} | |
} | |
public void Clear() | |
{ | |
lock (LockObject) | |
{ | |
data.Clear(); | |
} | |
} | |
public int Count() | |
{ | |
lock (LockObject) | |
{ | |
return data.Count; | |
} | |
} | |
public bool ContainsKey(TKey key) | |
{ | |
lock (LockObject) | |
{ | |
return data.ContainsKey(key); | |
} | |
} | |
public TValue Find(TKey key) | |
{ | |
lock (LockObject) | |
{ | |
if (data.ContainsKey(key) == false) | |
return default(TValue); | |
return data[key]; | |
} | |
} | |
public void DumpAppend(List<TValue> dumpData) | |
{ | |
lock (LockObject) | |
{ | |
foreach (var item in data.Values) | |
{ | |
dumpData.Add(item); | |
} | |
} | |
} | |
public List<TValue> Dump() | |
{ | |
lock (LockObject) | |
{ | |
List<TValue> dumpData = new List<TValue>(); | |
foreach (var item in data.Values) | |
{ | |
dumpData.Add(item); | |
} | |
return dumpData; | |
} | |
} | |
public List<TValue> Dump(int count) | |
{ | |
lock (LockObject) | |
{ | |
List<TValue> dumpData = new List<TValue>(); | |
int index = 0; | |
foreach (var item in data.Values) | |
{ | |
if (index > count) | |
break; | |
dumpData.Add(item); | |
index++; | |
} | |
return dumpData; | |
} | |
} | |
public Dictionary<TKey, TValue> DumpKeyValuePair() | |
{ | |
lock (LockObject) | |
{ | |
Dictionary<TKey, TValue> dumpData = new Dictionary<TKey, TValue>(); | |
foreach (var kvp in data) | |
{ | |
dumpData.Add(kvp.Key, kvp.Value); | |
} | |
return dumpData; | |
} | |
} | |
public TValue GetRandom() | |
{ | |
lock (LockObject) | |
{ | |
int count = data.Count; | |
if (count == 0) | |
return default(TValue); | |
return data.ElementAt(random.Next(0, count)).Value; | |
} | |
} | |
public void Dispose() | |
{ | |
Clear(); | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
// 스레드에 안전한 List | |
// 이미 닷넷에 ConcurrentXXXX 시리즈 함수가 존재하긴 하는데 | |
// 잘못사용하는 경우에 문제가 있다. 사용방식에 있어서 통일하기 위함 Concurrent함수가 좋다면 이 클래스만 바꾸면됨 | |
namespace GMTool.Sources.Util | |
{ | |
public class ThreadSafeList<T> : IDisposable | |
{ | |
private object LockObject = new object(); | |
private List<T> data = new List<T>(); | |
private Random random = new Random(); | |
public void Add(T item) | |
{ | |
lock (LockObject) | |
{ | |
data.Add(item); | |
} | |
} | |
public bool Remove(T item) | |
{ | |
lock (LockObject) | |
{ | |
return data.Remove(item); | |
} | |
} | |
public void Clear() | |
{ | |
lock (LockObject) | |
{ | |
data.Clear(); | |
} | |
} | |
public int Count() | |
{ | |
lock (LockObject) | |
{ | |
return data.Count; | |
} | |
} | |
public T GetAt(int index) | |
{ | |
lock (LockObject) | |
{ | |
if (index >= data.Count) | |
return default(T); | |
return data[index]; | |
} | |
} | |
public List<T> Dump() | |
{ | |
lock (LockObject) | |
{ | |
List<T> dumpData = new List<T>(); | |
foreach (var item in data) | |
{ | |
dumpData.Add(item); | |
} | |
return dumpData; | |
} | |
} | |
public T GetRandom() | |
{ | |
lock (LockObject) | |
{ | |
int count = data.Count; | |
if (count == 0) | |
return default(T); | |
return data[random.Next(0, count)]; | |
} | |
} | |
public void Dispose() | |
{ | |
Clear(); | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
// 스레드에 안전한 Queue | |
// 이미 닷넷에 ConcurrentXXXX 시리즈 함수가 존재하긴 하는데 | |
// 잘못사용하는 경우에 문제가 있다. 사용방식에 있어서 통일하기 위함 Concurrent함수가 좋다면 이 클래스만 바꾸면됨 | |
namespace GMTool.Sources.Util | |
{ | |
public class ThreadSafeQueue<T> : IDisposable | |
{ | |
private object LockObject = new object(); | |
private Queue<T> data = new Queue<T>(); | |
public void Enqueue(T item) | |
{ | |
lock (LockObject) | |
{ | |
data.Enqueue(item); | |
} | |
} | |
public T Dequeue() | |
{ | |
lock (LockObject) | |
{ | |
if (data.Count < 1) | |
return default(T); | |
return data.Dequeue(); | |
} | |
} | |
public T Peek() | |
{ | |
lock (LockObject) | |
{ | |
if (data.Count < 1) | |
return default(T); | |
return data.Peek(); | |
} | |
} | |
public void Clear() | |
{ | |
lock (LockObject) | |
{ | |
data.Clear(); | |
} | |
} | |
public int Count() | |
{ | |
lock (LockObject) | |
{ | |
return data.Count; | |
} | |
} | |
public List<T> Dump() | |
{ | |
lock (LockObject) | |
{ | |
List<T> dumpData = new List<T>(); | |
foreach (var item in data) | |
{ | |
dumpData.Add(item); | |
} | |
return dumpData; | |
} | |
} | |
public void Dispose() | |
{ | |
Clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment