public static XElement GetDocument(DataReference<IMediaFile> mediaFile, IDataReference apiKey) { var media = mediaFile.Data; using (new IssuuApi(apiKey.Data)) { lock (_lock) { var document = IssuuPlayerFacade.GetDocument(media); if (document == null) { document = IssuuPlayerFacade.UploadDocument(media); } else { var publishDateAttribute = document.AttributeValue("publishDate"); DateTime publishDate = DateTime.Now; DateTime.TryParse(publishDateAttribute, out publishDate); if (publishDate < media.LastWriteTime) { IssuuPlayerFacade.DeleteDocument(media); document = IssuuPlayerFacade.UploadDocument(media); } } return document; } } }
public PageUrlData GetPageUrlData(IDataReference instance) { if (!instance.IsSet || instance.ReferencedType != typeof (Entries)) { return null; } var entry = instance.Data as Entries; if (entry == null || entry.PageId == Guid.Empty) { return null; } using (new DataScope(entry.DataSourceId.LocaleScope)) { var page = PageManager.GetPageById(entry.PageId); if (page == null) { return null; } return new PageUrlData(page) { PathInfo = BlogFacade.GetBlogPath(entry) }; } }
public string BuildInternalUrl(IDataReference reference) { Verify.That(reference.ReferencedType == _type, "Incorrect type of referenced data"); string serializedKey = ValueTypeConverter.Convert<string>(reference.KeyValue); if (string.IsNullOrEmpty(serializedKey)) { return null; } return "~/{0}({1})".FormatWith(_shortTypeName, serializedKey); }
/// <exclude /> public static XhtmlDocument Render(IDataReference dataToRender, XhtmlRenderingType renderingType) { Type dataTypeToRender = dataToRender.ReferencedType; IEnumerable<XhtmlRendererProviderAttribute> rendererAttributes = dataTypeToRender.GetCustomInterfaceAttributes<XhtmlRendererProviderAttribute>(); XhtmlRendererProviderAttribute rendererAttribute = rendererAttributes.FirstOrDefault(f => f.SupportedRenderingType == renderingType); if (rendererAttribute == null) throw new NotImplementedException(string.Format("No '{0}' xhtml renderer found for type '{1}'",renderingType, dataTypeToRender.FullName)); IDataXhtmlRenderer renderer = rendererAttribute.BuildRenderer(); return renderer.Render(dataToRender); }
public PageUrlData GetPageUrlData(IDataReference dataReference) { if (dataReference.ReferencedType != typeof(NewsItem)) { return null; } var data = dataReference.Data; var newsItem = data as NewsItem; if (newsItem == null) return null; var page = PageManager.GetPageById(newsItem.PageId); if (page == null) return null; var newsPathInfo = NewsFacade.GetPathInfo(newsItem.TitleUrl, newsItem.Date); return new PageUrlData(page) { PathInfo = newsPathInfo }; }
private string GetUrlPart(IDataReference reference) { object labelValue = _isKeyField ? reference.KeyValue : _propertyInfo.GetValue(reference.Data); if (labelValue == null) { return null; } var label = ValueTypeConverter.Convert<string>(labelValue); return string.IsNullOrEmpty(label) ? null : LabelToUrlPart(label); }
public PageUrlData GetPageUrlData(IDataReference reference) { if(reference == null || !reference.IsSet) return null; Verify.That(reference.ReferencedType == _dataType, "Unexpected type of data reference"); Guid pageId; if (_pageId.HasValue) { pageId = _pageId.Value; } else { if (!typeof (IPageRelatedData).IsAssignableFrom(reference.ReferencedType)) { // Cannot resolve a url for a global data type without a global url mapper return null; } IData data = reference.Data; if(data == null) return null; pageId = (data as IPageRelatedData).PageId; } string pathInfo = _actionName != null ? "/" + _actionName : string.Empty; if (_isKeyField) { pathInfo += "/" + ValueTypeConverter.Convert<string>(reference.KeyValue); } else { string urlPart = GetUrlPart(reference); if(urlPart == null) return null; pathInfo += "/" + urlPart; } return new PageUrlData(pageId, DataScopeManager.CurrentDataScope.ToPublicationScope(), LocalizationScopeManager.CurrentLocalizationScope) { PathInfo = pathInfo }; }
public object done() { object result_ = null; try { switch (_type) { case ConstObjectNamePrefix.prefAdapter: //IAdapterObject adp_ = _environment.getFactoryAdapter().get(_cmd, _environment); //IAdapterObjectExecuteResult res_ = adp_.execute(_cmd, null, false); //if (res_ != null) //{ // try // { // res_.done(false); // result_ = res_.getExecResult(); // } // catch (Exception exc) // { // res_.failed(); // throw exc; // } //} var _editor = _environment.getAdapter(_cmd); if (_editor != null) { _editor.adapter.add(); _editor.edit(); } break; case ConstObjectNamePrefix.prefReference: //if (_ref == null) //{ // _ref = _environment.getFactoryReference().get(_cmd, _environment); // if (_ref != null) // _ref.getFlagStore().flagDisable(ReferenceFlags.dialog); //} //if (_ref != null) // _ref.begin(); if (_ref == null) { _ref = _environment.getReference(_cmd); } if (_ref != null) { _ref.begin(null, null, true, (_args != null && _args.Length > 0 ? _args[0] : null) as EventHandler); } break; case ConstObjectNamePrefix.prefReport: { try { FilterInfo[] filters_ = _args != null && _args.Length > 0 ? _args[0] as FilterInfo[] : null; string _location = ToolObjectName.getArgValue(_cmd, ConstCmdLine.loc); IReportSource repSource = new ImplReportSource(_environment, _location); if (filters_ != null) { foreach (FilterInfo f in filters_) { IFilter filter = new ImplFilter(_environment, repSource, f); repSource.addFilter(filter); } } repSource.getReports()[0].setDataSource(repSource.get()); IReportRender render = _environment.gerReportRender(); render.setReport(repSource.getReports()[0]); render.done(); } catch (Exception exc) { _environment.getExceptionHandler().setException(exc); } } break; case ConstObjectNamePrefix.prefReportServer: { var act = new ToolReportServer(_environment, _cmd); act.done(); } break; case ConstObjectNamePrefix.prefTool: { try { } catch (Exception exc) { _environment.getExceptionHandler().setException(exc); } } break; } } catch (Exception exc) { _environment.getExceptionHandler().setException(exc); } return(result_); }
public XhtmlDocument Render(IDataReference dataReferenceToRender) { if (!dataReferenceToRender.IsSet) { return(new XhtmlDocument()); } IData dataToRender; if (dataReferenceToRender.ReferencedType == typeof(IPage)) { dataToRender = DataFacade.TryGetDataByUniqueKey <IPage>(dataReferenceToRender.KeyValue); if (dataToRender == null) { return(new XhtmlDocument()); } } else { dataToRender = dataReferenceToRender.Data; } string markup = _templateString; string labelEncoded = ""; string keyValue = ""; if (_labelHasToBeEvaluated) { labelEncoded = HttpUtility.HtmlEncode(dataToRender.GetLabel()); } if (_idHasToBeEvaluated) { keyValue = dataReferenceToRender.KeyValue.ToString(); } var parameters = new object[2 + _fieldNames.Count]; parameters[0] = labelEncoded; parameters[1] = keyValue; // Getting field values for (int i = 0; i < _fieldNames.Count; i++) { Type referenceType = dataReferenceToRender.ReferencedType; var propertiesMap = _reflectionCache.EnsureValue(referenceType, () => new Hashtable <string, PropertyInfo>()); string fieldName = _fieldNames[i]; PropertyInfo propertyInfo; if (!propertiesMap.TryGetValue(fieldName, out propertyInfo)) { lock (propertiesMap) { if (!propertiesMap.TryGetValue(fieldName, out propertyInfo)) { Type type = referenceType; while (type != null && type != typeof(object)) { propertyInfo = type.GetProperty(fieldName); if (propertyInfo != null) { propertiesMap.Add(fieldName, propertyInfo); break; } if (type.GetInterfaces().Length > 0) { type = type.GetInterfaces()[0]; } } if (propertyInfo == null) { LoggingService.LogWarning(LogTitle, "Failed to find property '{0}' on type '{1}'" .FormatWith(fieldName, referenceType.FullName)); propertiesMap.Add(fieldName, null); } } } } string value = String.Empty; if (propertyInfo != null) { value = (propertyInfo.GetValue(dataToRender, new object[0]) ?? String.Empty).ToString(); } switch (_renderingEncoding) { case XhtmlRenderingEncoding.None: break; case XhtmlRenderingEncoding.AttributeContent: value = HttpUtility.HtmlAttributeEncode(value); break; case XhtmlRenderingEncoding.TextContent: value = HttpUtility.HtmlEncode(value); break; default: throw new NotImplementedException("Unexpected XhtmlRenderingEncoding value"); } parameters[2 + i] = value; } string evaluatedMarkup = string.Format(markup, parameters); XElement bodyMarkup = XElement.Parse(evaluatedMarkup); XhtmlDocument xhtmlDocument = new XhtmlDocument(); xhtmlDocument.Body.Add(bodyMarkup.Nodes()); return(xhtmlDocument); }
public XhtmlDocument Render(IDataReference dataReferenceToRender) { if (!dataReferenceToRender.IsSet) { return new XhtmlDocument(); } IData dataToRender; if (dataReferenceToRender.ReferencedType == typeof(IPage)) { dataToRender = DataFacade.TryGetDataByUniqueKey<IPage>(dataReferenceToRender.KeyValue); if (dataToRender == null) { return new XhtmlDocument(); } } else { dataToRender = dataReferenceToRender.Data; } string markup = _templateString; string labelEncoded = ""; string keyValue = ""; if (_labelHasToBeEvaluated) { labelEncoded = HttpUtility.HtmlEncode(dataToRender.GetLabel()); } if (_idHasToBeEvaluated) { keyValue = dataReferenceToRender.KeyValue.ToString(); } var parameters = new object[2 + _fieldNames.Count]; parameters[0] = labelEncoded; parameters[1] = keyValue; // Getting field values for (int i = 0; i < _fieldNames.Count; i++) { Type referenceType = dataReferenceToRender.ReferencedType; var propertiesMap = _reflectionCache.EnsureValue(referenceType, () => new Hashtable<string, PropertyInfo>()); string fieldName = _fieldNames[i]; PropertyInfo propertyInfo; if (!propertiesMap.TryGetValue(fieldName, out propertyInfo)) { lock (propertiesMap) { if (!propertiesMap.TryGetValue(fieldName, out propertyInfo)) { Type type = referenceType; while (type != null && type != typeof(object)) { propertyInfo = type.GetProperty(fieldName); if (propertyInfo != null) { propertiesMap.Add(fieldName, propertyInfo); break; } if (type.GetInterfaces().Length > 0) { type = type.GetInterfaces()[0]; } } if (propertyInfo == null) { LoggingService.LogWarning(LogTitle, "Failed to find property '{0}' on type '{1}'" .FormatWith(fieldName, referenceType.FullName)); propertiesMap.Add(fieldName, null); } } } } string value = String.Empty; if (propertyInfo != null) { value = (propertyInfo.GetValue(dataToRender, new object[0]) ?? String.Empty).ToString(); } switch (_renderingEncoding) { case XhtmlRenderingEncoding.None: break; case XhtmlRenderingEncoding.AttributeContent: value = HttpUtility.HtmlAttributeEncode(value); break; case XhtmlRenderingEncoding.TextContent: value = HttpUtility.HtmlEncode(value); break; default: throw new NotImplementedException("Unexpected XhtmlRenderingEncoding value"); } parameters[2 + i] = value; } string evaluatedMarkup = string.Format(markup, parameters); XElement bodyMarkup = XElement.Parse(evaluatedMarkup); XhtmlDocument xhtmlDocument = new XhtmlDocument(); xhtmlDocument.Body.Add(bodyMarkup.Nodes()); return xhtmlDocument; }
public PageUrlData GetPageUrlData(IDataReference instance) { var data = instance.Data; return(data != null?_mapper.BuildItemUrl(data) : null); }
/** * Resolves a binding to a particular question data element * * @param binding * The binding representing a particular question * @return A QuestionDataElement corresponding to the binding provided. Null * if none exists in this tree. */ public TreeElement resolveReference(IDataReference binding) { return(resolveReference(unpackReference(binding))); }
public TreeReference unpackReference2(IDataReference ref_) { return((TreeReference)ref_.Reference); }