none
Using the API RRS feed

  • Question

  • Hi All,

    I'm trying to find information / examples on the following...

    I would like to be able to create an IP that has a "connection" in the Options (Opalis Integration Server Client -> Options) the same way as the SCDPM IP has.  So basically one with remote powershell integration.  The reason for that is that I'm experimenting with an Exchange Integration Pack that uses powershell commands (each powershell command = 1 Opalis object with the necessary parameters).

    However, I can't find information how I should do that.

    Any ideas?

    Many thanks

    Mike


    Visit System Center User Group Belgium @ http://scug.be and http://scug.be/blogs/scdpm
    Tuesday, December 14, 2010 12:16 PM

Answers

  • Mike,

    To have connection properties you make a OpalisData class and reference it in the objects you want to be able to use it with [OpalisConfiguration]

    Here is an example of the OpalisData class

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Opalis.QuickIntegrationKit;
    using Microsoft.Exchange.WebServices.Data;
    using Microsoft.Exchange.WebServices.Autodiscover;
    
    namespace ExchangeMail
    {
      [OpalisData("Exchange Mailbox Settings")]
      public class MailSettings
      {
        private String userName = String.Empty;
        private String password = String.Empty;
        private String domain = String.Empty;
        private String exchangeVersion = String.Empty;
    
        [OpalisInput("User Name")]
        public String UserName
        {
          get { return userName; }
          set { userName = value; }
        }
    
        [OpalisInput("Exchange Version",Options="Exchange2007_SP1,Exchange2010,Exchange2010_SP1")]
        public String ExchangeVersion
        {
          get { return exchangeVersion; }
          set { exchangeVersion = value; }
        }
    
        [OpalisInput(PasswordProtected = true)]
        public String Password
        {
          get { return password; }
          set { password = value; }
        }
        
        [OpalisInput]
        public String Domain
        {
          get { return domain; }
          set { domain = value; }
        }
      }
    }
    
    

    Here is an example of a object using that class for config

    using System;
    using System.Collections.Generic;
    using Opalis.QuickIntegrationKit;
    using Microsoft.Exchange.WebServices.Data;
    using Microsoft.Exchange.WebServices.Autodiscover;
    using System.Text;
    using System.Net;
    using System.Threading;
    
    namespace ExchangeMail
    {
      [OpalisObject("Monitor Mailbox"), OpalisMonitor()]
      public class MonitorMailbox : IOpalisObject
      {
        private MailSettings settings;
        private String exchangeVersion = String.Empty;
        private String userName = String.Empty;
        private String password = String.Empty;
        private String domain = String.Empty;
        private String folderName = String.Empty;
        private int MonitorInterval = 60;
        private FolderId folderID = new FolderId(WellKnownFolderName.Inbox);
    
        [OpalisConfiguration]
        public MailSettings Settings
        {
          get { return settings; }
          set { settings = value; }
        }
    
    
        public void Design(IOpalisDesigner designer)
        {
          designer.AddInput("Folder Name").WithDefaultValue("Inbox");
          designer.AddInput("Monitor Interval [Seconds]").WithDefaultValue(60);
          designer.AddCorellatedData(typeof(Email));
        }
    
        public void Execute(IOpalisRequest request, IOpalisResponse response)
        {
          userName = settings.UserName;
          password = settings.Password;
          domain = settings.Domain;
          exchangeVersion = settings.ExchangeVersion;
    
          folderName = request.Inputs["Folder Name"].AsString();
          MonitorInterval = request.Inputs["Monitor Interval [Seconds]"].AsInt32();
          
          response.WithFiltering().PublishRange(getMail());
        }
    
        private IEnumerable<Email> getMail()
        {
          DateTime StartTime = DateTime.Now;
          Boolean complete = false;
          ExchangeService service = new ExchangeService();
          switch (exchangeVersion)
          {
            case "Exchange2007_SP1":
              service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
              break;
            case "Exchange2010":
              service = new ExchangeService(ExchangeVersion.Exchange2010);
              break;
            case "Exchange2010_SP1":
              service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
              break;
            default:
              service = new ExchangeService();
              break;
          }
    
          service.Credentials = new NetworkCredential(userName, password, domain);
          String AccountUrl = userName + "@" + domain;
    
          service.AutodiscoverUrl(AccountUrl);
    
          if (!folderName.Equals(String.Empty))
          {
            SearchFilter filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, folderName);
            FolderView view = new FolderView(int.MaxValue);
            view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
            view.PropertySet.Add(FolderSchema.DisplayName);
            view.Traversal = FolderTraversal.Deep;
            FindFoldersResults results = service.FindFolders(WellKnownFolderName.MsgFolderRoot, filter, view);
    
            foreach (Folder folder in results)
            {
              folderID = folder.Id;
              break;
            }
          }
    
          while(!complete)
          {
            Thread.Sleep(TimeSpan.FromSeconds(Convert.ToDouble(MonitorInterval)));
            SearchFilter filter = new SearchFilter.IsGreaterThanOrEqualTo(EmailMessageSchema.LastModifiedTime,StartTime);
            FindItemsResults<Item> findResults = service.FindItems(folderID, filter, new ItemView(100));
            
            foreach (EmailMessage item in findResults.Items)
            {
              EmailMessage message = EmailMessage.Bind(service, item.Id);
              String body = message.Body.ToString();
              String from = message.From.Address.ToString();
              String subject = message.Subject.ToString();
              String id = item.Id.ToString();
              DateTime recievedDate = message.DateTimeReceived;
              Boolean Attachments = message.HasAttachments;
    
              complete = true;
              yield return new Email(subject, body, from, id, recievedDate, Attachments);
            }
          }
        }
      }
    }
    
    
    Are you planning to wrap up the exchange powershell cmdlets?  Thats really cool if so :-).  If your interested this is a project that uses Exchange Web Services Managed API 1.1 -- I wrote it to do mailbox functions not exchange admin http://opalisexchangemail.codeplex.com/. Here is a project that I am working on that will be wrapping the VMWare VSphere cmdlets for VMWare integration if you want a reference project for wrapping powershell http://opalisvmwareip.codeplex.com.  Check out the source code sections to see how they work (all of it is uploaded)
    Friday, December 17, 2010 6:37 AM

All replies

  • QIK doesn't support this.  One can still create centrally-configured connections in QIK but they are all configured from the "Invoke .NET 3.0" options menu.
    Tuesday, December 14, 2010 3:22 PM
  • Hey Jim,

    Thanks for the answer... Could you point me then to a start (guidelines, documentation...) on how to create IP's without the QIK?  I would want to create one similar to the sharepoint example but then for exchange.

    Thanks

    Brgds,

    Mike


    Visit System Center User Group Belgium @ http://scug.be and http://scug.be/blogs/scdpm
    Wednesday, December 15, 2010 12:23 PM
  • Hi Mike:

    One can't create IPs without QIK.  I must not understand your question.  If you do want to build an IP there are docs for QIK that get put down with it's install. 

    When you install QIK it gets placed in the following directory by default:

    C:\Program Files\Opalis Software\Quick Integration Kit 3

    For C# the documentation can be found at:

    C:\Program Files\Opalis Software\Quick Integration Kit 3\Docs\C#

    C# samples can be found at:

    C:\Program Files\Opalis Software\Quick Integration Kit 3\Examples\C#

    Other languages are supported and are reflected in the directory structure.  We only have docs and samples for C# and J#.

    In the example code is an email example you could use as a template for your MS Exchange IP.  I know the community would appreciate a well-built MS Exchange IP.  Good luck to you!

    ..Jim

    Wednesday, December 15, 2010 3:00 PM
  • Mike,

    To have connection properties you make a OpalisData class and reference it in the objects you want to be able to use it with [OpalisConfiguration]

    Here is an example of the OpalisData class

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Opalis.QuickIntegrationKit;
    using Microsoft.Exchange.WebServices.Data;
    using Microsoft.Exchange.WebServices.Autodiscover;
    
    namespace ExchangeMail
    {
      [OpalisData("Exchange Mailbox Settings")]
      public class MailSettings
      {
        private String userName = String.Empty;
        private String password = String.Empty;
        private String domain = String.Empty;
        private String exchangeVersion = String.Empty;
    
        [OpalisInput("User Name")]
        public String UserName
        {
          get { return userName; }
          set { userName = value; }
        }
    
        [OpalisInput("Exchange Version",Options="Exchange2007_SP1,Exchange2010,Exchange2010_SP1")]
        public String ExchangeVersion
        {
          get { return exchangeVersion; }
          set { exchangeVersion = value; }
        }
    
        [OpalisInput(PasswordProtected = true)]
        public String Password
        {
          get { return password; }
          set { password = value; }
        }
        
        [OpalisInput]
        public String Domain
        {
          get { return domain; }
          set { domain = value; }
        }
      }
    }
    
    

    Here is an example of a object using that class for config

    using System;
    using System.Collections.Generic;
    using Opalis.QuickIntegrationKit;
    using Microsoft.Exchange.WebServices.Data;
    using Microsoft.Exchange.WebServices.Autodiscover;
    using System.Text;
    using System.Net;
    using System.Threading;
    
    namespace ExchangeMail
    {
      [OpalisObject("Monitor Mailbox"), OpalisMonitor()]
      public class MonitorMailbox : IOpalisObject
      {
        private MailSettings settings;
        private String exchangeVersion = String.Empty;
        private String userName = String.Empty;
        private String password = String.Empty;
        private String domain = String.Empty;
        private String folderName = String.Empty;
        private int MonitorInterval = 60;
        private FolderId folderID = new FolderId(WellKnownFolderName.Inbox);
    
        [OpalisConfiguration]
        public MailSettings Settings
        {
          get { return settings; }
          set { settings = value; }
        }
    
    
        public void Design(IOpalisDesigner designer)
        {
          designer.AddInput("Folder Name").WithDefaultValue("Inbox");
          designer.AddInput("Monitor Interval [Seconds]").WithDefaultValue(60);
          designer.AddCorellatedData(typeof(Email));
        }
    
        public void Execute(IOpalisRequest request, IOpalisResponse response)
        {
          userName = settings.UserName;
          password = settings.Password;
          domain = settings.Domain;
          exchangeVersion = settings.ExchangeVersion;
    
          folderName = request.Inputs["Folder Name"].AsString();
          MonitorInterval = request.Inputs["Monitor Interval [Seconds]"].AsInt32();
          
          response.WithFiltering().PublishRange(getMail());
        }
    
        private IEnumerable<Email> getMail()
        {
          DateTime StartTime = DateTime.Now;
          Boolean complete = false;
          ExchangeService service = new ExchangeService();
          switch (exchangeVersion)
          {
            case "Exchange2007_SP1":
              service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
              break;
            case "Exchange2010":
              service = new ExchangeService(ExchangeVersion.Exchange2010);
              break;
            case "Exchange2010_SP1":
              service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
              break;
            default:
              service = new ExchangeService();
              break;
          }
    
          service.Credentials = new NetworkCredential(userName, password, domain);
          String AccountUrl = userName + "@" + domain;
    
          service.AutodiscoverUrl(AccountUrl);
    
          if (!folderName.Equals(String.Empty))
          {
            SearchFilter filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, folderName);
            FolderView view = new FolderView(int.MaxValue);
            view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
            view.PropertySet.Add(FolderSchema.DisplayName);
            view.Traversal = FolderTraversal.Deep;
            FindFoldersResults results = service.FindFolders(WellKnownFolderName.MsgFolderRoot, filter, view);
    
            foreach (Folder folder in results)
            {
              folderID = folder.Id;
              break;
            }
          }
    
          while(!complete)
          {
            Thread.Sleep(TimeSpan.FromSeconds(Convert.ToDouble(MonitorInterval)));
            SearchFilter filter = new SearchFilter.IsGreaterThanOrEqualTo(EmailMessageSchema.LastModifiedTime,StartTime);
            FindItemsResults<Item> findResults = service.FindItems(folderID, filter, new ItemView(100));
            
            foreach (EmailMessage item in findResults.Items)
            {
              EmailMessage message = EmailMessage.Bind(service, item.Id);
              String body = message.Body.ToString();
              String from = message.From.Address.ToString();
              String subject = message.Subject.ToString();
              String id = item.Id.ToString();
              DateTime recievedDate = message.DateTimeReceived;
              Boolean Attachments = message.HasAttachments;
    
              complete = true;
              yield return new Email(subject, body, from, id, recievedDate, Attachments);
            }
          }
        }
      }
    }
    
    
    Are you planning to wrap up the exchange powershell cmdlets?  Thats really cool if so :-).  If your interested this is a project that uses Exchange Web Services Managed API 1.1 -- I wrote it to do mailbox functions not exchange admin http://opalisexchangemail.codeplex.com/. Here is a project that I am working on that will be wrapping the VMWare VSphere cmdlets for VMWare integration if you want a reference project for wrapping powershell http://opalisvmwareip.codeplex.com.  Check out the source code sections to see how they work (all of it is uploaded)
    Friday, December 17, 2010 6:37 AM
  • Hey Jim, Ryan

    Again, many thanks for the responses... It is very much appreciated and thanks for the cool info.

    To answer the last question... Yes, the idea is to wrap up exchange powershell cmdlets.  I would love to do it the exact way as the DPM IP is created.  This means you just have an option to create a connection to an Exchange server through powershell remoting (as the DPM IP).

    If I would be able to built that, then it would be pretty easy to insert all the commands (non-programming) through the QiK with all the different parameters, which would also mean that all IT-pro's could start building IP's for about everything that works with powershell (so in the Microsoft world... everything :-)).

    Is this something that is achievable?

    Mike


    Visit System Center User Group Belgium @ http://scug.be and http://scug.be/blogs/scdpm
    Friday, December 17, 2010 8:50 AM