本文整理汇总了C#中IResource.GetResourceTypeDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C# IResource.GetResourceTypeDescriptor方法的具体用法?C# IResource.GetResourceTypeDescriptor怎么用?C# IResource.GetResourceTypeDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResource
的用法示例。
在下文中一共展示了IResource.GetResourceTypeDescriptor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
/// <summary>
/// Converts the resource to the specified version
/// </summary>
/// <param name="resource">The resource.</param>
/// <param name="targetVersion">The target version.</param>
/// <returns></returns>
public IResource Convert(IResource resource, Version targetVersion)
{
//How does this work? If source and target versions are known, it means the classes
//that represent them are also known and we just serialize from the source type to xml
//and deserialize that xml to the target type, with any unsupported bits falling by the
//wayside in the process, and any new bits flubbed with default values as part of deserialization
var resVer = resource.GetResourceTypeDescriptor().Version;
var dstVer = string.Format("{0}.{1}.{2}", targetVersion.Major, targetVersion.Minor, targetVersion.Build); //NOXLATE
var dstXsd = resource.ValidatingSchema.Replace(resVer, dstVer);
using (var sr = ResourceTypeRegistry.Serialize(resource))
{
using (var str = new StreamReader(sr))
{
var xml = new StringBuilder(str.ReadToEnd());
xml.Replace(resource.ValidatingSchema, dstXsd);
xml.Replace("version=\"" + resVer, "version=\"" + dstVer); //NOXLATE
var convRes = ResourceTypeRegistry.Deserialize(xml.ToString());
convRes.CurrentConnection = resource.CurrentConnection;
convRes.ResourceID = resource.ResourceID;
return convRes;
}
}
}
示例2: Validate
/// <summary>
/// Validats the specified resources for common issues associated with this
/// resource type
/// </summary>
/// <param name="context"></param>
/// <param name="resource"></param>
/// <param name="recurse"></param>
/// <returns></returns>
public virtual ValidationIssue[] Validate(ResourceValidationContext context, IResource resource, bool recurse)
{
if (!resource.GetResourceTypeDescriptor().Equals(this.SupportedResourceAndVersion))
return null;
return ValidateBase(context, resource, recurse);
}
示例3: Open
/// <summary>
/// Opens the specified resource using its assigned editor. If the resource is already
/// open, the the existing editor view is activated instead. If the resource has no assigned
/// editor or useXmlEditor is true, the resource will be opened in the default
/// XML editor.
/// </summary>
/// <param name="res"></param>
/// <param name="conn"></param>
/// <param name="useXmlEditor"></param>
/// <param name="siteExp"></param>
public IEditorViewContent Open(IResource res, IServerConnection conn, bool useXmlEditor, ISiteExplorer siteExp)
{
string key = ComputeResourceKey(res, conn);
if (!_openItems.ContainsKey(key))
{
var svc = ServiceRegistry.GetService<ViewContentManager>();
IEditorViewContent ed = null;
if (useXmlEditor || !res.IsStronglyTyped)
{
ed = svc.OpenContent<XmlEditor>(ViewRegion.Document);
}
else
{
ed = FindEditor(svc, res.GetResourceTypeDescriptor());
}
var launcher = ServiceRegistry.GetService<UrlLauncherService>();
var editorSvc = new ResourceEditorService(res.ResourceID, conn, launcher, siteExp, this);
ed.EditorService = editorSvc;
_openItems[key] = ed;
ed.ViewContentClosing += (sender, e) =>
{
if (ed.IsDirty && !ed.DiscardChangesOnClose)
{
if (ed.IsNew)
{
if (!MessageService.AskQuestion(string.Format(Strings.CloseUnsavedResource, string.Empty)))
{
e.Cancel = true;
}
}
else
{
using (var diag = new DirtyStateConfirmationDialog(ed.EditorService))
{
if (diag.ShowDialog() == System.Windows.Forms.DialogResult.No)
{
e.Cancel = true;
}
}
}
}
};
ed.ViewContentClosed += (sender, e) =>
{
//Recompute the resource key as that may have changed by a save as operation
_openItems.Remove(ComputeResourceKey(((EditorContentBase)sender).EditorService.ResourceID, conn));
siteExp.FlagNode(conn.DisplayName, ed.EditorService.ResourceID, NodeFlagAction.None);
};
ed.EditorService.Saved += (sender, e) =>
{
//If saved from new resource, the resource id would be session based
//So we need to update this to the new resource id as defined by the
//editor service
if (_openItems.ContainsKey(key))
{
var ed2 = _openItems[key];
_openItems.Remove(key);
_openItems[ComputeResourceKey(ed.EditorService.ResourceID, conn)] = ed2;
}
};
ed.DirtyStateChanged += (sender, e) =>
{
siteExp.FlagNode(conn.DisplayName, res.ResourceID, ed.IsDirty ? NodeFlagAction.HighlightDirty : NodeFlagAction.HighlightOpen);
};
}
_openItems[key].Activate();
siteExp.FlagNode(conn.DisplayName, res.ResourceID, _openItems[key].IsDirty ? NodeFlagAction.HighlightDirty : NodeFlagAction.HighlightOpen);
return _openItems[key];
}
示例4: Validate
/// <summary>
/// Validates the specified item using an existing validation context to skip over
/// items already validated
/// </summary>
/// <param name="context"></param>
/// <param name="item"></param>
/// <param name="recurse"></param>
/// <returns></returns>
public static ValidationIssue[] Validate(ResourceValidationContext context, IResource item, bool recurse)
{
Check.NotNull(item, "item"); //NOXLATE
var issueSet = new ValidationResultSet();
if (!HasValidator(item.ResourceType, item.ResourceVersion))
{
issueSet.AddIssue(new ValidationIssue(item, ValidationStatus.Warning, ValidationStatusCode.Warning_General_NoRegisteredValidatorForResource, string.Format(Strings.ERR_NO_REGISTERED_VALIDATOR, item.ResourceType, item.ResourceVersion)));
}
else
{
foreach (IResourceValidator v in m_validators)
{
if (!v.SupportedResourceAndVersion.Equals(item.GetResourceTypeDescriptor()))
continue;
try
{
ValidationIssue[] tmp = v.Validate(context, item, recurse);
if (tmp != null)
issueSet.AddIssues(tmp);
}
catch (Exception ex)
{
string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
if (ex is NullReferenceException)
msg = ex.ToString();
issueSet.AddIssue(new ValidationIssue(item, ValidationStatus.Error, ValidationStatusCode.Error_General_ValidationError, string.Format(Strings.ErrorValidationGeneric, msg)));
}
}
}
return issueSet.GetAllIssues();
}
示例5: Serialize
/// <summary>
/// Serializes the specified resource.
/// </summary>
/// <param name="res">The resource.</param>
/// <returns></returns>
public static Stream Serialize(IResource res)
{
var rd = res.GetResourceTypeDescriptor();
if (!_serializers.ContainsKey(rd))
{
var utr = res as UntypedResource;
if (utr == null)
throw new SerializationException(Strings.ERR_NO_SERIALIZER + rd.ToString());
return utr.SerializeToStream();
}
return _serializers[rd].Serialize(res);
}