This week we begin to delve into the code side of our Ultimate Lync Presentation Tool Helper, and yes that is getting to be a mouthful to type. On a side note I used ULPTH yesterday in a developer meeting, and loved how easy it was to share the many whiteboards to pngs on the fly to easily have a record of some of the great ideas we had (more on that another day).
Last week we declared some basic variables like our Lync client and Conversation that we will need for some of the more advanced functions. First lets talk about the a fore mentioned whiteboards. There are 3 basic "advanced" functions here, create, clear, and save.
Create
private void AddWhiteboard(string wbname)
{
try
{
if (!lWhiteboards.Contains(wbname))
lWhiteboards.Add(wbname);
//14.3 - Create new whiteboard and upload it to content bin.
ContentSharingModality csm = (ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing];
if (csm.State == ModalityState.Disconnected)
{
if (((Modality)_conversation.Modalities[ModalityTypes.ContentSharing]).CanInvoke(ModalityAction.Connect))
{
try
{
((Modality)_conversation.Modalities[ModalityTypes.ContentSharing]).BeginConnect((ar) =>
{
((Modality)_conversation.Modalities[ModalityTypes.ContentSharing]).EndConnect(ar);
}
, null);
}
catch (OperationException oe)
{
Console.WriteLine("Operation exception " + oe.Message);
}
}
}
else
{
if (csm.CanInvoke(ModalityAction.CreateShareableWhiteboardContent))
{
csm.BeginCreateContent(ShareableContentType.Whiteboard, wbname, (ar) =>
{
try
{
ShareableContent sContent = csm.EndCreateContent(ar);
sContent.Upload();
}
catch (MaxContentsExceededException)
{
MessageBox.Show(
"The meeting content bin is full. Whiteboard "
+ "cannot be uploaded");
}
catch (ContentTitleExistException)
{
MessageBox.Show(
"The meeting content bin already contains an item "
+ "with this title. Whiteboard cannot be uploaded");
}
catch (ContentTitleInvalidException)
{
MessageBox.Show(
"The whiteboard title is invalid. Whiteboard cannot "
+ "be uploaded");
}
}
, null);
}
}
}
catch { }
}
Clear
try
{
ContentSharingModality csm =
(ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing];
int hrReason;
if (csm.ActiveContent.CanInvoke(
ShareableContentAction.ClearAllAnnotations, out hrReason))
{
csm.ActiveContent.ClearAllAnnotations();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Save
try
{
ContentSharingModality csm = (ContentSharingModality)_conversation
.Modalities[ModalityTypes.ContentSharing];
int hrReason;
if (csm.ActiveContent.CanInvoke(ShareableContentAction.SaveAnnotation, out hrReason))
{
DirectoryInfo dirInfo = new DirectoryInfo(@"c:\users\public\");
if (dirInfo.Exists)
{
csm.ActiveContent.SaveAnnotation(
@"c:\users\public\"
+ csm.ActiveContent.Title
+ ".png"
, ContentSavingFileType.PNG);
//Get a FileInfo object that wraps the downloaded file
FileInfo file = new FileInfo(
@"c:\users\public\"
+ csm.ActiveContent.Title
+ ".png");
//If the file was downloaded then give the user the download path
//and file name
if (file.Exists)
{
MessageBox.Show(
"Annotations have been saved at "
+ file.Directory.FullName + @"\"
+ csm.ActiveContent.Title + ".png");
}
}
}
else
{
MessageBox.Show("Annotations cannot be saved for " + _ShareableContent.Title);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
The last piece when working with whiteboards, it to be able to switch which item is shared. This code will pertain to a ppt as well but I figured this was a great spot to introduce it.
private void shareItem(string item)
{
try
{
Task.Factory.StartNew(() =>
{
System.Threading.Thread.Sleep(2500);
string selectedItem = item;
foreach (ShareableContent sContent in ((ContentSharingModality)_conversation
.Modalities[ModalityTypes.ContentSharing]).ContentCollection)
{
if (sContent.Title == selectedItem)
{
int hrReason;
if (sContent.CanInvoke(ShareableContentAction.Present, out hrReason))
{
_ShareableContent = sContent;
sContent.Present();
}
else
{
MessageBox.Show(
"Cannot present "
+ sContent.Type.ToString()
+ ": "
+ hrReason.ToString());
}
break;
}
}
});
}
catch { }
}
Next we want to be able to add a PowerPoint as easily as a whiteboard. We can do that with this snip-it.
private void AddPPT(string pptname)
{
if (!lPowerPoints.Contains(pptname))
lPowerPoints.Add(pptname);
try
{
if (((Modality)_conversation.Modalities[ModalityTypes
.ContentSharing]).State == ModalityState.Disconnected)
{
ConnectCSM();
}
else
{
if (!((Modality)_conversation.Modalities[ModalityTypes.ContentSharing])
.CanInvoke(ModalityAction.CreateShareablePowerPointContent))
{
return;
}
if (pptname.Length > 0)
{
try
{
ContentSharingModality c = ((ContentSharingModality)_conversation
.Modalities[ModalityTypes.ContentSharing]);
string pptTitle = string.Empty;
Int32 lastWhack = pptname.LastIndexOf(@"\");
//Strip off PowerPoint deck path, leaving only the file name to
//be assigned as the ShareableContent.Title property
pptTitle = pptname.Substring(
lastWhack + 1, pptname.Length - (lastWhack + 1));
c.BeginCreateContentFromFile(
ShareableContentType.PowerPoint,
pptTitle,
pptname,
false,
CreateShareableContentCallback,
c);
}
catch (InvalidStateException)
{
MessageBox.Show("Invalid state exception on BeginCreateContent ");
}
catch (NotInitializedException)
{
MessageBox.Show("Not initialized exception on BeginCreateContent ");
}
}
}
}
catch { }
}
The same shareItem(string item) method will allow you to switch between sharing a selected whiteboard or Powerpoint.
The final item for today is a section that let's us add an attachment for all users to be able to download, perhaps a png, jpg, Word doc, etc, basically something other than a ppt.
private void AddAttach(string attachname)
{
if (!lAttachs.Contains(attachname))
lAttachs.Add(attachname);
try
{
if (((Modality)_conversation.Modalities[ModalityTypes
.ContentSharing]).State == ModalityState.Disconnected)
{
ConnectCSM();
}
else
{
if (!((Modality)_conversation.Modalities[ModalityTypes.ContentSharing])
.CanInvoke(ModalityAction.CreateShareablePowerPointContent))
{
return;
}
if (attachname.Length > 0)
{
try
{
ContentSharingModality c = ((ContentSharingModality)_conversation
.Modalities[ModalityTypes.ContentSharing]);
string pptTitle = string.Empty;
Int32 lastWhack = attachname.LastIndexOf(@"\");
//Strip off PowerPoint deck path, leaving only the file name to
//be assigned as the ShareableContent.Title property
pptTitle = attachname.Substring(
lastWhack + 1, attachname.Length - (lastWhack + 1));
c.BeginCreateContentFromFile(
ShareableContentType.NativeFile,
pptTitle,
attachname,
false,
CreateShareableContentCallback,
c);
}
catch (InvalidStateException)
{
MessageBox.Show("Invalid state exception on BeginCreateContent ");
}
catch (NotInitializedException)
{
MessageBox.Show("Not initialized exception on BeginCreateContent ");
}
}
}
}
catch { }
}
Tune in next week when we begin to look at monitor and application sharing.
Doug Routledge, C# Lync, SQL, Exchange, UC Developer
No comments:
Post a Comment
Any spam comments will be deleted and your user account will be disabled.