Guest User

Untitled

a guest
May 21st, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.ServiceModel;
  5. using GPDMS.Service.Interfaces;
  6. using GPDMS.Service.Message;
  7. using Microsoft.SharePoint;
  8.  
  9. namespace GPDMS.Service.Client
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. if (args.Length != 4)
  16. {
  17. Console.WriteLine("Usage: GPDMS.Integration.Client.exe <url> <file name>");
  18. return;
  19. }
  20.  
  21. var documents = new List<string>();
  22. var scf = new ChannelFactory<IIntegrationService>("BasicHttpBinding_IIntegrationService");
  23. if (scf.Credentials != null)
  24. {
  25. scf.Credentials.UserName.UserName = args[2];
  26. scf.Credentials.UserName.Password = args[3];
  27. }
  28. var client = scf.CreateChannel();
  29.  
  30. try
  31. {
  32. Console.WriteLine();
  33. Console.WriteLine("check server");
  34. Console.WriteLine("--------------------------------------------------------------------------------");
  35. Console.WriteLine(
  36. client.Ping(SerializationHelper.Serialize(new PingIn
  37. {
  38. CorrelationId = Guid.NewGuid().ToString()
  39. })));
  40. }
  41. catch (Exception ex)
  42. {
  43. Console.WriteLine(ex);
  44. }
  45.  
  46. try
  47. {
  48. Console.WriteLine();
  49. Console.WriteLine("create document: uznesenie");
  50. Console.WriteLine("--------------------------------------------------------------------------------");
  51. using (var fileStream = new FileStream(args[1], FileMode.Open, FileAccess.Read))
  52. {
  53. using (var reader = new BinaryReader(fileStream))
  54. {
  55. var guid = Guid.NewGuid().ToString();
  56. var length = Convert.ToInt32(new FileInfo(args[1]).Length);
  57. var buffer = new byte[length];
  58.  
  59. var arguments = new VytvorUznesenieIn
  60. {
  61. CorrelationId = guid,
  62. Autor = "AQUINAS\\mkallo",
  63. Metadata = new UznesenieMetadata
  64. {
  65. DatumVydania = DateTime.Today,
  66. FormaRozhodnutia = "FormaRozhodnutia",
  67. OblastPravnejUpravy = "OblastPravnejUpravy",
  68. PoradoveCislo = guid,
  69. PouziteUstanovenia = "PouziteUstanovenia",
  70. PovahaRozhodnutia = "PovahaRozhodnutia",
  71. Predmet = "Uznesenie",
  72. Prokuratura = 1000,
  73. Publish = false,
  74. SpisovaZnacka = "SpisovaZnacka"
  75. }
  76. };
  77.  
  78. if (reader.Read(buffer, 0, length) != length)
  79. throw new ApplicationException("Could not read file content.");
  80.  
  81. arguments.Content = Convert.ToBase64String(buffer);
  82.  
  83. var response = client.VytvorUznesenie(SerializationHelper.Serialize(arguments));
  84. Console.WriteLine(response);
  85.  
  86. var result = (VytvorUznesenieOut)SerializationHelper.Deserialize(response, typeof(VytvorUznesenieOut));
  87. if (!String.IsNullOrEmpty(result.DocumentId))
  88. documents.Add(result.DocumentId);
  89. }
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. Console.WriteLine(ex);
  95. }
  96.  
  97. try
  98. {
  99. Console.WriteLine();
  100. Console.WriteLine("create document: uznesenie (without content)");
  101. Console.WriteLine("--------------------------------------------------------------------------------");
  102. var guid = Guid.NewGuid().ToString();
  103. var arguments = new VytvorUznesenieIn
  104. {
  105. CorrelationId = guid,
  106. Autor = "AQUINAS\\mkallo",
  107. Metadata = new UznesenieMetadata
  108. {
  109. DatumVydania = DateTime.Today,
  110. FormaRozhodnutia = "FormaRozhodnutia",
  111. OblastPravnejUpravy = "OblastPravnejUpravy",
  112. PoradoveCislo = guid,
  113. PouziteUstanovenia = "PouziteUstanovenia",
  114. PovahaRozhodnutia = "PovahaRozhodnutia",
  115. Predmet = "Uznesenie (without content)",
  116. Prokuratura = 1000,
  117. Publish = false,
  118. SpisovaZnacka = "SpisovaZnacka"
  119. }
  120. };
  121.  
  122. var response = client.VytvorUznesenie(SerializationHelper.Serialize(arguments));
  123. Console.WriteLine(response);
  124.  
  125. var result = (VytvorUznesenieOut)SerializationHelper.Deserialize(response, typeof(VytvorUznesenieOut));
  126. if (!String.IsNullOrEmpty(result.DocumentId))
  127. documents.Add(result.DocumentId);
  128. }
  129. catch (Exception ex)
  130. {
  131. Console.WriteLine(ex);
  132. }
  133.  
  134. try
  135. {
  136. Console.WriteLine();
  137. Console.WriteLine("update original document content");
  138. Console.WriteLine("--------------------------------------------------------------------------------");
  139. if (documents.Count == 0)
  140. {
  141. throw new ArgumentException("No input documents provided.");
  142. }
  143. using (var fileStream = new FileStream(args[1], FileMode.Open, FileAccess.Read))
  144. {
  145. using (var reader = new BinaryReader(fileStream))
  146. {
  147. var guid = Guid.NewGuid().ToString();
  148. var length = Convert.ToInt32(new FileInfo(args[1]).Length);
  149. var buffer = new byte[length];
  150.  
  151. var arguments = new AktualizujPovodnyObsahUzneseniaIn
  152. {
  153. CorrelationId = guid,
  154. DocumentId = new Guid(documents[0]),
  155. Autor = "AQUINAS\\mkallo"
  156. };
  157.  
  158. if (reader.Read(buffer, 0, length) != length)
  159. throw new ApplicationException("Could not read file content.");
  160.  
  161. arguments.Content = Convert.ToBase64String(buffer);
  162.  
  163. var response = client.AktualizujPovodnyObsahUznesenia(SerializationHelper.Serialize(arguments));
  164. Console.WriteLine(response);
  165. }
  166. }
  167. }
  168. catch (Exception ex)
  169. {
  170. Console.WriteLine(ex);
  171. }
  172.  
  173. try
  174. {
  175. Console.WriteLine();
  176. Console.WriteLine("add depersonalized content");
  177. Console.WriteLine("--------------------------------------------------------------------------------");
  178. if (documents.Count == 0)
  179. {
  180. throw new ArgumentException("No input documents provided.");
  181. }
  182. using (var fileStream = new FileStream(args[1], FileMode.Open, FileAccess.Read))
  183. {
  184. using (var reader = new BinaryReader(fileStream))
  185. {
  186. var guid = Guid.NewGuid().ToString();
  187. var length = Convert.ToInt32(new FileInfo(args[1]).Length);
  188. var buffer = new byte[length];
  189.  
  190. var arguments = new AktualizujDepersonalizovanyObsahUzneseniaIn
  191. {
  192. CorrelationId = guid,
  193. DocumentId = new Guid(documents[0]),
  194. Autor = "AQUINAS\\mkallo",
  195. };
  196.  
  197. if (reader.Read(buffer, 0, length) != length)
  198. throw new ApplicationException("Could not read file content.");
  199.  
  200. arguments.Content = Convert.ToBase64String(buffer);
  201.  
  202. var response = client.AktualizujDepersonalizovanyObsahUznesenia(SerializationHelper.Serialize(arguments));
  203. Console.WriteLine(response);
  204. }
  205. }
  206. }
  207. catch (Exception ex)
  208. {
  209. Console.WriteLine(ex);
  210. }
  211.  
  212. try
  213. {
  214. Console.WriteLine();
  215. Console.WriteLine("update document metadata");
  216. Console.WriteLine("--------------------------------------------------------------------------------");
  217. if (documents.Count == 0)
  218. {
  219. throw new ArgumentException("No input documents provided.");
  220. }
  221. var guid = Guid.NewGuid().ToString();
  222. var arguments = new AktualizujMetadataUzneseniaIn
  223. {
  224. CorrelationId = guid,
  225. DocumentId = new Guid(documents[0]),
  226. Autor = "AQUINAS\\mkallo",
  227. Metadata = new UznesenieMetadata
  228. {
  229. DatumVydania = DateTime.Today,
  230. FormaRozhodnutia = "FormaRozhodnutia",
  231. OblastPravnejUpravy = "OblastPravnejUpravy",
  232. PoradoveCislo = guid,
  233. PouziteUstanovenia = "PouziteUstanovenia",
  234. PovahaRozhodnutia = "PovahaRozhodnutia",
  235. Predmet = "[UPDATED] Uznesenie",
  236. Prokuratura = 1000,
  237. Publish = true,
  238. SpisovaZnacka = "SpisovaZnacka"
  239. }
  240. };
  241.  
  242. var response = client.AktualizujMetadataUznesenia(SerializationHelper.Serialize(arguments));
  243. Console.WriteLine(response);
  244. }
  245. catch (Exception ex)
  246. {
  247. Console.WriteLine(ex);
  248. }
  249.  
  250. try
  251. {
  252. Console.WriteLine();
  253. Console.WriteLine("suspend document");
  254. Console.WriteLine("--------------------------------------------------------------------------------");
  255. if (documents.Count == 0)
  256. {
  257. throw new ArgumentException("No input documents provided.");
  258. }
  259. var guid = Guid.NewGuid().ToString();
  260. var arguments = new ZrusUznesenieIn
  261. {
  262. CorrelationId = guid,
  263. DocumentId = new Guid(documents[0]),
  264. Autor = "AQUINAS\\mkallo",
  265. };
  266.  
  267. var response = client.ZrusUznesenie(SerializationHelper.Serialize(arguments));
  268. Console.WriteLine(response);
  269. }
  270. catch (Exception ex)
  271. {
  272. Console.WriteLine(ex);
  273. }
  274.  
  275. try
  276. {
  277. var performCleanup = false;
  278. Console.WriteLine();
  279. Console.WriteLine("Do you want to erase test documents? [y/n]");
  280. while (true)
  281. {
  282. var answer = Console.ReadKey(true);
  283. if (answer.Key == ConsoleKey.Y)
  284. {
  285. performCleanup = true;
  286. break;
  287. }
  288. if (answer.Key == ConsoleKey.N)
  289. {
  290. break;
  291. }
  292. }
  293. if (performCleanup)
  294. {
  295. Console.WriteLine();
  296. Console.WriteLine("cleanup");
  297. Console.WriteLine("--------------------------------------------------------------------------------");
  298. foreach (var id in documents)
  299. {
  300. using (var site = new SPSite(args[0]))
  301. {
  302. using (var web = site.OpenWeb("zverejnovane dokumenty"))
  303. {
  304. var ctype = web.Site.RootWeb.ContentTypes["uznesenie"];
  305. var item = Helpers.GetListItem(web, new Guid(id), ctype);
  306. if (item == null) continue;
  307. item.Delete();
  308. }
  309. }
  310. }
  311. }
  312. }
  313. catch (Exception ex)
  314. {
  315. Console.WriteLine(ex);
  316. }
  317.  
  318. Console.WriteLine();
  319. Console.WriteLine("Press Enter to exit...");
  320. Console.ReadLine();
  321. }
  322. }
  323. }
Add Comment
Please, Sign In to add comment