///
/// Copyright © 2003-2008 JetBrains s.r.o.
/// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder).
///
using System;
using JetBrains.Omea.Jiffa.JiraSoap;
using JetBrains.Omea.OpenAPI;
using JetBrains.Omea.OpenApiEx;
namespace JetBrains.Omea.Jiffa
{
public class JiraUser : ResourceObject, ISyncableTo
{
private readonly JiraServer _server;
public JiraUser(JiraServer server, IResource resource)
: base(resource)
{
_server = server;
}
///
/// Looks up a user on the given server that has the name specified.
/// Null if none such found.
///
public static JiraUser FromName(JiraServer server, string name)
{
if(server == null)
throw new ArgumentNullException("server");
if(string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
IResourceList reslist = server.Resource.GetLinksTo(Types.JiraUser, Core.Props.Parent);
reslist = reslist.Intersect(Core.ResourceStore.FindResources(Types.JiraUser, Core.Props.Name, name), true);
return reslist.Count > 0 ? new JiraUser(server, reslist[0]) : null;
}
/*
///
/// Contacts the server, gets the user data and
///
///
///
///
public static JiraUser FromJiraTransient(JiraServer server, string username)
{ }
* */
public JiraServer Server
{
get
{
return _server;
}
}
public void Sync(RemoteUser itemJira)
{
ResourceProxy proxy = new ResourceProxy(Resource, AsyncPriority);
proxy.BeginUpdate();
proxy.SetProp(Core.Props.Name, itemJira.name);
proxy.SetProp(Props.FullName, itemJira.fullname);
proxy.SetProp(Props.Email, itemJira.email);
if(Async)
proxy.EndUpdateAsync();
else
proxy.EndUpdate();
}
///
/// Gets the item's ID on the JIRA server.
///
public string JiraId
{
get
{
return Resource.GetPropText(Props.JiraId);
}
}
///
/// Gets the user's name.
///
public string Name
{
get
{
return Resource.GetPropText(Core.Props.Name);
}
}
///
/// Gets the user's full name.
///
public string FullName
{
get
{
return Resource.GetPropText(Props.FullName);
}
}
///
/// Gets the user's email address.
///
public string Email
{
get
{
return Resource.GetPropText(Props.Email);
}
}
}
}