Exemplo n.º 1
0
        /// <summary>
        /// Edits the contexts for result row.
        /// </summary>
        /// <param name="resultRow">The result row.</param>
        /// <param name="tabConfig">The tab configuration.</param>
        /// <param name="editFieldDictionary">The edit field dictionary.</param>
        /// <param name="initialValues">The initial values.</param>
        /// <param name="fieldPostfix">The field postfix.</param>
        /// <param name="initialRecords">The initial records.</param>
        /// <returns></returns>
        public List <object> EditContextsForResultRow(UPCRMResultRow resultRow, FieldControlTab tabConfig,
                                                      Dictionary <string, UPEditFieldContext> editFieldDictionary, Dictionary <string, object> initialValues, string fieldPostfix, List <UPCRMRecord> initialRecords)
        {
            var recordIdentification = resultRow?.RecordIdentificationAtIndex(0);

            var         fieldArray        = new List <object>();
            UPCRMRecord offlineRootRecord = null;

            if (initialRecords?.Count > 0)
            {
                offlineRootRecord = initialRecords.FirstOrDefault();
            }

            var identifierPrefix = recordIdentification;

            if (string.IsNullOrEmpty(identifierPrefix))
            {
                identifierPrefix = $"{this.TabConfig.FieldControl.UnitName}_{this.TabIndex}";
            }

            var fieldCount = tabConfig?.NumberOfFields ?? 0;

            for (var j = 0; j < fieldCount; j++)
            {
                var fieldConfig = tabConfig?.FieldAtIndex(j);
                if (fieldConfig == null)
                {
                    continue;
                }

                var        fieldAttributes   = fieldConfig.Attributes;
                var        currentInfoAreaId = fieldConfig.InfoAreaId;
                var        currentLinkId     = fieldConfig.LinkId;
                var        fieldIdentifier   = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(identifierPrefix, fieldConfig.Identification);
                UPSelector selector          = null;
                var        selectorDef       = fieldConfig.Attributes?.Selector;
                if (selectorDef != null)
                {
                    var filterParameters = this.EditPageContext?.ViewReference?.ContextValueForKey("copyFields")?.JsonDictionaryFromString();
                    if (resultRow?.Result != null && resultRow.IsNewRow)
                    {
                        selector = UPSelector.SelectorFor(
                            resultRow.RootRecordIdentification?.InfoAreaId(),
                            resultRow.Result.ParentRecordIdentification,
                            resultRow.Result.LinkId,
                            selectorDef,
                            filterParameters,
                            fieldConfig);
                    }
                    else
                    {
                        selector = UPSelector.SelectorFor(resultRow?.RootRecordIdentification, selectorDef, filterParameters, fieldConfig);
                    }

                    selector.Build();
                    if (selector.OptionCount == 0 && selector.IsStaticSelector)
                    {
                        selector = null;
                    }
                }

                var isEditField = this.enableLinkedEditFields ||
                                  selector != null ||
                                  (tabConfig.FieldControl.InfoAreaId == currentInfoAreaId && currentLinkId <= 0);

                var isHidden       = fieldAttributes.Hide;
                var isReadOnly     = isEditField && fieldAttributes.ReadOnly;
                var rawFieldValue0 = resultRow?.RawValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                var fieldInfo      = fieldConfig.Field.FieldInfo;
                if (isEditField && !isReadOnly && !(selector is UPRecordSelector && ((UPRecordSelector)selector).IgnoreFieldInfo))
                {
                    if (fieldInfo.IsReadOnly)
                    {
                        isReadOnly = true;
                    }
                    else if (resultRow?.IsNewRow == true || string.IsNullOrEmpty(rawFieldValue0))
                    {
                        if (fieldInfo.LockedOnNew)
                        {
                            isReadOnly = true;
                        }
                    }
                    else if (fieldInfo.LockedOnUpdate && !fieldInfo.IsEmptyValue(rawFieldValue0))
                    {
                        isReadOnly = true;
                    }
                }

                string             offlineValue = null;
                bool               offlineChanged;
                string             rawFieldValue;
                UPEditFieldContext editFieldContext;
                if (isEditField)
                {
                    List <UPEditFieldContext> childFields = null;
                    if (fieldAttributes.FieldCount > 1 && selector == null)
                    {
                        childFields = new List <UPEditFieldContext>();
                        for (var k = 1; k < fieldAttributes.FieldCount; k++)
                        {
                            var childFieldConfig = tabConfig.FieldAtIndex(++j);
                            if (childFieldConfig != null)
                            {
                                rawFieldValue = resultRow.RawValueAtIndex(childFieldConfig.TabIndependentFieldIndex);
                                if (initialValues != null)
                                {
                                    rawFieldValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, childFieldConfig, initialValues);
                                }

                                offlineChanged = false;

                                if (offlineRootRecord != null)
                                {
                                    offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(childFieldConfig.FieldId);
                                    if (offlineValue != null && !offlineValue.Equals(rawFieldValue))
                                    {
                                        offlineChanged = true;
                                    }
                                }

                                editFieldContext = UPEditFieldContext.ChildFieldContextForFieldConfigValue(childFieldConfig, rawFieldValue);
                                if (offlineChanged)
                                {
                                    editFieldContext.SetOfflineChangeValue(offlineValue);
                                }

                                childFields.Add(editFieldContext);
                            }
                        }
                    }

                    var markAsChanged = false;
                    rawFieldValue = rawFieldValue0;
                    if (initialValues != null)
                    {
                        string initialValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, fieldConfig, initialValues);
                        if (!rawFieldValue.Equals(initialValue))
                        {
                            markAsChanged = true;
                            rawFieldValue = initialValue;
                        }
                    }

                    offlineChanged = false;
                    offlineValue   = null;
                    if (offlineRootRecord != null)
                    {
                        offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(fieldConfig.FieldId);
                        if (offlineValue != null && !offlineValue.Equals(rawFieldValue))
                        {
                            offlineChanged = true;
                        }
                    }

                    if (selector != null)
                    {
                        // Sometimes it makes sense to add the Link field , so you have the link information on the EditPage , but the field is not displayed .
                        // Thus, the field is interpreted as EditField Selector must be set.
                        if (isHidden)
                        {
                            editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else if (isReadOnly && ConfigurationUnitStore.DefaultStore.ConfigValueIsSet("Disable.82213"))
                        {
                            editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else
                        {
                            editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, selector);
                        }
                    }
                    else
                    {
                        if (isHidden)
                        {
                            editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else if (isReadOnly)
                        {
                            editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else
                        {
                            editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, childFields as List <UPEditFieldContext>);
                        }
                    }

                    if (fieldInfo.DateFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId)
                    {
                        editFieldContext.DateOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.DateFieldId, currentInfoAreaId, -1);
                    }
                    else if (fieldInfo.TimeFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId)
                    {
                        editFieldContext.TimeOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.TimeFieldId, currentInfoAreaId, -1);
                    }

                    if (offlineChanged)
                    {
                        editFieldContext.SetOfflineChangeValue(offlineValue);
                    }
                    else if (markAsChanged)
                    {
                        editFieldContext.SetChanged(true);
                    }

                    if (editFieldContext != null)
                    {
                        if (!string.IsNullOrEmpty(fieldPostfix))
                        {
                            editFieldContext.FieldLabelPostfix = fieldPostfix;
                        }

                        if (editFieldDictionary != null)
                        {
                            editFieldDictionary.SetObjectForKey(editFieldContext, fieldConfig.Identification);
                            if (childFields != null)
                            {
                                foreach (var childFieldContext in childFields)
                                {
                                    editFieldDictionary.SetObjectForKey(childFieldContext, childFieldContext.FieldConfig.Identification);
                                }
                            }
                        }

                        fieldArray.Add(editFieldContext);
                    }
                }
                else
                {
                    string fieldValue;
                    if (fieldAttributes.FieldCount > 1)
                    {
                        fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                        if (string.IsNullOrEmpty(fieldValue))
                        {
                            fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues);
                        }

                        var values = !string.IsNullOrEmpty(fieldValue) ?
                                     new List <string> {
                            fieldValue
                        } :
                        new List <string>();

                        for (var k = 1; k < fieldAttributes.FieldCount; k++)
                        {
                            var childfieldConfig = tabConfig.FieldAtIndex(++j);
                            if (childfieldConfig == null)
                            {
                                continue;
                            }

                            fieldValue = resultRow?.ValueAtIndex(childfieldConfig.TabIndependentFieldIndex);
                            if (string.IsNullOrEmpty(fieldValue))
                            {
                                fieldValue = this.ValueForLinkFieldFromInitialValues(childfieldConfig, initialValues);
                            }

                            if (string.IsNullOrEmpty(fieldValue))
                            {
                                fieldValue = string.Empty;
                            }

                            values.Add(fieldValue);
                        }

                        fieldValue = fieldAttributes.FormatValues(values);
                    }
                    else
                    {
                        fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                        if (string.IsNullOrEmpty(fieldValue))
                        {
                            fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues);
                        }
                    }

                    UPMField field;
                    if (!isHidden && !string.IsNullOrEmpty(fieldValue))
                    {
                        field = new UPMStringField(fieldIdentifier);
                        ((UPMStringField)field).StringValue = fieldValue;
                    }
                    else
                    {
                        field = null;
                    }

                    if (field != null)
                    {
                        if (!fieldConfig.Attributes.NoLabel)
                        {
                            field.LabelText = fieldConfig.Label;
                        }

                        SetAttributesOnField(fieldAttributes, field);
                        fieldArray.Add(field);
                    }
                }
            }

            return(fieldArray);
        }
Exemplo n.º 2
0
 protected override void OnInitialized()
 {
     _fieldIdentifier = FieldIdentifier.Create(ValueExpression);
 }
        private static UPMPhoneField CreatePhoneField(FieldAttributes fieldAttributes, FieldIdentifier fieldIdentifier)
        {
            var field = new UPMPhoneField(fieldIdentifier);
            var phoneInExtendedOptions = fieldAttributes.ExtendedOptions.ValueOrDefault("phone");

            if (phoneInExtendedOptions != null)
            {
                field.UseTelprompt = phoneInExtendedOptions == "telprompt";
            }

            return(field);
        }
        private UPMGroup AddFieldsToDetailGroup(UPMGroup upmGroup, string recordIdentification, UPCRMResultRow resultRow, out string documentKey, out UPConfigFieldControlField documentFieldConfig)
        {
            var configStore     = ConfigurationUnitStore.DefaultStore;
            var hideEmptyFields = configStore.ConfigValueIsSet("View.HideEmptyFields");

            documentKey         = string.Empty;
            documentFieldConfig = null;
            var listFormatter = new UPCRMListFormatter(this.TabConfig, false);
            var fieldCount    = listFormatter.PositionCount;
            var detailGroup   = upmGroup;

            for (var j = 0; j < fieldCount; j++)
            {
                var fieldConfig     = listFormatter.FirstFieldForPosition(j);
                var fieldAttributes = fieldConfig.Attributes;
                var fieldIdentifier = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(recordIdentification, fieldConfig.Identification);
                var hasFieldValue   = false;
                if (fieldAttributes.Image)
                {
                    documentKey         = resultRow.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                    documentFieldConfig = fieldConfig;
                    if (!string.IsNullOrEmpty(documentKey) && fieldCount == 1)
                    {
                        detailGroup = this.AddFieldToDetailGroup(detailGroup, fieldIdentifier, recordIdentification);
                    }

                    continue;
                }

                if (fieldAttributes.Hide)
                {
                    continue;
                }

                if (fieldAttributes.Empty)
                {
                    detailGroup = this.AddFieldToDetailGroup(detailGroup, recordIdentification, fieldIdentifier, fieldAttributes);
                    continue;
                }

                string fieldValue = null;

                try
                {
                    fieldValue = listFormatter.StringFromRowForPosition(resultRow, j);
                }
                catch (Exception error)
                {
                    SimpleIoc.Default.GetInstance <ILogger>().LogError(error);
                }

                if (!string.IsNullOrEmpty(fieldValue))
                {
                    hasFieldValue = true;
                }

                if (!hasFieldValue && hideEmptyFields && !this.columnStyle)
                {
                    if (!(detailGroup is UPMCalendarPopoverGroup) || j > 3)
                    {
                        continue;
                    }
                }

                if (fieldAttributes.MultiLine && j + 1 == fieldCount && detailGroup == null)
                {
                    var multiLineGroup = this.CreateMultilineGroup(recordIdentification, CreateStringField(fieldIdentifier, fieldAttributes, fieldValue), fieldConfig);
                    this.ControllerState = GroupModelControllerState.Finished;
                    this.Group           = multiLineGroup;
                    return(multiLineGroup);
                }

                var field = this.CreateField(fieldAttributes, fieldIdentifier, fieldConfig, resultRow, recordIdentification, configStore);
                if (field == null)
                {
                    continue;
                }

                UpdateField(field, fieldAttributes, fieldConfig, fieldValue);
                if (string.IsNullOrWhiteSpace(field.LabelText) && string.IsNullOrEmpty(fieldValue))
                {
                    continue;
                }

                detailGroup = this.AddFieldToDetailGroup(detailGroup, fieldAttributes, field, recordIdentification);
            }

            return(detailGroup);
        }
 /// <summary>
 /// Gets a string that indicates the status of the specified field as a CSS class. This will include
 /// some combination of "modified", "valid", or "invalid", depending on the status of the field.
 /// </summary>
 /// <param name="editContext">The <see cref="EditContext"/>.</param>
 /// <param name="accessor">An identifier for the field.</param>
 /// <returns>A string that indicates the status of the field.</returns>
 public static string FieldCssClass <TField>(this EditContext editContext, Expression <Func <TField> > accessor)
 => FieldCssClass(editContext, FieldIdentifier.Create(accessor));
Exemplo n.º 6
0
 /// <summary>
 /// Adds the message and apply it to the field identifier.
 /// </summary>
 /// <param name="fieldIdentifier">Field identifier to which messages belong.</param>
 /// <param name="message">Message result.</param>
 public void Add(FieldIdentifier fieldIdentifier, ValidationMessageResult message)
 => GetOrCreateMessagesListForField(fieldIdentifier).Add(message);
Exemplo n.º 7
0
 public void AddError(FieldIdentifier field, string errMessage)
 {
     _messageStore.Add(field, errMessage);
 }
Exemplo n.º 8
0
		private string GetColumnAttributeStr (int column, FieldIdentifier fieldId)
		{
			OdbcReturn ret = OdbcReturn.Error;
			byte [] buffer = new byte [255];
			short outsize = 0;
			int val = 0;
			ret = libodbc.SQLColAttribute (hstmt, (short)column, fieldId,
							buffer, (short)buffer.Length,
							ref outsize, ref val);
			if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo)
				throw Connection.CreateOdbcException (
					OdbcHandleType.Stmt, hstmt);
			string value = string.Empty;
			if (outsize > 0)
				value = Encoding.Unicode.GetString (buffer, 0, outsize);
			return value;
		}
Exemplo n.º 9
0
 public void ClearError(FieldIdentifier fieldIdentifier)
 {
     _validationMessageStore.Clear(fieldIdentifier);
     EditContext.NotifyValidationStateChanged();
 }
        protected override void OnInit()
        {
            if (CurrentEditContext == null)
            {
                throw new InvalidOperationException($"{nameof(FluentValidationValidator)} requires a cascading " +
                                                    $"parameter of type {nameof(EditContext)}. For example, you can use {nameof(FluentValidationValidator)} " +
                                                    $"inside an {nameof(EditForm)}.");
            }

            var validator = Validator ?? GetValidatorForModel(CurrentEditContext.Model);

            if (validator == null)
            {
                throw new InvalidOperationException($"{nameof(FluentValidationValidator)} requires either a " +
                                                    $"parameter of type {nameof(IValidator)}, or validator for type {nameof(CurrentEditContext.Model)} " +
                                                    $"should be reachable via reflection from the calling assembly.");
            }

            var messages  = new ValidationMessageStore(CurrentEditContext);
            var modelName = CurrentEditContext.Model.GetType().FullName;
            // This field collects errors that are model-related but not specific to concrete property on the model
            var modelErrorField = new FieldIdentifier(CurrentEditContext.Model, string.Empty);
            var _event          = _eventAggregator?.GetEvent <ValidationEvent>();

            // This subscription fires when Submit button is pressed,
            // acts as a guard against not validated still-focused field
            formValidationSub = Observable.FromEventPattern <ValidationRequestedEventArgs>(
                handler => CurrentEditContext.OnValidationRequested += handler,
                handler => CurrentEditContext.OnValidationRequested -= handler)
                                .Subscribe(e =>
            {
                messages.Clear();
                var validationResults = validator.Validate(CurrentEditContext.Model);

                if (validationResults.IsValid)
                {
                    _event?.Publish(new ValidationEventArgs(true, modelName));
                    if (OnValidation.HasDelegate)
                    {
                        OnValidation.InvokeAsync(true);
                    }
                }
                else
                {
                    _event?.Publish(new ValidationEventArgs(false, modelName));
                    if (OnValidation.HasDelegate)
                    {
                        OnValidation.InvokeAsync(false);
                    }
                    foreach (var validationResult in validationResults.Errors)
                    {
                        messages.Add(CurrentEditContext.Field(validationResult.PropertyName), validationResult.ErrorMessage);
                    }
                }
                CurrentEditContext.NotifyValidationStateChanged();
            });

            // This subscription fires every time an input field loses a focus, main workhorse
            fieldValidationSub = Observable.FromEventPattern <FieldChangedEventArgs>(
                handler => CurrentEditContext.OnFieldChanged += handler,
                handler => CurrentEditContext.OnFieldChanged -= handler)
                                 .Subscribe(e =>
            {
                var validationResults = validator.Validate(CurrentEditContext.Model);

                if (validationResults.IsValid)
                {
                    messages.Clear();
                    _event?.Publish(new ValidationEventArgs(true, modelName));
                    if (OnValidation.HasDelegate)
                    {
                        OnValidation.InvokeAsync(true);
                    }
                }
                else
                {
                    _event?.Publish(new ValidationEventArgs(false, modelName));
                    if (OnValidation.HasDelegate)
                    {
                        OnValidation.InvokeAsync(false);
                    }
                    messages.Clear(e.EventArgs.FieldIdentifier);
                    messages.AddRange(e.EventArgs.FieldIdentifier, validationResults.Errors
                                      .Where(failure => failure.PropertyName == e.EventArgs.FieldIdentifier.FieldName)
                                      .Select(failure => failure.ErrorMessage));

                    // add errors that are not specific to field, e.g. complex rules
                    messages.Clear(modelErrorField);
                    messages.AddRange(modelErrorField, validationResults.Errors
                                      .Where(failure => failure.PropertyName == string.Empty)
                                      .Select(failure => failure.ErrorMessage));
                }
                CurrentEditContext.NotifyValidationStateChanged();
            });
        }
Exemplo n.º 11
0
 public void Visit(FieldIdentifier f)
 {
     this.Translated = $"{f.Identifier}()";
 }
 /// <summary>
 /// Initializes a new instance of <see cref="FormFieldChangedEventArgs"/>
 /// </summary>
 /// <param name="isValid">true if the form is currently valid; otherwise, false.</param>
 /// <param name="fieldIdentifier">The field whose value has changed.</param>
 public FormFieldChangedEventArgs(bool isValid, FieldIdentifier fieldIdentifier)
 {
     IsValid = isValid;
     Field   = fieldIdentifier;
 }
Exemplo n.º 13
0
 public static Field Unresolved(FieldIdentifier fieldIdentifier, DeclaredType type, IReferencable returnType)
 {
     return new Field(fieldIdentifier, type) { IsResolved = false, ReturnType = returnType };
 }
Exemplo n.º 14
0
 /// <summary>
 /// 获取显示名称方法
 /// </summary>
 /// <param name="fieldIdentifier"></param>
 /// <returns></returns>
 public static string GetDisplayName(this FieldIdentifier fieldIdentifier) => Utility.GetDisplayName(fieldIdentifier.Model, fieldIdentifier.FieldName);
Exemplo n.º 15
0
        /// <summary>
        /// Adds an error message to the message store but without notification for display.
        /// This enables adding multiple messages, e.g. from a foreach loop
        /// </summary>
        /// <param name="model"></param>
        /// <param name="fieldName"></param>
        /// <param name="errMessage"></param>
        public void AddErrorNoNotify(object model, string fieldName, string errMessage)
        {
            var field = new FieldIdentifier(model, fieldName);

            _messageStore.Add(field, errMessage);
        }
Exemplo n.º 16
0
 protected override void OnParametersSet()
 {
     base.OnParametersSet();
     _fieldIdentifier = base.FieldIdentifier;
 }
Exemplo n.º 17
0
        public static NodeDevice StaticBuildHelper(string deviceName, int serialNumber, string code, string typeId,
                                                   int discreteInputs, int discreteOutputs, int analogInputs, int analogOutputs, int stringInputs, int stringOutputs,
                                                   string analogOutputNameOverride, string discreteOutputNameOverride)
        {
            FieldIdentifier c;
            FieldGuid       typ;
            FieldString     address;
            FieldBase64     configuration;
            FieldDeviceName dName;

            c             = new FieldIdentifier(code);
            typ           = new FieldGuid(typeId);
            address       = new FieldString(serialNumber.ToString());
            configuration = new FieldBase64(string.Empty);
            dName         = new FieldDeviceName(deviceName);

            NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName);

            // Add the inputs
            var inputsMutable = new Collection <NodeDiscreteInput>();

            for (int i = 0; i < discreteInputs; i++)
            {
                inputsMutable.Add(NodeDiscreteInput.BuildWith(
                                      new FieldIdentifier(Resources.Strings.Input + i),
                                      new FieldString(i.ToString()),
                                      new FieldSignalName(Resources.Strings.Input + " " + i)));
            }
            var inputs = new ReadOnlyCollection <NodeDiscreteInput>(inputsMutable);

            device = device.NodeDiscreteInputChildren.Append(inputs);

            var analogInputsMutable = new Collection <NodeAnalogInput>();

            for (int i = 0; i < analogInputs; i++)
            {
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.AnalogInput + i),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.AnalogInput + " " + i)));
            }
            device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable));

            var stringInputsMutable = new Collection <NodeStringInput>();

            for (int i = 0; i < stringInputs; i++)
            {
                stringInputsMutable.Add(NodeStringInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.StringInput + i),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.StringInput + " " + i)));
            }
            device = device.NodeStringInputChildren.Append(new ReadOnlyCollection <NodeStringInput>(stringInputsMutable));

            // Add the outputs
            var outputsMutable = new Collection <NodeDiscreteOutput>();

            for (int i = 0; i < discreteOutputs; i++)
            {
                outputsMutable.Add(NodeDiscreteOutput.BuildWith(
                                       new FieldIdentifier(Resources.Strings.Output + i),
                                       new FieldString(i.ToString()),
                                       new FieldSignalName(discreteOutputNameOverride + " " + i)));
            }
            var outputs = new ReadOnlyCollection <NodeDiscreteOutput>(outputsMutable);

            device = device.NodeDiscreteOutputChildren.Append(outputs);

            var analogOutputsMutable = new Collection <NodeAnalogOutput>();

            for (int i = 0; i < analogOutputs; i++)
            {
                analogOutputsMutable.Add(NodeAnalogOutput.BuildWith(
                                             new FieldIdentifier(Resources.Strings.AnalogOutput + i),
                                             new FieldString(i.ToString()),
                                             new FieldSignalName(analogOutputNameOverride + " " + i)));
            }
            device = device.NodeAnalogOutputChildren.Append(new ReadOnlyCollection <NodeAnalogOutput>(analogOutputsMutable));

            var stringOutputsMutable = new Collection <NodeStringOutput>();

            for (int i = 0; i < stringOutputs; i++)
            {
                stringOutputsMutable.Add(NodeStringOutput.BuildWith(
                                             new FieldIdentifier(Resources.Strings.StringOutput + i),
                                             new FieldString(i.ToString()),
                                             new FieldSignalName(Resources.Strings.StringOutput + " " + i)));
            }
            device = device.NodeStringOutputChildren.Append(new ReadOnlyCollection <NodeStringOutput>(stringOutputsMutable));

            return(device);
        }
Exemplo n.º 18
0
 public static Field Unresolved(FieldIdentifier fieldIdentifier, DeclaredType type)
 {
     return new Field(fieldIdentifier, type) { IsResolved = false };
 }
Exemplo n.º 19
0
 protected virtual Type GetEntityType(FieldIdentifier identifier)
 {
     return(identifier.Model.GetType());
 }
Exemplo n.º 20
0
 /// <summary>
 /// Clears the messages for the supplied <see cref="FieldIdentifier"/>.
 /// </summary>
 /// <param name="fieldIdentifier">Field identifier to which messages belong.</param>
 public void Clear(FieldIdentifier fieldIdentifier)
 => messages.Remove(fieldIdentifier);
Exemplo n.º 21
0
 protected virtual IEntityId GetEntityModel(FieldIdentifier identifier)
 {
     return(identifier.Model as IEntityId);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Adds the list of messages and apply it to the field identifier.
 /// </summary>
 /// <param name="fieldIdentifier">Field identifier to which messages belong.</param>
 /// <param name="messages"></param>
 public void Add(FieldIdentifier fieldIdentifier, IEnumerable <ValidationMessageResult> messages)
 => GetOrCreateMessagesListForField(fieldIdentifier).AddRange(messages);
Exemplo n.º 23
0
 public FieldInstructionType(FieldIdentifier language, FieldIdentifier library, FieldIdentifier code)
     : base(
         language.ToString() + SEPARATOR +
         library.ToString() + SEPARATOR +
         code.ToString())
 {
     m_Language = language;
     m_Library  = library;
     m_Code     = code;
 }
        private static UPMStringField CreateStringField(FieldAttributes fieldAttributes, FieldIdentifier fieldIdentifier)
        {
            UPMStringField field;
            var            phoneInExtendedOptions = fieldAttributes?.ExtendedOptions?.ValueOrDefault("phone");

            if (phoneInExtendedOptions != null)
            {
                field = new UPMPhoneField(fieldIdentifier);
                ((UPMPhoneField)field).UseTelprompt = phoneInExtendedOptions == "telprompt";
            }
            else
            {
                field = new UPMStringField(fieldIdentifier);
            }

            return(field);
        }
Exemplo n.º 25
0
        public static NodeDevice StaticBuildHelper(string deviceName, string typeId, Guid instanceId, string code,
                                                   int buttons, int axes, int povhats)
        {
            FieldIdentifier c;
            FieldGuid       typ;
            FieldString     address;
            FieldBase64     configuration;
            FieldDeviceName dName;

            c             = new FieldIdentifier(code);
            typ           = new FieldGuid(typeId);
            address       = new FieldString(instanceId.ToString());
            configuration = new FieldBase64(string.Empty);
            dName         = new FieldDeviceName(deviceName);

            NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName);

            // Add the inputs
            var inputsMutable = new Collection <NodeDiscreteInput>();

            for (int i = 0; i < buttons; i++)
            {
                int buttonNumber = i + 1;
                inputsMutable.Add(NodeDiscreteInput.BuildWith(
                                      new FieldIdentifier(Resources.Strings.Button + buttonNumber),
                                      new FieldString(i.ToString()),
                                      new FieldSignalName(Resources.Strings.Button + " " + buttonNumber)));
            }
            var inputs = new ReadOnlyCollection <NodeDiscreteInput>(inputsMutable);

            device = device.NodeDiscreteInputChildren.Append(inputs);

            var analogInputsMutable = new Collection <NodeAnalogInput>();

            for (int i = 0; i < axes; i++)
            {
                if (i == 3)
                {
                    break;         // only supports up to 3 axes
                }
                int    axisNumber = i + 1;
                string axisName   =
                    axisNumber == 1 ? "X" :
                    axisNumber == 2 ? "Y" :
                    axisNumber == 3 ? "Z" :
                    null;

                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(axisName),
                                            new FieldString(axisName),
                                            new FieldSignalName(axisName)));

                string rotationName = "Rotation" + axisName;
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(rotationName),
                                            new FieldString(rotationName),
                                            new FieldSignalName(rotationName)));
            }
            for (int i = 0; i < povhats; i++)
            {
                int povNumber = i + 1;
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.PoVHat + povNumber.ToString()),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.PoVHat + " " + povNumber.ToString())));
            }
            device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable));

            return(device);
        }
        private UPMGroup AddFieldToDetailGroup(UPMGroup detailGroup, string recordIdentification, FieldIdentifier fieldIdentifier, FieldAttributes fieldAttributes)
        {
            if (detailGroup == null)
            {
                detailGroup = new UPMStandardGroup(this.TabIdentifierForRecordIdentification(recordIdentification));
                ((UPMStandardGroup)detailGroup).ColumnStyle = this.columnStyle;
                detailGroup.LabelText = this.TabLabel;
            }

            var field = new UPMStringField(fieldIdentifier)
            {
                StripNewLines = fieldAttributes.NoMultiLine
            };

            detailGroup.AddField(field);

            return(detailGroup);
        }
Exemplo n.º 27
0
    public void CanUseEmptyFieldName()
    {
        var fieldIdentifier = new FieldIdentifier(new object(), string.Empty);

        Assert.Equal(string.Empty, fieldIdentifier.FieldName);
    }
Exemplo n.º 28
0
 /// <summary>
 ///
 /// </summary>
 protected override void OnInitialized()
 {
     EditForm?.AddValidator((EditForm, FieldIdentifier.Model.GetType(), FieldIdentifier.FieldName), this);
     DisplayName = FieldIdentifier.GetDisplayName();
 }
Exemplo n.º 29
0
 private string GetColumnAttributeStr (int column, FieldIdentifier fieldId)
 {
         OdbcReturn ret = OdbcReturn.Error;
         byte [] buffer = new byte [255];
         int outsize = 0;
         int val = 0;
         ret = libodbc.SQLColAttribute (hstmt, column, fieldId, 
                                        buffer, buffer.Length, 
                                        ref outsize, ref val);
         if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo)
                 throw new OdbcException (new OdbcError ("SQLColAttribute",
                                                         OdbcHandleType.Stmt,
                                                         hstmt)
                                          );
         string value = "";
         if (outsize > 0)
                 value = Encoding.Default.GetString (buffer, 0, outsize);
         return value;
 }
        private static async void ValidatField(EditContext editContext, ValidationMessageStore message, FieldIdentifier fieldIdentifier, IServiceProvider serviceProvider, IValidator validator = null)
        {
            var Proparties = new[] { fieldIdentifier.FieldName };
            var Context    = new ValidationContext(fieldIdentifier.Model, new PropertyChain(), new MemberNameValidatorSelector(Proparties));

            validator = validator ?? GetValidatorForModel(serviceProvider, fieldIdentifier.Model);
            if (validator != null)
            {
                var ValidationResults = await validator.ValidateAsync(Context);

                message.Clear(fieldIdentifier);
                message.Add(fieldIdentifier, ValidationResults.Errors.Select(e => e.ErrorMessage));
                editContext.NotifyValidationStateChanged();
            }
        }
        private static async void ValidateField(EditContext editContext, ValidationMessageStore messages, FieldIdentifier fieldIdentifier, IServiceProvider serviceProvider, IValidator validator = null)
        {
            var properties = new[] { fieldIdentifier.FieldName };
            var context    = new ValidationContext(fieldIdentifier.Model, new PropertyChain(), new MemberNameValidatorSelector(properties));

            if (validator == null)
            {
                validator = GetValidatorForModel(serviceProvider, editContext.Model);
            }

            var validationResults = await validator.ValidateAsync(context);

            messages.Clear(fieldIdentifier);
            messages.AddRange(fieldIdentifier, validationResults.Errors.Select(error => error.ErrorMessage));

            editContext.NotifyValidationStateChanged();
        }
Exemplo n.º 32
0
 /// <summary>
 /// 获取 PlaceHolder 方法
 /// </summary>
 /// <param name="fieldIdentifier"></param>
 /// <returns></returns>
 public static string?GetPlaceHolder(this FieldIdentifier fieldIdentifier) => Utility.GetPlaceHolder(fieldIdentifier.Model, fieldIdentifier.FieldName);
Exemplo n.º 33
0
        public static T GetValue <T>(this FieldIdentifier fi)
        {
            var prop = fi.Model.GetType().GetProperty(fi.FieldName);

            return((T)prop.GetValue(fi.Model));
        }
Exemplo n.º 34
0
		private int GetColumnAttribute (int column, FieldIdentifier fieldId)
		{
			OdbcReturn ret = OdbcReturn.Error;
			byte [] buffer = new byte [255];
			short outsize = 0;
			int val = 0;
			ret = libodbc.SQLColAttribute (hstmt, (short)column, fieldId, 
							buffer, (short)buffer.Length, 
							ref outsize, ref val);
			if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo)
				throw Connection.CreateOdbcException (
					OdbcHandleType.Stmt, hstmt);
			return val;
		}
 private void ClearPreviousParsingMessage(ref bool previousParsingAttemptFailed, FieldIdentifier fieldIdentifier)
 {
     if (previousParsingAttemptFailed)
     {
         previousParsingAttemptFailed = false;
         validationMessageStore.Clear(fieldIdentifier);
         EditContext.NotifyValidationStateChanged();
     }
 }
Exemplo n.º 36
0
		internal static extern OdbcReturn SQLColAttribute (
			IntPtr StmtHandle,
			short column,
			FieldIdentifier fieldId,
			byte [] charAttributePtr,
			short bufferLength,
			ref short strLengthPtr,
			ref int numericAttributePtr);
Exemplo n.º 37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Field"/> class.
 /// </summary>
 /// <param name="identifier">
 /// The identifier.
 /// </param>
 /// <param name="type">
 /// The type.
 /// </param>
 public Field(FieldIdentifier identifier, DeclaredType type)
     : base(identifier)
 {
     this.Type = type;
 }