Advertisement
robgonsalves

Get Expiring Reservations

Sep 28th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7. using InterplayWSTest.InterplayWS;
  8.  
  9. namespace InterplayWSCSharpTest
  10. {
  11.     class Program
  12.     {
  13.         static DateTime midnight;
  14.         static AssetsPortTypeClient port;
  15.         static UserCredentialsType creds;
  16.  
  17.         static void Main(string[] args)
  18.         {
  19.             Console.WriteLine("Interplay WS Test");
  20.  
  21.             midnight = DateTime.Now.Date.AddDays(1).AddTicks(-1);
  22.             Console.WriteLine("Print out reservations that will expire today.");
  23.  
  24.             port = new AssetsPortTypeClient();
  25.  
  26.             creds = new UserCredentialsType();
  27.             creds.Username = "uuuu";
  28.             creds.Password = "pppp";
  29.  
  30.             string path = "interplay://WGC/Projects/";
  31.  
  32.             ListFolderContents(path);
  33.  
  34.             Console.Write("Hit enter to end.");
  35.             Console.ReadLine();
  36.         }
  37.  
  38.         private static void ListFolderContents(string path)
  39.         {
  40.             Console.WriteLine(path);
  41.  
  42.             GetChildrenType getChildrenParams = new GetChildrenType();
  43.             getChildrenParams.InterplayURI = path;
  44.  
  45.             getChildrenParams.IncludeFolders = true;            // get folders
  46.             getChildrenParams.IncludeFoldersSpecified = true;
  47.  
  48.             getChildrenParams.IncludeMOBs = false;               // no mobs
  49.             getChildrenParams.IncludeMOBsSpecified = true;
  50.  
  51.             getChildrenParams.IncludeFiles = false;             // no files
  52.             getChildrenParams.IncludeFilesSpecified = true;
  53.  
  54.             getChildrenParams.ReturnAttributes = new AttributeType[1];
  55.             getChildrenParams.ReturnAttributes[0] = new AttributeType();
  56.             getChildrenParams.ReturnAttributes[0].Group = "USER";
  57.             getChildrenParams.ReturnAttributes[0].Name = "Display Name";
  58.  
  59.             GetChildrenResponseType getChildrenResponse = port.GetChildren(creds, getChildrenParams);
  60.             if (getChildrenResponse.Results != null && getChildrenResponse.Results.Length > 0)
  61.             {
  62.                 foreach (AssetDescriptionType ad in getChildrenResponse.Results)
  63.                 {
  64.                     string childPath = null;
  65.                     foreach (AttributeType att in ad.Attributes)
  66.                     {
  67.                         if (att.Group.Equals("USER") && att.Name.Equals("Display Name"))
  68.                             childPath = att.Value;
  69.                     }
  70.  
  71.                     InspectReservations(ad.InterplayURI);
  72.  
  73.                     if (childPath != null)
  74.                         ListFolderContents(path + "/" + childPath);
  75.                 }
  76.             }
  77.         }
  78.  
  79.         private static void InspectReservations(string uri)
  80.         {
  81.             GetReservationsType getReservationsParams = new GetReservationsType();
  82.             getReservationsParams.InterplayURIs = new string[1];
  83.             getReservationsParams.InterplayURIs[0] = uri;
  84.  
  85.             // first call to get the mobs
  86.             GetReservationsResponseType getReservationsResponse = port.GetReservations(creds, getReservationsParams);
  87.  
  88.             if (getReservationsResponse.Results != null && getReservationsResponse.Results.Length > 0)
  89.             {
  90.                 foreach (ReservationInformationType ri in getReservationsResponse.Results)
  91.                 {
  92.                     if (ri.ReservationDetails != null)
  93.                     {
  94.                         foreach (ReservationDetailsType rd in ri.ReservationDetails)
  95.                         {
  96.                             DateTime theDate = DateTime.Parse(rd.ExpirationDate);
  97.  
  98.                             if (theDate < midnight)
  99.                             {
  100.                                 Console.WriteLine("Expiring reservation: " + rd.ReservedAsset + ", " + rd.ReservedBy + ", " + rd.ExpirationDate);
  101.                             }
  102.                         }
  103.                     }
  104.                 }
  105.             }
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement