/// <summary>
        /// Creates a new instance of <see cref="SqlParameter"/> and initializes its properties.
        /// </summary>
        /// <param name="source">
        /// The source object.
        /// </param>
        /// <returns>
        /// The <see cref="SqlParameter"/>.
        /// </returns>
        public SqlParameter CreateParameter(IDynamicObject source)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            int? stateId;

            var infoClass = source as IInfoClass;
            if (infoClass != null)
            {
                var property = infoClass.GetPropertyByName(Constants.CurrentStateIdColumnName);
                if (property == null)
                    throw new ArgumentException(@"Info class is not supported.", "source");

                stateId = (int?)infoClass.GetValueByPropertyName(property.Name);
                if (stateId == 0)
                    stateId = null;
            }
            else
            {
                stateId = (int?)source.GetValueByPropertyName(Constants.CurrentStateColumnName);
            }

            return new SqlParameter(ParameterName, SqlDbType.Int) { Value = (object)stateId ?? DBNull.Value };
        }
        /// <summary>
        /// Creates a new instance of <see cref="SqlParameter"/> and initializes its properties.
        /// </summary>
        /// <param name="source">
        /// The source object.
        /// </param>
        /// <returns>
        /// The <see cref="SqlParameter"/>.
        /// </returns>
        public SqlParameter CreateParameter(IDynamicObject source)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            int? itemId;

            var infoClass = source as IInfoClass;
            if (infoClass != null)
            {
                var property = infoClass.GetPropertyByName(_fieldName + "Id");
                if (property == null)
                    throw new ArgumentException(@"Info class is not supported.", "source");

                itemId = (int?)infoClass.GetValueByPropertyName(property.Name);
                if (itemId == 0)
                    itemId = null;
            }
            else
            {
                itemId = (int?)source.GetValueByPropertyName(_fieldName);
            }

            return new SqlParameter(_parameterName, SqlDbType.Int) { Value = (object)itemId ?? DBNull.Value };
        }
예제 #3
0
        /// <summary>
        /// Gets the collection of items referenced by this field.
        /// </summary>
        /// <param name="item">
        /// The source item.
        /// </param>
        /// <returns>
        /// The collection of items.
        /// </returns>
        public IEnumerable<IDynamicObject> GetItems(IDynamicObject item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            var sampleList = (ISampleList)item.GetValueByPropertyName(Property.Name);

            return sampleList != null ? sampleList.Cast<IDynamicObject>() : Enumerable.Empty<IDynamicObject>();
        }
        /// <summary>
        /// Creates a new instance of <see cref="SqlParameter"/> and initializes its properties.
        /// </summary>
        /// <param name="source">
        /// The source object.
        /// </param>
        /// <returns>
        /// The <see cref="SqlParameter"/>.
        /// </returns>
        public SqlParameter CreateParameter(IDynamicObject source)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            if (!(source is IEditableRoot))
                throw new ArgumentException(
                    string.Format(CultureInfo.InvariantCulture, "Editable root source expected. Actual type: {0}.", source.GetType().AssemblyQualifiedName),
                    "source");

            var crList = (IList)source.GetValueByPropertyName(_fieldName);
            var idList = crList != null ? crList.OfType<IDynamicObject>().Select(x => x.Id) : Enumerable.Empty<int>();

            return new SqlParameter(_parameterName, SqlDbType.Xml) { Value = ConvertToXml(idList) };
        }
예제 #5
0
        private static object GetFieldValue(IDynamicObject source, string fieldName)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            var property = source.GetPropertyByName(fieldName);
            if (property == null)
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Could not find the property '{0}' in type '{1}'.",
                        fieldName,
                        source.GetType().AssemblyQualifiedName),
                    "fieldName");

            return source.GetValueByPropertyName(fieldName);
        }
예제 #6
0
        private static string GetRichTextFieldValue(IDynamicObject item, PropertyInfo prop, bool isHtml)
        {
            var richText = item.GetValueByPropertyName(prop.Name);
            var converter = new HtmlToText();
            var plainText = converter.ConvertHtml(richText);

            return Encode(plainText, isHtml);
        }
예제 #7
0
        /// <summary>
        /// Gets the numeric field value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="property">The property.</param>
        /// <param name="formatAttribute">The format attribute.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private static string GetNumericFieldValue(IDynamicObject item, PropertyInfo property, NumericAttribute formatAttribute, bool isHtml)
        {
            var value = (decimal?)item.GetValueByPropertyName(property.Name);

            if (value == null)
                return string.Empty;

            switch (formatAttribute.NumericType)
            {
                case NumericTypes.Currency:
                    return Encode(string.Format(CultureInfo.InvariantCulture, "${0}", value), isHtml);

                case NumericTypes.Percentage:
                    return Encode(string.Format(CultureInfo.InvariantCulture, "{0}%", value), isHtml);

                default:
                    return Encode(Convert.ToString(value, CultureInfo.InvariantCulture), isHtml);
            }
        }
예제 #8
0
        /// <summary>
        /// Gets the generic field value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="property">The property.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private string GetGenericFieldValue(IDynamicObject item, PropertyInfo property, bool isHtml)
        {
            var value = item.GetValueByPropertyName(property.Name);

            return Encode(value == null ? "<not defined>" : string.Format(CultureInfo.InvariantCulture, "{0}", value), isHtml);
        }
예제 #9
0
        private string GetFileValue(IDynamicObject item, PropertyInfo property, bool isHtml)
        {
            var fileUrl = string.Empty;
            string displayName;

            if (item is IEditableRoot)
            {
                var file = item.GetValueByPropertyName(property.Name) as IFileProcess;
                if (file == null)
                    return string.Empty;

                var fileName = file.FileName;
                if (!string.IsNullOrEmpty(fileName))
                    fileUrl = FileHelper.GetFullNavigateUrl(fileName);

                displayName = file.OriginalFileName;
                if (string.IsNullOrEmpty(displayName))
                    displayName = fileName;
            }
            else
            {
                displayName = item.GetValueByPropertyName(property.Name);
                fileUrl = item.GetValueByPropertyName(property.Name + Constants.Url);
            }

            if (string.IsNullOrEmpty(fileUrl))
            {
                return string.Empty;
            }

            if (isHtml)
            {
                return !string.IsNullOrEmpty(fileUrl)
                           ? string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" target=\"_blank\">{1}</a>", fileUrl, HtmlEncode(displayName))
                           : HtmlEncode(displayName);
            }

            return displayName;
        }
예제 #10
0
        /// <summary>
        /// Gets the collection of items referenced by this field.
        /// </summary>
        /// <param name="item">
        /// The source item.
        /// </param>
        /// <returns>
        /// The collection of items.
        /// </returns>
        public IEnumerable<IDynamicObject> GetItems(IDynamicObject item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            var checklist = (ChecklistEdit)item.GetValueByPropertyName(Property.Name);

            if (checklist == null || checklist.AnswerProcessList == null)
                return Enumerable.Empty<IDynamicObject>();

            return checklist.AnswerProcessList.Cast<IDynamicObject>();
        }
예제 #11
0
        /// <summary>
        /// Gets the multi cross reference value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="prop">The property.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private static string GetMultiCrossRefValue(IDynamicObject item, PropertyInfo prop, bool isHtml)
        {
            if (item is IEditableRoot)
            {
                var crList = item.GetValueByPropertyName(prop.Name) as IEnumerable;

                if (crList == null)
                    return string.Empty;

                var crValues = crList.OfType<ICrossRefItemInfo>().Select(crItem => crItem.ToString()).ToList();

                return Encode(string.Join(", ", crValues), isHtml);
            }

            return Encode(item.GetValueByPropertyName(prop.Name), isHtml);
        }
예제 #12
0
        /// <summary>
        /// Gets the multi reverse cross reference value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="prop">The property.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private static string GetMultiReverseCrossRefValue(IDynamicObject item, PropertyInfo prop, bool isHtml)
        {
            if (item is IEditableRoot)
            {
                var rcrList = item.GetValueByPropertyName(prop.Name) as IEnumerable;

                if (rcrList == null)
                    return string.Empty;

                var itemValues = rcrList.OfType<IReverseCrossReferenceItem>().Select(x => x.ToString());

                return Encode(string.Join(", ", itemValues), isHtml);
            }

            return Encode(item.GetValueByPropertyName(prop.Name), isHtml);
        }
        private IEnumerable<IDynamicObject> GetSingleCrossReferenceItems(IDynamicObject item)
        {
            var crId = (int?)item.GetValueByPropertyName(Property.Name);

            if (!crId.HasValue)
                return Enumerable.Empty<IDynamicObject>();

            var criteria = new DetailCriteria(crId.Value) { AllowLazyLoading = true };
            var crItem = DynamicTypeManager.GetEditableRoot<IEditableRoot>(ElementProcessName, criteria);

            if (crItem == null || crItem.Id <= 0)
                return Enumerable.Empty<IDynamicObject>();

            return Enumerable.Repeat(crItem, 1);
        }
예제 #14
0
        private static IDynamicObject GetReferencedItem(IDynamicObject item, string propertyName)
        {
            var property = item.GetPropertyByName(propertyName);
            if (property == null)
                return null;

            var crAttribute = property.GetCustomAttribute<CrossRefFieldAttribute>();
            if (crAttribute != null && !crAttribute.AllowMultiple)
            {
                return item.GetValueByPropertyName(propertyName + "Member");
            }

            return item.GetValueByPropertyName(propertyName) as IDynamicObject;
        }
예제 #15
0
        private object GetPropertyValue(IDynamicObject item, string path)
        {
            if (item == null)
                return null;

            if (string.IsNullOrEmpty(path))
                return item;

            var propertyName = path;
            var suffix = string.Empty;
            var index = path.IndexOf('.');

            if (index > 0)
            {
                propertyName = path.Substring(0, index);
                suffix = path.Substring(index + 1, path.Length - index - 1);
            }

            if (string.IsNullOrEmpty(suffix))
                return item.GetValueByPropertyName(propertyName);

            var value = GetReferencedItem(item, propertyName);

            return value == null ? null : GetPropertyValue(value, suffix);
        }
예제 #16
0
        /// <summary>
        /// Gets the date time field value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="property">The property.</param>
        /// <param name="formatAttribute">The format attribute.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private static string GetDateTimeFieldValue(IDynamicObject item, PropertyInfo property, DateTimeFormatAttribute formatAttribute, bool isHtml)
        {
            var value = (DateTime?)item.GetValueByPropertyName(property.Name);

            if (value == null)
                return string.Empty;

            var dtFormat = (DateTimeFormat)Enum.Parse(typeof(DateTimeFormat), formatAttribute.Value, true);

            switch (dtFormat)
            {
                case DateTimeFormat.Date:
                    return Encode(value.Value.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, CultureInfo.InvariantCulture), isHtml);

                case DateTimeFormat.Time:
                    return Encode(value.Value.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern, CultureInfo.InvariantCulture), isHtml);

                default:
                    return
                        Encode(
                            value.Value.ToString(
                                CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern, CultureInfo.InvariantCulture),
                            isHtml);
            }
        }
예제 #17
0
        /// <summary>
        /// Gets the reverse single cross reference value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="prop">The property.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private static string GetReverseSingleCrossRefValue(IDynamicObject item, PropertyInfo prop, bool isHtml)
        {
            if (item is IEditableRoot)
            {
                var rcrItem = item.GetValueByPropertyName(prop.Name);

                if (rcrItem == null)
                    return string.Empty;

                return Encode(rcrItem.ToString(), isHtml);
            }

            var value = item.GetValueByPropertyName(prop.Name);
            return value != null ? Encode(value.ToString(), isHtml) : string.Empty;
        }
        private IEnumerable<IDynamicObject> GetSingleReverseCrossReferenceItems(IDynamicObject item)
        {
            var rcrItem = (IReverseCrossReferenceItem)item.GetValueByPropertyName(Property.Name);

            if (rcrItem == null)
                return Enumerable.Empty<IDynamicObject>();

            var criteria = new DetailCriteria(rcrItem.Id) { AllowLazyLoading = true };
            var editableRoot = DynamicTypeManager.GetEditableRoot<IEditableRoot>(ElementProcessName, criteria);

            if (editableRoot == null || editableRoot.Id <= 0)
                return Enumerable.Empty<IDynamicObject>();

            return Enumerable.Repeat(editableRoot, 1);
        }
예제 #19
0
        /// <summary>
        /// Gets the single cross reference value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="prop">The property.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private string GetSingleCrossRefValue(IDynamicObject item, PropertyInfo prop, bool isHtml)
        {
            var editableRoot = item as IEditableRoot;
            if (editableRoot != null)
            {
                var crId = editableRoot.GetValueByPropertyName(prop.Name) as int?;

                if (!crId.HasValue)
                    return string.Empty;

                var ancestor = editableRoot.GetAncestor(prop);

                if (ancestor == null)
                    return string.Empty;

                var crItem = DynamicTypeManager.GetCrossReferenceItem(ancestor.ProcessName, prop.Name, crId.Value);

                if (crItem == null)
                    return string.Empty;

                return Encode(crItem.ToString(), isHtml);
            }

            var value = item.GetValueByPropertyName(prop.Name);
            return value != null ? Encode(value.ToString(), isHtml) : string.Empty;
        }
        private IEnumerable<IDynamicObject> GetMultiReverseCrossReferenceItems(IDynamicObject item)
        {
            var rcrItems = (ICollection)item.GetValueByPropertyName(Property.Name);

            if (rcrItems == null)
                return Enumerable.Empty<IDynamicObject>();

            var result = new List<IDynamicObject>();

            foreach (IReverseCrossReferenceItem rcrItem in rcrItems)
            {
                var criteria = new DetailCriteria(rcrItem.Id) { AllowLazyLoading = true };
                var editableItem = DynamicTypeManager.GetEditableRoot<IEditableRoot>(ElementProcessName, criteria);

                if (editableItem != null && editableItem.Id > 0)
                    result.Add(editableItem);
            }

            return result;
        }
예제 #21
0
        /// <summary>
        /// Gets the due date.
        /// </summary>
        /// <param name="actionDefinition">The action definition.</param>
        /// <param name="item">The item.</param>
        /// <returns>DateTime.</returns>
        public DateTime GetDueDate(IActionDefinition actionDefinition, IDynamicObject item)
        {
            var actionDef = actionDefinition as IAssignmentActionDefinition;

            if (actionDef == null)
            {
                return DateTime.MinValue;
            }

            if (item == null)
            {
                return DateTime.MinValue;
            }

            if (string.IsNullOrEmpty(actionDef.DueDateFieldName))
            {
                return DateTime.MinValue;
            }

            var date = item.GetValueByPropertyName(actionDef.DueDateFieldName) as DateTime?;
            return date ?? DateTime.MinValue;
        }
예제 #22
0
        /// <summary>
        /// Gets the paperclips.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        private static string GetPaperclips(IDynamicObject item, bool isHtml)
        {
            var hasPaperclips = item as IHasPaperclips;

            if (hasPaperclips == null)
            {
                var value = (string)item.GetValueByPropertyName(Constants.PaperclipsColumnName) ?? string.Empty;

                return isHtml ? HtmlEncode(value) : value;
            }

            var result = new StringBuilder();

            foreach (var paperclip in hasPaperclips.Paperclips.OfType<IPaperclip>())
            {
                if (result.Length > 0)
                    result.Append(", ");

                if (isHtml)
                {
                    result.AppendFormat(CultureInfo.InvariantCulture, "<a href=\"{0}\" target=\"_blank\">{1}</a>", paperclip.CurrentURI, HtmlEncode(paperclip.Name));
                }
                else
                {
                    result.Append(paperclip.Name);
                }
            }

            return result.ToString();
        }