///
/// 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
{
///
/// Describes a server-global custom field in JIRA.
///
public class JiraCustomField : ResourceObject, ISyncableTo
{
private readonly JiraServer _server;
///
/// Creates a new instance upon a resource.
///
public JiraCustomField(JiraServer server, IResource resource)
: base(resource)
{
_server = server;
}
///
/// Looks up a custom field on the given server that has the name specified.
/// Null if none such found.
///
public static JiraCustomField 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.JiraCustomField, Core.Props.Parent);
reslist = reslist.Intersect(Core.ResourceStore.FindResources(Types.JiraCustomField, Core.Props.Name, name), true);
return reslist.Count > 0 ? new JiraCustomField(server, reslist[0]) : null;
}
///
/// Gets the owning server.
///
public JiraServer Server
{
get
{
return _server;
}
}
public void Sync(RemoteField itemJira)
{
ResourceProxy proxy = new ResourceProxy(Resource, AsyncPriority);
proxy.BeginUpdate();
proxy.SetProp(Core.Props.Name, itemJira.name);
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 name of the JIRA item.
///
public string Name
{
get
{
return Resource.DisplayName;
}
}
}
}