Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.ServiceModel;
- using GPDMS.Service.Interfaces;
- using GPDMS.Service.Message;
- using Microsoft.SharePoint;
- namespace GPDMS.Service.Client
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length != 4)
- {
- Console.WriteLine("Usage: GPDMS.Integration.Client.exe <url> <file name>");
- return;
- }
- var documents = new List<string>();
- var scf = new ChannelFactory<IIntegrationService>("BasicHttpBinding_IIntegrationService");
- if (scf.Credentials != null)
- {
- scf.Credentials.UserName.UserName = args[2];
- scf.Credentials.UserName.Password = args[3];
- }
- var client = scf.CreateChannel();
- try
- {
- Console.WriteLine();
- Console.WriteLine("check server");
- Console.WriteLine("--------------------------------------------------------------------------------");
- Console.WriteLine(
- client.Ping(SerializationHelper.Serialize(new PingIn
- {
- CorrelationId = Guid.NewGuid().ToString()
- })));
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- try
- {
- Console.WriteLine();
- Console.WriteLine("create document: uznesenie");
- Console.WriteLine("--------------------------------------------------------------------------------");
- using (var fileStream = new FileStream(args[1], FileMode.Open, FileAccess.Read))
- {
- using (var reader = new BinaryReader(fileStream))
- {
- var guid = Guid.NewGuid().ToString();
- var length = Convert.ToInt32(new FileInfo(args[1]).Length);
- var buffer = new byte[length];
- var arguments = new VytvorUznesenieIn
- {
- CorrelationId = guid,
- Autor = "AQUINAS\\mkallo",
- Metadata = new UznesenieMetadata
- {
- DatumVydania = DateTime.Today,
- FormaRozhodnutia = "FormaRozhodnutia",
- OblastPravnejUpravy = "OblastPravnejUpravy",
- PoradoveCislo = guid,
- PouziteUstanovenia = "PouziteUstanovenia",
- PovahaRozhodnutia = "PovahaRozhodnutia",
- Predmet = "Uznesenie",
- Prokuratura = 1000,
- Publish = false,
- SpisovaZnacka = "SpisovaZnacka"
- }
- };
- if (reader.Read(buffer, 0, length) != length)
- throw new ApplicationException("Could not read file content.");
- arguments.Content = Convert.ToBase64String(buffer);
- var response = client.VytvorUznesenie(SerializationHelper.Serialize(arguments));
- Console.WriteLine(response);
- var result = (VytvorUznesenieOut)SerializationHelper.Deserialize(response, typeof(VytvorUznesenieOut));
- if (!String.IsNullOrEmpty(result.DocumentId))
- documents.Add(result.DocumentId);
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- try
- {
- Console.WriteLine();
- Console.WriteLine("create document: uznesenie (without content)");
- Console.WriteLine("--------------------------------------------------------------------------------");
- var guid = Guid.NewGuid().ToString();
- var arguments = new VytvorUznesenieIn
- {
- CorrelationId = guid,
- Autor = "AQUINAS\\mkallo",
- Metadata = new UznesenieMetadata
- {
- DatumVydania = DateTime.Today,
- FormaRozhodnutia = "FormaRozhodnutia",
- OblastPravnejUpravy = "OblastPravnejUpravy",
- PoradoveCislo = guid,
- PouziteUstanovenia = "PouziteUstanovenia",
- PovahaRozhodnutia = "PovahaRozhodnutia",
- Predmet = "Uznesenie (without content)",
- Prokuratura = 1000,
- Publish = false,
- SpisovaZnacka = "SpisovaZnacka"
- }
- };
- var response = client.VytvorUznesenie(SerializationHelper.Serialize(arguments));
- Console.WriteLine(response);
- var result = (VytvorUznesenieOut)SerializationHelper.Deserialize(response, typeof(VytvorUznesenieOut));
- if (!String.IsNullOrEmpty(result.DocumentId))
- documents.Add(result.DocumentId);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- try
- {
- Console.WriteLine();
- Console.WriteLine("update original document content");
- Console.WriteLine("--------------------------------------------------------------------------------");
- if (documents.Count == 0)
- {
- throw new ArgumentException("No input documents provided.");
- }
- using (var fileStream = new FileStream(args[1], FileMode.Open, FileAccess.Read))
- {
- using (var reader = new BinaryReader(fileStream))
- {
- var guid = Guid.NewGuid().ToString();
- var length = Convert.ToInt32(new FileInfo(args[1]).Length);
- var buffer = new byte[length];
- var arguments = new AktualizujPovodnyObsahUzneseniaIn
- {
- CorrelationId = guid,
- DocumentId = new Guid(documents[0]),
- Autor = "AQUINAS\\mkallo"
- };
- if (reader.Read(buffer, 0, length) != length)
- throw new ApplicationException("Could not read file content.");
- arguments.Content = Convert.ToBase64String(buffer);
- var response = client.AktualizujPovodnyObsahUznesenia(SerializationHelper.Serialize(arguments));
- Console.WriteLine(response);
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- try
- {
- Console.WriteLine();
- Console.WriteLine("add depersonalized content");
- Console.WriteLine("--------------------------------------------------------------------------------");
- if (documents.Count == 0)
- {
- throw new ArgumentException("No input documents provided.");
- }
- using (var fileStream = new FileStream(args[1], FileMode.Open, FileAccess.Read))
- {
- using (var reader = new BinaryReader(fileStream))
- {
- var guid = Guid.NewGuid().ToString();
- var length = Convert.ToInt32(new FileInfo(args[1]).Length);
- var buffer = new byte[length];
- var arguments = new AktualizujDepersonalizovanyObsahUzneseniaIn
- {
- CorrelationId = guid,
- DocumentId = new Guid(documents[0]),
- Autor = "AQUINAS\\mkallo",
- };
- if (reader.Read(buffer, 0, length) != length)
- throw new ApplicationException("Could not read file content.");
- arguments.Content = Convert.ToBase64String(buffer);
- var response = client.AktualizujDepersonalizovanyObsahUznesenia(SerializationHelper.Serialize(arguments));
- Console.WriteLine(response);
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- try
- {
- Console.WriteLine();
- Console.WriteLine("update document metadata");
- Console.WriteLine("--------------------------------------------------------------------------------");
- if (documents.Count == 0)
- {
- throw new ArgumentException("No input documents provided.");
- }
- var guid = Guid.NewGuid().ToString();
- var arguments = new AktualizujMetadataUzneseniaIn
- {
- CorrelationId = guid,
- DocumentId = new Guid(documents[0]),
- Autor = "AQUINAS\\mkallo",
- Metadata = new UznesenieMetadata
- {
- DatumVydania = DateTime.Today,
- FormaRozhodnutia = "FormaRozhodnutia",
- OblastPravnejUpravy = "OblastPravnejUpravy",
- PoradoveCislo = guid,
- PouziteUstanovenia = "PouziteUstanovenia",
- PovahaRozhodnutia = "PovahaRozhodnutia",
- Predmet = "[UPDATED] Uznesenie",
- Prokuratura = 1000,
- Publish = true,
- SpisovaZnacka = "SpisovaZnacka"
- }
- };
- var response = client.AktualizujMetadataUznesenia(SerializationHelper.Serialize(arguments));
- Console.WriteLine(response);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- try
- {
- Console.WriteLine();
- Console.WriteLine("suspend document");
- Console.WriteLine("--------------------------------------------------------------------------------");
- if (documents.Count == 0)
- {
- throw new ArgumentException("No input documents provided.");
- }
- var guid = Guid.NewGuid().ToString();
- var arguments = new ZrusUznesenieIn
- {
- CorrelationId = guid,
- DocumentId = new Guid(documents[0]),
- Autor = "AQUINAS\\mkallo",
- };
- var response = client.ZrusUznesenie(SerializationHelper.Serialize(arguments));
- Console.WriteLine(response);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- try
- {
- var performCleanup = false;
- Console.WriteLine();
- Console.WriteLine("Do you want to erase test documents? [y/n]");
- while (true)
- {
- var answer = Console.ReadKey(true);
- if (answer.Key == ConsoleKey.Y)
- {
- performCleanup = true;
- break;
- }
- if (answer.Key == ConsoleKey.N)
- {
- break;
- }
- }
- if (performCleanup)
- {
- Console.WriteLine();
- Console.WriteLine("cleanup");
- Console.WriteLine("--------------------------------------------------------------------------------");
- foreach (var id in documents)
- {
- using (var site = new SPSite(args[0]))
- {
- using (var web = site.OpenWeb("zverejnovane dokumenty"))
- {
- var ctype = web.Site.RootWeb.ContentTypes["uznesenie"];
- var item = Helpers.GetListItem(web, new Guid(id), ctype);
- if (item == null) continue;
- item.Delete();
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- Console.WriteLine();
- Console.WriteLine("Press Enter to exit...");
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment