Example #1
0
        /// <summary>
        /// The create.
        /// </summary>
        /// <returns>
        /// The <see cref="ResultFieldOptions"/>.
        /// </returns>
        public static SampleFieldOptions Create(PropertyInfo property, IEditableRoot model)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var result = new SampleFieldOptions();

            var settingsString = model.GetValueByPropertyName(string.Format(CultureInfo.InvariantCulture, "{0}{1}", property.Name, Constants.SampleSettingPostfix));
            if (!string.IsNullOrEmpty(settingsString))
            {
                var sampleSettings = XElement.Parse(settingsString);
                SetProperties(result, sampleSettings, model);
            }

            result.IsNewItem = model.Id == 0;

            return result;
        }
Example #2
0
        /// <summary>
        /// The create.
        /// </summary>
        /// <returns>
        /// The <see cref="ResultFieldOptions"/>.
        /// </returns>
        public static ResultFieldOptions Create(PropertyInfo property, IEditableRoot model)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var result = new ResultFieldOptions();

            result.ChoiceList = new ChoiceModel[0];

            var listProperty = model.GetType().GetProperty(string.Format(CultureInfo.InvariantCulture, "{0}{1}", property.Name, Constants.ResultListPostfix));
            if (listProperty != null)
            {
                var listValue = listProperty.GetValue(model, null);
                if (listValue != null)
                {
                    result.ChoiceList = ((IEnumerable<ChoiceInfo>)listValue).Select(i => new ChoiceModel(i));
                }
                else
                {
                    result.IsEditable = true;
                }
            }
            
            return result;
        }
        public static IFieldOptions Create(PropertyInfo property, IEditableRoot obj)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var crossRefAttr = property.GetCustomAttributes(typeof(CrossRefFieldAttribute), false).Select(d => d).FirstOrDefault() as CrossRefFieldAttribute;
            if (crossRefAttr == null)
            {
                throw new VeyronException("CrossRef attribute not found on Cross-reference field property");
            }

            var result = new MultiCrossRefFieldOptions { ProcessSystemName = crossRefAttr.ReferenceTableName, FieldName = crossRefAttr.RefFieldName };

            result.LinkVisibility = crossRefAttr.MultiCrAllowLinkUnlink && string.IsNullOrEmpty(crossRefAttr.LinkFieldSystemName);
            result.UnlinkVisibility = crossRefAttr.MultiCrAllowLinkUnlink;
            result.AddNewVisibility = crossRefAttr.MultiCrAllowAddNew;
            result.LinkFieldSystemName = crossRefAttr.LinkFieldSystemName;

            var recentVersionAttr = (from d in property.GetCustomAttributes(typeof(RecentVersionAttribute), true) select d).FirstOrDefault();
            if (recentVersionAttr != null)
            {
                result.AllowRecentVersion = true;
            }

            var deepCopyAttr = (from d in property.GetCustomAttributes(typeof(DeepCopyAttribute), true) select d).FirstOrDefault();
            if (deepCopyAttr != null)
            {
                result.AllowDeepCopy = true;
            }

            return result;
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldVisibilityRule"/> class.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="actionRule">The action rule.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="sourceFields">The source fields.</param>
        public FieldVisibilityRule(IEditableRoot item, IActionRule actionRule, string fieldName, IEnumerable<string> sourceFields)
        {
            Item = item;
            Rule = actionRule;
            FieldName = fieldName;

            if (sourceFields != null)
            {
                _sourceFields = new HashSet<string>(sourceFields);
            }

            if (_sourceFields != null && _sourceFields.Count > 0)
            {
                if (Item != null)
                {
                    Item.PropertyChanged += OnItemPropertyChanged;
                }

                var notifyChildChanged = Item as INotifyChildChanged;

                if (notifyChildChanged != null)
                {
                    notifyChildChanged.ChildChanged += OnItemChildChanged;
                }
            }
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="property">
        /// The property.
        /// </param>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <returns>
        /// The <see cref="ChecklistFieldOptions"/>.
        /// </returns>
        public static ChecklistFieldOptions Create(PropertyInfo property, IEditableRoot model)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var result = new ChecklistFieldOptions();
            Ioc.SatisfyImportsOnce(result);

            var value = property.GetValue(model) as ChecklistEdit;

            if (value == null)
            {
                result.NeedSaving = true;
                return result;
            }

            result.AllowAdhocQuestions = value.AllowAdhocQuestions;
            result.AnswerProcessSystemName = value.AnswerProcessSystemName;
            result.ListDisplayFieldSystemName = value.ListDisplayFieldSystemName;
            result.CanChangeItemState = value.CanChangeItemState;
            if (!string.IsNullOrEmpty(value.HiddenAnswersId))
            {
                result.HiddenAnswersId = value.HiddenAnswersId.Split(',').Select(SafeTypeConverter.Convert<int>).ToArray();
            }

            if (!string.IsNullOrEmpty(value.AnswerProcessSystemName))
            {
                var editableRootType = result.DynamicTypeManager.GetEditableRootType(value.AnswerProcessSystemName);
                result.CanAddItem = Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.CreateObject, editableRootType);
                result.CanDeleteItem = Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.DeleteObject, editableRootType) && model.CanWritePropertyByName(property.Name);

                if (value.AnswerProcessList != null && value.AnswerProcessList.Count > 0)
                {
                    result.AnswerProcessFields = result.GetFields((IEditableRoot)value.AnswerProcessList[0]);
                }
                else
                {
                    result.AnswerProcessFields = result.GetFields((IEditableRoot)DataPortal.Create(editableRootType, null));
                }

                var displayFieldAttributes = (ChecklistDisplayFieldAttribute[])property.GetCustomAttributes(typeof(ChecklistDisplayFieldAttribute), false);

                foreach (var displayFieldAttribute in displayFieldAttributes)
                {
                    result.AnswerDisplayFields.Add(
                        new FieldSettingsOverride
                        {
                            FieldName = displayFieldAttribute.SystemName,
                            Position = displayFieldAttribute.Sequence,
                            Width = displayFieldAttribute.Width,
                            RowSpan = displayFieldAttribute.NumberOfRows
                        });
                }
            }

            return result;
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <returns>
        /// The <see cref="SamplingTechniqueFieldOptions"/>.
        /// </returns>
        public static SamplingTechniqueFieldOptions Create(PropertyInfo property, IEditableRoot model)
        {
            var result = new SamplingTechniqueFieldOptions();

            var list = (from SampleSizeTypes sampleType in Enum.GetValues(typeof(SampleSizeTypes)) select new { Text = GetDescriptionFromEnumValue(sampleType), Value = sampleType.ToString() }).ToList();
            result.PossibleValues = list;
            
            return result;
        }
Example #7
0
        private static DetailsCommandResult CreateDetailsResult(IEditableRoot editableRoot)
        {
            var result = new DetailsCommandResult { Id = editableRoot.Id, DisplayName = editableRoot.ProcessDisplayName, IsTabbedUI = IsTabbedUI(editableRoot) };
            var visibleFields = new HashSet<string>(editableRoot.Sections.SelectMany(s => s.Fields).Where(f => !f.IsHidden).Select(f => f.SystemName));
            var validationContext = editableRoot.GetValidationContext();

            foreach (var sect in editableRoot.Sections)
            {
                var section = new SectionInfo { Name = sect.Name };
                var row = new RowInfo();
                var rowLength = 0d;

                foreach (var field in sect.Fields)
                {
                    var prop = editableRoot.GetPropertyByName(field.SystemName);
                    if (!visibleFields.Contains(prop.Name))
                    {
                        continue;
                    }

                    var fieldInfo = FieldInfoFactory.Create(prop, editableRoot, field, GetValue(prop, editableRoot), validationContext);
                    if (rowLength + fieldInfo.Width > 100)
                    {
                        if (row.Fields.Any())
                            section.Rows.Add(row);
                        row = new RowInfo();
                        rowLength = fieldInfo.Width >= 100 ? 100 : fieldInfo.Width;
                    }
                    else
                        rowLength += fieldInfo.Width;

                    row.Fields.Add(fieldInfo);
                }

                if (row.Fields.Any())
                    section.Rows.Add(row);

                if (section.Rows.Any())
                    result.Sections.Add(section);
            }


            result.States = new List<IStateInfo>();
            var supportStates = editableRoot as ISupportStates;
            if (supportStates != null)
            {
                foreach (var s in supportStates.StateManager.States)
                {
                    result.States.Add(new StateInfo(s.Name, s.Guid));
                }
            }

            result.CurrentStateGuid = editableRoot.GetCurrentStateGuid();

            return result;
        }
        /// <summary>
        /// Gets the sample type field value.
        /// </summary>
        /// <param name="field">
        /// The field.
        /// </param>
        /// <param name="editableRoot">
        /// The editable root.
        /// </param>
        /// <returns>
        /// The value.
        /// </returns>
        public object GetValue(DetailsSaveFieldModel field, IEditableRoot editableRoot)
        {
            var jObject = field.Value as JObject;
            if (jObject != null)
            {
                return jObject.ToObject<SampleTypeModel>();
            }

            return field.Value;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EditableRootDataContext"/> class.
        /// </summary>
        /// <param name="item">
        /// The source item.
        /// </param>
        /// <param name="retrieverFactory">
        /// The retriever factory.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="item"/> parameter is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="retrieverFactory"/> parameter is null.
        /// </exception>
        public EditableRootDataContext(IEditableRoot item, IProcessFieldItemsRetrieverFactory retrieverFactory)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            if (retrieverFactory == null)
                throw new ArgumentNullException("retrieverFactory");

            _item = item;
            _itemsRetrieverFactory = retrieverFactory;
        }
Example #10
0
        public object GetValue(DetailsSaveFieldModel field, IEditableRoot editableRoot)
        {
            var bytes = field.Value as byte[];

            var base64 = field.Value as string;
            if (!string.IsNullOrEmpty(base64))
            {
                bytes = Convert.FromBase64String(base64);
            }

            return bytes;
        }
Example #11
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="editableRoot">The editable root.</param>
        /// <returns></returns>
        public object GetValue(DetailsSaveFieldModel field, IEditableRoot editableRoot)
        {
            if (field.Settings == null)
                return null;

            var fileFieldOptions = field.Settings.ToObject<FileFieldOptions>();
            if (fileFieldOptions == null)
                return null;

            IFileProcess fileEdit = editableRoot.GetValueByPropertyName(field.SystemName);
            if (fileEdit == null)
                return null;

            fileEdit.FileName = fileFieldOptions.FileName;
            fileEdit.OriginalFileName = fileFieldOptions.OriginalFileName;

            if (!fileFieldOptions.Locked)
            {
                fileEdit.LockedDate = null;
            }
            else if (!fileEdit.Locked.HasValue || !fileEdit.Locked.Value)
            {
                fileEdit.LockedDate = DateTime.Now;
            }
            fileEdit.Locked = fileFieldOptions.Locked;
            fileEdit.LockedByAccountId = fileFieldOptions.LockedByAccountId;
            fileEdit.LockedByAccountName = fileFieldOptions.LockedByAccountName;

            if (fileFieldOptions.AuditLog != null)
            {
                fileEdit.FileChangeInfo = new AuditLogInfo
                {
                    LogType = fileFieldOptions.AuditLog.LogType,
                    ProcessName = fileFieldOptions.AuditLog.ProcessName,
                    ItemId = fileFieldOptions.AuditLog.ItemId,
                    FieldName = fileFieldOptions.AuditLog.FieldName,
                    OldValue = fileFieldOptions.AuditLog.OldValue,
                    NewValue = fileFieldOptions.AuditLog.NewValue,
                    DateUpdated = fileFieldOptions.AuditLog.DateUpdated,
                    User = fileFieldOptions.AuditLog.User
                };
            }

            var newModel = ((IBusinessBase)fileEdit).Save();

            if (fileFieldOptions.FileId == 0)
            {
                editableRoot.SetValueByPropertyName(string.Format("{0}Id", field.SystemName), ((IDynamicObject)newModel).Id);
            }

            return newModel;
        }
Example #12
0
        /// <summary>
        /// Copies the answer data.
        /// </summary>
        /// <param name="answerFieldValues">
        /// The answer field values.
        /// </param>
        /// <param name="answerItem">
        /// The answer item.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="answerFieldValues"/> parameter is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="answerItem"/> parameter is null.
        /// </exception>
        public static void CopyAnswerData(ICollection<ChecklistAnswerFieldValue> answerFieldValues, IEditableRoot answerItem)
        {
            if (answerFieldValues == null)
                throw new ArgumentNullException("answerFieldValues");

            if (answerItem == null)
                throw new ArgumentNullException("answerItem");

            using (new ThreadLocalBypassPropertyCheckContext())
            {
                foreach (var fieldValue in answerFieldValues.Where(f => f.Value != null))
                {
                    var answerProperty = answerItem.GetPropertyByName(fieldValue.FieldName);
                    var answerValue = answerItem.GetValueByPropertyName(fieldValue.FieldName);

                    if (fieldValue.Value is ICrossRefItemList && answerValue is ICrossRefItemList)
                    {
                        var qList = (ICrossRefItemList)fieldValue.Value;
                        var aList = (ICrossRefItemList)answerValue;

                        aList.Clear();
                        foreach (var crItem in qList.Cast<ICrossRefItemInfo>())
                        {
#if !SILVERLIGHT
                            aList.Assign(crItem.Id);
#else
                            aList.Assign(crItem.Id, (o, e) => { });
#endif
                        }

                        continue;
                    }

                    if (answerProperty.PropertyType.IsInstanceOfType(fieldValue.Value))
                    {
                        answerItem.SetValueByPropertyName(fieldValue.FieldName, fieldValue.Value);
                    }
                    else
                    {
                        throw new VeyronException(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                "Cannot assign value of type \"{0}\" to property \"{1}\".",
                                fieldValue.Value.GetType().AssemblyQualifiedName,
                                fieldValue.FieldName));
                    }
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessItemUpdatedEvent"/> class.
        /// </summary>
        /// <param name="item">
        /// The item that was modified.
        /// </param>
        /// <param name="rootWindow">
        /// The root window.
        /// </param>
        /// <param name="depth">
        /// The depth.
        /// </param>
        public ProcessItemUpdatedEvent(IEditableRoot item, ITopLevelWindow rootWindow, int depth)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            if (rootWindow == null)
                throw new ArgumentNullException("rootWindow");

            if (depth < 0)
                throw new ArgumentOutOfRangeException("depth", @"Depth cannot be negative.");

            Item = item;
            RootWindow = rootWindow;
            Depth = depth;
        }
Example #14
0
        /// <summary>
        /// Extracts and returns field back color, if specified. 
        /// </summary>
        /// <param name="baseModel">Editable root model.</param>
        /// <param name="property">Field property.</param>
        /// <returns>
        /// HTML color string (like "#ffffff") if field has back color. 
        /// Empty string if field does not have back color.
        /// null if field does not support back color change.
        /// </returns>
        private static string GetBackColor(IEditableRoot baseModel, PropertyInfo property)
        {
            if (baseModel == null)
            {
                throw new ArgumentNullException("baseModel");
            }

            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var fieldBackgoundAttr =
                (FieldBackgroundAttribute)
                    property.GetCustomAttributes(typeof(FieldBackgroundAttribute), false)
                        .Select(d => d)
                        .FirstOrDefault();

            if (fieldBackgoundAttr != null)
            {
                var backcolorFieldName = fieldBackgoundAttr.BackcolorFieldName;

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

                var bcProperty = baseModel.GetPropertyByName(backcolorFieldName);
                if (bcProperty != null)
                {
                    long longColor = 0;
                    try
                    {
                        longColor = (long)(bcProperty.GetValue(baseModel, null) ?? 0);
                    }
                    catch  {                   
                    }

                    return longColor == 0 ? string.Empty : ColorTranslator.ToHtml(Color.FromArgb((int)longColor));
                }

                return string.Empty;
            }

            return null;
        }
        public static IFieldOptions Create(PropertyInfo property, IEditableRoot editableRoot)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (editableRoot == null)
            {
                throw new ArgumentNullException("editableRoot");
            }

            var crossRefAttr = property.GetCustomAttributes(typeof(CrossRefFieldAttribute), false).Select(d => d).FirstOrDefault() as CrossRefFieldAttribute;
            if (crossRefAttr == null)
            {
                throw new VeyronException("CrossRef attribute not found on Cross-reference field property");
            }

            string valueAsText = "Unknown";

            var crId = editableRoot.GetValueByPropertyName(property.Name) as int?;

            if (crId.HasValue)
            {
                var ancestor = editableRoot.GetAncestor(property);
                if (ancestor != null)
                {
                    var crItem = DynamicTypeManager.Instance.GetCrossReferenceItem(ancestor.ProcessName, property.Name, crId.Value);
                    if (crItem != null)
                    {
                        valueAsText = crItem.GetValueByPropertyName(crossRefAttr.RefFieldName) == null ? "Unknown" : crItem.GetValueByPropertyName(crossRefAttr.RefFieldName).ToString();
                    }
                }
            }
            
            var result = new SingleCrossRefFieldOptions
            {
                ValueAsText = valueAsText, 
                ProcessSystemName = crossRefAttr.ReferenceTableName, 
                FieldName = crossRefAttr.RefFieldName,
                AllowViewDetail = crossRefAttr.AllowViewDetail,
                AllowClear = crossRefAttr.AllowClear
            };

            return result;
        }
        /// <summary>
        /// Updates the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        public void Update(IDynamicObject source, IEditableRoot destination)
        {
            var currentState = ESyncTypeConverter.Convert<string>(_valueCalculator.GetValue(source, _field.MappingKey));

            if (currentState == null)
                return;

            var supportStates = destination as ISupportStates;

            if (supportStates == null)
                return;

            var state =
                supportStates.StateManager.States.FirstOrDefault(
                    s => string.Compare(s.Name, currentState, StringComparison.OrdinalIgnoreCase) == 0);

            if (state != null)
                supportStates.CurrentState = state.Id;
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <returns>
        /// The <see cref="SampleTypeFieldOptions"/>.
        /// </returns>
        public static SampleTypeFieldOptions Create(PropertyInfo property, IEditableRoot model)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var result = new SampleTypeFieldOptions();

            var list = (from object sampleType in Enum.GetValues(typeof(SampleTypes)) select sampleType.ToString()).ToList();
            result.PossibleValues = list;

            var trueLabelProperty = model.GetPropertyByName(property.Name + Constants.SampleTrueLabel);
            var falseLabelProperty = model.GetPropertyByName(property.Name + Constants.SampleFalseLabel);

            if (trueLabelProperty != null)
            {
                result.TrueLabel = trueLabelProperty.GetValue(model, null) as string;
                if (string.IsNullOrEmpty(result.TrueLabel))
                {
                    result.TrueLabel = LanguageService.Translate("Item_Pass");
                }
            }

            if (falseLabelProperty != null)
            {
                result.FalseLabel = falseLabelProperty.GetValue(model, null) as string;
                if (string.IsNullOrEmpty(result.FalseLabel))
                {
                    result.FalseLabel = LanguageService.Translate("Item_Fail");
                }
            }

            return result;
        }
Example #18
0
        public static IFieldInfo Create(PropertyInfo prop, IEditableRoot editableRoot, IField field, object rawValue, IValidationContext validationContext)
        {
            var customAttr = prop.GetCustomAttribute<CommonSettingsAttribute>();
            var promptAttr = prop.GetCustomAttribute<PromptAttribute>();
            var docAttr = prop.GetCustomAttribute<DocumentationAttribute>();
            var fieldTypeAttr = prop.GetCustomAttribute<FieldTypeAttribute>();
            var hasCalculatedAttr = prop.GetCustomAttributes(typeof(CalculatedAttribute), false).Any();
            var hasDefaultExpressionAttr = prop.GetCustomAttributes(typeof(HasDefaultExpressionAttribute), false).Any();

            //Set common properties
            var fieldInfo = CreateFieldInfo(fieldTypeAttr.ColumnType, prop, rawValue, editableRoot);
            fieldInfo.Id = editableRoot.Id;
            fieldInfo.SystemName = field.SystemName;
            fieldInfo.DisplayName = customAttr.Name;
            fieldInfo.Width = customAttr.Width;
            fieldInfo.CanRead = editableRoot.CanReadProperty(prop.Name);
            fieldInfo.IsRequired = validationContext != null && validationContext.IsRequired(editableRoot.ProcessName, field.SystemName, editableRoot.GetCurrentStateGuid());
            fieldInfo.CanRead = editableRoot.CanReadProperty(prop.Name);
            fieldInfo.CanWrite = editableRoot.CanWriteProperty(prop.Name) && !hasCalculatedAttr;
            fieldInfo.BackColor = GetBackColor(editableRoot, prop);
            fieldInfo.Prompt = promptAttr == null
                ? string.Format(CultureInfo.InvariantCulture,
                    LanguageService.Translate("Tooltip_EnterPrompt"), customAttr.Name)
                : promptAttr.PromptString;

            fieldInfo.IsDocumentationAvailable = docAttr != null;

            if (hasCalculatedAttr || hasDefaultExpressionAttr)
            {
                fieldInfo.ExpressionType = hasCalculatedAttr ? FieldExpressionType.Calculated : FieldExpressionType.Default;
                fieldInfo.Expression = GetExpression(editableRoot, prop);
            }

            // docAttr == null ? string.Empty : ClrUnicodeConverter.ToText(docAttr.DocumentationBody),

            return fieldInfo;
        }
        private void UpdateFields(IDataContext dataContext, IEditableRoot item)
        {
            foreach (var fieldMapping in ChildMappings)
            {
                fieldMapping.Update(dataContext, item);

                if (fieldMapping.IsKey)
                {
                    item.KeyFields.Add(fieldMapping.FieldName);
                }
            }
        }
        /// <summary>
        /// Updates the specified item.
        /// </summary>
        /// <param name="dataContext">
        /// The data context.
        /// </param>
        /// <param name="item">
        /// The destination item.
        /// </param>
        public void Update(IDataContext dataContext, IEditableRoot item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            var crList = (ICrossRefItemList)item.GetValueByPropertyName(Property.Name);
            if (crList == null)
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Cross reference field \"{0}\" is null.", Property.Name), "item");

            try
            {
            if (ValueExpression != null)
            {
                var items = ValueExpression(dataContext) as IEnumerable;

                if (items != null)
                {
                    var enumerator = items.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        InsertOrUpdateChildren(dataContext, crList);
                    }
                }
            }
            else
            {
                InsertOrUpdateChildren(dataContext, crList);
            }
        }
            catch (Exception ex)
            {
                var message = new StringBuilder();
                message.AppendFormat(CultureInfo.InvariantCulture, "Could not update the field \"{0}\" in process \"{1}\".", DisplayName, item.ProcessDisplayName);

                throw new InvalidOperationException(message.ToString(), ex);
            }
        }
        private static ICollection<string> GetPersonFieldNames(IEditableRoot model)
        {
            var supportStates = model as ISupportStates;

            return supportStates == null ? new string[] { } : supportStates.StateManager.GetPersonFieldsNames();
        }
        private void UnsubscribeListeners(IEditableRoot model)
        {
            var notifyPropertyChanged = model as INotifyPropertyChanged;

            if (notifyPropertyChanged != null && _weakListenerNotifyPropertyChanged != null)
            {
                notifyPropertyChanged.PropertyChanged -= _weakListenerNotifyPropertyChanged.OnEvent;
            }

            var notifyChildChanged = model as INotifyChildChanged;

            if (notifyChildChanged != null && _weakListenerNotifyChildChanged != null)
            {
                notifyChildChanged.ChildChanged -= _weakListenerNotifyChildChanged.OnEvent;
            }
        }
        private void SubscribeListeners(IEditableRoot model)
        {
            var notifyPropertyChanged = model as INotifyPropertyChanged;
            if (notifyPropertyChanged != null)
            {
                _weakListenerNotifyPropertyChanged = new WeakEventListener<DetailsSaveControlViewModel, INotifyPropertyChanged, PropertyChangedEventArgs>(this, notifyPropertyChanged);
                notifyPropertyChanged.PropertyChanged += _weakListenerNotifyPropertyChanged.OnEvent;
                _weakListenerNotifyPropertyChanged.OnEventAction += OnModelPropertyChanged;
                _weakListenerNotifyPropertyChanged.OnDetachAction += Static;
            }

            var notifyChildChanged = model as INotifyChildChanged;
            if (notifyChildChanged != null)
            {
                _weakListenerNotifyChildChanged = new WeakEventListener<DetailsSaveControlViewModel, INotifyChildChanged, ChildChangedEventArgs>(this, notifyChildChanged);
                notifyChildChanged.ChildChanged += _weakListenerNotifyChildChanged.OnEvent;
                _weakListenerNotifyChildChanged.OnEventAction += OnModelChildChanged;
                _weakListenerNotifyChildChanged.OnDetachAction += Static;
            }
        }
        /// <summary>
        /// Updates the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        public void Update(IDynamicObject source, IEditableRoot destination)
        {
            var filterList = new List<ColumnFilter>();

            foreach (var filterBuilder in _filterBuilders)
            {
                ColumnFilter filter;
                if (!filterBuilder.TryGetFilter(source, out filter))
                    return;
                filterList.Add(filter);
            }

            var itemIds = RuntimeDatabase.FindItems(_referencedProcess, filterList);
            if (itemIds.Count <= 0)
                return;

            if (_allowMultiple)
            {
                var crList = (ICrossRefItemList)destination.GetValueByPropertyName(_property.Name);

                if (crList == null)
                    return;

                foreach (var id in itemIds.Where(id => !crList.Contains(id)))
                {
                    crList.Assign(id);
                }
            }
            else
            {
                destination.SetValueByPropertyName(_property.Name, itemIds[0]);
            }
        }
 /// <summary>
 /// Determines whether current user has rights to execute command.
 /// </summary>
 /// <param name="model">
 /// An object that implements ISupportScheduling and/or ISupportVersioning interfaces.
 /// </param>
 /// <param name="securityConfigurations">
 /// The security configurations.
 /// </param>
 /// <returns>
 /// <c>true</c> if this instance can execute the specified model; otherwise, <c>false</c>.
 /// </returns>
 public bool CanExecute(IEditableRoot model, IEnumerable<HasAccessToExecuteCommandValidator.ProcessCommandSecurityConfiguration> securityConfigurations)
 {
     return new HasAccessToExecuteCommandValidator(securityConfigurations.ToArray()).CanExecute(model);
 }
 /// <summary>
 /// Creates a <see cref="IDataContext"/>.
 /// </summary>
 /// <param name="editableRoot">
 /// The source editable root.
 /// </param>
 /// <returns>
 /// The <see cref="IDataContext"/>.
 /// </returns>
 public IDataContext CreateDataContext(IEditableRoot editableRoot)
 {
     return new EditableRootDataContext(editableRoot, RetrieverFactory);
 }
        /// <summary>
        /// Updates the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        public void Update(IDynamicObject source, IEditableRoot destination)
        {
            var supportVersioning = destination as ISupportVersioning;

            if (supportVersioning == null)
                return;

            var filterList = new List<ColumnFilter>();

            foreach (var filterBuilder in _filterBuilders)
            {
                ColumnFilter filter;

                if (!filterBuilder.TryGetFilter(source, out filter))
                    return;

                filterList.Add(filter);
            }

            var itemIds = RuntimeDatabase.FindItems(destination.ProcessName, filterList);

            if (itemIds.Count <= 0)
                return;

            supportVersioning.VersionMasterId = itemIds[0];
        }
        /// <summary>
        /// Gets a collection of editable root items.
        /// </summary>
        /// <param name="item">The editable root item that invoked the data trigger.</param>
        /// <param name="oldItem">The old copy of the item that invoked the data trigger. This parameter can be null.</param>
        /// <returns>Returns a collection of editable root items.</returns>
        /// <exception cref="System.ArgumentNullException">item</exception>
        /// <exception cref="ArgumentNullException">The item parameter is null.</exception>
        public IEnumerable<IEditableRoot> GetItems(IEditableRoot item, IEditableRoot oldItem)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            var allItems = new List<IEditableRoot>();

            if (IncludeNewItems)
                allItems.AddRange(ItemsRetriever.GetNewItems(item, oldItem));

            if (IncludeOldItmes)
                allItems.AddRange(ItemsRetriever.GetOldItems(item, oldItem));

            if (IncludeRemovedItems)
                allItems.AddRange(ItemsRetriever.GetRemovedItems(item, oldItem));

            var foundItems = new HashSet<int>();

            foreach (var editableRoot in allItems)
            {
                if (foundItems.Contains(editableRoot.Id))
                    continue;

                foundItems.Add(editableRoot.Id);
                yield return editableRoot;
            }
        }
Example #29
0
 public void ReplacePredefinedValues(IEditableRoot entity)
 {
     throw new NotImplementedException();
 }
Example #30
0
        /// <summary>
        /// Gets the sections and fields.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="sections">The sections.</param>
        /// <param name="fields">The fields.</param>
        private static void GetSectionsAndFields(IEditableRoot item, out string sections, out string fields)
        {
            var sectionsList = item.Sections;
            var fieldsList = new List<IField>();

            foreach (var section in sectionsList)
                fieldsList.AddRange(section.Fields);

            sections = string.Join(";", sectionsList.Select(s => s.Name));
            fields = string.Join(";", fieldsList.Select(s => s.SystemName));
        }