Field represent an atomic data of a Content
A Field represents an atomic data type from the perspective of the system. It usually handles Fields usually handles a single ContentHandler property. It is also capable of handling of multiple ContentHandler properties (see the WhoAndWhen Field for an example). It may also consist of values computed from the handled ContentHandler propery(s) or even represent data independent of these properties. In the communication bus this atomic data type is resembled as a transfer object: ContentHandler<--properties--> Field <--transfer object--> FieldControl (Content, ContenView) The Field constructs a transfer object from ContentHandler properties and passes it up to the FieldControl. At the same time this tranfer object is disassembled to ContentHandler properties when passing its data down to the ContentHandler. The Field class is responsible for invoking data validation (data validation itself is done by the FieldSetting property). The class Field can be resembled as bridge between ContentHandlerproperties and ContentView (or any other ways of data output/input). The Field class is also one of the most important system extension points (among with ContentHandler). By defining a new Field class a system-wide usable atomic data type is defined. This kind of extension is usually done when having a need of a more complex or different type than ones already defined in the system.
Inheritance: IIndexableField
Ejemplo n.º 1
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            textExtract = String.Empty;
            var value = (string)snField.GetData() ?? String.Empty;

            return(CreateFieldInfo(snField.Name, value));
        }
Ejemplo n.º 2
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            var nodeTypeName = snField.Content.ContentHandler.NodeType.Name.ToLower();

            textExtract = nodeTypeName;
            return(CreateFieldInfo(snField.Name, nodeTypeName));
        }
Ejemplo n.º 3
0
        public override IEnumerable <string> GetParsableValues(SenseNet.ContentRepository.Field snField)
        {
            var value    = snField.GetData();
            var intValue = value == null ? 0 : (int)value;

            return(new[] { intValue.ToString() });
        }
Ejemplo n.º 4
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            var data = (SenseNet.ContentRepository.Fields.HyperLinkField.HyperlinkData)snField.GetData();

            if (data == null)
            {
                textExtract = String.Empty;
                return(null);
            }
            var strings = new List <string>();

            if (data.Href != null)
            {
                strings.Add(data.Href.ToLower());
            }
            if (data.Target != null)
            {
                strings.Add(data.Target.ToLower());
            }
            if (data.Text != null)
            {
                strings.Add(data.Text.ToLower());
            }
            if (data.Title != null)
            {
                strings.Add(data.Title.ToLower());
            }
            textExtract = String.Join(" ", strings.ToArray());
            return(CreateFieldInfo(snField.Name, strings));
        }
Ejemplo n.º 5
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var data = (SenseNet.ContentRepository.Fields.HyperLinkField.HyperlinkData)snField.GetData();

            if (data == null)
            {
                return(null);
            }
            var strings = new List <string>();

            if (data.Href != null)
            {
                strings.Add(data.Href.ToLower());
            }
            if (data.Target != null)
            {
                strings.Add(data.Target.ToLower());
            }
            if (data.Text != null)
            {
                strings.Add(data.Text.ToLower());
            }
            if (data.Title != null)
            {
                strings.Add(data.Title.ToLower());
            }
            return(strings);
        }
Ejemplo n.º 6
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var value     = snField.GetData();
            var boolValue = value == null ? false : (bool)value;

            return(new[] { boolValue?YES : NO });
        }
Ejemplo n.º 7
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var data = snField.GetData() ?? string.Empty;

            var stringData = data as string;

            if (stringData != null)
            {
                return new[] { stringData.ToLower() }
            }
            ;

            var listData = data as IEnumerable <string>;

            if (listData != null)
            {
                return(listData.Select(s => s.ToLower()).ToArray());
            }

            var enumerableData = data as System.Collections.IEnumerable;

            if (enumerableData != null)
            {
                return((from object item in enumerableData select Convert.ToString(item, System.Globalization.CultureInfo.InvariantCulture).ToLower()).ToList());
            }

            return(new[] { string.Empty });
        }
    }
Ejemplo n.º 8
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var value    = snField.GetData();
            var intValue = value == null ? 0 : (int)value;

            return(new[] { intValue.ToString() });
        }
Ejemplo n.º 9
0
        private long SetPrecision(SnCR.Field snField, long ticks)
        {
            var setting = snField.FieldSetting as SenseNet.ContentRepository.Fields.DateTimeFieldSetting;

            SenseNet.ContentRepository.Fields.DateTimePrecision?precision = null;
            if (setting != null)
            {
                precision = setting.Precision;
            }
            if (precision == null)
            {
                precision = SenseNet.ContentRepository.Fields.DateTimeFieldSetting.DefaultPrecision;
            }

            switch (precision.Value)
            {
            case SenseNet.ContentRepository.Fields.DateTimePrecision.Millisecond:
                return(ticks / TimeSpan.TicksPerMillisecond * TimeSpan.TicksPerMillisecond);

            case SenseNet.ContentRepository.Fields.DateTimePrecision.Second:
                return(ticks / TimeSpan.TicksPerSecond * TimeSpan.TicksPerSecond);

            case SenseNet.ContentRepository.Fields.DateTimePrecision.Minute:
                return(ticks / TimeSpan.TicksPerMinute * TimeSpan.TicksPerMinute);

            case SenseNet.ContentRepository.Fields.DateTimePrecision.Hour:
                return(ticks / TimeSpan.TicksPerHour * TimeSpan.TicksPerHour);

            case SenseNet.ContentRepository.Fields.DateTimePrecision.Day:
                return(ticks / TimeSpan.TicksPerDay * TimeSpan.TicksPerDay);

            default:
                throw new NotImplementedException("Unknown DateTimePrecision: " + precision.Value);
            }
        }
Ejemplo n.º 10
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            var data = snField.GetData() as string;

            textExtract = data == null ? String.Empty : data;
            return(CreateFieldInfo(snField.Name, textExtract));
        }
Ejemplo n.º 11
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var value      = (string)snField.GetData() ?? String.Empty;
            var parentPath = RepositoryPath.GetParentPath(value.ToLower()) ?? "/";

            return(new[] { parentPath.ToLower() });
        }
Ejemplo n.º 12
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            var data = snField.GetData() as SenseNet.ContentRepository.Storage.BinaryData;

            textExtract = data == null ? String.Empty : SenseNet.Search.TextExtractor.GetExtract(data, snField.Content.ContentHandler);
            return(CreateFieldInfo(snField.Name, textExtract));
        }
Ejemplo n.º 13
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SenseNet.ContentRepository.Field snField, out string textExtract)
        {
            var data        = snField.GetData();
            var stringValue = data == null ? String.Empty : data.ToString().ToLower();

            textExtract = stringValue;
            return(CreateFieldInfo(snField.Name, stringValue));
        }
Ejemplo n.º 14
0
 public override FieldValidationResult ValidateData(object value, Field field)
 {
     int intValue = (int)value;
     if (this.EvenOnly != null)
         if (intValue % 2 != 0)
             return new FieldValidationResult(EvenOnlyName);
     return base.ValidateData(value, field);
 }
Ejemplo n.º 15
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var value        = snField.GetData();
            var decimalValue = value == null ? (Decimal)0.0 : (Decimal)value;
            var doubleValue  = Convert.ToDouble(decimalValue);

            return(new[] { decimalValue.ToString(System.Globalization.CultureInfo.InvariantCulture) });
        }
Ejemplo n.º 16
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            textExtract = String.Empty;
            var nodeType = snField.Content.ContentHandler.NodeType;
            var types    = nodeType.NodeTypePath.Split('/').Select(p => p.ToLower());

            return(CreateFieldInfo(snField.Name, types));
        }
Ejemplo n.º 17
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            textExtract = String.Empty;
            var data  = snField.GetData();
            var ticks = data == null ? 0 : ((DateTime)data).Ticks;

            return(CreateFieldInfo(snField.Name, SetPrecision(snField, ticks)));
        }
Ejemplo n.º 18
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            var value     = snField.GetData();
            var boolValue = value == null ? false : (bool)value;

            textExtract = String.Empty;
            return(CreateFieldInfo(snField.Name, boolValue ? YES : NO));
        }
Ejemplo n.º 19
0
 internal static FieldParsingException GetException(Field field, Exception innerException)
 {
     string msg = String.Concat(
         "Field parsing error. Content: ", field.Content.Path,
         ", Field: ", field.Name,
         ", FieldType: ", field.FieldSetting.ShortName,
         ", field value type: ", field.FieldSetting.HandlerSlots[0][field.FieldSetting.HandlerSlotIndices[0]].FullName);
     return innerException == null ? new FieldParsingException(msg) : new FieldParsingException(msg, innerException);
 }
Ejemplo n.º 20
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            var value        = snField.GetData();
            var decimalValue = value == null ? (Decimal)0.0 : (Decimal)value;
            var doubleValue  = Convert.ToDouble(decimalValue);

            textExtract = decimalValue.ToString(System.Globalization.CultureInfo.InvariantCulture);
            return(CreateFieldInfo(snField.Name, doubleValue));
        }
Ejemplo n.º 21
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            var value = (string)snField.GetData() ?? String.Empty;

            textExtract = value.ToLower();
            var parentPath = RepositoryPath.GetParentPath(textExtract) ?? "/";

            return(CreateFieldInfo(snField.Name, parentPath));
        }
Ejemplo n.º 22
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var snFieldValue = (string)snField.GetData();

            if (String.IsNullOrEmpty(snFieldValue))
            {
                return(null);
            }
            snFieldValue = snFieldValue.ToLower();
            var terms = snFieldValue.Split(",;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(w => w.Trim()).ToArray();

            return(terms);
        }
Ejemplo n.º 23
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var path      = (string)snField.GetData() ?? String.Empty;
            var separator = "/";

            string[] fragments = path.ToLower().Split(separator.ToCharArray(), StringSplitOptions.None);
            string[] pathSteps = new string[fragments.Length];
            for (int i = 0; i < fragments.Length; i++)
            {
                pathSteps[i] = string.Join(separator, fragments, 0, i + 1);
            }
            return(pathSteps);
        }
Ejemplo n.º 24
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            textExtract = String.Empty;

            var snFieldValue = (string[])snField.GetData();

            if (snFieldValue == null || snFieldValue.Length == 0)
            {
                return(CreateFieldInfo(snField.Name, string.Empty));
            }

            var terms = snFieldValue.Select(x => x.ToLowerInvariant()).ToArray();

            return(CreateFieldInfo(snField.Name, terms));
        }
Ejemplo n.º 25
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            var value    = snField.GetData();
            var intValue = 0;

            try
            {
                intValue = value == null ? 0 : (int)value;
            }
            catch (Exception e)
            {
                Logger.WriteVerbose(String.Format("IntegerIndexHandler ERROR: content: {0} field: {1}, value: {2}", snField.Content.Path, snField.Name, value));
                throw;
            }
            textExtract = intValue.ToString();
            return(CreateFieldInfo(snField.Name, intValue));
        }
Ejemplo n.º 26
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            string className, name;

            if (SenseNetResourceManager.Running && snField.LocalizationEnabled && snField.IsLocalized && SenseNetResourceManager.ParseResourceKey(snField.GetStoredValue(), out className, out name))
            {
                var strings = SenseNetResourceManager.Current.GetStrings(className, name);
                textExtract = string.Join(" ", strings);
                return(CreateFieldInfo(snField.Name, strings));
            }
            var data        = snField.GetData();
            var stringValue = data == null ? String.Empty : data.ToString().ToLower();

            textExtract = stringValue;

            return(CreateFieldInfo(snField.Name, stringValue));
        }
Ejemplo n.º 27
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SnCR.Field snField, out string textExtract)
        {
            textExtract = String.Empty;
            var data = snField.GetData();
            var node = data as Node;

            if (node != null)
            {
                return(CreateFieldInfo(snField.Name, node.Id.ToString()));
            }
            var nodes = data as System.Collections.IEnumerable;

            if (nodes != null)
            {
                return(CreateFieldInfo(snField.Name, nodes.Cast <Node>().Select(n => n.Id.ToString())));
            }
            return(CreateFieldInfo(snField.Name, LucQuery.NullReferenceValue));
        }
Ejemplo n.º 28
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(SenseNet.ContentRepository.Field snField, out string textExtract)
        {
            textExtract = String.Empty;
            var data = snField.GetData();
            var node = data as Node;

            if (node != null)
            {
                return(CreateFieldInfo(snField.Name, node.Id.ToString()));
            }
            var nodes = data as System.Collections.IEnumerable;

            if (nodes != null)
            {
                return(CreateFieldInfo(snField.Name, nodes.Cast <Node>().Select(n => n.Id.ToString())));
            }
            return(null);
        }
Ejemplo n.º 29
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var data = snField.GetData();
            var node = data as Node;

            if (node != null)
            {
                return new[] { node.Id.ToString() }
            }
            ;
            var nodes = data as System.Collections.IEnumerable;

            if (nodes != null)
            {
                return(nodes.Cast <Node>().Select(n => n.Id.ToString()));
            }
            return(null);
        }
    }
Ejemplo n.º 30
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var data = snField.GetData();

            try
            {
                var dateData = Convert.ToDateTime(data);
                if (dateData != DateTime.MinValue)
                {
                    return new[] { "'" + dateData.ToString("yyyy.MM.dd HH:mm:ss") + "'" }
                }
                ;
            }
            catch (Exception ex)
            {
                Logger.WriteInformation(Logger.EventId.NotDefined, ex);
            }
            return(new[] { string.Empty });
        }
Ejemplo n.º 31
0
        public override IEnumerable <string> GetParsableValues(SenseNet.ContentRepository.Field snField)
        {
            var data = snField.GetData();

            try
            {
                var dateData = Convert.ToDateTime(data);
                if (dateData != DateTime.MinValue)
                {
                    return new[] { "'" + dateData.ToString("yyyy.MM.dd hh:mm:ss") + "'" }
                }
                ;
            }
            catch (Exception ex)
            {
                Logger.WriteInformation(ex);
            }
            return(new[] { string.Empty });
        }
Ejemplo n.º 32
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var content   = snField.Content;
            var boolValue = false;

            //check Trash
            if (TrashBin.IsInTrash(content.ContentHandler as GenericContent))
            {
                boolValue = true;
            }

            //check SystemFile
            if (!boolValue)
            {
                if (content.ContentHandler.NodeType.IsInstaceOfOrDerivedFrom("SystemFile"))
                {
                    boolValue = true;
                }
            }

            //check SystemFolder
            if (!boolValue)
            {
                var parent = content.ContentHandler;

                using (new SystemAccount())
                {
                    while (parent != null)
                    {
                        if (parent.NodeType.IsInstaceOfOrDerivedFrom("SystemFolder"))
                        {
                            boolValue = true;
                            break;
                        }

                        parent = parent.Parent;
                    }
                }
            }

            return(new[] { boolValue?BooleanIndexHandler.YES : BooleanIndexHandler.NO });
        }
Ejemplo n.º 33
0
        protected virtual string SetEmptyFieldValue(ContentSearchPortlet.EmptyQueryTermHandler mode, Field field)
        {
            if (mode == ContentSearchPortlet.EmptyQueryTermHandler.ReplaceToWildcard)
            {
                if(field is DateTimeField)
                    return string.Format("{{{0} TO {1}}}", DateTime.MinValue, DateTime.MaxValue);
                if(field is IntegerField)
                    return string.Format("{{{0} TO {1}}}", int.MinValue, int.MaxValue);
                return "*";
            }

            if (mode == ContentSearchPortlet.EmptyQueryTermHandler.RemoveEmpty)
                return ContentQuery.EmptyText;

            return string.Empty;
        }
Ejemplo n.º 34
0
        public static FieldControl CreateDefaultFieldControl(Field field)
        {
            FieldControl control = null;

            var choiceSetting = field.FieldSetting as ChoiceFieldSetting;
            var longTextSetting = field.FieldSetting as LongTextFieldSetting;
            var dateTimeFieldSetting = field.FieldSetting as DateTimeFieldSetting;
            string hint = field.FieldSetting.ControlHint;

            if (!string.IsNullOrEmpty(hint))
                control = CreateFieldControlByHint(hint);
            //choice field?
            else if (choiceSetting != null)
                control = CreateDefaultChoiceControl(choiceSetting);
            //longtext field?
            else if (longTextSetting != null)
                control = CreateDefaultLongTextControl(longTextSetting);
            //datetime field?
            else if (dateTimeFieldSetting != null)
                control = CreateDefaultDateTimeControl(dateTimeFieldSetting);

            //generic way, also a fallback logic if we don't have a field control by now
            if (control == null)
            {
                Type controlType = null;

                if (!ControlTable.TryGetValue(field.FieldSetting.ShortName, out controlType))
                    throw new ApplicationException(String.Concat("Cannot resolve the generic field control by '", field.GetType().FullName, "'"));

                control = (FieldControl)Activator.CreateInstance(controlType);
            }

            if (control == null)
                throw new ApplicationException(string.Concat("Failed to instantiate a field control for field ", field.Name));

            control.FieldName = field.Name;
            control.DoAutoConfigure(field.FieldSetting);

            return control;
        }
Ejemplo n.º 35
0
        private void AddFieldControl(ContentView cv, Field field)
        {
            if (field == null)
                return;
            if (field.FieldSetting.FieldClassName == typeof(PageBreakField).ToString())
            {
                currentPage++;
                return;
            }

            Control control = CreateDefaultFieldControl(field);

            var fieldControl = control as FieldControl;
            if (IsReadOnly(field.Name) && fieldControl != null)
                fieldControl.ReadOnly = true;

            if (fieldControl != null)
                fieldControl.FrameMode = FieldControlFrameMode.ShowFrame;

            control.ID = String.Concat("Generic", _id++);

            var visibility = GetFieldVisibility(cv.ViewMode, field);

            if (!EnablePaging)
            {
                if (visibility == FieldVisibility.Advanced && AdvancedPanel != null)
                {
                    AdvancedPanel.Controls.Add(control);
                }
                else
                {
                    Controls.Add(control);
                }
            }
            else
            {
                _wizard.WizardSteps[currentPage].Controls.Add(control);
            }
        }
Ejemplo n.º 36
0
 public static void SetDataToFiled(Field field, string value)
 {
     switch (field.FieldSetting.ShortName)
     {
         case "Integer":
             field.SetData(int.Parse(value));
             break;
         case "Boolean":
             field.SetData(bool.Parse(value));
             break;
         case "DateTime":
             field.SetData(DateTime.Parse(value));
             break;
         case "ShortText":
         case "LongText":
         default:
             field.SetData(value);
             break;
     }
 }
Ejemplo n.º 37
0
        public static FieldVisibility GetFieldVisibility(ViewMode viewMode, Field field)
        {
            if (field == null)
                return FieldVisibility.Show;

            switch (viewMode)
            {
                case ViewMode.Browse:
                    return field.FieldSetting.VisibleBrowse;
                case ViewMode.Edit:
                case ViewMode.InlineEdit:
                    return field.FieldSetting.VisibleEdit;
                case ViewMode.New:
                case ViewMode.InlineNew:
                    return field.FieldSetting.VisibleNew;
                default:
                    return FieldVisibility.Show;
            }
        }
Ejemplo n.º 38
0
 internal static FieldParsingException GetException(Field field)
 {
     return GetException(field, null);
 }