Display User Picture in Lync 2013 - c#

I am working on small application using the lync 2013 sdk. Is there any way provided in sdk where I can implement a functionality to allow user to upload his picture using any API provided in the SDK.
If it is possible then what and where is the best way to store it, if the users are configured in the active directory?
Waiting for a positive response from your side.
Regards
Amit

You can get a stream to the photo via the SDK using
var photoStream = Client.Self.Contact.GetContactInformation(ContactInformationType.Photo) as System.IO.Stream
And whilst you can read the stream you can't write to it as you are at this point looking at contact information from AD.
Kind of feels like you want to write something to change the photo in the photoThumbnails attribute of AD not in Lync.

Update as of 12/11/2013
The latest Lync update (Lync Client CU3 (November Update)) has the option to set a photo added back to the GUI.
Link to the KB Article
Link to the Download
Article with explanations and screenshots can be found here: Lync Client CU3 (November Update) – Show a picture from a website!.
Original Answer
Though this is a different problem, my answer to this question (Displaying a photo for an Application endpoint) is valid here as well:
Basicly, there is an option to set a user's photo to an URL, but it is no longer displayed in the Lync 2013 client interface (it was there in the Lync 2010 client). If you can get your code to publish the image to a web-accessible location, you could publish the URL to it and change your user picture that way.
For reference, the answer to the other question:
Publishing presence information (which includes photo settings) is done on the LocalEndpoint.LocalOwnerPresence. Both UserEndpoint and ApplicationEndpoint derive from LocalEndpoint, so this should be doable really.
The actual publishing gets slightly complex because there are a lot of different combinations of 'levels' to publish on:
First, there are a bunch of InstanceID values that you need to know about, read up on them here: Presence data source and category instance ID
Second, there is a value for who this presence applies to, see Microsoft.Rtc.Collaboration.Presence.PresenceRelationshipLevel. Don't publish on Unknown, you'll get an exception.
public enum PresenceRelationshipLevel
{
Unknown = -1,
Everyone = 0,
External = 100,
Colleagues = 200,
Workgroup = 300,
Personal = 400,
Blocked = 32000,
}
You need to publish a PresenceCategoryWithMetaData for the user photo properties, which is part of container 0x5, "Presentity information".
var photoPresence = new PresenceCategoryWithMetaData(
0x5, // The container id
(int)PresenceRelationshipLevel.Everyone,
new ContactCard(0x5) // Same container ID again
{
IsAllowedToShowPhoto = true,
PhotoUri = "<uri to your photo here"
});
You can set an ExpiryPolicy on this object too, should be self explainatory really. Then publish this presence object on your endpoint:
Endpoint.LocalOwnerPresence.BeginPublishPresence(new[] { photoPresence }, cb => {
Endpoint.LocalOwnerPresence.EndPublishPresence(cb);
}, null);
And that should do it, really. I ended up explicitly publishing to all relationship levels because it didn't cascade the data as logically expected.

Related

Xamarin Forms - Tracking what links a user is sharing from my app

I am using the method below in order to share uri's from my app.
ShareTextRequest share = new ShareTextRequest
{
Uri = uri,
Title = "Share Link"
};
await Share.RequestAsync(share);
All is working fine on both Android and iOS, however I am running into an issue as I would like to track and log to what applications the users are sharing the link, for security purposes as per company policy.
An example of the log would be something like;
{
'UserId': '999',
'Link': 'http://example.com',
'SharedTo': 'Facebook',
'SharedOn': '29/08/2019 11:00.000'
}
Would it be possible to use a callback method for example, where I can return the name of the application the link was shared to?
I have already tried accessing any returns of the function but it returns void.
My only other option might be to create a custom share functionality without using the native options.

Simplified LDAP/AD Server on C#

I've searched without much success to the simplest (and yet working) example of an LDAP/AD Server for C#. Many libraries exist to connect to LDAP servers, but not the LDAP Server by itself (on C#).
I found however some information about it and even a post requesting a simple LDAP server that was answered "LDAP isn't simple"; and yet i read a lot of the RFC4511 and this sample code at GitHub Flexinet LDAP Server, but unfortunatly i don't have yet the knowledge to complete it's code.
My goal is not to make a fully functional LDAP server, but one that can at least do:
Serve as a login pool for softwares that allow it's users to be
registered and log on a AD/LDAP server (just check for login and
password for authentication).
Allow softwares like Outlook and Thunderbird to get a list of users (without passwords) with first and last name, e-mail address, phone number and department for contact list model.
No delete, add (or create), move, and other
functions are required since the main software that i aim to
integrate it with will do all the user and group management.
UPDATE
I'm trying to implement the Flexinet sample and adjust to that functionalities; as form of a question what should i do to change this function to prevent it from causing an exception (on the "var filter = searchRequest.ChildAttributes[6];" line it always breaks) when i call from a LDAP client software:
private void HandleSearchRequest(NetworkStream stream, LdapPacket requestPacket)
{
var searchRequest = requestPacket.ChildAttributes.SingleOrDefault(o => o.LdapOperation == LdapOperation.SearchRequest);
var filter = searchRequest.ChildAttributes[6];
if ((LdapFilterChoice)filter.ContextType == LdapFilterChoice.equalityMatch && filter.ChildAttributes[0].GetValue<String>() == "sAMAccountName" && filter.ChildAttributes[1].GetValue<String>() == "testuser") // equalityMatch
{
var responseEntryPacket = new LdapPacket(requestPacket.MessageId);
var searchResultEntry = new LdapAttribute(LdapOperation.SearchResultEntry);
searchResultEntry.ChildAttributes.Add(new LdapAttribute(UniversalDataType.OctetString, "cn=testuser,cn=Users,dc=dev,dc=company,dc=com"));
searchResultEntry.ChildAttributes.Add(new LdapAttribute(UniversalDataType.Sequence));
responseEntryPacket.ChildAttributes.Add(searchResultEntry);
var responsEntryBytes = responseEntryPacket.GetBytes();
stream.Write(responsEntryBytes, 0, responsEntryBytes.Length);
}
var responseDonePacket = new LdapPacket(requestPacket.MessageId);
responseDonePacket.ChildAttributes.Add(new LdapResultAttribute(LdapOperation.SearchResultDone, LdapResult.success));
var responseDoneBytes = responseDonePacket.GetBytes();
stream.Write(responseDoneBytes, 0, responseDoneBytes.Length);
}
The code is on the github link.
Finally i made a fork of the Flexinet LDAP Server on #Sammuel-Miranda/LdapServerLib and with the author's support and some changes and adaptations i completed this implementation. It responds to the bind and search calls and works perfectly for Outlook and Thunderbird to use as a shared address book.
I did not implemente however any ADD/MODIFY/DELETE request (but would not be hard to do) since i don't need then.
I found on the RFC4511 the explanation on how the search works ... and i'm "kind" of understanding it, not very well - and i see that the method implemented on the GitHub from Flexinet LDAP Server only answer to bind and search requests of one single user (since it's only a example implementation).
The client is requesting diferent calls to verify capabilities, structure and other info before making the search request itself. So i'll implement it all, one by one.
Still, if any other lib (in C#) exists, and anyone know about, would be better than writing a hole new server. If my implementation works, i'll fork it on github and share.

Microsoft.Graph.ServiceException when trying to download user image

I have a really frustrating issue, where all I want to do is get user images from O365 and simply display them on my web page, which is hosted on Azure azpp service.
As you can see from this SO and this SharePoint.StackExchange question, The images fail to load when simply trying to display the link taken from SharePoint in an <img> tag.
However, after navigating to the image in a a new tab, and refreshing my page, the iamges load fine. can anyone explain this behaviour? it makes no sense to me at all
Anyways since that just dont work for whatever reason (logged in user clearly has the right permissions, as the images do disaply after navigating to them),
I thought I would try downloading the images using graph API.
SO I downloaded the quick start project and trying to download the iamges with
public async Task<Stream> TestAsync(GraphServiceClient graphClient)
{
var users = graphClient.Users;
var jk = users["user.name#domain.com"];
return await jk.Photo.Content.Request().GetAsync();
}
But I just get
Exception of type 'Microsoft.Graph.ServiceException' was thrown.
Yet when I try to view the same image in the API graph explorer, I can download the image. Please can someone just help me to display SharePoint user images in my web page without the user having to first navigate to the image directly.. Why must it be so difficult?
Once you have a valid token, make sure your permission scopes include User.Read.All, for example:
The query:
var user = graphClient.Users["<userPrincipalName>"];
corresponds to the following endpoint
Url: /users/{userPrincipalName}
Method: GET
which requires User.Read.All scope, see permission section for a more details.
In addition, in case of access without a user token requires Administrative Consent before it can be used.
Example
var users = graphClient.Users;
var user = users[accountName];
var photo = await user.Photo.Content.Request().GetAsync() as MemoryStream;
using (var file = new FileStream("./user.jpg", FileMode.Create, FileAccess.Write))
{
if (photo != null) photo.WriteTo(file);
}

MS Bot framework emulator chang user id

Is there a way to change the default user id (which is 'default-user') in bot emulator?
Or maybe it supports something about multi conversations in the same time?
I want to emulate two different users at the same time (because I have multiple user types in my project.
When I try to create new conversation like this
....
var connector = new ConnectorClient(new Uri(context.Activity.ServiceUrl));
var userAccount = new ChannelAccount("//here we need to provide user id which is always default-user", "Provider");
var botAccount = context.Activity.Recipient;
var conversation = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);
var message = context.MakeMessage();
message.Recipient = userAccount;
message.From = botAccount;
message.Conversation = new ConversationAccount(false, conversation.Id);
await connector.Conversations.SendToConversationAsync((Activity) message);
My emulator opens new conversation in the same chat-window
Bot Framework Channel Emulator had the functions you need in the previous versions. In the latest one AFAIK changing user id and group conversation simulation are not available out of the box. However the good thing is that what this tool is doing - it is just sending http requests to your WebApi endpoint. It means that you can catch those requests using Fiddler or any other similar tool and then edit and reissue the request. It is a workaround, but for testing pusposes I think it is okay to use such an approach.
Below is the Fiddler screen and screen of debug session to show it is working:
If you want to go further and automate it - there is a REST Api documentation on botframework site, so you can build your own client.
I work on the Bot Framework Emulator. We've recently added the ability to override generated user ids to be used in conversations without the need of a tool like Fiddler. You can utilize this feature in our latest release. I hope you find this useful for your scenario.
I don't know a way of having multiple conversations with different users, but you cant change the id/name of the user that is currently sending messages.
You can do this by editing the config file that the emulator uses to store its settings.
On linux I found this settings file here:
~/.config/botframework-emulator/botframework-emulator/server.json
You'll find a section "users" in that json file.
Change that section to:
"users": {
"currentUserId": "default-user2",
"usersById": {
"default-user": {
"id": "default-user",
"name": "User"
},
"default-user2": {
"id": "default-user2",
"name": "User2"
}
}
You'll need to restart the emulator and then your conversation should be with User2 now instead of User.
When you want to change it back you just need to change:
"currentUserId": "default-user2",
back to
"currentUserId": "default-user",
On windows follow these steps:
go to directory
%APPDATA%\botframework-emulator\botframework-emulator
locate server.json file
In the sections of users replace default-user
with id you need (in my case romel)
"users": {
"currentUserId": "default-user",
"usersById": {
"default-user": {
"id": "romel",
"name": "User"
}
}
}
restart bot emulator

How to retrieve rendered Sharepoint WebPart Data using Client Object Model

I am trying to access data remotely from sharepoint 2010 site using client object model. For some restrictions I am not able to use CAML query even if I use I am not able to filter for proper audiences based on user login (if you can help me regarding the CAML query is also fine :: i do not know how to get current user audience name and all audiences using CAML/client object model. This code sits on the mobile site and calling the share point site as shown in my code). This following code works good but not able to get the content from the webpart. Can someone help regarding this.
using (ClientContext ctx = new ClientContext("https://mysite.com/Pages/Default.aspx"))
{
ctx.ExecutingWebRequest += new EventHandler<WebRequestEventArgs> (clientContext_ExecutingWebRequest);
File home=ctx.Web.GetFileByServerRelativeUrl("/Student/Pages/default.aspx");
//get the web part manager
Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager wpm = home.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
IEnumerable<Microsoft.SharePoint.Client.WebParts.WebPartDefinition> wpds = null;
//create the LINQ query to get the web parts from
//the web part definition collection
wpds = ctx.LoadQuery(wpm.WebParts.Include(wp => wp.Id,wp => wp.WebPart));
//load the list of web parts
ctx.ExecuteQuery();
//enumerate the results
foreach (Microsoft.SharePoint.Client.WebParts.WebPartDefinition wpd in wpds)
{
string title= wpd.WebPart.Title;
Microsoft.SharePoint.Client.WebParts.WebPart wpart = wpd.WebPart;
????? How to render and receive the data (looking for the same data When you browse the site with the browser)
}
Code continues...
I am also struggling with this issue. It really looks like this is not possible with client object model. Actually i've asked it to some SharePoint staff member at Build Conference 2012.
But, with the SharePoint Designer it's actually possible to download the wanted WebPart. Fiddler may come handy to track down which service will deliver you the bits.
Take a look at this post here on SharePoint StackExchange
Unfortunately the post will not give you any concrete way to solve it.
Wish you good luck!

Categories

Resources