private object GetCompletionData(INakedObject nakedObject, ITypeSpec spec) { string label = nakedObject.TitleString(); string value = nakedObject.TitleString(); string link = spec.IsParseable ? label : NakedObjectsContext.GetObjectId(nakedObject); string src = GetIconSrc(nakedObject); string alt = GetIconAlt(nakedObject); return(new { label, value, link, src, alt }); }
//TODO: Mark obsolete when Menus refactoring complete //[Obsolete("Add CustomMenuItems into an IMenu directly when constructing menus")] public static MvcHtmlString Service(this HtmlHelper html, object service, params CustomMenuItem[] menuItems) { INakedObject nakedObject = html.Framework().GetNakedObject(service); return(CommonHtmlHelper.BuildMenuContainer(html.ObjectActions(nakedObject, false, menuItems), IdHelper.MenuContainerName, IdHelper.GetServiceContainerId(nakedObject), nakedObject.TitleString())); }
public static string PropertyTitle(this INakedObjectFeature feature, INakedObject nakedObject) { if (nakedObject == null) { return ""; } string text = null; var regex = feature.GetFacet<IRegExFacet>(); if (regex != null) { text = regex.Format(nakedObject.TitleString()); } var mask = feature.GetFacet<IMaskFacet>(); if (mask != null) { var title = feature.Specification.GetFacet<ITitleFacet>(); text = title.GetTitleWithMask(mask.Value, nakedObject); } if (text == null) { text = nakedObject.TitleString(); } return text; }
public virtual string Invalidates(InteractionContext ic) { INakedObject proposedArgument = ic.ProposedArgument; if (DoesNotMatch(proposedArgument)) { return(string.Format(Resources.NakedObjects.MaskMismatch, proposedArgument.TitleString(), Value)); } return(null); }
public static string PropertyTitle(this IMemberSpec memberSpec, INakedObject nakedObject, INakedObjectManager manager) { if (nakedObject == null) { return(""); } string text = null; var regex = memberSpec.GetFacet <IRegExFacet>(); if (regex != null) { text = regex.Format(nakedObject.TitleString()); } var mask = memberSpec.GetFacet <IMaskFacet>(); if (mask != null) { var title = memberSpec.ReturnSpec.GetFacet <ITitleFacet>(); text = title.GetTitleWithMask(mask.Value, nakedObject, manager); } return(text ?? (nakedObject.TitleString())); }
public virtual string Invalidates(InteractionContext ic) { INakedObject proposedArgument = ic.ProposedArgument; if (proposedArgument == null) { return(null); } string titleString = proposedArgument.TitleString(); if (!DoesNotMatch(titleString)) { return(null); } return(failureMessage ?? Resources.NakedObjects.InvalidEntry); }
public DataUpdateException(INakedObject nakedObject, IVersion updated) : this(string.Format(Resources.NakedObjects.DataUpdateMessage, nakedObject.Version.User, nakedObject.TitleString(), DateTime.Now.ToLongTimeString(), Environment.NewLine, Environment.NewLine, nakedObject.Version, updated), nakedObject.Oid) { }
private static bool GetSelectedForChoice(INakedObject choice, INakedObject existingNakedObject) { IEnumerable<INakedObject> existingNakedObjects; if (existingNakedObject == null) { existingNakedObjects = new INakedObject[] {}; } else if (existingNakedObject.Specification.IsParseable || !existingNakedObject.Specification.IsCollection) { // isParseable to catch strings existingNakedObjects = new[] {existingNakedObject}; } else { existingNakedObjects = existingNakedObject.GetCollectionFacetFromSpec().AsEnumerable(existingNakedObject); } var enumFacet = choice.Specification.GetFacet<IEnumValueFacet>(); if (enumFacet != null) { return existingNakedObjects.Any(no => no != null && enumFacet.IntegralValue(choice) == enumFacet.IntegralValue(no)); } if (choice.Specification.IsParseable) { return existingNakedObjects.Any(no => choice.TitleString() == no.TitleString()); } return existingNakedObjects.Any(no => choice == no); }
private static string GetMaskedValue(INakedObject valueNakedObject, IMaskFacet mask) { if (valueNakedObject != null) { return mask != null ? valueNakedObject.Specification.GetFacet<ITitleFacet>().GetTitleWithMask(mask.Value, valueNakedObject) : valueNakedObject.TitleString(); } return null; }
public DataUpdateException(INakedObject nakedObject, IVersion updated) : this(string.Format(Resources.NakedObjects.DataUpdateMessage, nakedObject.Version.User, nakedObject.TitleString(), DateTime.Now.ToLongTimeString(), Environment.NewLine, Environment.NewLine, nakedObject.Version, updated), nakedObject.Oid) {}
public Place ObjectToElement(INakedObject nakedObject) { Log.Debug("objectToElement(" + DoLog("object", nakedObject) + ")"); IObjectSpec nos = (IObjectSpec)nakedObject.Spec; Log.Debug("objectToElement(NO): create element and nof:title"); XElement element = Schema.CreateElement(XmlDocument, nos.ShortName, nos.FullName, nos.SingularName, nos.PluralName); NofMetaModel.AppendNofTitle(element, nakedObject.TitleString()); Log.Debug("objectToElement(NO): create XS element for NOF class"); XElement xsElement = Schema.CreateXsElementForNofClass(XsdDocument, element, topLevelElementWritten); // hack: every element in the XSD schema apart from first needs minimum cardinality setting. topLevelElementWritten = true; var place = new Place(nakedObject, element); NofMetaModel.SetAttributesForClass(element, OidOrHashCode(nakedObject)); IAssociationSpec[] fields = nos.Properties; Log.Debug("objectToElement(NO): processing fields"); var seenFields = new List <string>(); foreach (IAssociationSpec field in fields) { string fieldName = field.Id; Log.Debug("objectToElement(NO): " + DoLog("field", fieldName)); // Skip field if we have seen the name already // This is a workaround for getLastActivity(). This method exists // in AbstractNakedObject, but is not (at some level) being picked up // by the dot-net reflector as a property. On the other hand it does // exist as a field in the meta model (NakedObjectSpecification). // // Now, to re-expose the lastactivity field for .Net, a deriveLastActivity() // has been added to BusinessObject. This caused another field ofthe // same name, ultimately breaking the XSD. if (seenFields.Contains(fieldName)) { Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " SKIPPED"); continue; } seenFields.Add(fieldName); XNamespace ns = Schema.GetUri(); var xmlFieldElement = new XElement(ns + fieldName); XElement xsdFieldElement; var oneToOneAssociation = field as IOneToOneAssociationSpec; var oneToManyAssociation = field as IOneToManyAssociationSpec; if (field.ReturnSpec.IsParseable && oneToOneAssociation != null) { Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is value"); IObjectSpec fieldNos = field.ReturnSpec; // skip fields of type XmlValue if (fieldNos != null && fieldNos.FullName != null && fieldNos.FullName.EndsWith("XmlValue")) { continue; } XElement xmlValueElement = xmlFieldElement; // more meaningful locally scoped name try { INakedObject value = oneToOneAssociation.GetNakedObject(nakedObject); // a null value would be a programming error, but we protect // against it anyway if (value == null) { continue; } ITypeSpec valueNos = value.Spec; // XML NofMetaModel.SetAttributesForValue(xmlValueElement, valueNos.ShortName); bool notEmpty = (value.TitleString().Length > 0); if (notEmpty) { string valueStr = value.TitleString(); xmlValueElement.Add(new XText(valueStr)); } else { NofMetaModel.SetIsEmptyAttribute(xmlValueElement, true); } } catch (Exception) { Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": getField() threw exception - skipping XML generation"); } // XSD xsdFieldElement = Schema.CreateXsElementForNofValue(xsElement, xmlValueElement); } else if (oneToOneAssociation != null) { Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is IOneToOneAssociation"); XElement xmlReferenceElement = xmlFieldElement; // more meaningful locally scoped name try { INakedObject referencedNakedObject = oneToOneAssociation.GetNakedObject(nakedObject); string fullyQualifiedClassName = field.ReturnSpec.FullName; // XML NofMetaModel.SetAttributesForReference(xmlReferenceElement, Schema.Prefix, fullyQualifiedClassName); if (referencedNakedObject != null) { NofMetaModel.AppendNofTitle(xmlReferenceElement, referencedNakedObject.TitleString()); } else { NofMetaModel.SetIsEmptyAttribute(xmlReferenceElement, true); } } catch (Exception) { Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": getAssociation() threw exception - skipping XML generation"); } // XSD xsdFieldElement = Schema.CreateXsElementForNofReference(xsElement, xmlReferenceElement, oneToOneAssociation.ReturnSpec.FullName); } else if (oneToManyAssociation != null) { Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is IOneToManyAssociation"); XElement xmlCollectionElement = xmlFieldElement; // more meaningful locally scoped name try { INakedObject collection = oneToManyAssociation.GetNakedObject(nakedObject); ITypeOfFacet facet = collection.GetTypeOfFacetFromSpec(); IObjectSpecImmutable referencedTypeNos = facet.GetValueSpec(collection, metamodelManager.Metamodel); string fullyQualifiedClassName = referencedTypeNos.FullName; // XML NofMetaModel.SetNofCollection(xmlCollectionElement, Schema.Prefix, fullyQualifiedClassName, collection, nakedObjectManager); } catch (Exception) { Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": get(obj) threw exception - skipping XML generation"); } // XSD xsdFieldElement = Schema.CreateXsElementForNofCollection(xsElement, xmlCollectionElement, oneToManyAssociation.ReturnSpec.FullName); } else { Log.Info("objectToElement(NO): " + DoLog("field", fieldName) + " is unknown type; ignored"); continue; } if (xsdFieldElement != null) { xmlFieldElement.AddAnnotation(xsdFieldElement); } // XML Log.Debug("objectToElement(NO): invoking mergeTree for field"); MergeTree(element, xmlFieldElement); // XSD if (xsdFieldElement != null) { Log.Debug("objectToElement(NO): adding XS element for field to schema"); Schema.AddFieldXsElement(xsElement, xsdFieldElement); } } return(place); }
private void Validate(INakedObject adapter) { if (adapter.Spec.ContainsFacet <IValidateProgrammaticUpdatesFacet>()) { string state = adapter.ValidToPersist(); if (state != null) { throw new PersistFailedException(string.Format(Resources.NakedObjects.PersistStateError, adapter.Spec.ShortName, adapter.TitleString(), state)); } } }
private static string GetDisplayTitle(IFacetHolder holder, INakedObject nakedObject) { var mask = holder.GetFacet<IMaskFacet>(); string title = mask != null ? nakedObject.Specification.GetFacet<ITitleFacet>().GetTitleWithMask(mask.Value, nakedObject) : nakedObject.TitleString(); return string.IsNullOrWhiteSpace(title) && !nakedObject.Specification.IsParseable ? nakedObject.Specification.UntitledName : title; }
private static string GetTextForChoice(INakedObject choice) { var enumFacet = choice.Specification.GetFacet<IEnumValueFacet>(); if (enumFacet != null) { choice.TitleString(); } return choice.TitleString(); }
/// <summary> /// Display name of object with icon /// </summary> public static MvcHtmlString Object(this HtmlHelper html, object model) { INakedObject nakedObject = html.Framework().NakedObjectManager.CreateAdapter(model, null, null); string title = nakedObject.Spec.IsCollection ? GetCollectionTitle(nakedObject, html) : nakedObject.TitleString(); title = string.IsNullOrWhiteSpace(title) ? nakedObject.Spec.UntitledName : title; return(CommonHtmlHelper.WrapInDiv(html.ObjectIcon(nakedObject) + title, IdHelper.ObjectName)); }
/// <summary> /// Display name (Title) of object /// </summary> public static MvcHtmlString Name <TModel>(this HtmlHelper html, TModel model) { INakedObject nakedObject = html.Framework().GetNakedObject(model); return(MvcHtmlString.Create(nakedObject.TitleString())); }
public static MvcHtmlString ObjectTitle(this HtmlHelper html, INakedObject nakedObject) { string title = nakedObject.TitleString(); return(MvcHtmlString.Create(string.IsNullOrWhiteSpace(title) ? nakedObject.Spec.UntitledName : title)); }
public static string GetServiceLabel(INakedObject nakedObject) { return nakedObject.TitleString(); }
public string TitleString() { return(nakedObject.TitleString()); }
private static string DoLog(string label, INakedObject nakedObject) { return DoLog(label, (nakedObject == null ? "(null)" : nakedObject.TitleString() + "[" + OidOrHashCode(nakedObject) + "]")); }
private object GetCompletionData(INakedObject nakedObject, INakedObjectSpecification spec) { string label = nakedObject.TitleString(); string value = nakedObject.TitleString(); string link = spec.IsParseable ? label : FrameworkHelper.GetObjectId(nakedObject); string src = GetIconSrc(nakedObject); string alt = GetIconAlt(nakedObject); return new {label, value, link, src, alt}; }
public Place ObjectToElement(INakedObject nakedObject) { Log.Debug("objectToElement(" + DoLog("object", nakedObject) + ")"); INakedObjectSpecification nos = nakedObject.Specification; Log.Debug("objectToElement(NO): create element and nof:title"); XElement element = Schema.CreateElement(XmlDocument, nos.ShortName, nos.FullName, nos.SingularName, nos.PluralName); NofMetaModel.AppendNofTitle(element, nakedObject.TitleString()); Log.Debug("objectToElement(NO): create XS element for NOF class"); XElement xsElement = Schema.CreateXsElementForNofClass(XsdDocument, element, topLevelElementWritten); // hack: every element in the XSD schema apart from first needs minimum cardinality setting. topLevelElementWritten = true; var place = new Place(nakedObject, element); NofMetaModel.SetAttributesForClass(element, OidOrHashCode(nakedObject)); INakedObjectAssociation[] fields = nos.Properties; Log.Debug("objectToElement(NO): processing fields"); var seenFields = new List<string>(); foreach (INakedObjectAssociation field in fields) { string fieldName = field.Id; Log.Debug("objectToElement(NO): " + DoLog("field", fieldName)); // Skip field if we have seen the name already // This is a workaround for getLastActivity(). This method exists // in AbstractNakedObject, but is not (at some level) being picked up // by the dot-net reflector as a property. On the other hand it does // exist as a field in the meta model (NakedObjectSpecification). // // Now, to re-expose the lastactivity field for .Net, a deriveLastActivity() // has been added to BusinessObject. This caused another field ofthe // same name, ultimately breaking the XSD. if (seenFields.Contains(fieldName)) { Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " SKIPPED"); continue; } seenFields.Add(fieldName); XNamespace ns = Schema.GetUri(); var xmlFieldElement = new XElement(ns + fieldName); XElement xsdFieldElement; if (field.Specification.IsParseable) { Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is value"); INakedObjectSpecification fieldNos = field.Specification; // skip fields of type XmlValue if (fieldNos != null && fieldNos.FullName != null && fieldNos.FullName.EndsWith("XmlValue")) { continue; } var oneToOneAssociation = ((IOneToOneAssociation) field); XElement xmlValueElement = xmlFieldElement; // more meaningful locally scoped name try { INakedObject value = oneToOneAssociation.GetNakedObject(nakedObject); // a null value would be a programming error, but we protect // against it anyway if (value == null) { continue; } INakedObjectSpecification valueNos = value.Specification; // XML NofMetaModel.SetAttributesForValue(xmlValueElement, valueNos.ShortName); bool notEmpty = (value.TitleString().Length > 0); if (notEmpty) { string valueStr = value.TitleString(); xmlValueElement.Add(new XText(valueStr)); } else { NofMetaModel.SetIsEmptyAttribute(xmlValueElement, true); } } catch (Exception) { Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": getField() threw exception - skipping XML generation"); } // XSD xsdFieldElement = Schema.CreateXsElementForNofValue(xsElement, xmlValueElement); } else if (field is IOneToOneAssociation) { Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is IOneToOneAssociation"); var oneToOneAssociation = ((IOneToOneAssociation) field); XElement xmlReferenceElement = xmlFieldElement; // more meaningful locally scoped name try { INakedObject referencedNakedObject = oneToOneAssociation.GetNakedObject(nakedObject); string fullyQualifiedClassName = field.Specification.FullName; // XML NofMetaModel.SetAttributesForReference(xmlReferenceElement, Schema.Prefix, fullyQualifiedClassName); if (referencedNakedObject != null) { NofMetaModel.AppendNofTitle(xmlReferenceElement, referencedNakedObject.TitleString()); } else { NofMetaModel.SetIsEmptyAttribute(xmlReferenceElement, true); } } catch (Exception) { Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": getAssociation() threw exception - skipping XML generation"); } // XSD xsdFieldElement = Schema.CreateXsElementForNofReference(xsElement, xmlReferenceElement, oneToOneAssociation.Specification.FullName); } else if (field is IOneToManyAssociation) { Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is IOneToManyAssociation"); var oneToManyAssociation = (IOneToManyAssociation) field; XElement xmlCollectionElement = xmlFieldElement; // more meaningful locally scoped name try { INakedObject collection = oneToManyAssociation.GetNakedObject(nakedObject); ITypeOfFacet facet = collection.GetTypeOfFacetFromSpec(); INakedObjectSpecification referencedTypeNos = facet.ValueSpec; string fullyQualifiedClassName = referencedTypeNos.FullName; // XML NofMetaModel.SetNofCollection(xmlCollectionElement, Schema.Prefix, fullyQualifiedClassName, collection); } catch (Exception) { Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": get(obj) threw exception - skipping XML generation"); } // XSD xsdFieldElement = Schema.CreateXsElementForNofCollection(xsElement, xmlCollectionElement, oneToManyAssociation.Specification.FullName); } else { Log.Info("objectToElement(NO): " + DoLog("field", fieldName) + " is unknown type; ignored"); continue; } if (xsdFieldElement != null) { xmlFieldElement.AddAnnotation(xsdFieldElement); } // XML Log.Debug("objectToElement(NO): invoking mergeTree for field"); MergeTree(element, xmlFieldElement); // XSD if (xsdFieldElement != null) { Log.Debug("objectToElement(NO): adding XS element for field to schema"); Schema.AddFieldXsElement(xsElement, xsdFieldElement); } } return place; }
private static string DoLog(string label, INakedObject nakedObject) { return(DoLog(label, (nakedObject == null ? "(null)" : nakedObject.TitleString() + "[" + OidOrHashCode(nakedObject) + "]"))); }
public static void CheckCanAssociate(this IResolveStateMachine stateMachine, INakedObject associate) { if (stateMachine.IsPersistent() && associate != null && associate.ResolveState.IsTransient()) { throw new TransientReferenceException(string.Format(Resources.NakedObjects.TransientErrorMessage, associate.TitleString())); } }
public static string GetServiceLabel(INakedObject nakedObject) { return(nakedObject.TitleString()); }
private static string GetValueForChoice(INakedObject choice) { var enumFacet = choice.Specification.GetFacet<IEnumValueFacet>(); if (enumFacet != null) { return enumFacet.IntegralValue(choice); } if (choice.Specification.IsParseable) { return choice.TitleString(); } return FrameworkHelper.GetObjectId(choice); }