Exemple #1
0
        private Field AddMove(int insertIndex, char character, string color)
        {
            var insertField =
                FieldsList.FirstOrDefault(
                    f => f.FieldCoordinates.XCoordinate == 6 && f.FieldCoordinates.YCoordinate == insertIndex);
            List <Field> fieldsInColumn = new List <Field>();

            for (int i = 0; i < 6; i++)
            {
                var busyField =
                    FieldsList.FirstOrDefault(
                        f => f.FieldCoordinates.XCoordinate == i && f.FieldCoordinates.YCoordinate == insertIndex);
                if (busyField != null)
                {
                    fieldsInColumn.Add(busyField);
                }
            }
            var   x        = fieldsInColumn.Count;
            Field newField = new Field(new FieldCoordinates(x, insertIndex), character, color, "");

            FieldsList.Add(newField);
            if (x == 5)
            {
                insertField.FieldValue = '-';
                insertField.Activity   = "disabled";
                insertField.Color      = "black";
            }
            return(newField);
        }
        private bool HasDifferentFieldsList(FieldsList fl)
        {
            bool diff = false;

            if (m_Fields == null)
            {
                diff = true;
            }
            else if (m_Fields.fieldIndices == null)
            {
                diff = fl.fieldIndices != null;
            }
            else if (m_Fields.fieldIndices.Length != fl.fieldIndices.Length)
            {
                diff = true;
            }
            else
            {
                for (int i = 0; i != m_Fields.fieldIndices.Length; ++i)
                {
                    if (m_Fields.fieldIndices[i] != fl.fieldIndices[i])
                    {
                        diff = true;
                        break;
                    }
                }
            }
            return(diff);
        }
Exemple #3
0
        public void ExpandComponents(Accumulator accumulator)
        {
            // Traverse the field list
            // Change to for loop so we can add items as we iterate
            for (int i = 0; i < FieldsList.Count; ++i)
            {
                List <FieldComponent> componentList = null;
                // Determine the active subfield
                ushort activeSubfield = GetActiveSubFieldIndex(FieldsList[i].Num);

                if (activeSubfield == Fit.SubfieldIndexMainField)
                {
                    componentList = FieldsList[i].components;
                }
                else
                {
                    componentList = FieldsList[i].GetSubfield(activeSubfield).Components;
                }

                // Traverse the component list
                int offset = 0;
                foreach (FieldComponentExpansion f in ExpandComponentsInList(componentList, FieldsList[i], offset, accumulator))
                {
                    //Add the new field
                    FieldsList.Add(f.GetField());
                    //update offset
                    offset = f.GetOffset();
                }
            }
        }
Exemple #4
0
 private IEnumerable <Field> GetFieldsList()
 {
     return(FieldsList.Select(field =>
                              new Field()
     {
         CleanName = field
     }));
 }
        public void Field(AstPrintFieldDefinition field)
        {
            if (FieldsList.Exists(x => x.Name == field.Name))
            {
                throw new ArgumentException($"A field with name \"{field.Name}\" already exists!", nameof(field));
            }

            FieldsList.Add(field);
        }
Exemple #6
0
        public void Field(AstPrintFieldDefinition field)
        {
            if (FieldsList.Exists(x => x.Name == field.Name))
            {
                throw new ExecutionError($"A field with name \"{field.Name}\" already exists!");
            }

            FieldsList.Add(field);
        }
Exemple #7
0
            public override int FindIndex(CsvField field)
            {
                if (null == field)
                {
                    throw new ArgumentNullException(nameof(field));
                }

                return(FieldsList.IndexOf(field));
            }
Exemple #8
0
 public FieldCalculatorDlg(IFeatureLayer pFeaLayer)
 {
     InitializeComponent();
     this.DataContext = this;
     m_CurrentFeaSet  = (pFeaLayer as FeatureLayer).FeatureSet;
     foreach (DataColumn col in m_CurrentFeaSet.DataTable.Columns)
     {
         FieldsList.Add(col.ColumnName);
     }
 }
 public void CreateFields(ContentType targetContextType)
 {
     if (FieldsList != null && FieldsList.Count != 0)
     {
         FieldsList.ForEach(field =>
         {
             field.TargetContentType = targetContextType;
             field.Create();
         });
     }
 }
        private void LoadFields()
        {
            FormBuilder.FormBuilderDataContext dc = new FormBuilderDataContext();
            var fields = from f in dc.FormBuilder_Fields
                         where f.ModuleId == this.ModuleId
                         orderby f.SortOrder
                         select f;

            FieldsList.DataSource = fields;
            FieldsList.DataBind();
        }
Exemple #11
0
 /// <summary>
 /// Replace an existing field, otherwise add a reference to fields list
 /// </summary>
 /// <param name="field">Caller allocated field</param>
 public void SetField(Field field)
 {
     for (int i = 0; i < FieldsList.Count; i++)
     {
         if (FieldsList[i].Num == field.Num)
         {
             FieldsList[i] = field;
             return;
         }
     }
     FieldsList.Add(field);
 }
Exemple #12
0
        private string CreateDbSetType(EntityDefinition entityDef, DbSetInfo dbSetInfo, DotNet2TS dotNet2TS)
        {
            StringBuilder      sb          = new StringBuilder(512);
            string             dbSetType   = GetDbSetTypeName(dbSetInfo.dbSetName);
            List <Association> childAssoc  = _associations.Where(assoc => assoc.childDbSetName == dbSetInfo.dbSetName).ToList();
            List <Association> parentAssoc = _associations.Where(assoc => assoc.parentDbSetName == dbSetInfo.dbSetName).ToList();
            FieldsList         fieldInfos  = dbSetInfo.fieldInfos;

            Field[] pkFields = dbSetInfo.GetPKFields();
            string  pkVals   = "";

            foreach (Field pkField in pkFields)
            {
                if (!string.IsNullOrEmpty(pkVals))
                {
                    pkVals += ", ";
                }

                pkVals += pkField.fieldName.ToCamelCase() + ": " + GetFieldDataType(pkField);
            }
            Dictionary <string, Func <TemplateParser.Context, string> > dic = new Dictionary <string, Func <TemplateParser.Context, string> >
            {
                { "DBSET_NAME", (context) => dbSetInfo.dbSetName },
                { "DBSET_TYPE", (context) => dbSetType },
                { "ENTITY_NAME", (context) => entityDef.entityName },
                { "ASPECT_NAME", (context) => entityDef.aspectName },
                { "INTERFACE_NAME", (context) => entityDef.interfaceName },
                { "VALS_NAME", (context) => entityDef.valsName },
                {
                    "DBSET_INFO",
                    (context) =>
                    {
                        //we are making copy of the object, in order that we don't change original object
                        //while it can be accessed by other threads
                        //we change our own copy, making it threadsafe
                        DbSetInfo copy = dbSetInfo.ShallowCopy();
                        copy.SetFieldInfos(new FieldsList()); //serialze with empty field infos
                        return(_serializer.Serialize(copy));
                    }
                },
                { "FIELD_INFOS", (context) => _serializer.Serialize(dbSetInfo.fieldInfos) },
                { "CHILD_ASSOC", (context) => _serializer.Serialize(childAssoc) },
                { "PARENT_ASSOC", (context) => _serializer.Serialize(parentAssoc) },
                { "QUERIES", (context) => CreateDbSetQueries(dbSetInfo, dotNet2TS) },
                { "CALC_FIELDS", (context) => CreateCalcFields(dbSetInfo) },
                { "PK_VALS", (context) => pkVals }
            };

            return(_dbSetTemplate.ToString(dic));
        }
Exemple #13
0
            public override void Add(CsvField field)
            {
                if (null == field)
                {
                    throw new ArgumentNullException(nameof(field));
                }

                if (0 <= FindIndex(field))
                {
                    throw new InvalidOperationException();
                }

                FieldsList.Add(field);
            }
Exemple #14
0
        private bool WinningMove(char character)
        {
            List <Field> allPlayerFields = FieldsList.Where(f => f.FieldValue == character).ToList();//all fields from one player

            if (allPlayerFields.Count >= 5)
            {
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        var playerCombo =
                            allPlayerFields.Where(
                                f =>
                                f.FieldCoordinates.XCoordinate == i && f.FieldCoordinates.YCoordinate >= j &&
                                f.FieldCoordinates.YCoordinate <= j + 4).ToList();
                        if (playerCombo.Count >= 5)
                        {
                            foreach (var item in FieldsList)
                            {
                                item.Activity = "disabled";
                            }
                            return(true);
                        }
                    }
                }
                for (int i = 0; i < 7; i++)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        var playerCombo =
                            allPlayerFields.Where(
                                f =>
                                f.FieldCoordinates.YCoordinate == i && f.FieldCoordinates.XCoordinate >= j &&
                                f.FieldCoordinates.XCoordinate <= j + 4).ToList();
                        if (playerCombo.Count >= 5)
                        {
                            foreach (var item in FieldsList)
                            {
                                item.Activity = "disabled";
                            }
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemple #15
0
        private int RandomFromFreeInserts()
        {
            List <int>   freeIndexes = new List <int>();
            List <Field> freeFields  =
                FieldsList.Where(f => f.FieldCoordinates.XCoordinate == 6 && f.Activity == "").ToList();

            foreach (var item in freeFields)
            {
                freeIndexes.Add(item.FieldCoordinates.YCoordinate);
            }

            Random rand      = new Random();
            int    index     = rand.Next(0, freeIndexes.Count - 1);
            var    compIndex = freeIndexes[index];

            return(compIndex);
        }
Exemple #16
0
        private void ExtractFieldNames(EventPageBase EventPageBase)
        {
            if (EventPageBase.RegistrationForm == null)
            {
                return;
            }

            XForm xform = XForm.CreateInstance(new Guid(EventPageBase.RegistrationForm.Id.ToString()));
            NameValueCollection formControls = xform.CreateFormData().GetValues();

            foreach (string data in formControls)
            {
                if (!FieldsList.Contains(data))
                {
                    FieldsList.Add(data);
                }
            }
        }
Exemple #17
0
 private static IEnumerable <XElement> _FieldsToXElements(FieldsList fields)
 {
     return(from fld in fields
            select new XElement(NS_DATA + "Field",
                                new XAttribute("fieldName", fld.fieldName),
                                fld.dataType != DataType.None ? new XAttribute("dataType", fld.dataType) : null,
                                fld.isPrimaryKey > 0 ? new[] { new XAttribute("isPrimaryKey", fld.isPrimaryKey) } : new XAttribute[0],
                                fld.dataType == DataType.String && fld.maxLength > -1
                    ? new[] { new XAttribute("maxLength", fld.maxLength) }
                    : new XAttribute[0],
                                !fld.isNullable ? new[] { new XAttribute("isNullable", fld.isNullable) } : new XAttribute[0],
                                fld.isAutoGenerated
                    ? new[] { new XAttribute("isAutoGenerated", fld.isAutoGenerated) }
                    : new XAttribute[0],
                                fld.allowClientDefault
                    ? new[] { new XAttribute("allowClientDefault", fld.allowClientDefault) }
                    : new XAttribute[0],
                                !fld.isNeedOriginal
                    ? new[] { new XAttribute("isNeedOriginal", fld.isNeedOriginal) }
                    : new XAttribute[0],
                                fld.isReadOnly ? new[] { new XAttribute("isReadOnly", fld.isReadOnly) } : new XAttribute[0],
                                fld.fieldType != FieldType.None
                    ? new[] { new XAttribute("fieldType", fld.fieldType) }
                    : new XAttribute[0],
                                fld.dateConversion != DateConversion.None
                    ? new[] { new XAttribute("dateConversion", fld.dateConversion) }
                    : new XAttribute[0],
                                !string.IsNullOrWhiteSpace(fld.range)
                    ? new[] { new XAttribute("range", fld.range) }
                    : new XAttribute[0],
                                !string.IsNullOrWhiteSpace(fld.regex)
                    ? new[] { new XAttribute("regex", fld.regex) }
                    : new XAttribute[0],
                                !string.IsNullOrWhiteSpace(fld.dependentOn)
                    ? new[] { new XAttribute("dependentOn", fld.dependentOn) }
                    : new XAttribute[0],
                                !string.IsNullOrWhiteSpace(fld.GetDataTypeName())
                    ? new[] { new XAttribute("dataTypeName", fld.GetDataTypeName()) }
                    : new XAttribute[0],
                                !fld.IsHasNestedFields()
                    ? new XElement[0]
                    : new[] { new XElement(NS_DATA + "Field.nested", _FieldsToXElements(fld.nested)) }
                                ));
 }
Exemple #18
0
        public void Write(Stream outStream, MesgDefinition mesgDef)
        {
            if (mesgDef == null)
            {
                mesgDef = new MesgDefinition(this);
            }

            EndianBinaryWriter bw = new EndianBinaryWriter(outStream, mesgDef.IsBigEndian);

            bw.Write(LocalNum);

            foreach (FieldDefinition fieldDef in mesgDef.GetFields())
            {
                Field field = GetField(fieldDef.Num);
                if (null == field)
                {
                    field = Profile.GetField(this.Num, fieldDef.Num);
                    if (null != field)
                    {
                        FieldsList.Add(field);
                    }
                    else
                    {
                        //Field does not exist in profile, continue to next field
                        continue;
                    }
                }

                WriteField(field, fieldDef.Size, bw);
            }

            foreach (DeveloperFieldDefinition fieldDef in mesgDef.DeveloperFieldDefinitions)
            {
                DeveloperField field = GetDeveloperField(fieldDef.FieldNum, fieldDef.DeveloperDataIndex);

                if (field == null)
                {
                    field = new DeveloperField(fieldDef);
                    SetDeveloperField(field);
                }

                WriteField(field, fieldDef.Size, bw);
            }
        }
Exemple #19
0
 public void BindData(string expressionPlace, string expressionKey, FilterExpressionNode node)
 {
     string[] parts = expressionPlace.Split(':');
     //Change orig place
     if (parts.Length > 1)
     {
         parts[1] = "Sum";
     }
     else
     {
         parts = new string[] { parts[0], "Sum" };
     }
     FieldsList.DataSource     = ((FilterExpressionFunctionParams)this.Parent).ControlContainer.Provider.GetNewElements(String.Join(":", parts), node);
     FieldsList.Visible        = ((FilterExpressionNodeCollection)FieldsList.DataSource).Count != 0;
     FieldsList.DataTextField  = "Name";
     FieldsList.DataValueField = "Key";
     FieldsList.DataBind();
     //this.CurrentNode = node;
 }
Exemple #20
0
        /// <summary>
        ///  Get the value of colName at the supplied row
        /// </summary>
        /// <param name="datatableBag"></param>
        /// <param name="colName">The name of the column </param>
        /// <param name="row">The FieldsList which is a List<> of record values  </param>
        /// <returns></returns>
        public string GetValueAtRow(DatatableBag datatableBag, string colName, FieldsList row)
        {
            string thisColumn;

            int columnNum = 0;
            int fcol      = 0;

            for (columnNum = 0; columnNum < datatableBag.ColumnNameList.Count; columnNum++)
            {
                thisColumn = datatableBag.ColumnNameList[columnNum].VarName;

                if (thisColumn.ToLower() == colName.ToLower())
                {
                    fcol = columnNum;
                    break;
                }
            }

            return(row.Fields[fcol].VarName);
        }
Exemple #21
0
 /// <summary>
 /// Insert a field at the desired index.  If the field already exists in the mesg it is first removed.
 /// </summary>
 /// <param name="index">Index to insert the field, if index is out of range, the field is added to the end of the list</param>
 /// <param name="field">Caller allocated field</param>
 public void InsertField(int index, Field field)
 {
     // if message already contains this field, remove it
     for (int i = 0; i < FieldsList.Count; i++)
     {
         if (FieldsList[i].Num == field.Num)
         {
             FieldsList.RemoveAt(i);
         }
     }
     // if the index is out of range, add to the end
     if (index < 0 || index > FieldsList.Count)
     {
         FieldsList.Add(field);
     }
     // insert the new field at desired index
     else
     {
         FieldsList.Insert(index, field);
     }
 }
Exemple #22
0
        private void btnNewAdd_Click(object sender, EventArgs e)
        {
            switch (_editingFieldIndex)
            {
            case null when Program.FieldsList.Any(fli => fli.Name == txtName.Text):
                MessageBox.Show(
                    $@"There already is a field named {txtName.Text}. Field names should be unique.",
                    @"Gmail Scraper - add field",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                return;

            case null:
                Program.FieldsList.Add(new FieldToFind
                {
                    Name        = txtName.Text,
                    Regex       = txtRegexPattern.Text,
                    GroupNumber = (int)numericUpDown1.Value,
                    Required    = cbRequired.Checked
                });
                break;

            default:
            {
                FieldToFind f = Program.FieldsList[_editingFieldIndex.Value];
                f.Name             = txtName.Text;
                f.Regex            = txtRegexPattern.Text;
                f.GroupNumber      = (int)numericUpDown1.Value;
                f.Required         = cbRequired.Checked;
                _editingFieldIndex = null;
                break;
            }
            }

            this.SetFieldsToFind();
            pnlNewField.Visible           = false;
            Settings.Default.FieldsToFind = JsonConvert.SerializeObject(Program.FieldsList);
            Settings.Default.Save();
        }
Exemple #23
0
 /// <summary>
 /// Removes the specified field from this message.
 /// </summary>
 /// <param name="field">The Field to be removed from this message.</param>
 public void RemoveField(Field field)
 {
     FieldsList.Remove(field);
 }
Exemple #24
0
 /// <summary>
 /// Sets the Ord3 value.
 /// </summary>
 /// <param name="ord3">The ord3.</param>
 /// <returns></returns>
 public WLTableMessagesFilter SetOrd3(FieldsList ord3)
 {
     this.ord3 = ord3;
     return(this);
 }
Exemple #25
0
 /// <summary>
 /// Sets the Ord2 value.
 /// </summary>
 /// <param name="ord2">The ord2.</param>
 /// <returns></returns>
 public WLTableMessagesFilter SetOrd2(FieldsList ord2)
 {
     this.ord2 = ord2;
     return(this);
 }
Exemple #26
0
 /// <summary>
 /// Sets the Ord1 value.
 /// </summary>
 /// <param name="ord1">The ord1.</param>
 /// <returns></returns>
 public WLTableMessagesFilter SetOrd1(FieldsList ord1)
 {
     this.ord1 = ord1;
     return(this);
 }
Exemple #27
0
        private static FieldsList _XElementsToFieldList(IEnumerable<XElement> xFields)
        {
            FieldsList fields = new FieldsList();
            foreach (XElement xField in xFields)
            {
                Field field = new Field()
                {
                    fieldName = (string)xField.Attribute("fieldName")
                };
                if (xField.Attributes("isPrimaryKey").Any())
                    field.isPrimaryKey = (short)xField.Attribute("isPrimaryKey");
                if (xField.Attributes("dataType").Any())
                    field.dataType = (DataType)Enum.Parse(typeof(DataType), xField.Attribute("dataType").Value);
                if (xField.Attributes("maxLength").Any())
                    field.maxLength = (short)xField.Attribute("maxLength");
                if (xField.Attributes("isNullable").Any())
                    field.isNullable = (bool)xField.Attribute("isNullable");
                if (xField.Attributes("isReadOnly").Any())
                    field.isReadOnly = (bool)xField.Attribute("isReadOnly");
                if (xField.Attributes("isAutoGenerated").Any())
                    field.isAutoGenerated = (bool)xField.Attribute("isAutoGenerated");
                if (xField.Attributes("allowClientDefault").Any())
                    field.allowClientDefault = (bool)xField.Attribute("allowClientDefault");
                if (xField.Attributes("isNeedOriginal").Any())
                    field.isNeedOriginal = (bool)xField.Attribute("isNeedOriginal");
                if (xField.Attributes("dateConversion").Any())
                    field.dateConversion = (DateConversion)Enum.Parse(typeof(DateConversion), xField.Attribute("dateConversion").Value);
                if (xField.Attributes("fieldType").Any())
                    field.fieldType = (FieldType)Enum.Parse(typeof(FieldType), xField.Attribute("fieldType").Value);
                if (xField.Attributes("range").Any())
                    field.range = (string)xField.Attribute("range");
                if (xField.Attributes("regex").Any())
                    field.regex = (string)xField.Attribute("regex");
                if (xField.Attributes("dependentOn").Any())
                    field.dependentOn = (string)xField.Attribute("dependentOn");

                if (xField.Elements(NS_DATA + "Field.nested").Any())
                {
                    field.nested.AddRange(_XElementsToFieldList(xField.Element(NS_DATA + "Field.nested").Elements(NS_DATA + "Field")));
                }
                fields.Add(field);
            }
            return fields;
        }
Exemple #28
0
 private static IEnumerable<XElement> _FieldsToXElements(FieldsList fields)
 {
     return from fld in fields
            select new XElement(NS_DATA + "Field",
                    new XAttribute("fieldName", fld.fieldName),
                    new XAttribute("dataType", fld.dataType),
                    fld.isPrimaryKey > 0 ? new XAttribute[] { new XAttribute("isPrimaryKey", fld.isPrimaryKey) } : new XAttribute[0],
                    fld.dataType == DataType.String ? new XAttribute[] { new XAttribute("maxLength", fld.maxLength) } : new XAttribute[0],
                    !fld.isNullable? new XAttribute[] { new XAttribute("isNullable", fld.isNullable) } : new XAttribute[0],
                    fld.isAutoGenerated ? new XAttribute[] { new XAttribute("isAutoGenerated", fld.isAutoGenerated) } : new XAttribute[0],
                    fld.allowClientDefault ? new XAttribute[] { new XAttribute("allowClientDefault", fld.allowClientDefault) } : new XAttribute[0],
                    !fld.isNeedOriginal ? new XAttribute[] { new XAttribute("isNeedOriginal", fld.isNeedOriginal) } : new XAttribute[0],
                    fld.isReadOnly ? new XAttribute[] { new XAttribute("isReadOnly", fld.isReadOnly) } : new XAttribute[0],
                    fld.fieldType != FieldType.None ? new XAttribute[] { new XAttribute("fieldType", fld.fieldType) } : new XAttribute[0],
                    fld.dateConversion != DateConversion.None ? new XAttribute[] { new XAttribute("dateConversion", fld.dateConversion) } : new XAttribute[0],
                    !string.IsNullOrWhiteSpace(fld.range) ? new XAttribute[] { new XAttribute("range", fld.range) } : new XAttribute[0],
                    !string.IsNullOrWhiteSpace(fld.regex) ? new XAttribute[] { new XAttribute("regex", fld.regex) } : new XAttribute[0],
                    !string.IsNullOrWhiteSpace(fld.dependentOn) ? new XAttribute[] { new XAttribute("dependentOn", fld.dependentOn) } : new XAttribute[0],
                    !fld.IsHasNestedFields() ? new XElement[0] : new XElement[] { new XElement(NS_DATA + "Field.nested", _FieldsToXElements(fld.nested)) }
                );
 }
Exemple #29
0
 public override void Clear()
 {
     FieldsList.Clear();
 }
        private FieldsList BuildFieldList()
        {
            FieldsList fl     = new FieldsList();
            List <int> fields = new List <int>();

            switch (obj.dataType)
            {
            case ObjectDataType.Type:
                fl.mbHasStaticGroup = false;
                fl.mbHasBaseGroup   = false;
                if (Renderer.flattenFields)
                {
                    //take all static field
                    fl.fieldIndices = Snapshot.typeDescriptions.fieldIndices_static[obj.managedTypeIndex];
                    return(fl);
                }
                else
                {
                    var staticFields = Snapshot.typeDescriptions.fieldIndices[obj.managedTypeIndex].Where(x => Snapshot.fieldDescriptions.isStatic[x]);
                    fields.AddRange(staticFields);
                }
                break;

            case ObjectDataType.BoxedValue:
            case ObjectDataType.Object:
            case ObjectDataType.Value:
            case ObjectDataType.ReferenceObject:
                if (Renderer.flattenFields)
                {
                    fl.mbHasBaseGroup = false;
                    fields.AddRange(Snapshot.typeDescriptions.fieldIndices_instance[obj.managedTypeIndex]);
                    if (Renderer.flattenStaticFields)
                    {
                        fl.mbHasStaticGroup = false;
                        fields.AddRange(Snapshot.typeDescriptions.fieldIndices_static[obj.managedTypeIndex]);
                    }
                    else
                    {
                        fl.mbHasStaticGroup = true;
                    }
                }
                else
                {
                    fl.mbHasBaseGroup = objBase.IsValid;
                    if (Renderer.flattenStaticFields)
                    {
                        fl.mbHasStaticGroup = false;
                        //already has instance and static fields in the same array
                        fl.fieldIndices = Snapshot.typeDescriptions.fieldIndices[obj.managedTypeIndex];
                        return(fl);
                    }
                    else
                    {
                        var staticFields = Snapshot.typeDescriptions.fieldIndices[obj.managedTypeIndex].Where(x => Snapshot.fieldDescriptions.isStatic[x]);
                        fl.mbHasStaticGroup = (staticFields.Count() > 0);
                        var instanceFields = Snapshot.typeDescriptions.fieldIndices[obj.managedTypeIndex].Where(x => !Snapshot.fieldDescriptions.isStatic[x]);
                        fields.AddRange(instanceFields);
                    }
                }
                break;
            }
            fl.fieldIndices = fields.ToArray();
            return(fl);
        }
Exemple #31
0
        private EntityDefinition CreateEntityType(DbSetInfo dbSetInfo, DotNet2TS dotNet2TS)
        {
            EntityDefinition entityDef = new EntityDefinition();

            string dbSetType = GetDbSetTypeName(dbSetInfo.dbSetName);

            entityDef.interfaceName = GetEntityInterfaceName(dbSetInfo.dbSetName);
            entityDef.valsName      = GetValsInterfaceName(dbSetInfo.dbSetName);
            entityDef.entityName    = GetEntityTypeName(dbSetInfo.dbSetName);
            entityDef.aspectName    = string.Format("T{0}Aspect", entityDef.interfaceName);

            FieldsList    fieldInfos   = dbSetInfo.fieldInfos;
            StringBuilder sbFields     = new StringBuilder();
            StringBuilder sbFieldsDef  = new StringBuilder();
            StringBuilder sbFieldsInit = new StringBuilder();

            StringBuilder sbEntityFields = new StringBuilder();
            StringBuilder sbValsFields   = new StringBuilder();

            if (dotNet2TS.IsTypeNameRegistered(entityDef.interfaceName))
            {
                throw new ApplicationException(
                          string.Format("Names collision. Name '{0}' can not be used for an entity type's name because this name is used for a client's type.",
                                        entityDef.interfaceName));
            }

            Action <Field> AddCalculatedField = f =>
            {
                string dataType = GetFieldDataType(f);
                sbFields.AppendFormat("\tget {0}(): {1} {{ return this._aspect._getCalcFieldVal('{0}'); }}", f.fieldName,
                                      dataType);
                sbFields.AppendLine();

                sbEntityFields.AppendFormat("\treadonly {0}: {1};", f.fieldName, dataType);
                sbEntityFields.AppendLine();
            };

            Action <Field> AddNavigationField = f =>
            {
                string dataType = GetFieldDataType(f);
                sbFields.AppendFormat("\tget {0}(): {1} {{ return this._aspect._getNavFieldVal('{0}'); }}", f.fieldName,
                                      dataType);
                sbFields.AppendLine();
                //no writable properties to ParentToChildren navigation fields
                bool isReadonly = dataType.EndsWith("[]");
                if (!isReadonly)
                {
                    sbFields.AppendFormat("\tset {0}(v: {1}) {{ this._aspect._setNavFieldVal('{0}',v); }}", f.fieldName,
                                          dataType);
                    sbFields.AppendLine();
                }

                sbEntityFields.AppendFormat("\t{0}{1}: {2};", isReadonly ? "readonly " : "", f.fieldName, dataType);
                sbEntityFields.AppendLine();
            };

            Action <Field> AddComplexTypeField = f =>
            {
                string dataType   = GetFieldDataType(f);
                string interfName = string.Format("I{0}", dataType);
                sbFields.AppendFormat("\tget {0}(): {2} {{ if (!this._{0}) {{this._{0} = new {1}('{0}', this._aspect);}} return this._{0}; }}",
                                      f.fieldName, dataType, interfName);
                sbFields.AppendLine();
                sbFieldsDef.AppendFormat("\tprivate _{0}: {1};", f.fieldName, dataType);
                sbFieldsDef.AppendLine();
                sbFieldsInit.AppendFormat("\t\tthis._{0} = null;", f.fieldName);
                sbFieldsInit.AppendLine();

                sbValsFields.AppendFormat("\treadonly {0}: {1};", f.fieldName, interfName);
                sbValsFields.AppendLine();
            };

            Action <Field> AddSimpleField = f =>
            {
                string dataType = GetFieldDataType(f);
                sbFields.AppendFormat("\tget {0}(): {1} {{ return this._aspect._getFieldVal('{0}'); }}", f.fieldName,
                                      dataType);
                sbFields.AppendLine();
                if (!f.isReadOnly || f.allowClientDefault)
                {
                    sbFields.AppendFormat("\tset {0}(v: {1}) {{ this._aspect._setFieldVal('{0}',v); }}", f.fieldName,
                                          dataType);
                    sbFields.AppendLine();
                }

                sbValsFields.AppendFormat("\t{0}{1}: {2};", (!f.isReadOnly || f.allowClientDefault) ? "" : "readonly ", f.fieldName, dataType);
                sbValsFields.AppendLine();
            };

            fieldInfos.ForEach(fieldInfo =>
            {
                if (fieldInfo.fieldType == FieldType.Calculated)
                {
                    AddCalculatedField(fieldInfo);
                }
                else if (fieldInfo.fieldType == FieldType.Navigation)
                {
                    AddNavigationField(fieldInfo);
                }
                else if (fieldInfo.fieldType == FieldType.Object)
                {
                    AddComplexTypeField(fieldInfo);
                }
                else
                {
                    AddSimpleField(fieldInfo);
                }
            });

            Dictionary <string, Func <TemplateParser.Context, string> > dic = new Dictionary <string, Func <TemplateParser.Context, string> >
            {
                { "DBSET_NAME", (context) => dbSetInfo.dbSetName },
                { "DBSET_TYPE", (context) => dbSetType },
                { "ENTITY_NAME", (context) => entityDef.entityName },
                { "INTERFACE_NAME", (context) => entityDef.interfaceName },
                { "VALS_NAME", (context) => entityDef.valsName },
                { "ASPECT_NAME", (context) => entityDef.aspectName },
                { "ENTITY_FIELDS", (context) => TrimEnd(sbFields.ToString()) },
                { "FIELDS_DEF", (context) => TrimEnd(sbFieldsDef.ToString()) },
                { "FIELDS_INIT", (context) => TrimEnd(sbFieldsInit.ToString()) }
            };

            entityDef.entityDefinition    = TrimEnd(_entityTemplate.ToString(dic));
            entityDef.interfaceDefinition = CreateEntityInterface(entityDef, TrimEnd(sbValsFields.ToString()), TrimEnd(sbEntityFields.ToString()));

            return(entityDef);
        }
 private void SetFieldsList(FieldsList fl)
 {
     m_Fields = fl;
 }