Пример #1
0
        public virtual FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            // return null if not present, should return all shared fields as well as all fields in the version
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
            Assert.ArgumentNotNull(versionUri, "versionUri");

            if (DisableSerialization || DisableTransparentSync || itemDefinition == ItemDefinition.Empty)
            {
                return(null);
            }

            var item = GetTargetFromId(itemDefinition.ID);

            if (item == null)
            {
                return(null);
            }

            var fields = new FieldList();

            foreach (var sharedField in item.SharedFields)
            {
                if (sharedField.BlobId.HasValue || sharedField.Value != null)
                {
                    fields.Add(new ID(sharedField.FieldId), sharedField.BlobId?.ToString() ?? sharedField.Value);
                }
            }

            var version = item.Versions.FirstOrDefault(v => v.VersionNumber == versionUri.Version.Number && v.Language.Name == versionUri.Language.Name);

            if (version == null)
            {
                return(fields);
            }

            foreach (var versionedField in version.Fields)
            {
                if (versionedField.BlobId.HasValue || versionedField.Value != null)
                {
                    fields.Add(new ID(versionedField.FieldId), versionedField.BlobId?.ToString() ?? versionedField.Value);
                }
            }

            var unversionedFields = item.UnversionedFields.FirstOrDefault(language => language.Language.Name == versionUri.Language.Name);

            if (unversionedFields != null)
            {
                foreach (var unversionedField in unversionedFields.Fields)
                {
                    fields.Add(new ID(unversionedField.FieldId), unversionedField.BlobId?.ToString() ?? unversionedField.Value);
                }
            }

            fields.Add(FieldIDs.UpdatedBy, TransparentSyncUpdatedByValue);
            fields.Add(FieldIDs.Revision, Guid.NewGuid().ToString());

            AddBlobsToCache(item);

            return(fields);
        }
        private FieldList GetItemFieldsInternal(ItemDefinition item, VersionUri version, CallContext context)
        {
            var            list           = new FieldList();
            ControllerType controllerType = null;

            if (item.ID == FolderId || ControllerType.GetAllNamespaces().ContainsKey(item.ID.ToGuid()) || ((controllerType = ControllerType.GetControllerType(item.ID)) != null))
            {
                list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/elements.png"));
                if (controllerType != null)
                {
                    list.Add(FieldIDs.DisplayName, controllerType.Description);
                }
                AddStandardFields(list);
            }
            else
            {
                var action = ControllerAction.GetControllerAction(item.ID);
                if (action != null)
                {
                    AddActionFields(list, action);
                    AddStandardFields(list);
                }
            }
            return(list.Count == 0 ? base.GetItemFields(item, version, context) : list);
        }
Пример #3
0
        public void Verify_TryRemove_can_remove_field_last_using_index()
        {
            IFieldList fields = new FieldList();

            var field1 = Field.Builder <Primitive>()
                         .Id("field1")
                         .DataType(SchemaDataType.Primitive)
                         .IsNullable()
                         .Build();

            fields.Add(field1);

            var field2 = Field.Builder <Primitive>()
                         .Id("field2")
                         .DataType(SchemaDataType.Primitive)
                         .IsNullable()
                         .Build();

            fields.Add(field2);

            var field3 = Field.Builder <Primitive>()
                         .Id("field3")
                         .DataType(SchemaDataType.Primitive)
                         .IsNullable()
                         .Build();

            fields.Add(field3);

            Assert.IsTrue(fields.HasValues);
            Assert.AreEqual(3, fields.Count);
            Assert.IsTrue(fields.TryRemove(2, out PrimitiveField field));
            Assert.IsNotNull(field);
            Assert.IsFalse(fields.Contains(field));
            Assert.AreEqual(2, fields.Count);
        }
Пример #4
0
        public void Verify_does_not_throw_when_index_is_less_than_zero()
        {
            var fields = new FieldList();

            fields.Add <Primitive>(x => x.Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            PrimitiveField field = Field.Builder <Decimal>()
                                   .Id("field3A")
                                   .Precision(2)
                                   .Scale(5)
                                   .IsNullable()
                                   .Build();

            Assert.AreEqual(5, fields.Count);

            PrimitiveField replaced = fields.Replace(-1, field);

            Assert.AreEqual(5, fields.Count);
            Assert.IsFalse(replaced.HasValue);
            Assert.AreEqual("field3", fields[2].Id);
        }
Пример #5
0
        public void Test()
        {
            var fields = new FieldList();

            fields.Add <Primitive>(x => x.Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            PrimitiveField field = Field.Builder <Decimal>()
                                   .Id("field3")
                                   .Precision(2)
                                   .Scale(5)
                                   .IsNullable()
                                   .Build();

            Assert.AreEqual(5, fields.Count);

            PrimitiveField replaced = fields.Replace(2, field);

            Assert.AreEqual(5, fields.Count);

            DecimalField decimalField = fields[2].Cast <DecimalField>();

            Assert.AreEqual(SchemaDataType.Decimal, decimalField.DataType);
            Assert.AreEqual("field3", decimalField.Id);
            Assert.AreEqual(2, decimalField.Precision);
            Assert.AreEqual(5, decimalField.Scale);
        }
        public override FieldList GetItemFields(ItemDefinition item, VersionUri version, CallContext context)
        {
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(version, "version");
            Assert.ArgumentNotNull(context, "context");

            var list = new FieldList();

            if (item.ID == FolderId || (ControllerType.GetControllerType(ParentId, item.ID) != null))
            {
                list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/elements.png"));
            }
            else
            {
                var action = ControllerAction.GetControllerAction(ParentId, item.ID);
                if (action != null && HttpContext.Current != null)
                {
                    //VirtualPathData vpd;
                    //MvcActionHelper.GetRouteData(new HttpContextWrapper(HttpContext.Current), action.ActionName, action.ControllerType.ControllerName, null, false, out vpd);

                    //list.Add(LayoutFieldIDs.Path, vpd.VirtualPath);
                    list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/element.png"));
                }
            }
            if (list.Count == 0)
            {
                return(base.GetItemFields(item, version, context));
            }

            return(list);
        }
Пример #7
0
        public void Verify_can_replace_by_id()
        {
            var fields = new FieldList();

            fields.Add <Primitive>(x => x.Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add <Primitive>(x => x.Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            PrimitiveField field = Field.Builder <Decimal>()
                                   .Id("field3A")
                                   .Precision(2)
                                   .Scale(5)
                                   .IsNullable()
                                   .Build();

            Assert.AreEqual(5, fields.Count);
            Assert.IsTrue(fields.TryReplace("field3", field, out PrimitiveField replaced));
            Assert.AreEqual(5, fields.Count);
            Assert.IsTrue(replaced.HasValue);
            Assert.AreEqual("field3", replaced.Id);
            Assert.AreEqual(SchemaDataType.Primitive, replaced.DataType);

            DecimalField f1 = fields[2].Cast <DecimalField>();

            Assert.AreEqual("field3A", f1.Id);
            Assert.AreEqual(2, f1.Precision);
            Assert.AreEqual(5, f1.Scale);
        }
Пример #8
0
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, Sitecore.Data.DataProviders.CallContext context)
        {
            if (!Templates.Contains(itemDefinition.TemplateID))
            {
                return(null);
            }

            var currentFields = context.CurrentResult as FieldList;
            var productCode   = currentFields != null ? currentFields[ActiveCommerce.TemplateFields.ProductCode] : null;

            if (productCode.IsNullOrEmpty())
            {
                return(null);
            }

            var book = Data.Elements("book").SingleOrDefault(x => x.Attribute("id").Value == productCode);

            if (book == null)
            {
                return(null);
            }

            var fields = new FieldList();

            fields.Add(FieldIDs.Author, book.Element("author").Value);
            fields.Add(FieldIDs.Genre, book.Element("genre").Value);
            var dateValue = DateTime.ParseExact(book.Element("publish_date").Value, "yyyy-MM-dd", CultureInfo.InvariantCulture);

            fields.Add(FieldIDs.PublishDate, Sitecore.DateUtil.ToIsoDate(dateValue));
            return(fields);
        }
Пример #9
0
        public void Verify_does_not_allow_adding_any_null_fields_using_AddRange_via_IList()
        {
            var fields = new FieldList();

            var field1 = Field.Builder <Primitive>()
                         .Id("field1")
                         .DataType(SchemaDataType.Primitive)
                         .IsNullable()
                         .Build();

            fields.Add(field1);

            var field = Field.Builder <Primitive>()
                        .Id("field2")
                        .DataType(SchemaDataType.Primitive)
                        .IsNullable()
                        .Build();

            IList <PrimitiveField> fields2 = new List <PrimitiveField>();

            fields.Add(field);
            fields.Add(null);

            fields.AddRange(fields2);

            Assert.IsTrue(fields.HasValues);
            Assert.AreEqual(2, fields.Count);
        }
Пример #10
0
        public void Verify_TryRemove_does_not_throw_when_index_greater_than_field_list()
        {
            IFieldList fields = new FieldList();

            var field1 = Field.Builder <Primitive>()
                         .Id("field1")
                         .DataType(SchemaDataType.Primitive)
                         .IsNullable()
                         .Build();

            fields.Add(field1);

            var field2 = Field.Builder <Primitive>()
                         .Id("field2")
                         .DataType(SchemaDataType.Primitive)
                         .IsNullable()
                         .Build();

            fields.Add(field2);

            var field3 = Field.Builder <Primitive>()
                         .Id("field3")
                         .DataType(SchemaDataType.Primitive)
                         .IsNullable()
                         .Build();

            fields.Add(field3);

            Assert.IsTrue(fields.HasValues);
            Assert.AreEqual(3, fields.Count);
            Assert.IsFalse(fields.TryRemove(5, out PrimitiveField field));
            Assert.IsNotNull(field);
            Assert.IsFalse(fields.Contains(field));
            Assert.AreEqual(3, fields.Count);
        }
 private void AddStandardFields(FieldList list)
 {
     list.Add(global::Sitecore.FieldIDs.Created, "20140716T211810Z");
     list.Add(global::Sitecore.FieldIDs.CreatedBy, "sitecore\\admin");
     list.Add(global::Sitecore.FieldIDs.Revision, Guid.NewGuid().ToString("D"));
     list.Add(global::Sitecore.FieldIDs.Updated, "20140716T211810Z");
     list.Add(global::Sitecore.FieldIDs.UpdatedBy, "sitecore\\admin");
 }
Пример #12
0
        public void FakeItemAddMultipleFieldShouldReturnField(FieldList fieldList, string fieldValue)
        {
            var fieldIdOne = ID.NewID;
            var fieldIdTwo = ID.NewID;
            fieldList.Add(fieldIdOne, fieldValue);
            fieldList.Add(fieldIdTwo, fieldValue);
            var fake = new FakeItem(fieldList);

            fake.Fields.Should().HaveCount(2);
        }
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            if (Items.ContainsKey(itemDefinition.ID))
            {
                FieldList itemFields = new FieldList();
                itemFields.Add(_titleFieldId, Items[itemDefinition.ID].Title.Text);
                itemFields.Add(_textFieldId, Items[itemDefinition.ID].Summary.Text);

                return(itemFields);
            }
            return(null);
        }
Пример #14
0
        public void Verify_can_access_list_with_multiple_field_types()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Map).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.List).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            for (int i = 0; i < temp.Count; i++)
            {
                switch (temp[i].DataType)
                {
                case SchemaDataType.None:
                    break;

                case SchemaDataType.Primitive:
                    PrimitiveField specification = temp[i];
                    Assert.IsNotNull(specification);
                    Assert.That(specification.Id, Is.EqualTo("field1").Or.EqualTo("field4").Or.EqualTo("field5"));
                    break;

                case SchemaDataType.Map:
//                        MapField mapField = schema.Fields[i].Cast<MapField>();
//                        Assert.IsNotNull(mapField);
//                        Assert.AreEqual("field2", mapField.Id);
                    break;

                case SchemaDataType.List:
//                        ListField listField = schema.Fields[i].Cast<ListField>();
//                        Assert.IsNotNull(listField);
//                        Assert.AreEqual("field3", listField.Id);
                    break;

                case SchemaDataType.Decimal:
                    DecimalField spec = temp[i].Cast <DecimalField>();
                    Assert.IsNotNull(spec);
                    Assert.AreEqual("field6", spec.Id);
                    break;

                case SchemaDataType.Struct:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Пример #15
0
        public FieldList GetItemFields([NotNull] ID itemID, [NotNull] VersionUri versionUri)
        {
            Assert.ArgumentNotNull(itemID, "itemID");
            Assert.ArgumentNotNull(versionUri, "versionUri");

            var item = this.GetItem(itemID);

            if (item == null)
            {
                return(null);
            }

            var fieldList = new FieldList();

            // add shared fields
            foreach (var field in item.Fields.Shared)
            {
                fieldList.Add(field.Key, field.Value);
            }

            var language = versionUri.Language;

            Assert.IsNotNull(language, "language");

            if (language == Language.Invariant)
            {
                return(fieldList);
            }

            // add unversioned fields
            foreach (var field in item.Fields.Unversioned[language])
            {
                fieldList.Add(field.Key, field.Value);
            }

            var number  = versionUri.Version.Number;
            var version = item.Fields.Versioned[language][number];

            if (version == null)
            {
                return(fieldList);
            }

            // add versioned fields
            foreach (var field in version)
            {
                fieldList.Add(field.Key, field.Value);
            }

            return(fieldList);
        }
Пример #16
0
    static void SetupStandardFields(uint specVersion)
    {
        FieldList definedFields = new FieldList();

        StringField mission       = new StringField("MISSION-ID", "MISSION");
        StringField constellation = new StringField("CONSTELLATION-ID", "CONSTELLATION");
        StringField satIdPhys     = new StringField("SAT-ID-PHYSICAL", "SATELLITE");
        StringField satIdLog      = new StringField("SAT-ID-LOGICAL", "SATELLITE");
        StringField facility      = new StringField("FACILITY", "GMSEC-LAB");
        StringField component     = new StringField("COMPONENT", "VALIDATE-CUSTOM");

        definedFields.Add(mission);
        definedFields.Add(constellation);
        definedFields.Add(satIdPhys);
        definedFields.Add(satIdLog);
        definedFields.Add(facility);
        definedFields.Add(component);

        if (specVersion >= Gmsec.GMSEC_ISD_2018_00)
        {
            StringField domain1 = new StringField("DOMAIN1", "DOMAIN1");
            StringField domain2 = new StringField("DOMAIN2", "DOMAIN2");

            definedFields.Add(domain1);
            definedFields.Add(domain2);
        }

        MistMessage.SetStandardFields(definedFields);
    }
        protected virtual void AddActionFields(FieldList list, ControllerAction action)
        {
            list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/element.png"));
            list.Add(FieldIDs.DisplayName, action.Description);
            list.Add(FieldIds.ControllerName, action.ControllerType.ControllerName);
            list.Add(FieldIds.ControllerAction, action.ActionName);
            var customAttributes = action.MethodInfo.GetCustomAttributes(true);

            foreach (var item in customAttributes.OfType <ActionAttribute>()
                     .SelectMany(customAttribute => customAttribute.GetFields()))
            {
                list.Add(item.Key, item.Value);
            }
        }
Пример #18
0
        public void Verify_cannot_find_field_by_field_id()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            Assert.IsFalse(temp.Contains("field7"));
        }
Пример #19
0
        public void Verify_TryGetValue_will_not_throw_when_index_less_than_zero()
        {
            var fields = new FieldList();

            fields.Add(Field.Builder <Primitive>().Id("field1").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field2").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field3").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field4").DataType(SchemaDataType.Primitive).IsNullable().Build());
            fields.Add(Field.Builder <Primitive>().Id("field5").DataType(SchemaDataType.Primitive).IsNullable().Build());

            IReadOnlyFieldList temp = fields;

            Assert.IsFalse(temp.TryGetValue(-1, out PrimitiveField field));
            Assert.IsNotNull(field);
        }
Пример #20
0
        protected override Expression VisitMember(MemberExpression m)
        {
            if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter)
            {
                if (!list.Contains(m.Member.Name))
                {
                    list.Add(m.Member.Name);
                }

                return(Expression.Convert(Expression.Call(row, miGetValue,
                                                          Expression.Constant(m.Member.Name)), m.Type));
            }

            return(base.VisitMember(m));
        }
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, Sitecore.Data.DataProviders.CallContext context)
        {
            var fields = new FieldList();

            if (!Templates.Contains(itemDefinition.TemplateID))
            {
                return(null);
            }

            //important for this data provider to be chained after the SQL provider because of this
            var currentFields = context.CurrentResult as FieldList;
            var productCode   = currentFields != null ? currentFields[FieldIds.Product.ExternalId] : null;

            if (productCode.IsNullOrEmpty())
            {
                return(null);
            }

            var client     = new MongoClient(ConnectionString);
            var server     = client.GetServer();
            var database   = server.GetDatabase(MongoDatabase);
            var collection = database.GetCollection(Collection);

            //look for this product in the mongo collection
            var query = new QueryDocument("id", productCode);
            var book  = collection.FindOne(query);

            if (book == null)
            {
                fields.Add(FieldIds.Product.Hidden, "1");
                //TODO: return empty values for other fields
                return(fields);
            }

            //map fields
            //TODO: more dynamic field mapping, via config?
            //TODO: field mapping differences by template

            //base product fields
            fields.Add(FieldIds.Product.Sku, productCode);
            fields.Add(FieldIds.Product.Title, book["title"].AsString);
            fields.Add(FieldIds.Product.Description, book["description"].AsString);
            fields.Add(FieldIds.Product.Weight, book["weight"].AsString);
            fields.Add(FieldIds.Product.Price, book["price"].AsString);

            //book fields
            fields.Add(FieldIds.BookProduct.Author, book["author"].AsString);
            fields.Add(FieldIds.BookProduct.Genre, book["genre"].AsString);
            var dateValue = DateTime.ParseExact(book["publishDate"].AsString, "yyyy-MM-dd", CultureInfo.InvariantCulture);

            fields.Add(FieldIds.BookProduct.PublishDate, Sitecore.DateUtil.ToIsoDate(dateValue));
            return(fields);
        }
Пример #22
0
        // In this method we re-retrieve the item form the repository and populate the
        // Sitecore item fields we care about from this item. By breaking this out from
        // GetItemDefinition, we're able to keeps things flexible in terms of later updates.
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            if (this.canProcessItem(itemDefinition.ID))
            {
                Trace.WriteLine(String.Format("GetItemFields({0}, {1}, {2})", itemDefinition, versionUri, context), "ProductDataProvider");

                var fields = new FieldList();

                var template = TemplateManager.GetTemplate(this.productTemplateId, this.ContentDatabase);
                if (template != null)
                {
                    var originalId = this.getExternalId(itemDefinition.ID);
                    if (originalId != Guid.Empty)
                    {
                        if (context.DataManager.DataSource.ItemExists(itemDefinition.ID))
                        {
                            ReflectionUtil.CallMethod(typeof(ItemCache), "RemoveItem", true, true, new Object[] { itemDefinition.ID });
                        }

                        var product = this.productRepository.Find(originalId);
                        if (product != null)
                        {
                            foreach (var dataField in template.GetFields().Where(ItemUtil.IsDataField))
                            {
                                fields.Add(dataField.ID, this.getFieldValue(dataField, product));
                            }
                        }
                    }
                }

                return(fields);
            }
            return(base.GetItemFields(itemDefinition, versionUri, context));
        }
Пример #23
0
        protected override void ProcessValue()
        {
            if (_value.Length > 0)
            {
                _value = _value.TrimEnd(this.Encoding.FieldDelimiter);
                List <string> allFields = MessageHelper.SplitString(_value, this.Encoding.FieldDelimiter);

                if (allFields.Count > 1)
                {
                    allFields.RemoveAt(0);
                }
                for (int i = 0; i < allFields.Count; i++)
                {
                    string strField = allFields[i];

                    Field field = new Field(this.Encoding);
                    if (Name == "MSH" && i == 0)
                    {
                        field.IsDelimiters = true;  // special case
                    }
                    field.Value = strField;

                    FieldList.Add(field);
                }
            }
        }
Пример #24
0
		public ColumnInfo( ObjectMap objectMap, string[] columnNames )
		{
			this.columnNames = columnNames;
			columnComboHashCode = ObjectConstructor.GetFieldComboHashCode( columnNames );
			fields = new FieldList();
			for( int i = 0; i < columnNames.Length; i++ )
			{
				string columnName = columnNames[ i ];
				FieldMap fm = objectMap.GetFieldMapFromColumn( columnName );
				if( fm == null )
				{
					// check for column names with table name prefixes
					int pos = columnName.IndexOf( '.' );
					if( pos > 0 )
					{
						columnName = columnName.Substring( pos + 1, columnName.Length - pos - 1 );
						fm = objectMap.GetFieldMapFromColumn( columnName );
						if( fm != null )
						{
							columnNames[ i ] = columnName;
						}
					}
					if( fm == null ) // no corresponding member could be found - assume column is calculated
					{
						columnCalculatedMask |= 1 << i;
					}
				}
				fields.Add( fm ); // intentionally add null entries to preserve column order 
			}
		}
Пример #25
0
        private void AddFields(JObject models, List <double> mids)
        {
            var regex = new Regex("{{hint:(.*?)}}|{{type:(.*?)}}|{{(.*?)}}");

            foreach (var mid in mids)
            {
                var qfmt = models["" + mid]["tmpls"].First["qfmt"].ToString().Replace("\"", "");
                var afmt = models["" + mid]["tmpls"].First["afmt"].ToString();
                var css  = models["" + mid]["css"].ToString();

                afmt = afmt.Replace("{{FrontSide}}", qfmt);

                var       matches = regex.Matches(afmt);
                FieldList fields  = new FieldList();

                foreach (Match match in matches)
                {
                    if (match.Value.Contains("type:") || match.Value.Contains("hint:"))
                    {
                        continue;
                    }

                    var value = match.Value;
                    var field = new Field(value.Replace("{{", "").Replace("}}", ""));

                    fields.Add(field);
                }

                _infoPerMid.Add("" + mid, new Info(afmt.Replace("\n", "\\n"), css.Replace("\n", "\\n"), fields));
            }
        }
Пример #26
0
 public void FakeItemAddFieldShouldReturnField(FieldList fieldList,string fieldValue)
 {
     var fieldId = ID.NewID;
     fieldList.Add(fieldId,fieldValue);
     var fake = new FakeItem(fieldList);
     fake[fieldId].ShouldBeEquivalentTo(fieldValue);
 }
 public void OnChangeColumns(DataGridViewColumnCollection cs)
 {
     if (cs != null)
     {
         EasyDataSet eds = getEasyDataSet();
         if (eds != null)
         {
             FieldList flds0 = eds.Fields;
             FieldList flds  = new FieldList();
             for (int c = 0; c < cs.Count; c++)
             {
                 EPField f = flds0[cs[c].DataPropertyName];
                 if (f == null)
                 {
                     f      = new EPField();
                     f.Name = cs[c].DataPropertyName;
                 }
                 f.FieldCaption = cs[c].HeaderText;
                 f.OleDbType    = EPField.ToOleDBType(cs[c].ValueType);
                 flds.Add(f);
             }
             eds.Fields = flds;
         }
     }
 }
Пример #28
0
 /// <summary>
 /// Add fields into fieldList and aggList
 /// </summary>
 void PushFields()
 {
     FieldList.Add(DeviceId);
     FieldList.Add(MessageId);
     FieldList.Add(When);
     FieldList.Add(Condition);
 }
Пример #29
0
 /// <summary>
 /// 每组表达式解析
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 protected override MemberBinding VisitMemberBinding(MemberBinding node)
 {
     SpliceField.Clear();
     base.VisitMemberBinding(node);
     FieldList.Add(SpliceField.ToString());
     return(node);
 }
Пример #30
0
        public static FieldList <TType> ToList(int[] bits, int count)
        {
            if (bits.Length != count)
            {
                throw new ArgumentException("unexpected array size", "bits");
            }

            var list = new FieldList <TType>();

            for (int i = 0; i < count; i++)
            {
                if (bits[i] == 0)
                {
                    continue;
                }

                var flags = (uint)bits[i];
                int j     = 0;
                while (flags != 0)
                {
                    if ((flags & 1) != 0)
                    {
                        list.Add((TType)Enum.ToObject(typeof(TType), (i * 32) + j));
                    }

                    flags >>= 1;
                    j++;
                }
            }

            return(list);
        }
Пример #31
0
        /// <exception cref="BadSyntaxException">
        /// The <paramref name="name"/> does not fit to the syntax.
        /// </exception>
        public override Field AddField(string name)
        {
            Field field = new CSharpField(name, this);

            FieldList.Add(field);
            return(field);
        }
Пример #32
0
        internal protected override bool TryCreate(MetaElementType elementType, out ReadElement element)
        {
            switch (elementType)
            {
            case MetaElementType.Field:
                FieldReadElement fieldReadElement = new FieldReadElement();
                fieldList.Add(fieldReadElement);
                element = fieldReadElement;
                return(true);

            case MetaElementType.Sequence:
                SequenceReadElement sequenceReadElement = new SequenceReadElement();
                sequenceList.Add(sequenceReadElement);
                element = sequenceReadElement;
                return(true);

            case MetaElementType.Substitution:
                SubstitutionReadElement substitutionReadElement = new SubstitutionReadElement();
                substitutionList.Add(substitutionReadElement);
                element = substitutionReadElement;
                return(true);

            default:
                element = null;
                return(false);
            }
        }
Пример #33
0
 protected void PopulateFieldList(bool blankOnly)
 {
     try
     {
         FieldList.Clear();
         EmptyFieldList.Clear();
         foreach (var propinfo in GetType().GetProperties())
         {
             if (_fieldListExclude.Contains(propinfo.Name) == false)
             {
                 if (!blankOnly)
                 {
                     FieldList.Add(propinfo.Name, propinfo.GetValue(this, null));
                     if (propinfo.GetValue(this, null).ToString() != string.Empty)
                     {
                         FieldListNoBlankRows.Add(propinfo.Name, propinfo.GetValue(this, null));
                     }
                 }
                 EmptyFieldList.Add(propinfo.Name, null);
             }
         }
     }
     catch (NullReferenceException ex)
     {
         throw new BookieException("Known issue with Mobi");
     }
 }
Пример #34
0
 public Resolve(string name, params string[] shows)
 {
     Name = name;
     Show = new FieldList();
     foreach (var show in shows) {
         Show.Add(show);
     }
 }
Пример #35
0
        public void FakeItemGetFieldFromIdShoudlReturnFieldValue(string fieldValue, FieldList fieldList)
        {
            var fieldId = ID.NewID;

            fieldList.Add(fieldId, fieldValue);
            var fake = new FakeItem(fieldList);

            fake[fieldId].ShouldAllBeEquivalentTo(fieldValue);
        }
		public override FieldList GetItemFields(ItemDefinition item, VersionUri version, CallContext context)
		{
			Assert.ArgumentNotNull(item, "item");
			Assert.ArgumentNotNull(version, "version");
			Assert.ArgumentNotNull(context, "context");

			var action = ControllerAction.GetControllerAction(ParentId, item.ID);
			if (action == null)
			{
				return base.GetItemFields(item, version, context);
			}

			FieldList list = new FieldList();
			var template = context.DataManager.Database.GetTemplate(BaseTemplateId);
			list.Add(template.GetField("Namespace").ID, typeof(MvcActionLoader).Namespace);
			list.Add(template.GetField("Tag").ID, typeof(MvcActionLoader).Name);
			list.Add(template.GetField("TagPrefix").ID, "mvc");
			list.Add(template.GetField("Assembly").ID, typeof(MvcActionLoader).Assembly.GetName().Name);
			list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/element_selection.png"));
			return list;
		}
        public void FieldAddingLinkFieldWithLinkFromOneItemToAnotherTargetItemShouldReturnLinkedToItem()
        {
            var linkedToItem = new FakeItem();
            var fakeLinkField = new FakeInternalLinkField(linkedToItem);

            var fieldId = ID.NewID;
            var fieldCollection = new FieldList();
            fieldCollection.Add(fieldId,fakeLinkField.ToString());

            var itemToLinkFrom = new FakeItem(fieldCollection);

            var sitecoreLinkField = (LinkField) itemToLinkFrom.Fields[fieldId];

            sitecoreLinkField.TargetItem.ID.ShouldBeEquivalentTo(linkedToItem.ID);
        }
Пример #38
0
        public static Item CreateFakeItem(Dictionary<Guid, string> fields, ID templateId, Database database, string name = "ItemName")
        {
            var id = new ID(Guid.NewGuid());
            var language = Language.Current;
            var version = Sitecore.Data.Version.Latest;

            var itemDefinition = new ItemDefinition(id, name, templateId, ID.Null);
            var fieldList = new FieldList();

            if (fields != null)
            {
                foreach (var fieldId in fields.Keys)
                {
                    fieldList.Add(new ID(fieldId), fields[fieldId]);
                }
            }

            var itemData = new ItemData(itemDefinition, language, version, fieldList);
            var item = new Item(id, itemData, database);
            return item;
        }
Пример #39
0
        public virtual FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            // return null if not present, should return all shared fields as well as all fields in the version
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
            Assert.ArgumentNotNull(versionUri, "versionUri");

            if (DisableSerialization || DisableTransparentSync || itemDefinition == ItemDefinition.Empty) return null;

            var item = GetTargetFromId(itemDefinition.ID);

            if (item == null) return null;

            var fields = new FieldList();

            foreach (var sharedField in item.SharedFields)
            {
                fields.Add(new ID(sharedField.FieldId), sharedField.BlobId.HasValue ? sharedField.BlobId.ToString() : sharedField.Value);
            }

            var version = item.Versions.FirstOrDefault(v => v.VersionNumber == versionUri.Version.Number && v.Language.Name == versionUri.Language.Name);

            if (version == null) return fields;

            foreach (var versionedField in version.Fields)
            {
                fields.Add(new ID(versionedField.FieldId), versionedField.BlobId.HasValue ? versionedField.BlobId.ToString() : versionedField.Value);
            }

            fields.Add(FieldIDs.UpdatedBy, TransparentSyncUpdatedByValue);
            fields.Add(FieldIDs.Revision, Guid.NewGuid().ToString());

            AddBlobsToCache(item);

            return fields;
        }
Пример #40
0
		public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
		{
			Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
			Assert.ArgumentNotNull(versionUri, "versionUri");

			if (itemDefinition == ItemDefinition.Empty) return null;

			var syncItem = SerializedDatabase.GetItem(itemDefinition.ID);

			if (syncItem == null) return null;

			var fields = new FieldList();

			foreach (var sharedField in syncItem.SharedFields)
			{
				fields.Add(sharedField.GetSitecoreId(), sharedField.FieldValue);
			}

			var syncVersion = syncItem.GetVersion(versionUri);

			if (syncVersion == null) return fields;

			foreach (var versionedField in syncVersion.Fields)
			{
				fields.Add(versionedField.GetSitecoreId(), versionedField.FieldValue);
			}

			return fields;
		}
        public virtual void Process(GetItemFieldsArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.ItemDefinition, "args.ItemDefinition");
            Assert.ArgumentNotNull(args.Context, "args.Context");

            var itemId = args.ItemDefinition.ID;
            var fields = new FieldList();
            var owner = typeof(ContactFacetDataProvider).Name;
            fields.Add(Sitecore.FieldIDs.CreatedBy, owner);
            fields.Add(Sitecore.FieldIDs.Owner, owner);
            if (IDTableHelper.IsFacetItem(itemId))
            {
                var facetName = IDTableHelper.GetFacetName(itemId);
                fields.Add(Sitecore.FieldIDs.DisplayName, facetName);
                fields.Add(Sitecore.Strategy.Contacts.DataProviders.FieldIDs.ContactFacetName, facetName);
                var contractType = ContactFacetHelper.GetContractTypeForFacet(facetName);
                if (contractType != null)
                {
                    fields.Add(Sitecore.Strategy.Contacts.DataProviders.FieldIDs.ContactFacetContract, contractType.AssemblyQualifiedName);
                    if (ContactFacetHelper.ContactFacetImplementations.ContainsKey(contractType))
                    {
                        var implType = ContactFacetHelper.ContactFacetImplementations[contractType];
                        if (implType != null)
                        {
                            fields.Add(Sitecore.Strategy.Contacts.DataProviders.FieldIDs.ContactFacetImplementation, implType.AssemblyQualifiedName);
                        }
                    }
                }
            }
            if (IDTableHelper.IsFacetMemberItem(itemId))
            {
                var memberName = IDTableHelper.GetFacetMemberName(itemId);
                fields.Add(Sitecore.FieldIDs.DisplayName, memberName);
                fields.Add(Sitecore.Strategy.Contacts.DataProviders.FieldIDs.ContactFacetMemberName, memberName);
                var facetId = IDTableHelper.GetFacetMemberParentId(itemId);
                var facetName = IDTableHelper.GetFacetName(facetId);
                var memberType = ContactFacetHelper.GetFacetMemberType(facetName, memberName);
                if (memberType != null)
                {
                    fields.Add(Sitecore.Strategy.Contacts.DataProviders.FieldIDs.ContactFacetMemberType, memberType.AssemblyQualifiedName);
                }
            }
            if (IDTableHelper.IsFacetMemberValueItem(itemId))
            {
                var value = IDTableHelper.GetFacetMemberValue(itemId);
                if (!string.IsNullOrEmpty(value))
                {
                    fields.Add(Sitecore.Strategy.Contacts.DataProviders.FieldIDs.ContactFacetMemberValueValue, value);
                }
                var description = IDTableHelper.GetFacetMemberValueDescription(itemId);
                if (!string.IsNullOrEmpty(description))
                {
                    fields.Add(Sitecore.FieldIDs.DisplayName, description);
                    fields.Add(Sitecore.Strategy.Contacts.DataProviders.FieldIDs.ContactFacetMemberValueDescription, description);
                }
            }
            args.FieldList = fields;
        }
 public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
 {
     if (Items.ContainsKey(itemDefinition.ID))
     {
         FieldList itemFields = new FieldList();
         foreach (KeyValuePair<ID,string> field in Items[itemDefinition.ID].Fields)
         {
             itemFields.Add(field.Key, field.Value);
         }
         return itemFields;
     }
     return null;
 }
Пример #43
0
 public virtual Differences VisitFieldList(FieldList list1, FieldList list2,
   out FieldList changes, out FieldList deletions, out FieldList insertions){
   changes = list1 == null ? null : list1.Clone();
   deletions = list1 == null ? null : list1.Clone();
   insertions = list1 == null ? new FieldList() : list1.Clone();
   //^ assert insertions != null;
   Differences differences = new Differences();
   //Compare definitions that have matching key attributes
   TrivialHashtable matchingPosFor = new TrivialHashtable();
   TrivialHashtable matchedNodes = new TrivialHashtable();
   for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){
     //^ assert list2 != null;
     Field nd2 = list2[j];
     if (nd2 == null || nd2.Name == null) continue;
     matchingPosFor[nd2.Name.UniqueIdKey] = j;
     insertions.Add(null);
   }
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Field nd1 = list1[i];
     if (nd1 == null || nd1.Name == null) continue;
     object pos = matchingPosFor[nd1.Name.UniqueIdKey];
     if (!(pos is int)) continue;
     //^ assert pos != null;
     //^ assume list2 != null; //since there was entry int matchingPosFor
     int j = (int)pos;
     Field nd2 = list2[j];
     //^ assume nd2 != null;
     //nd1 and nd2 have the same key attributes and are therefore treated as the same entity
     matchedNodes[nd1.UniqueKey] = nd1;
     matchedNodes[nd2.UniqueKey] = nd2;
     //nd1 and nd2 may still be different, though, so find out how different
     Differences diff = this.VisitField(nd1, nd2);
     if (diff == null){Debug.Assert(false); continue;}
     if (diff.NumberOfDifferences != 0){
       changes[i] = diff.Changes as Field;
       deletions[i] = diff.Deletions as Field;
       insertions[i] = diff.Insertions as Field;
       insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
       Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]);
       differences.NumberOfDifferences += diff.NumberOfDifferences;
       differences.NumberOfSimilarities += diff.NumberOfSimilarities;
       continue;
     }
     changes[i] = null;
     deletions[i] = null;
     insertions[i] = null;
     insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
   }
   //Find deletions
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Field nd1 = list1[i]; 
     if (nd1 == null) continue;
     if (matchedNodes[nd1.UniqueKey] != null) continue;
     changes[i] = null;
     deletions[i] = nd1;
     insertions[i] = null;
     differences.NumberOfDifferences += 1;
   }
   //Find insertions
   for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){
     //^ assert list2 != null;
     Field nd2 = list2[j]; 
     if (nd2 == null) continue;
     if (matchedNodes[nd2.UniqueKey] != null) continue;
     insertions[n+j] = nd2;  //Records nd2 as an insertion into list1, along with its position in list2
     differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here?
   }
   if (differences.NumberOfDifferences == 0){
     changes = null;
     deletions = null;
     insertions = null;
   }
   return differences;
 }
        private void GetFieldFields(FieldInfo info, FieldList fields){

            if (!string.IsNullOrEmpty(info.Title))
                fields.Add(TitleFieldId, info.Title);

            fields.Add(TypeFieldId, FieldInfo.GetFieldType(info.Type));

            if (!string.IsNullOrEmpty(info.Source))
                fields.Add(SourceFieldId, info.Source);

            fields.Add(TemplateFieldIDs.Shared, info.IsShared ? "1" : "0");
            fields.Add(TemplateFieldIDs.Unversioned, info.IsUnversioned ? "1" : "0");
            foreach (var fieldFieldValue in info.FieldFieldValues)
            {
                fields.Add(ID.Parse(fieldFieldValue.Key), fieldFieldValue.Value);
            }
            fields.Add(TemplateFieldIDs.Validation, info.ValidationRegularExpression ?? "");
            fields.Add(TemplateFieldIDs.ValidationText, info.ValidationErrorText ?? "");

            if (info.IsRequired)
            {
                fields.Add(QuickActionBarFieldId, IsRequiredId);
                fields.Add(ValidateButtonFieldId, IsRequiredId);
                fields.Add(ValidatorBarFieldId, IsRequiredId);
                fields.Add(WorkflowFieldId, IsRequiredId);
            }
        }
Пример #45
0
 public override Node VisitQueryGroupBy(QueryGroupBy groupby){
   if (groupby == null) return null;
   groupby.Source = this.VisitExpression(groupby.Source);
   if (groupby.Source == null || groupby.Source.Type == null) return groupby;
   TypeNode sourceElementType = this.typeSystem.GetStreamElementType(groupby.Source, this.TypeViewer);
   groupby.GroupContext = this.contextScope = new ContextScope(this.contextScope, sourceElementType);
   groupby.GroupList = this.VisitExpressionList(groupby.GroupList);
   this.contextScope = this.contextScope.Previous;
   // create result type
   FieldList fields = new FieldList();
   int cn = 0;
   for (int i = 0, n = groupby.GroupList.Count; i < n; i++){
     Expression x = groupby.GroupList[i];
     if (x != null && x.Type != null){
       Identifier name = this.GetExpressionName(x);
       Field f = new Field(null, new AttributeList(1), FieldFlags.Public, name, x.Type, null);
       if (name == null || name == Identifier.Empty){
         f.Name = Identifier.For("Item"+cn); cn++;
         f.Attributes.Add(new AttributeNode(new MemberBinding(null, SystemTypes.AnonymousAttribute.GetConstructor()), null));
       }
       fields.Add(f);
     }
   }
   for (int i = 0, n = groupby.AggregateList.Count; i < n; i++){
     QueryAggregate qa = groupby.AggregateList[i] as QueryAggregate;
     if (qa != null){
       qa.Group = groupby;
       this.contextScope = groupby.GroupContext;
       TypeNode aggType = null;
       QueryDistinct qd = qa.Expression as QueryDistinct;
       if (qd != null){
         qd.Group = groupby;
         qd.Source = this.VisitExpression(qd.Source);
         if (qd.Source == null) continue;
         qd.Type = this.GetResultType(qd.Source, null, Cardinality.ZeroOrMore);
         aggType = this.GetAggregateSubType(qa.AggregateType, this.typeSystem.GetStreamElementType(qd.Source, this.TypeViewer));
       }
       else{
         qa.Expression = this.VisitExpression(qa.Expression);
         if (qa.Expression == null) continue;
         aggType = this.GetAggregateSubType(qa.AggregateType, this.typeSystem.GetStreamElementType(qa.Expression, this.TypeViewer));
       }
       this.contextScope = this.contextScope.Previous;
       if (aggType == null) continue;
       qa.AggregateType = aggType;
       Method mgetval = this.GetTypeView(aggType).GetMethod(StandardIds.GetValue);
       if (mgetval != null){
         qa.Type = mgetval.ReturnType;
       }
       Identifier name = Identifier.For("Item"+cn); cn++;
       Field f = new Field(null, new AttributeList(1), FieldFlags.Public, name, qa.Type, null);
       f.Attributes.Add(new AttributeNode(new MemberBinding(null, SystemTypes.AnonymousAttribute.GetConstructor()), null));
       fields.Add(f);
     }
   }
   if (fields.Count == groupby.GroupList.Count + groupby.AggregateList.Count){
     TypeNode groupType = TupleType.For(fields, this.currentType);
     if (groupby.Having != null){
       groupby.HavingContext = this.contextScope = new ContextScope(this.contextScope, groupType);
       groupby.Having = this.VisitExpression(groupby.Having);
       this.contextScope = this.contextScope.Previous;
     }
     groupby.Type = this.GetResultType(groupby.Source, groupType, Cardinality.One);
   }
   return groupby;
 }
Пример #46
0
    protected void AddFieldsFromTemplate(FieldList allFields, DbItem fakeItem, DbTemplate fakeTemplate, Language language, Version version)
    {
      var sourceItem = this.GetSourceItem(fakeItem);

      foreach (var templateField in fakeTemplate.Fields)
      {
        var fieldId = templateField.ID;

        var itemField = this.FindItemDbField(fakeItem, templateField);
        if (itemField == null)
        {
          continue;
        }

        var value = itemField.GetValue(language.Name, version.Number);
        if (sourceItem != null && string.IsNullOrWhiteSpace(value))
        {
          continue;
        }

        if (value != null)
        {
          allFields.Add(fieldId, value);
        }
      }

      foreach (var template in fakeTemplate.BaseIDs.Select(this.GetFakeTemplate).Where(t => t != null))
      {
        this.AddFieldsFromTemplate(allFields, fakeItem, template, language, version);
      }

      if (fakeTemplate.BaseIDs.Any() || fakeTemplate.ID == TemplateIDs.StandardTemplate)
      {
        return;
      }

      var standardTemplate = this.GetFakeTemplate(TemplateIDs.StandardTemplate);
      this.AddFieldsFromTemplate(allFields, fakeItem, standardTemplate, language, version);
    }
Пример #47
0
    public override TypeNode VisitTypeReference(TypeNode type){ //TODO: break up this method
      if (type == null) return null;
      TypeNodeList pars = this.pars;
      TypeNodeList args = this.args;
      switch (type.NodeType){
        case NodeType.ArrayType:
          ArrayType arrType = (ArrayType)type;
          TypeNode elemType = this.VisitTypeReference(arrType.ElementType);
          if (elemType == arrType.ElementType || elemType == null) return arrType;
          if (arrType.IsSzArray()) return elemType.GetArrayType(1);
          return elemType.GetArrayType(arrType.Rank, arrType.Sizes, arrType.LowerBounds);
#if !MinimalReader
        case NodeType.DelegateNode:{
          FunctionType ftype = type as FunctionType;
          if (ftype == null) goto default;
          TypeNode referringType = ftype.DeclaringType == null ? this.CurrentType : this.VisitTypeReference(ftype.DeclaringType);
          return FunctionType.For(this.VisitTypeReference(ftype.ReturnType), this.VisitParameterList(ftype.Parameters), referringType);}
#endif
        case NodeType.Pointer:
          Pointer pType = (Pointer)type;
          elemType = this.VisitTypeReference(pType.ElementType);
          if (elemType == pType.ElementType || elemType == null) return pType;
          return elemType.GetPointerType();
        case NodeType.Reference:
          Reference rType = (Reference)type;
          elemType = this.VisitTypeReference(rType.ElementType);
          if (elemType == rType.ElementType || elemType == null) return rType;
          return elemType.GetReferenceType();
#if ExtendedRuntime
        case NodeType.TupleType:{
          TupleType tType = (TupleType)type;
          bool reconstruct = false;
          MemberList members = tType.Members;
          int n = members == null ? 0 : members.Count;
          FieldList fields = new FieldList(n);
          for (int i = 0; i < n; i++){
            //^ assert members != null;
            Field f = members[i] as Field;
            if (f == null) continue;
            f = (Field)f.Clone();
            fields.Add(f);
            TypeNode oft = f.Type;
            TypeNode ft = f.Type = this.VisitTypeReference(f.Type);
            if (ft != oft) reconstruct = true;
          }
          if (!reconstruct) return tType;
          TypeNode referringType = tType.DeclaringType == null ? this.CurrentType : this.VisitTypeReference(tType.DeclaringType);
          return TupleType.For(fields, referringType);}
        case NodeType.TypeIntersection:{
          TypeIntersection tIntersect = (TypeIntersection)type;
          TypeNode referringType = tIntersect.DeclaringType == null ? this.CurrentType : this.VisitTypeReference(tIntersect.DeclaringType);
          return TypeIntersection.For(this.VisitTypeReferenceList(tIntersect.Types), referringType);}
        case NodeType.TypeUnion:{
          TypeUnion tUnion = (TypeUnion)type;
          TypeNode referringType = tUnion.DeclaringType == null ? this.CurrentType : this.VisitTypeReference(tUnion.DeclaringType);
          TypeNodeList types = this.VisitTypeReferenceList(tUnion.Types);
          if (referringType == null || types == null) { Debug.Fail(""); return null; }
          return TypeUnion.For(types, referringType);}
#endif
#if !MinimalReader        
        case NodeType.ArrayTypeExpression:
          ArrayTypeExpression aExpr = (ArrayTypeExpression)type;
          aExpr.ElementType = this.VisitTypeReference(aExpr.ElementType);
          return aExpr;
        case NodeType.BoxedTypeExpression:
          BoxedTypeExpression bExpr = (BoxedTypeExpression)type;
          bExpr.ElementType = this.VisitTypeReference(bExpr.ElementType);
          return bExpr;
        case NodeType.ClassExpression:{
          ClassExpression cExpr = (ClassExpression)type;
          cExpr.Expression = this.VisitTypeExpression(cExpr.Expression);
          Literal lit = cExpr.Expression as Literal; //Could happen if the expression is a template parameter
          if (lit != null) return lit.Value as TypeNode;
          cExpr.TemplateArguments = this.VisitTypeReferenceList(cExpr.TemplateArguments);
          return cExpr;}
#endif
        case NodeType.ClassParameter:
        case NodeType.TypeParameter:
          int key = type.UniqueKey;
          var mappedTarget = this.forwarding[key] as TypeNode;
          if (mappedTarget != null) return mappedTarget;
          for (int i = 0, n = pars == null ? 0 : pars.Count, m = args == null ? 0 : args.Count; i < n && i < m; i++){
            //^ assert pars != null && args != null;
            TypeNode tp = pars[i];
            if (tp == null) continue;
            if (tp.UniqueKey == key) return args[i];
#if false
            if (tp.Name.UniqueIdKey == type.Name.UniqueIdKey && (tp is ClassParameter && type is TypeParameter)) {
              //This shouldn't really happen, but in practice it does. Hack past it.
              Debug.Assert(false);
              return args[i];
            }
#endif
          }
          return type;
#if ExtendedRuntime
        case NodeType.ConstrainedType:{
          ConstrainedType conType = (ConstrainedType)type;
          TypeNode referringType = conType.DeclaringType == null ? this.CurrentType : this.VisitTypeReference(conType.DeclaringType);
          TypeNode underlyingType = this.VisitTypeReference(conType.UnderlyingType);
          Expression constraint = this.VisitExpression(conType.Constraint);
          if (referringType == null || underlyingType == null || constraint == null) { Debug.Fail(""); return null; }
          return new ConstrainedType(underlyingType, constraint, referringType);}
#endif
#if !MinimalReader
        case NodeType.FlexArrayTypeExpression:
          FlexArrayTypeExpression flExpr = (FlexArrayTypeExpression)type;
          flExpr.ElementType = this.VisitTypeReference(flExpr.ElementType);
          return flExpr;
        case NodeType.FunctionTypeExpression:
          FunctionTypeExpression ftExpr = (FunctionTypeExpression)type;
          ftExpr.Parameters = this.VisitParameterList(ftExpr.Parameters);
          ftExpr.ReturnType = this.VisitTypeReference(ftExpr.ReturnType);
          return ftExpr;
        case NodeType.InvariantTypeExpression:
          InvariantTypeExpression invExpr = (InvariantTypeExpression)type;
          invExpr.ElementType = this.VisitTypeReference(invExpr.ElementType);
          return invExpr;
#endif
        case NodeType.InterfaceExpression:
          InterfaceExpression iExpr = (InterfaceExpression)type;
          if (iExpr.Expression == null) goto default;
          iExpr.Expression = this.VisitTypeExpression(iExpr.Expression);
          iExpr.TemplateArguments = this.VisitTypeReferenceList(iExpr.TemplateArguments);
          return iExpr;
#if !MinimalReader
        case NodeType.NonEmptyStreamTypeExpression:
          NonEmptyStreamTypeExpression neExpr = (NonEmptyStreamTypeExpression)type;
          neExpr.ElementType = this.VisitTypeReference(neExpr.ElementType);
          return neExpr;
        case NodeType.NonNullTypeExpression:
          NonNullTypeExpression nnExpr = (NonNullTypeExpression)type;
          nnExpr.ElementType = this.VisitTypeReference(nnExpr.ElementType);
          return nnExpr;
        case NodeType.NonNullableTypeExpression:
          NonNullableTypeExpression nbExpr = (NonNullableTypeExpression)type;
          nbExpr.ElementType = this.VisitTypeReference(nbExpr.ElementType);
          return nbExpr;
        case NodeType.NullableTypeExpression:
          NullableTypeExpression nuExpr = (NullableTypeExpression)type;
          nuExpr.ElementType = this.VisitTypeReference(nuExpr.ElementType);
          return nuExpr;
#endif
        case NodeType.OptionalModifier:{
          TypeModifier modType = (TypeModifier)type;
          TypeNode modifiedType = this.VisitTypeReference(modType.ModifiedType);
          TypeNode modifierType = this.VisitTypeReference(modType.Modifier);
          if (modifiedType == null || modifierType == null) { return type; }
#if ExtendedRuntime
          if (modifierType != null && modifierType == SystemTypes.NullableType){
            if (modifiedType.IsValueType) return modifiedType;
            if (TypeNode.HasModifier(modifiedType, SystemTypes.NonNullType))
              modifiedType = TypeNode.StripModifier(modifiedType, SystemTypes.NonNullType);
            if (modifiedType.IsTemplateParameter) {
              return OptionalModifier.For(modifierType, modifiedType);
            }
            return modifiedType;
          }
          if (modifierType == SystemTypes.NonNullType) {
            if (modifiedType.IsValueType) return modifiedType;
            modifiedType = TypeNode.StripModifier(modifiedType, SystemTypes.NonNullType);
          }
          //^ assert modifiedType != null;
#endif
          return OptionalModifier.For(modifierType, modifiedType);
        }
        case NodeType.RequiredModifier:{
          TypeModifier modType = (TypeModifier)type;
          TypeNode modifiedType = this.VisitTypeReference(modType.ModifiedType);
          TypeNode modifierType = this.VisitTypeReference(modType.Modifier);
          if (modifiedType == null || modifierType == null) { Debug.Fail(""); return type; }
          return RequiredModifier.For(modifierType, modifiedType);
        }
#if !MinimalReader && !CodeContracts
        case NodeType.OptionalModifierTypeExpression:
          OptionalModifierTypeExpression optmodType = (OptionalModifierTypeExpression)type;
          optmodType.ModifiedType = this.VisitTypeReference(optmodType.ModifiedType);
          optmodType.Modifier = this.VisitTypeReference(optmodType.Modifier);
          return optmodType;
        case NodeType.RequiredModifierTypeExpression:
          RequiredModifierTypeExpression reqmodType = (RequiredModifierTypeExpression)type;
          reqmodType.ModifiedType = this.VisitTypeReference(reqmodType.ModifiedType);
          reqmodType.Modifier = this.VisitTypeReference(reqmodType.Modifier);
          return reqmodType;
        case NodeType.PointerTypeExpression:
          PointerTypeExpression pExpr = (PointerTypeExpression)type;
          pExpr.ElementType = this.VisitTypeReference(pExpr.ElementType);
          return pExpr;
        case NodeType.ReferenceTypeExpression:
          ReferenceTypeExpression rExpr = (ReferenceTypeExpression)type;
          rExpr.ElementType = this.VisitTypeReference(rExpr.ElementType);
          return rExpr;
        case NodeType.StreamTypeExpression:
          StreamTypeExpression sExpr = (StreamTypeExpression)type;
          sExpr.ElementType = this.VisitTypeReference(sExpr.ElementType);
          return sExpr;
        case NodeType.TupleTypeExpression:
          TupleTypeExpression tuExpr = (TupleTypeExpression)type;
          tuExpr.Domains = this.VisitFieldList(tuExpr.Domains);
          return tuExpr;
        case NodeType.TypeExpression:{
          TypeExpression tExpr = (TypeExpression)type;
          tExpr.Expression = this.VisitTypeExpression(tExpr.Expression);
          if (tExpr.Expression is Literal) return type;
          tExpr.TemplateArguments = this.VisitTypeReferenceList(tExpr.TemplateArguments);
          return tExpr;}
        case NodeType.TypeIntersectionExpression:
          TypeIntersectionExpression tiExpr = (TypeIntersectionExpression)type;
          tiExpr.Types = this.VisitTypeReferenceList(tiExpr.Types);
          return tiExpr;
        case NodeType.TypeUnionExpression:
          TypeUnionExpression tyuExpr = (TypeUnionExpression)type;
          tyuExpr.Types = this.VisitTypeReferenceList(tyuExpr.Types);
          return tyuExpr;
#endif
        default:
          if (type.Template != null)
          {
            Debug.Assert(TypeNode.IsCompleteTemplate(type.Template));
            // map consolidated arguments
            bool mustSpecializeFurther = false;
            TypeNodeList targs = type.ConsolidatedTemplateArguments;
            int numArgs = targs == null ? 0 : targs.Count;
            if (targs != null)
            {
              targs = targs.Clone();
              for (int i = 0; i < numArgs; i++)
              {
                TypeNode targ = targs[i];
                targs[i] = this.VisitTypeReference(targ);
                if (targ != targs[i]) { mustSpecializeFurther = true; }
              }
            }
            if (targs == null || !mustSpecializeFurther) return type;
            TypeNode t = type.Template.GetGenericTemplateInstance(this.TargetModule, targs);
            return t;
          }
          return type;
#if OLD
          TypeNode declaringType = this.VisitTypeReference(type.DeclaringType);
          if (declaringType != null){
            Identifier tname = type.Name;
            if (type.Template != null && type.IsGeneric) tname = type.Template.Name;
            TypeNode nt = declaringType.GetNestedType(tname);
            if (nt != null){
              TypeNodeList arguments = type.TemplateArguments;
              type = nt;
              if (TargetPlatform.UseGenerics) {
                if (arguments != null && arguments.Count > 0 && nt.ConsolidatedTemplateParameters != null && nt.ConsolidatedTemplateParameters.Count > 0)
                  type = nt.GetTemplateInstance(this.TargetModule, this.CurrentType, declaringType, arguments);
              }
            }
          }
          if (type.Template != null && (type.ConsolidatedTemplateParameters == null || type.ConsolidatedTemplateParameters.Count == 0)){
            if (!type.IsNotFullySpecialized && !type.IsNormalized) return type;
            //Type is a template instance, but some of its arguments were themselves parameters.
            //See if any of these parameters are to be specialized by this specializer.
            bool mustSpecializeFurther = false;
            TypeNodeList targs = type.TemplateArguments;
            int numArgs = targs == null ? 0 : targs.Count;
            if (targs != null) {
              targs = targs.Clone();
              for (int i = 0; i < numArgs; i++) {
                TypeNode targ = targs[i];
                ITypeParameter tparg = targ as ITypeParameter;
                if (tparg != null) {
                  for (int j = 0, np = pars == null ? 0 : pars.Count, m = args == null ? 0 : args.Count; j < np && j < m; j++) {
                    //^ assert pars != null && args != null;
                    if (TargetPlatform.UseGenerics) {
                      ITypeParameter par = pars[j] as ITypeParameter;
                      if (par == null) continue;
                      if (tparg == par || (tparg.ParameterListIndex == par.ParameterListIndex && tparg.DeclaringMember == par.DeclaringMember)) {
                        targ = this.args[j]; break;
                      }
                    }
                    else {
                      if (targ == pars[j]) { targ = this.args[j]; break; }
                    }
                  }
                } else {
                  if (targ != type)
                    targ = this.VisitTypeReference(targ);
                  if (targ == type) continue;
                }
                mustSpecializeFurther |= targs[i] != targ;
                targs[i] = targ;
              }
            }
            if (targs == null || !mustSpecializeFurther) return type;
            TypeNode t = type.Template.GetTemplateInstance(this.TargetModule, this.CurrentType, declaringType, targs);
#if ExtendedRuntime
            if (this.CurrentType != null) {
              if (this.CurrentType.ReferencedTemplateInstances == null) this.CurrentType.ReferencedTemplateInstances = new TypeNodeList();
              this.CurrentType.ReferencedTemplateInstances.Add(t);
            }
#endif
            return t;
          }
          TypeNodeList tPars = type.TemplateParameters;
          if (tPars == null || tPars.Count == 0) return type; //Not a parameterized type. No need to get an instance.
          TypeNodeList tArgs = new TypeNodeList();
          for (int i = 0, n = tPars.Count; i < n; i++) {
            TypeNode tPar = tPars[i];
            tArgs.Add(tPar); //Leave parameter in place if there is no match
            if (tPar == null || tPar.Name == null) continue;
            int idKey = tPar.Name.UniqueIdKey;
            for (int j = 0, m = pars == null ? 0 : pars.Count, k = args == null ? 0 : args.Count; j < m && j < k; j++) {
              //^ assert pars != null && args != null;
              TypeNode par = pars[j];
              if (par == null || par.Name == null) continue;
              if (par.Name.UniqueIdKey == idKey) {
                tArgs[i] = args[j];
                break;
              }
            }
          }
          TypeNode ti = type.GetTemplateInstance(this.TargetModule, this.CurrentType, this.VisitTypeReference(type.DeclaringType), tArgs);
#if ExtendedRuntime
          if (this.CurrentType != null) {
            if (this.CurrentType.ReferencedTemplateInstances == null) this.CurrentType.ReferencedTemplateInstances = new TypeNodeList();
            this.CurrentType.ReferencedTemplateInstances.Add(ti);
          }
#endif
          return ti;
#endif
      }
    }
Пример #48
0
 private static FieldList GetAppliedFields(EnumNode enumeration, long value) {
     // if a single field matches, return it;
     // otherwise return all fields that are in value
     FieldList list = new FieldList();
     MemberList members = enumeration.Members;
     for (int i = 0; i < members.Count; i++) {
         if (members[i].NodeType != NodeType.Field) continue;
         Field field = (Field)members[i];
         if (field.DefaultValue == null) continue;
         long fieldValue = Convert.ToInt64(field.DefaultValue.Value);
         if (fieldValue == value) {
             return (new FieldList(new Field[1] { field }));
         } else if ((fieldValue & value) == fieldValue) {
             list.Add(field);
         }
     }
     return (list);
 }
Пример #49
0
 /// <summary>
 /// Gets the standard fields.
 /// </summary>
 /// <param name="fields">The fields.</param>
 /// <param name="index">The index.</param>
 private void GetStandardFields(FieldList fields, int index)
 {
     fields.Add(FieldIDs.ReadOnly, "1");
     fields.Add(FieldIDs.Sortorder, index.ToString());
 }
Пример #50
0
 public override Node VisitQueryProject(QueryProject project){
   if (project == null) return null;
   project.Source = this.VisitExpression(project.Source);
   if (project.Source == null || project.Source.Type == null) return project;
   TypeNode sourceElementType = this.typeSystem.GetStreamElementType(project.Source, this.TypeViewer);
   project.Context = this.contextScope = new ContextScope(this.contextScope, sourceElementType);
   ExpressionList list = new ExpressionList();
   for (int i=0; i < project.ProjectionList.Count; i++){
     QueryAxis axis = project.ProjectionList[i] as QueryAxis;
     if (axis != null && axis.Name == Identifier.Empty){
       axis.Source = this.VisitExpression(axis.Source);
       this.ResolveAxis(axis);
       this.GetProjectionList(axis.AccessPlan, axis.Source, list);
     }
     else{
       list.Add(this.VisitExpression(project.ProjectionList[i]));
     }
   }      
   project.ProjectionList = list;
   this.contextScope = this.contextScope.Previous;
   if (project.ProjectedType == null){
     int len = project.ProjectionList.Count;
     if (len == 1 && this.GetExpressionName(project.ProjectionList[0]) == null){
       Expression x = project.ProjectionList[0];
       if (x != null && x.Type != null) 
         project.ProjectedType = x.Type;
     }
     else{
       FieldList fields = new FieldList();
       for( int i = 0, cn = 0; i < len; i++ ){
         Expression x = project.ProjectionList[i];
         if (x != null && x.Type != null){
           Identifier name = this.GetExpressionName(x);
           Field f = new Field(null, new AttributeList(1), FieldFlags.Public, name, x.Type, null);
           if (name == null || name == Identifier.Empty){
             f.Name = Identifier.For("Item"+cn); cn++;
             f.Attributes.Add(new AttributeNode(new MemberBinding(null, SystemTypes.AnonymousAttribute.GetConstructor()), null));
           }
           fields.Add(f);
         }
       }
       if (fields.Count == len){
         project.ProjectedType = TupleType.For(fields, this.currentType);
         project.Members = this.typeSystem.GetDataMembers(project.ProjectedType);
       }
     }
   }
   if (project.ProjectedType != null){
     project.Type = this.GetResultType(project.Source, project.ProjectedType, Cardinality.One);
   }
   return project;
 }
Пример #51
0
    public virtual FieldList GetFieldList(ID templateId, string itemName)
    {
      Assert.ArgumentCondition(!ID.IsNullOrEmpty(templateId), "templateId", "Value cannot be null.");

      var template = this.GetFakeTemplate(templateId);
      Assert.IsNotNull(template, "Template '{0}' not found.", templateId);

      var fields = new FieldList();
      foreach (var field in template.Fields)
      {
        fields.Add(field.ID, string.Empty);
      }

      return fields;
    }
 /// <summary>
 /// Get a list of all the item's fields and their values.
 /// </summary>
 /// <param name="itemDefinition">Used to identify the particular item</param>
 /// <param name="versionUri">The language and version of the item to get field values for</param>
 /// <param name="context"></param>
 /// <returns></returns>
 public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
 {
     Item result = Items.FindOneById(itemDefinition.ID.ToGuid());
     if (result != null && result.FieldValues != null)
     {
         FieldList fields = new FieldList();
         foreach (KeyValuePair<FieldValueId, string> fieldValue in result.FieldValues.Where(fv => fv.Key.Matches(versionUri)))
         {
             fields.Add(new ID(fieldValue.Key.FieldId), fieldValue.Value);
         }
         return fields;
     }
     return null;
 }
Пример #53
0
 /// <summary>
 /// Gets the standard fields.
 /// </summary>
 /// <param name="fields">The fields.</param>
 /// <param name="index">The index.</param>
 private void GetStandardFields(FieldList fields, int index)
 {
     fields.Add(FieldIDs.ReadOnly, "1");
     fields.Add(FieldIDs.Sortorder, index.ToString(CultureInfo.InvariantCulture));
 }
 private void GetStandardFields(FieldList fields, int index)
 {
     fields.Add(ReadOnlyFieldId, "1");
     fields.Add(SortOrderFieldId, index.ToString());
 }
Пример #55
0
        public override Data.FieldList GetItemFields(Data.ItemDefinition itemDefinition, Data.VersionUri versionUri, CallContext context)
        {
            XPathNavigator element = (XPathNavigator)courseCache[itemDefinition.ID];// CourseData.SelectSingleNode(string.Format("//course[@id='{0}']", itemDefinition.ID.ToString()));
            if (element != null)
            {
                FieldList fieldList = new FieldList();
                fieldList.Add(ID.Parse("{DA699F8C-F0AF-4377-A57F-1FC0D63B4721}"), element.SelectSingleNode("./name").Value);
                fieldList.Add(ID.Parse("{372CD04F-9224-4302-AF9E-E3DED2DB5E64}"), element.SelectSingleNode("./costs").Value);
                return fieldList;
            }

            return base.GetItemFields(itemDefinition, versionUri, context);
        }
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            var fields = new FieldList();

            if (itemDefinition == ItemDefinition.Empty)
            {
                return fields;
            }

            var database = GetDatabase(context);
            var syncItem = database.GetItem(itemDefinition.ID.ToString(), versionUri.Language.Name);

            if (syncItem == null)
            {
                return fields;
            }

            foreach (var syncField in syncItem.SharedFields)
            {
                fields.Add(ID.Parse(syncField.FieldID), syncField.FieldValue);
            }

            var syncVersion = syncItem.GetLatestVersions().Where(v => v.Language.Equals(versionUri.Language.Name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (syncVersion == null)
            {
                return fields;
            }

            foreach (var syncField in syncVersion.Fields)
            {
                fields.Add(ID.Parse(syncField.FieldID), syncField.FieldValue);
            }

            return fields;
        }
Пример #57
0
    public FieldList BuildItemFieldList(DbItem fakeItem, ID templateId, Language language, Version version)
    {
      // build a sequence of templates that the item inherits from
      var templates = this.ExpandTemplatesSequence(templateId);

      var fields = new FieldList();
      foreach (var template in templates)
      {
        this.AddFieldsFromTemplate(fields, fakeItem, template, language, version);
      }

      // If the item is a Template item we also need to add the BaseTemplate field
      var fakeItemAsTemplate = fakeItem as DbTemplate;
      if (fakeItemAsTemplate != null && fakeItemAsTemplate.BaseIDs != null)
      {
        fields.Add(FieldIDs.BaseTemplate, string.Join("|", fakeItemAsTemplate.BaseIDs.ToList()));
      }

      return fields;
    }
        /// <summary>
        /// Get a list of all the item's fields and their values.
        /// </summary>
        /// <param name="itemDefinition">Used to identify the particular item</param>
        /// <param name="versionUri">The language and version of the item to get field values for</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            Language language = versionUri.Language;
            if (Language.Invariant.Equals(language))
            {
                language = Sitecore.Data.Managers.LanguageManager.DefaultLanguage;
            }
            if (ItemsById.ContainsKey(itemDefinition.ID))
            {
                FieldList fields = new FieldList();
                foreach (SyncField sharedField in ItemsById[itemDefinition.ID].SharedFields)
                {
                    fields.Add(ParseId(sharedField.FieldID), sharedField.FieldValue);
                }

                if (ItemsById[itemDefinition.ID].Versions != null)
                {
                    foreach (SyncVersion version in ItemsById[itemDefinition.ID].Versions)
                    {
                        if (language.Name.Equals(version.Language)
                            && versionUri.Version.Number.ToString().Equals(version.Version))
                        {
                            foreach (SyncField fieldValue in version.Fields)
                            {
                                fields.Add(ParseId(fieldValue.FieldID), fieldValue.FieldValue);
                            }
                            break;
                        }
                    }
                }

                return fields;
            }
            return null;
        }
Пример #59
0
 public virtual FieldList VisitFieldList(FieldList fields, FieldList changes, FieldList deletions, FieldList insertions){
   if (changes == null || deletions == null || insertions == null) return fields;
   int n = fields == null ? 0 : fields.Count;
   if (n > changes.Count){Debug.Assert(false); n = changes.Count;}
   if (n > deletions.Count){Debug.Assert(false); n = deletions.Count;}
   if (n > insertions.Count){Debug.Assert(false); n = insertions.Count;}
   if (fields != null)
     for (int i = 0; i < n; i++)
       fields[i] = this.VisitField(fields[i], changes[i], deletions[i], insertions[i]);
   FieldList result = new FieldList(insertions.Count-n);
   for (int i = n, m = insertions.Count; i < m; i++)
     result.Add(insertions[i]);
   return result;
 }
Пример #60
0
        public override TypeNode VisitTypeReference(TypeNode type)
        {
            if (type == null) return null;
            TypeNode dup = (TypeNode)this.DuplicateFor[type.UniqueKey];
            if (dup != null && (dup.Template != type || this.RecordOriginalAsTemplate)) return dup;
            switch (type.NodeType)
            {
                case NodeType.ArrayType:
                    ArrayType arrType = (ArrayType)type;
                    TypeNode elemType = this.VisitTypeReference(arrType.ElementType);
                    if (elemType == arrType.ElementType) return arrType;
                    if (elemType == null) { Debug.Fail(""); return null; }
                    this.TypesToBeDuplicated[arrType.UniqueKey] = arrType;
                    dup = elemType.GetArrayType(arrType.Rank, arrType.Sizes, arrType.LowerBounds);
                    break;
                case NodeType.ClassParameter:
                case NodeType.TypeParameter:
                    if (this.RecordOriginalAsTemplate) return type;
                    if (this.TypesToBeDuplicated[type.UniqueKey] == null) return type;
                    dup = this.VisitTypeNode(type);
                    break;
#if !MinimalReader
                case NodeType.DelegateNode:
                    {
                        FunctionType ftype = type as FunctionType;
                        if (ftype == null) goto default;
                        dup = FunctionType.For(this.VisitTypeReference(ftype.ReturnType), this.VisitParameterList(ftype.Parameters), this.TargetType);
                        break;
                    }
#endif
                case NodeType.Pointer:
                    Pointer pType = (Pointer)type;
                    elemType = this.VisitTypeReference(pType.ElementType);
                    if (elemType == pType.ElementType) return pType;
                    if (elemType == null) { Debug.Fail(""); return null; }
                    dup = elemType.GetPointerType();
                    break;
                case NodeType.Reference:
                    Reference rType = (Reference)type;
                    elemType = this.VisitTypeReference(rType.ElementType);
                    if (elemType == rType.ElementType) return rType;
                    if (elemType == null) { Debug.Fail(""); return null; }
                    dup = elemType.GetReferenceType();
                    break;
#if ExtendedRuntime    
        case NodeType.TupleType:{
          TupleType tType = (TupleType)type;
          bool reconstruct = false;
          MemberList members = tType.Members;
          int n = members == null ? 0 : members.Count;
          FieldList fields = new FieldList(n);
          for (int i = 0; i < n; i++){
            //^ assert members != null;
            Field f = members[i] as Field;
            if (f == null) continue;
            f = (Field)f.Clone();
            fields.Add(f);
            TypeNode oft = f.Type;
            TypeNode ft = f.Type = this.VisitTypeReference(f.Type);
            if (ft != oft) reconstruct = true;
          }
          if (!reconstruct) return tType;
          dup = TupleType.For(fields, this.TargetType);
          break;}
        case NodeType.TypeIntersection:
          TypeIntersection tIntersect = (TypeIntersection)type;
          dup = TypeIntersection.For(this.VisitTypeReferenceList(tIntersect.Types), this.TargetType);
          break;
        case NodeType.TypeUnion:
          TypeUnion tUnion = (TypeUnion)type;
          TypeNodeList types = this.VisitTypeReferenceList(tUnion.Types);
          if (types == null) { Debug.Fail(""); return null; }
          if (this.TargetType == null)
            dup = TypeUnion.For(types, TargetModule);
          else
            dup = TypeUnion.For(types, this.TargetType);
          break;
#endif
#if !MinimalReader
                //These types typically have only one reference and do not have pointer identity. Just duplicate them.
                case NodeType.ArrayTypeExpression:
                    ArrayTypeExpression aExpr = (ArrayTypeExpression)type.Clone();
                    elemType = this.VisitTypeReference(aExpr.ElementType);
                    if (elemType == null) { Debug.Fail(""); return aExpr; }
                    aExpr.ElementType = elemType;
                    return aExpr;
                case NodeType.BoxedTypeExpression:
                    BoxedTypeExpression bExpr = (BoxedTypeExpression)type.Clone();
                    bExpr.ElementType = this.VisitTypeReference(bExpr.ElementType);
                    return bExpr;
                case NodeType.ClassExpression:
                    ClassExpression cExpr = (ClassExpression)type.Clone();
                    cExpr.Expression = this.VisitExpression(cExpr.Expression);
                    cExpr.TemplateArguments = this.VisitTypeReferenceList(cExpr.TemplateArguments);
                    return cExpr;
#endif
#if ExtendedRuntime
        case NodeType.ConstrainedType:
          ConstrainedType conType = (ConstrainedType)type;
          TypeNode underlyingType = this.VisitTypeReference(conType.UnderlyingType);
          Expression constraint = this.VisitExpression(conType.Constraint);
          if (underlyingType == null || constraint == null) { Debug.Fail(""); return null; }
          if (this.TargetType == null)
            return null;
          else
            return new ConstrainedType(underlyingType, constraint, this.TargetType);
#endif
#if !MinimalReader
                case NodeType.FlexArrayTypeExpression:
                    FlexArrayTypeExpression flExpr = (FlexArrayTypeExpression)type.Clone();
                    flExpr.ElementType = this.VisitTypeReference(flExpr.ElementType);
                    return flExpr;
#endif
                case NodeType.FunctionPointer:
                    FunctionPointer funcPointer = (FunctionPointer)type.Clone();
                    funcPointer.ParameterTypes = this.VisitTypeReferenceList(funcPointer.ParameterTypes);
                    funcPointer.ReturnType = this.VisitTypeReference(funcPointer.ReturnType);
                    return funcPointer;
#if !MinimalReader
                case NodeType.FunctionTypeExpression:
                    FunctionTypeExpression ftExpr = (FunctionTypeExpression)type.Clone();
                    ftExpr.Parameters = this.VisitParameterList(ftExpr.Parameters);
                    ftExpr.ReturnType = this.VisitTypeReference(ftExpr.ReturnType);
                    return ftExpr;
                case NodeType.InvariantTypeExpression:
                    InvariantTypeExpression invExpr = (InvariantTypeExpression)type.Clone();
                    invExpr.ElementType = this.VisitTypeReference(invExpr.ElementType);
                    return invExpr;
#endif
                case NodeType.InterfaceExpression:
                    InterfaceExpression iExpr = (InterfaceExpression)type.Clone();
                    iExpr.Expression = this.VisitExpression(iExpr.Expression);
                    iExpr.TemplateArguments = this.VisitTypeReferenceList(iExpr.TemplateArguments);
                    return iExpr;
#if !MinimalReader
                case NodeType.NonEmptyStreamTypeExpression:
                    NonEmptyStreamTypeExpression neExpr = (NonEmptyStreamTypeExpression)type.Clone();
                    neExpr.ElementType = this.VisitTypeReference(neExpr.ElementType);
                    return neExpr;
                case NodeType.NonNullTypeExpression:
                    NonNullTypeExpression nnExpr = (NonNullTypeExpression)type.Clone();
                    nnExpr.ElementType = this.VisitTypeReference(nnExpr.ElementType);
                    return nnExpr;
                case NodeType.NonNullableTypeExpression:
                    NonNullableTypeExpression nbExpr = (NonNullableTypeExpression)type.Clone();
                    nbExpr.ElementType = this.VisitTypeReference(nbExpr.ElementType);
                    return nbExpr;
                case NodeType.NullableTypeExpression:
                    NullableTypeExpression nuExpr = (NullableTypeExpression)type.Clone();
                    nuExpr.ElementType = this.VisitTypeReference(nuExpr.ElementType);
                    return nuExpr;
#endif
                case NodeType.OptionalModifier:
                    TypeModifier modType = (TypeModifier)type;
                    TypeNode modified = this.VisitTypeReference(modType.ModifiedType);
                    TypeNode modifier = this.VisitTypeReference(modType.Modifier);
                    if (modified == null || modifier == null) { Debug.Fail(""); return null; }
                    return OptionalModifier.For(modifier, modified);
                case NodeType.RequiredModifier:
                    modType = (TypeModifier)type;
                    modified = this.VisitTypeReference(modType.ModifiedType);
                    modifier = this.VisitTypeReference(modType.Modifier);
                    if (modified == null || modifier == null) { Debug.Fail(""); return null; }
                    return RequiredModifier.For(modifier, modified);
#if !MinimalReader
                case NodeType.OptionalModifierTypeExpression:
                    OptionalModifierTypeExpression optmodType = (OptionalModifierTypeExpression)type.Clone();
                    optmodType.ModifiedType = this.VisitTypeReference(optmodType.ModifiedType);
                    optmodType.Modifier = this.VisitTypeReference(optmodType.Modifier);
                    return optmodType;
                case NodeType.RequiredModifierTypeExpression:
                    RequiredModifierTypeExpression reqmodType = (RequiredModifierTypeExpression)type.Clone();
                    reqmodType.ModifiedType = this.VisitTypeReference(reqmodType.ModifiedType);
                    reqmodType.Modifier = this.VisitTypeReference(reqmodType.Modifier);
                    return reqmodType;
                case NodeType.PointerTypeExpression:
                    PointerTypeExpression pExpr = (PointerTypeExpression)type.Clone();
                    elemType = this.VisitTypeReference(pExpr.ElementType);
                    if (elemType == null) { Debug.Fail(""); return pExpr; }
                    pExpr.ElementType = elemType;
                    return pExpr;
                case NodeType.ReferenceTypeExpression:
                    ReferenceTypeExpression rExpr = (ReferenceTypeExpression)type.Clone();
                    elemType = this.VisitTypeReference(rExpr.ElementType);
                    if (elemType == null) { Debug.Fail(""); return rExpr; }
                    rExpr.ElementType = elemType;
                    return rExpr;
                case NodeType.StreamTypeExpression:
                    StreamTypeExpression sExpr = (StreamTypeExpression)type.Clone();
                    sExpr.ElementType = this.VisitTypeReference(sExpr.ElementType);
                    return sExpr;
                case NodeType.TupleTypeExpression:
                    TupleTypeExpression tuExpr = (TupleTypeExpression)type.Clone();
                    tuExpr.Domains = this.VisitFieldList(tuExpr.Domains);
                    return tuExpr;
                case NodeType.TypeExpression:
                    TypeExpression tExpr = (TypeExpression)type.Clone();
                    tExpr.Expression = this.VisitExpression(tExpr.Expression);
                    tExpr.TemplateArguments = this.VisitTypeReferenceList(tExpr.TemplateArguments);
                    return tExpr;
                case NodeType.TypeIntersectionExpression:
                    TypeIntersectionExpression tiExpr = (TypeIntersectionExpression)type.Clone();
                    tiExpr.Types = this.VisitTypeReferenceList(tiExpr.Types);
                    return tiExpr;
                case NodeType.TypeUnionExpression:
                    TypeUnionExpression tyuExpr = (TypeUnionExpression)type.Clone();
                    tyuExpr.Types = this.VisitTypeReferenceList(tyuExpr.Types);
                    return tyuExpr;
#endif
                default:
                    if (type.Template != null && type.Template != type && (type.TemplateArguments != null ||
                    (!this.RecordOriginalAsTemplate && type.ConsolidatedTemplateArguments != null && type.ConsolidatedTemplateArguments.Count > 0)))
                    {
                        TypeNode templ = this.VisitTypeReference(type.Template);
                        //^ assume templ != null;
                        if (TargetPlatform.UseGenerics)
                        {
                            if (templ.Template != null)
                            {
                                if (this.RecordOriginalAsTemplate)
                                    templ = templ.Template;
                                else
                                    templ = this.VisitTypeReference(templ.Template);
                                //^ assume templ != null;
                            }
                            if (type.DeclaringType != null)
                            {
                                TypeNode declType = this.VisitTypeReference(type.DeclaringType);
                                if (declType != null)
                                {
                                    TypeNode templDup = declType.GetNestedType(templ.Name);
                                    if (templDup == null)
                                    {
                                        //Can happen when templ is nested in a type that is still being duplicated
                                        templDup = (TypeNode)templ.Clone();
                                        templDup.DeclaringModule = this.TargetModule;
                                        templDup.Template = templ;
                                        declType.NestedTypes.Add(templDup);
                                        templ = templDup;
                                    }
                                    else
                                    {
                                        templ = templDup;
                                        if (templ.Template != null)
                                        {
                                            if (this.RecordOriginalAsTemplate)
                                                templ = templ.Template;
                                            else
                                            {
                                                if (templ.Template.DeclaringType == null)
                                                    templ.Template.DeclaringType = templ.DeclaringType.Template;
                                                templ = this.VisitTypeReference(templ.Template);
                                            }
                                            //^ assume templ != null;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (templ.Template != null) return type;
                        }
                        bool duplicateReference = templ != type.Template;
                        TypeNodeList targs = type.TemplateArguments == null ? new TypeNodeList() : type.TemplateArguments.Clone();
                        if (!this.RecordOriginalAsTemplate)
                            targs = type.ConsolidatedTemplateArguments == null ? new TypeNodeList() : type.ConsolidatedTemplateArguments.Clone();
                        for (int i = 0, n = targs == null ? 0 : targs.Count; i < n; i++)
                        {
                            TypeNode targ = targs[i];
                            if (targ == null) continue;
                            TypeNode targDup = this.VisitTypeReference(targ);
                            if (targ != targDup) duplicateReference = true;
                            targs[i] = targDup;
                        }
                        if (!duplicateReference) return type;
                        if (!this.RecordOriginalAsTemplate)
                            dup = templ.GetGenericTemplateInstance(this.TargetModule, targs);
                        else
                            dup = templ.GetTemplateInstance(this.TargetModule, this.TargetType, type.DeclaringType, targs);
                        this.DuplicateFor[type.UniqueKey] = dup;
                        return dup;
                    }
                    if (this.TypesToBeDuplicated[type.UniqueKey] == null) return type;
                    TypeNode savedTargetType = this.TargetType;
                    TypeNode declaringType = this.VisitTypeReference(type.DeclaringType);
                    if (declaringType != null)
                    {
                        dup = (TypeNode)this.DuplicateFor[type.UniqueKey];
                        if (dup != null) return dup;
                        if (declaringType == type.DeclaringType)
                        {
                            //Trying to duplicate a nested type into a type that is not the duplicate of the declaring type.
                            //In this case, type is being duplicated into the original target type.
                            declaringType = this.OriginalTargetType;
                        }
                    }
                    this.TargetType = declaringType;
                    dup = (TypeNode)this.Visit(type);
                    this.TargetType = savedTargetType;
                    break;
            }
            this.DuplicateFor[type.UniqueKey] = dup;
            return dup;
        }