///
/// 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 System.Collections;
using System.IO;
using JetBrains.Annotations;
namespace JetBrains.Omea.OpenAPI
{
public class PropId
{
private readonly int _id;
public PropId(int id)
{
_id = id;
}
public int Id
{
get { return _id; }
}
}
///
/// Represents a single data object in the resource store. A resource has a type,
/// a collection of typed properties and can have links to other resources.
///
///
/// Only one IResource instance can exist at the same time for every given resource ID.
/// For non-transient resources, all methods which modify the resource can only be called
/// from the resource thread.
///
public interface IResource
{
///
/// Identifier of a resource. A positive number for a valid resource, or -1 if the
/// resource has been deleted.
///
int Id { get; }
///
/// For deleted resources - the identifier of the resource before it was deleted. For
/// existing resources - the same as .
///
int OriginalId { get; }
///
/// Name of the type of the resource.
///
string Type { get; }
///
/// Identifier of the type of the resource.
///
int TypeId { get; }
///
/// The default string representation of the resource in the user interface.
///
/// By default, the display name is automatically generated from the properties of the resource,
/// based on the template which is specified when the resource type is registered.
/// If a display name for a resource is assigned explicitly, it overrides the default generated
/// display name, but an explicitly assigned display name is not updated automatically
/// when the properties of a resource are changed.
///
string DisplayName { get; set; }
///
/// Gets the collection which allows to enumerate the properties of a resource.
///
/// Enumerating the collection returns objects of type .
/// For getting or setting properties, Get*Prop() and SetProp() methods should be used.
IPropertyCollection Properties { get; }
///
/// Clears all properties of a transient resource.
///
/// Has no effect for a persistent resource.
///840
void ClearProperties();
///
/// Locks the resource in blocking mode.
///
/// 862
/// For IResource instance, never use the lock statement or Monitor.Enter().
void Lock();
///
/// Tries to lock the resource in non-blocking mode.
///
/// True is resource was locked.
/// 862
bool TryLock();
///
/// Unlocks the resource.
///
/// 862
void UnLock();
///
/// Returns true if the Delete() method was called for a resource.
///
///
/// The resource is actually deleted only after it has been removed from all live resource
/// lists, so this method can return true even if the resource still exists (and is being
/// removed from resource lists).
///
bool IsDeleting { get; }
///
/// Returns true if the resource has been deleted from the resource store.
///
///
/// For deleted resources, calling all reader methods returns empty data, and calling
/// all writer methods throws a .
///
bool IsDeleted { get; }
///
/// Returns true if the resource is transient and not yet saved to the resource store.
///
///
/// Transient resources are created with
/// and exist only in memory, until the method has been called on them.
/// Transient resources can be created and modified in any thread, but the
/// method must be called in the resource thread.
///
bool IsTransient { get; }
///
/// Sets the property with the specified name to the specified value.
///
/// Name of the property to set.
/// The value to which the property is set.
///
/// The type of propValue must match the data type of the property: Int32
/// for Int properties, String for String properties, DateTime for Date properties,
/// Double for Double properties, Boolean for Bool properties, Stream for Blob properties,
/// IResource for Link properties.
///
/// String list properties cannot be set by SetProp. To set the value of a string
/// list property, call and use
/// methods to modify the value.
/// Setting the value of a link property deletes all other links of the same type
/// and in the same direction. If the link type is directed and there is a link of the same type
/// from the link target to the resource on which the link is set, that link is deleted
/// as well.
/// Setting the property value to null is equivalent to .
///
void SetProp( string propName, object propValue );
///
/// Sets the property with the specified ID to the specified value.
///
/// ID of the property to set.
/// The value to which the property is set.
///
/// The type of propValue must match the data type of the property: Int32
/// for Int properties, String for String properties, DateTime for Date properties,
/// Double for Double properties, Boolean for Bool properties, Stream for Blob properties,
/// IResource for Link properties.
///
/// String list properties cannot be set by SetProp. To set the value of a string
/// list property, call and use
/// methods to modify the value.
/// Setting the value of a link property deletes all other links of the same type
/// and in the same direction. If the link type is directed and there is a link of the same type
/// from the link target to the resource on which the link is set, that link is deleted
/// as well.
/// Setting the property value to null is equivalent to .
/// Since version 2.2 it is possible to set a string value to a blob property.
///
void SetProp( int propId, object propValue );
void SetProp( PropId propId, T value );
void SetReverseLinkProp(PropId propId, IResource propValue);
///
/// Deletes the property with the specified name.
///
/// Name of the property to delete.
/// For link properties, this works as .
void DeleteProp( string propName );
///
/// Deletes the property with the specified ID.
///
/// ID of the property to delete.
/// For link properties, this works as .
void DeleteProp( int propId );
///
/// Adds a link with the specified property name to the specified target resource.
///
/// Name of the link property.
/// Resource to which the link is added.
/// If the target resource is transient, the link will not be visible
/// in the list of the links of the current resource until
/// is called on the target.
void AddLink( string propName, IResource target );
///
/// Adds a link with the specified property ID to the specified target resource.
///
/// ID of the link property.
/// Resource to which the link is added.
/// If the target resource is transient, the link will not be visible
/// in the list of the links of the current resource until
/// is called on the target.
void AddLink( int propId, IResource target );
void AddLink(PropId propId, IResource target);
///
/// Deletes a link with the specified property name to the specified resource.
///
/// Name of the link property.
/// Resource to which the link is deleted.
/// Deleting a link which does not exist is not an error and has no effect.
void DeleteLink( string propName, IResource target );
///
/// Deletes a link with the specified property ID to the specified resource.
///
/// ID of the link property.
/// Resource to which the link is deleted.
/// Deleting a link which does not exist is not an error and has no effect.
void DeleteLink( int propId, IResource target );
///
/// Deletes all links with the specified property name.
///
/// Name of the property for which the links are deleted.
/// If is a directed link, only the links from the
/// resource are deleted.
void DeleteLinks( string propName );
///
/// Deletes all links with the specified property ID.
///
/// ID of the property for which the links are deleted.
/// If is a directed link, only the links from the
/// resource are deleted. To delete links to the resource, specify a negative property
/// ID (for example, -5 instead of 5).
void DeleteLinks( int propId );
///
/// Returns the value of the property with the specified ID.
///
/// ID of the property.
/// Value of the property, or null if no value was assigned for the current
/// resource.
/// For bool properties, a non-null value (true or false) is always returned.
/// For link properties, the return value is the same as for .
///
///
object GetProp( int propId );
///
/// Returns the value of the property with the specified name.
///
/// Name of the property.
/// Value of the property, or null if no value was assigned for the current
/// resource.
/// For bool properties, a non-null value (true or false) is always returned.
/// For link properties, the return value is the same as for .
///
///
object GetProp( string propName );
T GetProp( PropId propId );
///
/// Returns the value of the string property with the specified ID.
///
/// ID of the property.
/// Value of the property, or null if no value was assigned for the current
/// resource.
string GetStringProp( int propId );
///
/// Returns the value of the string property with the specified name.
///
/// Name of the property.
/// Value of the property, or null if no value was assigned for the current
/// resource.
string GetStringProp( string propName );
///
/// Returns the value of the int property with the specified ID.
///
/// ID of the property.
/// Value of the property, or 0 if no value was assigned for the current
/// resource.
int GetIntProp( int propId );
///
/// Returns the value of the int property with the specified name.
///
/// Name of the property.
/// Value of the property, or 0 if no value was assigned for the current
/// resource.
int GetIntProp( string propName );
///
/// Returns the value of the date/time property with the specified ID.
///
/// ID of the property.
/// Value of the property, or if no value
/// was assigned for the current resource.
DateTime GetDateProp( int propId );
///
/// Returns the value of the date/time property with the specified name.
///
/// Name of the property.
/// Value of the property, or if no value
/// was assigned for the current resource.
DateTime GetDateProp( string propName );
///
/// Returns the value of the double property with the specified ID.
///
/// ID of the property.
/// Value of the property, or 0.0 if no value
/// was assigned for the current resource.
double GetDoubleProp( int propId );
///
/// Returns the value of the double property with the specified name.
///
/// Name of the property.
/// Value of the property, or 0.0 if no value
/// was assigned for the current resource.
double GetDoubleProp( string propName );
///
/// Returns the value of the blob property with the specified ID.
///
/// ID of the property.
/// Value of the property, or null if no value
/// was assigned for the current resource.
/// A new stream is created every time the property is accessed. All
/// streams are opened over the same backing file for reading and writing, with
/// full sharing allowed, so there is a possibility that the stream is modified
/// concurrently. It is strongly recommended to close the stream after you've finished
/// working with it.
Stream GetBlobProp( int propId );
///
/// Returns the value of the blob property with the specified name.
///
/// Name of the property.
/// Value of the property, or null if no value
/// was assigned for the current resource.
/// A new stream is created every time the property is accessed. All
/// streams are opened over the same backing file for reading and writing, with
/// full sharing allowed, so there is a possibility that the stream is modified
/// concurrently. It is strongly recommended to close the stream after you've finished
/// working with it.
Stream GetBlobProp( string propName );
///
/// Returns the value of the string list property with the specified ID.
///
/// ID of the property.
/// Value of the property.
/// A non-null value is always returned. If no value was assigned to
/// the property, an empty list is returned.
IStringList GetStringListProp( int propId );
///
/// Returns the value of the string list property with the specified name.
///
/// Name of the property.
/// Value of the property.
/// A non-null value is always returned. If no value was assigned to
/// the property, an empty list is returned.
IStringList GetStringListProp( string propName );
///
/// Returns a resource to which the current resource is linked with the link of specified
/// name.
///
/// Name of the link property.
/// A resource linked to the current resource, or null if there are no
/// such resources.
///
/// If there are several resources linked to the current one with the specified
/// link type, an arbitrary one is returned.
/// For directed links, GetLinkProp() returns only links from the resource on which
/// the method was called, not links to it.
///
IResource GetLinkProp( string propName );
///
/// Returns a resource to which the current resource is linked with the link of specified
/// property ID.
///
/// ID of the link property.
/// A resource linked to the current resource, or null if there are no
/// such resources.
///
/// If there are several resources linked to the current one with the specified
/// link type, an arbitrary one is returned.
/// For directed links, GetLinkProp() returns only links from the resource on which
/// the method was called, not links to it.
///
IResource GetLinkProp( int propId );
///
/// Returns a resource which is linked to this resource with a directed link property of the
/// specified type.
///
/// ID of the directed link property type.
/// A resource linked to this resource or null.
[CanBeNull]
IResource GetReverseLinkProp([NotNull] PropId propId);
///
/// Returns the textual representation of the value of the property with the specified name.
///
/// Name of the property.
/// The textual (user-readable) representation of the value, or an empty string
/// if no value was assigned for the current resource.
/// For link properies, the representation consists of display names of all resources
/// linked to the current resource, separated with commas. For directed links, only links from
/// the current resource are included.
/// For string list properties, the representation consists of all strings in the list,
/// separated with commas.
///
string GetPropText( string propName );
///
/// Returns the textual representation of the value of the property with the specified ID.
///
/// ID of the property.
/// The textual (user-readable) representation of the value, or an empty string
/// if no value was assigned for the current resource.
/// For link properies, the representation consists of display names of all resources
/// linked to the current resource, separated with commas. For directed links, only links from
/// the current resource are included.
/// For string list properties, the representation consists of all strings in the list,
/// separated with commas.
///
string GetPropText( int propId );
///
/// Returns the count of links with the specified property name from the current resource.
///
/// Name of the link property.
/// Count of links.
/// If is a directed link, only the links from the
/// resource are counted.
int GetLinkCount( string propName );
///
/// Returns the count of links with the specified property ID from the current resource.
///
/// ID of the link property.
/// Count of links.
/// If is a directed link, only the links from the
/// resource are counted. To count links to the resource, specify a negative property
/// ID (for example, -5 instead of 5).
int GetLinkCount( int propId );
///
/// Returns the non-live list of the resources of the specified type linked to the current
/// resource with the link with the specified property name.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// Name of the link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// For directed links, both links from and to the resource are returned.
IResourceList GetLinksOfType( string resType, string propName );
///
/// Returns the non-live list of the resources of the specified type linked to the current
/// resource with the link with the specified property ID.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// ID of the link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// For directed links, both links from and to the resource are returned.
IResourceList GetLinksOfType( string resType, int propId );
IResourceList GetLinksOfType(string resType, PropId propId);
BusinessObjectList GetLinksOfType(ResourceTypeId resType, PropId propId)
where T : BusinessObject;
///
/// Returns the live list of the resources of the specified type linked to the current
/// resource with the link with the specified property name.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// Name of the link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// For directed links, both links from and to the resource are returned.
IResourceList GetLinksOfTypeLive( string resType, string propName );
///
/// Returns the live list of the resources of the specified type linked to the current
/// resource with the link with the specified property ID.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// ID of the link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// For directed links, both links from and to the resource are returned.
IResourceList GetLinksOfTypeLive( string resType, int propId );
IResourceList GetLinksOfTypeLive(string resType, PropId propId);
///
/// Returns the non-live list of the resources of the specified type to which there are directed links
/// from the current resource with the link with the specified property name.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// Name of the directed link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// This method can only be called for directed link properties.
IResourceList GetLinksFrom( string resType, string propName );
///
/// Returns the non-live list of the resources of the specified type to which there are directed links
/// from the current resource with the link with the specified property ID.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// ID of the directed link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// This method can only be called for directed link properties.
IResourceList GetLinksFrom( string resType, int propId );
IResourceList GetLinksFrom(string resType, PropId propId);
BusinessObjectList GetLinksFrom(ResourceTypeId resType, PropId propId)
where T : BusinessObject;
///
/// Returns the live list of the resources of the specified type to which there are directed links
/// from the current resource with the link with the specified property name.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// Name of the directed link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// This method can only be called for directed link properties.
IResourceList GetLinksFromLive( string resType, string propName );
///
/// Returns the live list of the resources of the specified type to which there are directed links
/// from the current resource with the link with the specified property ID.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// ID of the directed link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// This method can only be called for directed link properties.
IResourceList GetLinksFromLive( string resType, int propId );
///
/// Returns the non-live list of the resources of the specified type from which there are directed links
/// to the current resource with the link with the specified property name.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// Name of the directed link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// This method can only be called for directed link properties.
IResourceList GetLinksTo( string resType, string propName );
///
/// Returns the non-live list of the resources of the specified type from which there are directed links
/// to the current resource with the link with the specified property ID.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// Name of the directed link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// This method can only be called for directed link properties.
IResourceList GetLinksTo( string resType, int propId );
IResourceList GetLinksTo(string resType, PropId propId);
BusinessObjectList GetLinksTo(ResourceTypeId resType, PropId propId)
where T : BusinessObject;
///
/// Returns the live list of the resources of the specified type from which there are directed links
/// to the current resource with the link with the specified property name.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// Name of the directed link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// This method can only be called for directed link properties.
IResourceList GetLinksToLive( string resType, string propName );
///
/// Returns the live list of the resources of the specified type from which there are directed links
/// to the current resource with the link with the specified property ID.
///
/// Type of the resources which are returned, or null if resources
/// of all types should be returned.
/// Name of the directed link property.
/// The list of linked resources, or an empty list if there are no linked resources.
/// This method can only be called for directed link properties.
IResourceList GetLinksToLive( string resType, int propId );
///
/// Returns the array of distinct types of links from or to the resources.
///
/// An array of link property IDs, or an empty array if there are no links.
/// For directed links, both links from and to the resource are returned, and
/// all returned link type IDs are positive.
int[] GetLinkTypeIds();
///
/// Returns true if the resource has the property with the specified name.
///
/// Name of the property.
/// true if the resource has the property.
///
/// For directed link properties, HasProp() returns true only if there
/// are links from the resource.
/// For boolean properties, "the resource has the property" and "the value of the
/// property is true" are the same thing. Thus, you can use HasProp() to get the
/// value of boolean properties.
///
bool HasProp( string propName );
///
/// Returns true if the resource has the property with the specified ID.
///
/// ID of the property.
/// true if the resource has the property.
///
/// For directed link properties, HasProp() returns true only if there
/// are links from the resource.
/// For boolean properties, "the resource has the property" and "the value of the
/// property is true" are the same thing. Thus, you can use HasProp() to get the
/// value of boolean properties.
///
bool HasProp( int propId );
bool HasProp( PropId propId );
///
/// Returns true if the current resource is linked to the specified resource with a link
/// with the specified property name.
///
/// Name of the link property.
/// Target resource. May not be null.
/// true if the link to exists.
/// For directed links, only the links from the current resource are checked.
bool HasLink( string propName, IResource target );
///
/// Returns true if the current resource is linked to the specified resource with a link
/// with the specified property ID.
///
/// ID of the link property.
/// Target resource. May not be null.
/// true if the link to exists.
/// For directed links, only the links from the current resource are checked.
bool HasLink( int propId, IResource target );
///
/// Changes the type of the resource to the specified type.
///
/// New type of the resource.
void ChangeType( string newType );
///
/// Deletes the resource.
///
void Delete();
///
/// Begins a batch update of the resource properties.
///
/// If several properties of a resource are updated in a single operation, it is
/// recommended to surround them with BeginUpdate() and
/// to reduce the number of resource change notifications which are sent after the properties
/// are changed.
///
/// ///
void BeginUpdate();
///
/// Ends a batch update of the resource properties, and saves transient resources.
///
/// For transient resources, this method saves the properties and links of the
/// resource to disk, and must be called from the resource thread.
///
void EndUpdate();
///
/// Checks if any properties of the resource were changed after a call to .
///
/// true if any properties were changed, false otherwise.
/// This method can only be called between and
/// . Setting a property to the same value as the current value
/// of the property does not cause the resource to be changed.
bool IsChanged();
///
/// Returns a non-live resource list containing only the current resource.
///
/// The resource list instance.
IResourceList ToResourceList();
///
/// Returns a live resource list containing only the current resource.
///
/// The resource list instance.
/// The liveness of the resource list allows to receive notifications
/// when the resource is changed or deleted.
IResourceList ToResourceListLive();
}
///
/// Represents the value of a string list property of a resource.
///
/// The order of the strings in the list is persistent - the strings
/// are enumerated in the list in the same order as they were added.
/// The list may contain duplicate strings.
public interface IStringList: IDisposable, IEnumerable
{
///
/// Returns the number of strings in the list.
///
int Count { get; }
///
/// Returns the string at the specified (0-based) index.
///
string this[ int index ] { get; }
///
/// Adds a string to the list.
///
/// The string to add.
void Add( string value );
///
/// Removes the string at the specified index of the list.
///
/// The zero-based index of the string to remove.
void RemoveAt( int index );
///
/// Removes the specified string from the list.
///
/// The string to remove.
/// If the string is encountered multiple times in the list, only
/// the first instance is removed.
void Remove( string value );
///
/// Removes all strings from the list.
///
void Clear();
///
/// Returns the zero-based index of the first occurrence of a string in the list.
///
/// The string to locate.
/// The zero-based index of the string, or -1 if the string is not
/// present in the list.
int IndexOf( string value );
}
///
/// A collection of properties of the resource.
///
/// Enumerating the collection returns objects of type .
public interface IPropertyCollection: IEnumerable
{
///
/// Gets the count of properties of the resource.
///
int Count { get; }
}
///
/// Represents a single property of a resource.
///
/// Resource properties can be accessed by enumerating the
/// collection. The IResourceProperty
/// interface allows only read-only access to properties; to change property
/// values, use methods on like ,
/// and so on.
public interface IResourceProperty
{
///
/// The name of the property type.
///
string Name { get; }
///
/// The numeric ID of the property type.
///
int PropId { get; }
///
/// The data type of the property type.
///
PropDataType DataType { get; }
///
/// The value of the property for the resource.
///
/// For link properties, the return value is the same as that of
/// - that is, one randomly selected
/// resource linked to the current one.
object Value { get; }
}
}