Example #1
0
 public void Enum <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions = FieldOptions.None)
 #if USE_ENUM_CONSTRAINT
     where T : Enum
 #else
     where T : struct, IConvertible
 #endif // USE_ENUM_CONSTRAINT
 {
     DoSerialize <T>(inKey, ref ioData, inDefault, inOptions, Read_Enum <T>, Write_Enum <T>);
 }
Example #2
0
        /// <summary>
        /// Returns all fields that have the supplied set of options.
        /// </summary>
        /// <param name="contract">The contract to return the fields from.</param>
        /// <param name="option">The option to return the fields with.</param>
        /// <returns>The list of fields that have the given option.</returns>
        public static IEnumerable<IField> Fields(this IContract contract, FieldOptions option)
        {
            if (contract == null)
            {
                throw new ArgumentNullException(nameof(contract));
            }

            return contract.Fields.Where(field => field.Is(option)).ToList();
        }
Example #3
0
 public void EnumArray <T>(string inKey, ref List <T> ioArray, FieldOptions inOptions = FieldOptions.None)
 #if USE_ENUM_CONSTRAINT
     where T : Enum
 #else
     where T : struct, IConvertible
 #endif // USE_ENUM_CONSTRAINT
 {
     DoArray <T>(inKey, ref ioArray, inOptions, Read_Enum <T>, Write_Enum <T>);
 }
Example #4
0
        /// <summary>
        /// Returns a value indicating whether or not the field adheres to the list of specified options.
        /// </summary>
        /// <param name="field">The field to test the options against.</param>
        /// <param name="options">The list of options to test on the field.</param>
        /// <returns>true if the field contains the list of options, false if not.</returns>
        public static bool Is(this IField field, FieldOptions options)
        {
            if (field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            return (field.Options & options) == options;
        }
Example #5
0
        public void AddField(string field, TextReader indexedValue = null, string storedValue = null, FieldOptions options = FieldOptions.None)
        {
            if (storedValue != null)
            {
                var num = _parent.GetFieldNumber(field);
                _binaryWriter.Write(num);
                _binaryWriter.Write(storedValue);
                _currentStoredCount++;
            }

            if (indexedValue == null)
            {
                if (storedValue == null)
                    throw new ArgumentException("It isn't meaningful to pass null for both indexedValue and storedValue");
                return;
            }

            _source = _analyzer.CreateTokenSource(field, _source);
            _source.SetReader(indexedValue);
            while (_source.Next())
            {
                if (options.HasFlag(FieldOptions.NoAnalyzer) == false)
                {
                    if (_analyzer.Process(field, _source) == false)
                        continue;
                }

                var byteCount = Encoding.UTF8.GetByteCount(_source.Buffer, 0, _source.Size);
                var bytes = _bufferPool.Take(byteCount);
                Encoding.UTF8.GetBytes(_source.Buffer, 0, _source.Size, bytes, 0);
                Debug.Assert(byteCount < ushort.MaxValue);
                _currentTermCount++;

                var key = Tuple.Create(field, new ArraySegmentKey<byte>(bytes, byteCount));

                TermInfo info;
                if (_currentTerms.TryGetValue(key, out info))
                {
                    _bufferPool.Return(bytes);
                }
                else
                {
                    _currentTerms[key] = info = new TermInfo {Boost = 1.0f};
                    _usedBuffers.Add(bytes);
                }

                info.Freq++;

                if (options.HasFlag(FieldOptions.TermPositions))
                {
                    if (info.Positions == null)
                        info.Positions = new List<int>();
                    info.Positions.Add(_source.Position);
                }
            }
        }
Example #6
0
        public void CustomMap <T>(string inKey, ref Dictionary <int, T> ioMap, FieldOptions inOptions = FieldOptions.None)
        {
            var serializer = TypeUtility.CustomSerializer <T>();

            if (serializer == null)
            {
                AddErrorMessage("No serialization function registered for type '{0}'.", typeof(T).Name);
                return;
            }

            DoStructMap(inKey, ref ioMap, inOptions, serializer);
        }
Example #7
0
 public void SetFieldOptions(int VelDegree, int LevSetDegree, FieldOpts.SaveToDBOpt SaveFilteredVelocity = FieldOpts.SaveToDBOpt.TRUE, FieldOpts.SaveToDBOpt SaveCurvature = FieldOpts.SaveToDBOpt.TRUE)
 {
     FieldOptions.Add(VariableNames.VelocityX, new FieldOpts()
     {
         Degree   = VelDegree,
         SaveToDB = FieldOpts.SaveToDBOpt.TRUE
     });
     FieldOptions.Add(VariableNames.VelocityY, new FieldOpts()
     {
         Degree   = VelDegree,
         SaveToDB = FieldOpts.SaveToDBOpt.TRUE
     });
     FieldOptions.Add("FilteredVelocityX", new FieldOpts()
     {
         SaveToDB = SaveFilteredVelocity
     });
     FieldOptions.Add("FilteredVelocityY", new FieldOpts()
     {
         SaveToDB = SaveFilteredVelocity
     });
     FieldOptions.Add("SurfaceForceDiagnosticX", new FieldOpts()
     {
         SaveToDB = FieldOpts.SaveToDBOpt.FALSE
     });
     FieldOptions.Add("SurfaceForceDiagnosticY", new FieldOpts()
     {
         SaveToDB = FieldOpts.SaveToDBOpt.FALSE
     });
     FieldOptions.Add(VariableNames.Pressure, new FieldOpts()
     {
         Degree   = VelDegree - 1,
         SaveToDB = FieldOpts.SaveToDBOpt.TRUE
     });
     FieldOptions.Add("PhiDG", new FieldOpts()
     {
         SaveToDB = FieldOpts.SaveToDBOpt.TRUE
     });
     FieldOptions.Add("Phi", new FieldOpts()
     {
         Degree   = LevSetDegree,
         SaveToDB = FieldOpts.SaveToDBOpt.TRUE
     });
     FieldOptions.Add("Curvature", new FieldOpts()
     {
         Degree   = LevSetDegree * 2,
         SaveToDB = SaveCurvature
     });
     FieldOptions.Add(VariableNames.Temperature, new FieldOpts()
     {
         Degree   = VelDegree,
         SaveToDB = FieldOpts.SaveToDBOpt.TRUE
     });
 }
Example #8
0
        public void CustomArray <T>(string inKey, ref T[] ioArray, FieldOptions inOptions = FieldOptions.None)
        {
            var serializer = TypeUtility.CustomSerializer <T>();

            if (serializer == null)
            {
                AddErrorMessage("No serialization function registered for type '{0}'.", typeof(T).Name);
                return;
            }

            DoStructArray(inKey, ref ioArray, inOptions, serializer);
        }
Example #9
0
        /// <summary>
        /// Writes a value onto the current array.
        /// </summary>
        private void DoWriteUnity <T>(ref T ioData, FieldOptions inOptions, WriteFunc <T> inWriter) where T : UnityEngine.Object
        {
            if (ioData == null)
            {
                WriteNull();
                return;
            }

            BeginWriteValue();
            inWriter(ref ioData);
            EndValue();
        }
Example #10
0
        public static string Select <T>(ISqlDialect dialect, FieldOptions fields, ProjectionOptions projections)
        {
            return(StringBuilderPool.Scoped(sb =>
            {
                // SELECT * FROM ...
                sb.Append($"SELECT {BuildFields<T>(dialect, fields, projections)} " +
                          $"FROM {dialect.StartIdentifier}{typeof(T).Name}{dialect.EndIdentifier} r ");

                if (projections?.Fields == null)
                {
                    return;
                }

                // INNER JOIN...
                var joins = 0;
                foreach (var projection in projections.Fields)
                {
                    var name = projection.Field.ToTitleCase();
                    if (name.EndsWith("s"))
                    {
                        name = name.Substring(0, name.Length - 1);
                    }

                    switch (projection.Type)
                    {
                    case ProjectionType.OneToOne:
                        /*
                         *  INNER JOIN Role r0 ON r0.Id = x0.RoleId
                         */
                        sb.Append($"INNER JOIN {name} r{joins} ON r{joins}.Id = x{joins}.{name}Id ");
                        break;

                    case ProjectionType.OneToMany:
                        /*
                         *  INNER JOIN UserRole x0 ON x0.UserId = r.Id
                         *  INNER JOIN Role r0 ON r0.Id = x0.RoleId
                         */
                        sb.Append(
                            $"INNER JOIN {typeof(T).Name}{name} x{joins} ON x{joins}.{typeof(T).Name}Id = r.Id ");
                        sb.Append($"INNER JOIN {name} r{joins} ON r{joins}.Id = x{joins}.{name}Id ");
                        break;

                    case ProjectionType.Scalar:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    joins++;
                }
            }));
        }
Example #11
0
        public void Custom <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions = FieldOptions.None)
        {
            var serializer = TypeUtility.CustomSerializer <T>();

            if (serializer == null)
            {
                AddErrorMessage("No serialization function registered for type '{0}'.", typeof(T).Name);
                return;
            }

            DoCustom(inKey, ref ioData, inDefault, inOptions, serializer);
        }
Example #12
0
 /// <summary>
 /// Writes an object into the current object.
 /// </summary>
 private void DoWriteStruct <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer) where T : struct
 {
     if (!EqualityComparer <T> .Default.Equals(ioData, inDefault))
     {
         BeginWriteObject(inKey);
         Write_Struct(ref ioData, inSerializer);
         EndObject();
     }
     else if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull())
     {
         WriteNull(inKey);
     }
 }
Example #13
0
        public void FindByNameReturnsNullIfNoMatchingField()
        {
            var doc     = new Document();
            var result1 = doc.FindByName("No Found");
            var fi      = new FieldOptions(StoreOptions.STORED, IndexOptions.Analyzed, TermVectorOptions.STORED);
            var field1  = new Field("Test", fi, new FieldSource <string>("Test Field Source"));

            doc.Add(field1);
            var result2 = doc.FindByName("No Found");

            Verify.That(result1).IsNull();
            Verify.That(result2).IsNull();
        }
Example #14
0
        public virtual async Task <Operation <Person> > GetAsync(long id, FieldOptions fields = null, ProjectionOptions projection = null)
        {
            _db.SetTypeInfo(typeof(Person));

            var getById = DefaultFilter;

            getById.Fields[0].Value = id;

            var sql  = _dialect.Build <Person>(fields: fields, filter: DefaultFilter, projections: projection);
            var data = await _db.Current.QuerySingleOrDefaultAsync <Person>(sql, new { id });

            return(new Operation <Person>(data));
        }
Example #15
0
        public void FindByNameReturnsFirstAdded()
        {
            var doc    = new Document();
            var fi     = new FieldOptions(StoreOptions.STORED, IndexOptions.Analyzed, TermVectorOptions.STORED);
            var field1 = new Field("Test", fi, new FieldSource <string>("Test Field Source1"));
            var field2 = new Field("Test", fi, new FieldSource <string>("Test Field Source2"));

            doc.Add(field1);
            doc.Add(field2);

            Verify.That(doc.Count).Equals(2);
            Verify.That(doc.FindByName("Test")).IsTheSameObjectAs(field1);
        }
        /// <summary>
        /// Sets the given options for the field.
        /// </summary>
        /// <param name="options">The list of options to set.</param>
        /// <param name="setOptionOn">true if the options are to be set, false if not.</param>
        /// <returns>The relationship builder to continue building on.</returns>
        protected RelationshipBuilder <T> Options(FieldOptions options, bool setOptionOn = true)
        {
            if (setOptionOn)
            {
                Instance.Options |= options;
            }
            else
            {
                Instance.Options &= ~(options);
            }

            return(this);
        }
Example #17
0
 /// <summary>
 /// Writes an object into the current object.
 /// </summary>
 private void DoWriteCustom <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer)
 {
     if (ioData != null && !ioData.Equals(inDefault))
     {
         BeginWriteObject(inKey);
         Write_Custom(ref ioData, inSerializer);
         EndValue();
     }
     else if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull())
     {
         WriteNull(inKey);
     }
 }
Example #18
0
 /// <summary>
 /// Writes a value into the current object, substituting null if default.
 /// </summary>
 private void DoWrite <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions, WriteFunc <T> inWriter)
 {
     if (ioData != null && !ioData.Equals(inDefault))
     {
         BeginWriteValue(inKey, inOptions);
         inWriter(ref ioData);
         EndValue();
     }
     else if (RequiresExplicitNull())
     {
         WriteNull(inKey);
     }
 }
Example #19
0
 /// <summary>
 /// Writes a value onto the current array, substituting null if default.
 /// </summary>
 private void DoWrite <T>(ref T ioData, T inDefault, FieldOptions inOptions, WriteFunc <T> inWriter)
 {
     if (ioData != null && !ioData.Equals(inDefault))
     {
         BeginWriteValue();
         inWriter(ref ioData);
         EndValue();
     }
     else
     {
         WriteNull();
     }
 }
Example #20
0
 /// <summary>
 /// Writes a value onto the current array.
 /// </summary>
 private void DoWrite <T>(ref T ioData, FieldOptions inOptions, WriteFunc <T> inWriter)
 {
     if (ioData != null)
     {
         BeginWriteValue();
         inWriter(ref ioData);
         EndValue();
     }
     else
     {
         WriteNull();
     }
 }
Example #21
0
        public void FindByNameReturnEmptyListIfNoMatchingField()
        {
            var doc     = new Document();
            var result1 = doc.FindAllByName("Not Found");
            var fi      = new FieldOptions(StoreOptions.STORED, IndexOptions.Analyzed, TermVectorOptions.STORED);
            var field1  = new Field("Test", fi, new FieldSource <string>("Test Field Source1"));

            doc.Add(field1);
            var result2 = doc.FindAllByName("Not Found");

            Verify.That(result1).IsACollectionThat().Count().IsEqualTo(0);
            Verify.That(result2).IsACollectionThat().Count().IsEqualTo(0);
        }
Example #22
0
        /// <summary>
        /// Sets the given options for the field.
        /// </summary>
        /// <param name="options">The list of options to set.</param>
        /// <param name="setOptionOn">true if the options are to be set, false if not.</param>
        /// <returns>The field builder to continue building on.</returns>
        internal FieldBuilder <T> Options(FieldOptions options, bool setOptionOn = true)
        {
            if (setOptionOn)
            {
                Instance.Options |= options;
            }
            else
            {
                Instance.Options &= ~(options);
            }

            return(this);
        }
        public void UpdateFieldOption(FieldOptions fieldOption)
        {
            var fieldOptionFromDb = _fieldOptionsRepository.Get(fieldOption.Id);

            if (fieldOptionFromDb != null)
            {
                _util.CopyProperties(fieldOption, fieldOptionFromDb);
                _fieldOptionsRepository.Update(fieldOptionFromDb);
            }
            else
            {
                throw new Exception("This field option does not exist");
            }
        }
        public int GetFieldOptions(uint fieldID, out FieldOptions options)
        {
            options = FieldOptions.None;

            var control = Globals.GetControlFromID(fieldID);

            if (control != null && control is IStringControl stringControl)
            {
                options = stringControl.Options;
                return(HRESULT.S_OK);
            }

            return(HRESULT.E_INVALIDARG);
        }
Example #25
0
        public async Task <Operation <TObject> > GetAsync(long id, FieldOptions fields = null,
                                                          ProjectionOptions projection = null)
        {
            _db.SetTypeInfo(typeof(TObject));

            var getById = FilterOptions.FromType <TObject>(x => x.Id);

            getById.Fields[0].Value = id;

            var sql  = _dialect.Build <TObject>(fields: fields, filter: getById, projections: projection);
            var data = await _db.Current.QuerySingleOrDefaultAsync <TObject>(sql, new { id });

            return(new Operation <TObject>(data));
        }
Example #26
0
        public void ReadFile(string filePath)
        {
            var lines = File.ReadAllLines(filePath);

            foreach (var line in lines)
            {
                int    position = 0;
                T      t        = new T();
                string value    = string.Empty;

                foreach (PropertyInfo prop in t.GetType().GetProperties())
                {
                    FieldOptions options = new FieldOptions();

                    var attributes = prop.GetCustomAttributes();

                    foreach (var attribute in attributes)
                    {
                        if (attribute is FieldOptions)
                        {
                            var attrib = attribute as FieldOptions;
                            options.FieldWidth = attrib.FieldWidth;
                            options.TrimType   = attrib.TrimType;
                        }
                    }

                    // Index within bounds
                    if (line.Length >= position + options.FieldWidth)
                    {
                        value = Trim(options.TrimType, line.Substring(position, options.FieldWidth));
                    }

                    // Index out of bounds, get as much as possible
                    else if (line.Length >= position)
                    {
                        value = Trim(options.TrimType, line.Substring(position, line.Length - position));
                    }
                    else
                    {
                        throw new Exception($"Not enough characters in line. Expected length >= {position}. Line: {line}");
                    }

                    t.GetType().GetProperty(prop.Name).SetValue(t, value);
                    position += options.FieldWidth;
                }

                FieldList.Enqueue(t);
            }
        }
Example #27
0
        /// <summary>
        /// Reads a value from the current node.
        /// </summary>
        private bool DoReadAsset <T>(string inKey, ref T ioData, FieldOptions inOptions) where T : class
        {
            bool bSuccess = BeginReadValue(inKey);

            if (IsMissing())
            {
                if ((inOptions & FieldOptions.Optional) != 0)
                {
                    ioData   = null;
                    bSuccess = true;
                }
                else
                {
                    bSuccess &= false;
                }
            }
            else if (IsNull())
            {
                ioData   = null;
                bSuccess = true;
            }
            else
            {
                string id         = string.Empty;
                bool   bIdSuccess = Read_String(ref id);
                bSuccess &= bIdSuccess;

                if (!bIdSuccess)
                {
                    AddErrorMessage("No id present");
                }
                else if (Context == null)
                {
                    AddErrorMessage("No context available to resolve asset {0} with id {1}", typeof(T).FullName, id);
                }
                else
                {
                    bool bResolveSuccess = Context.TryResolveAsset(id, out ioData);
                    bSuccess &= bResolveSuccess;
                    if (!bResolveSuccess)
                    {
                        AddErrorMessage("Unable to resolve asset {0} with id {1}", typeof(T).FullName, id);
                    }
                }
            }
            EndValue();

            return(bSuccess);
        }
Example #28
0
        /// <summary>
        /// Writes a value into the current object.
        /// </summary>
        private void DoWriteUnity <T>(string inKey, ref T ioData, FieldOptions inOptions, WriteFunc <T> inWriter) where T : UnityEngine.Object
        {
            if (ioData == null)
            {
                if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull())
                {
                    WriteNull(inKey);
                }
                return;
            }

            BeginWriteValue(inKey, inOptions);
            inWriter(ref ioData);
            EndValue();
        }
Example #29
0
        public void Object <T>(string inKey, ref T ioData, FieldOptions inOptions = FieldOptions.None) where T : ISerializedObject
        {
            if (IsReading)
            {
                bool bSuccess = DoReadObject <T>(inKey, ref ioData, inOptions);

                if (!bSuccess)
                {
                    AddErrorMessage("Unable to read object '{0}'.", inKey);
                }
                return;
            }

            DoWriteObject <T>(inKey, ref ioData, inOptions);
        }
Example #30
0
        private void DoCustom <T>(string inKey, ref T ioData, T inDefault, FieldOptions inOptions, TypeUtility.TypeSerializerDelegate <T> inSerializer)
        {
            if (IsReading)
            {
                bool bSuccess = DoReadCustom <T>(inKey, ref ioData, inDefault, inOptions, inSerializer);

                if (!bSuccess)
                {
                    AddErrorMessage("Unable to read struct '{0}'.", inKey);
                }
                return;
            }

            DoWriteCustom <T>(inKey, ref ioData, inDefault, inOptions, inSerializer);
        }
        public IWebDriver TestFixtureSetUp(string Bname, string testCaseName)
        {
            driver = StartBrowser(Bname);
            Common.CurrentDriver = driver;
            Results.WriteTestSuiteHeading(typeof(TestSuite02_Reskin_FieldOptions).Name);
            starttest(Bname + " - " + testCaseName, typeof(TestSuite02_Reskin_FieldOptions).Name);

            loginPage    = new Login(driver, test);
            homePage     = new Home(driver, test);
            searchPage   = new Search(driver, test);
            fieldOptions = new FieldOptions(driver, test);
            userProfile  = new UserProfile(driver, test);

            return(driver);
        }
Example #32
0
        /// <summary>
        /// Writes an object into the current object.
        /// </summary>
        private void DoWriteObject <T>(string inKey, ref T ioData, FieldOptions inOptions) where T : ISerializedObject
        {
            if (ioData == null)
            {
                if ((inOptions & FieldOptions.Optional) == 0 || RequiresExplicitNull())
                {
                    WriteNull(inKey);
                }
                return;
            }

            BeginWriteObject(inKey);
            Write_Object(ref ioData);
            EndValue();
        }
Example #33
0
        /// <summary>
        /// DG degree of Level-Set is hard-coded to 2.
        /// </summary>
        /// <param name="p"></param>
        public override void SetDGdegree(int p)
        {
            FieldOptions.Clear();

            FieldOptions.Add("Phi", new FieldOpts()
            {
                Degree   = Math.Max(2, p),
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });

            FieldOptions.Add("u", new FieldOpts()
            {
                Degree   = p,
                SaveToDB = FieldOpts.SaveToDBOpt.TRUE
            });
        }
 /// <summary>Helper: Serialize with a varint length prefix</summary>
 public static void SerializeLengthDelimited(Stream stream, FieldOptions instance)
 {
     var data = SerializeToBytes(instance);
     global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, (uint)data.Length);
     stream.Write(data, 0, data.Length);
 }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, FieldOptions instance)
        {
            if (instance.Ctype != CType.STRING)
            {
                // Key for field: 1, Varint
                stream.WriteByte(8);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.Ctype);
            }
            // Key for field: 2, Varint
            stream.WriteByte(16);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.Packed);
            // Key for field: 5, Varint
            stream.WriteByte(40);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.Lazy);
            // Key for field: 3, Varint
            stream.WriteByte(24);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.Deprecated);
            if (instance.ExperimentalMapKey != null)
            {
                // Key for field: 9, LengthDelimited
                stream.WriteByte(74);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.ExperimentalMapKey));
            }
            // Key for field: 10, Varint
            stream.WriteByte(80);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.Weak);
            if (instance.UninterpretedOption != null)
            {
                foreach (var i999 in instance.UninterpretedOption)
                {
                    // Key for field: 999, LengthDelimited
                    stream.Write(new byte[]{186, 62}, 0, 2);
                    using (var ms999 = new MemoryStream())
                    {
                        Google.protobuf.UninterpretedOption.Serialize(ms999, i999);
                        // Length delimited byte array
                        uint ms999Length = (uint)ms999.Length;
                        global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms999Length);
                        stream.Write(ms999.GetBuffer(), 0, (int)ms999Length);
                    }

                }
            }
        }
 /// <summary>Helper: create a new instance to deserializing into</summary>
 public static FieldOptions DeserializeLengthDelimited(Stream stream)
 {
     FieldOptions instance = new FieldOptions();
     DeserializeLengthDelimited(stream, instance);
     return instance;
 }
 /// <summary>Helper: create a new instance to deserializing into</summary>
 public static FieldOptions DeserializeLength(Stream stream, int length)
 {
     FieldOptions instance = new FieldOptions();
     DeserializeLength(stream, length, instance);
     return instance;
 }
 /// <summary>Helper: put the buffer into a MemoryStream and create a new instance to deserializing into</summary>
 public static FieldOptions Deserialize(byte[] buffer)
 {
     FieldOptions instance = new FieldOptions();
     using (var ms = new MemoryStream(buffer))
         Deserialize(ms, instance);
     return instance;
 }
Example #39
0
 public void AddField(string field, string indexedValue = null, string storedValue = null, FieldOptions options = FieldOptions.None)
 {
     AddField(field, indexedValue == null ? null : new StringReader(indexedValue), storedValue, options);
 }
Example #40
0
 public FieldSlot AddField (Box parent, Widget label, Widget field, string syncTooltip, FieldLabelClosure labelClosure,
     FieldValueClosure readClosure, FieldValueClosure writeClosure, FieldOptions options)
 {
     return AddField (parent, label, field, syncTooltip, labelClosure, readClosure, writeClosure, null, options);
 }
Example #41
0
        private static void fillFields(ValidationOptions options, IValidationNode node, IServiceLocator services, Accessor accessor, Type type)
        {
            var mode = node.DetermineMode(services, accessor);
            var field = new FieldOptions
            {
                field = accessor.Name,
                mode = mode.Mode
            };

            var graph = services.GetInstance<ValidationGraph>();
            var rules = graph.FieldRulesFor(type, accessor);
            var ruleOptions = new List<FieldRuleOptions>();

            rules.Each(rule =>
            {
                var ruleMode = rule.Mode ?? mode;
                ruleOptions.Add(new FieldRuleOptions
                {
                    rule = RuleAliases.AliasFor(rule),
                    mode = ruleMode.Mode
                });
            });

            field.rules = ruleOptions.ToArray();

            options._fields.Add(field);
        }
Example #42
0
        public ThinModel CalculateImplementationClosure(bool isCSharp, FieldOptions fieldOptions)
        {
            ImplementationModel implModel = new ImplementationModel(this);

            implModel.ImportRoots(IncludeStatus.ImplRoot);
            implModel.ImportRoots(IncludeStatus.ApiRoot);
            implModel.ImportRoots(IncludeStatus.ApiClosure);
            implModel.ImportRoots(IncludeStatus.ApiFxInternal);

            //implModel.PrintStats();
            implModel.CalculateImplementationClosure(isCSharp, fieldOptions);

            return implModel.ExportModel(IncludeStatus.ImplClosure);
        }
Example #43
0
 public FieldSlot AddField (Box parent, Widget field, string syncTooltip, FieldLabelClosure labelClosure,
     FieldValueClosure readClosure, FieldValueClosure writeClosure, FieldOptions options)
 {
     return AddField (parent, EditorUtilities.CreateLabel (String.Empty), field, syncTooltip,
         labelClosure, readClosure, writeClosure, options);
 }
 /// <summary>Helper: Serialize into a MemoryStream and return its byte array</summary>
 public static byte[] SerializeToBytes(FieldOptions instance)
 {
     using (var ms = new MemoryStream())
     {
         Serialize(ms, instance);
         return ms.ToArray();
     }
 }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, FieldOptions instance)
        {
            var msField = global::SilentOrbit.ProtocolBuffers.ProtocolParser.Stack.Pop();
            if (instance.Ctype != CType.STRING)
            {
                // Key for field: 1, Varint
                stream.WriteByte(8);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream,(ulong)instance.Ctype);
            }
            // Key for field: 2, Varint
            stream.WriteByte(16);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.Packed);
            // Key for field: 5, Varint
            stream.WriteByte(40);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.Lazy);
            // Key for field: 3, Varint
            stream.WriteByte(24);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.Deprecated);
            if (instance.ExperimentalMapKey != null)
            {
                // Key for field: 9, LengthDelimited
                stream.WriteByte(74);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.ExperimentalMapKey));
            }
            // Key for field: 10, Varint
            stream.WriteByte(80);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteBool(stream, instance.Weak);
            if (instance.UninterpretedOption != null)
            {
                foreach (var i999 in instance.UninterpretedOption)
                {
                    // Key for field: 999, LengthDelimited
                    stream.WriteByte(186);
                    stream.WriteByte(62);
                    msField.SetLength(0);
                    Google.Protobuf.UninterpretedOption.Serialize(msField, i999);
                    // Length delimited byte array
                    uint length999 = (uint)msField.Length;
                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, length999);
                    msField.WriteTo(stream);

                }
            }
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.Stack.Push(msField);
        }
Example #46
0
 /// <summary>
 /// Returns a value indicating whether the field does not adheres to the list of specified options.
 /// </summary>
 /// <param name="field">The field to test the options against.</param>
 /// <param name="options">The list of options to test on the field.</param>
 /// <returns>true if the field does not contain the list of options, false if it does.</returns>
 public static bool IsNot(this IField field, FieldOptions options)
 {
     return Is(field, options) == false;
 }
 /// <summary>Helper: create a new instance to deserializing into</summary>
 public static FieldOptions Deserialize(Stream stream)
 {
     FieldOptions instance = new FieldOptions();
     Deserialize(stream, instance);
     return instance;
 }
Example #48
0
 public void CalculateImplementationClosure(bool isCSharp, FieldOptions fieldOptions)
 {
     ImplClosureVisitor visitor = new ImplClosureVisitor(this, new ImplClosureVisitorOptions(true, fieldOptions));
     Validate(visitor);
 }
Example #49
0
 public ImplClosureVisitorOptions(bool useCscRules, FieldOptions fieldOptions)
 {
     UseCscRules = useCscRules; FieldOptions = fieldOptions;
 }
 public FieldPropertiesAttribute(FieldOptions attributes)
 {
     _attributes = attributes;
 }
Example #51
0
        public FieldSlot AddField (Box parent, Widget label, Widget field, string syncTooltip, FieldLabelClosure labelClosure,
            FieldValueClosure readClosure, FieldValueClosure writeClosure, FieldValueClosure syncClosure, FieldOptions options)
        {
            var editor_field = field as IEditorField;

            if (editor_field != null && dialog.Mode == EditorMode.View) {
                editor_field.SetAsReadOnly ();
            }

            FieldSlot slot = new FieldSlot ();

            slot.Parent = parent;
            slot.Label = label;
            slot.Field = field;
            slot.LabelClosure = labelClosure;
            slot.ReadClosure = readClosure;
            slot.WriteClosure = writeClosure;
            slot.SyncClosure = syncClosure;

            if (MultipleTracks && (options & FieldOptions.NoSync) == 0) {
                slot.Sync = delegate {
                    dialog.ForeachNonCurrentTrack (delegate (EditorTrackInfo track) {
                        (slot.SyncClosure ?? slot.WriteClosure) (track, slot.Field);
                    });
                };
            }

            if (MultipleTracks && (options & FieldOptions.NoSync) == 0 && (options & FieldOptions.NoShowSync) == 0) {
                slot.SyncButton = new SyncButton ();
                if (syncTooltip != null) {
                    TooltipSetter.Set (tooltip_host, slot.SyncButton, syncTooltip);
                }

                slot.SyncButton.Clicked += delegate { slot.Sync (); };
            }

            Table table = new Table (1, 1, false);
            table.ColumnSpacing = 1;

            table.Attach (field, 0, 1, 1, 2,
                AttachOptions.Expand | AttachOptions.Fill,
                AttachOptions.Fill, 0, 0);

            if (editor_field != null) {
                editor_field.Changed += delegate {
                    if (CurrentTrack != null) {
                        slot.WriteClosure (CurrentTrack, slot.Field);
                    }
                };
            }

            if (slot.SyncButton != null) {
                table.Attach (slot.SyncButton, 1, 2, 1, 2,
                    AttachOptions.Fill,
                    AttachOptions.Fill, 0, 0);
            }

            if (label != null) {
                if (label is Label) {
                    ((Label)label).MnemonicWidget = field;
                }
                table.Attach (label, 0, table.NColumns, 0, 1,
                    AttachOptions.Fill | AttachOptions.Expand,
                    AttachOptions.Fill, 0, 0);
            }

            table.ShowAll ();

            if ((options & FieldOptions.Shrink) == 0) {
                slot.Container = table;
                parent.PackStart (table, false, false, 0);
            } else {
                HBox shrink = new HBox ();
                shrink.Show ();
                slot.Container = shrink;
                shrink.PackStart (table, false, false, 0);
                parent.PackStart (shrink, false, false, 0);
            }

            field_slots.Add (slot);
            return slot;
        }