/// <summary>
        /// Sets field mapper for the specified <paramref name="field"/>
        /// </summary>
        /// <typeparam name="TSPItem">Exact SP list item type, i.e. SPListItem for SSOM, or ListItem for CSOM.</typeparam>
        /// <param name="field">Current field.</param>
        /// <param name="mapper">Instance of <see cref="FieldMapper{TSPItem}"/> that should be associated with specified <see cref="MetaField"/></param>
        /// <exception cref="ArgumentNullException"><paramref name="field"/> or <paramref name="mapper"/> is null.</exception>
        public static void SetMapper <TSPItem>([NotNull] this MetaField field, [NotNull] FieldMapper <TSPItem> mapper)
        {
            Guard.CheckNotNull(nameof(field), field);
            Guard.CheckNotNull(nameof(mapper), mapper);

            field.SetAdditionalProperty(MapperProperty, mapper);
        }
Exemple #2
0
        public void FieldMapperTests_NestedKeys_OnSameLine()
        {
            // Arrange
            var emailKey      = "Email Name";
            var emailValue    = "*****@*****.**";
            var phoneKey      = "Phone";
            var phoneValue    = "5555551234";
            var fullNameKey   = "Name";
            var fullNameValue = "Joe Moceri";
            var zipKey        = "Zip Name";
            var zipValue      = "00000";

            var content  = $"{emailKey} {emailValue} {phoneKey} {phoneValue} {fullNameKey} {fullNameValue} {zipKey} {zipValue}";
            var mappings = new List <string>();

            mappings.Add(emailKey);
            mappings.Add(fullNameKey);
            mappings.Add(phoneKey);
            mappings.Add(zipKey);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(emailValue, result[emailKey]);
            Assert.AreEqual(fullNameValue, result[fullNameKey]);
            Assert.AreEqual(phoneValue, result[phoneKey]);
            Assert.AreEqual(zipValue, result[zipKey]);
        }
Exemple #3
0
        public void FieldMapperTests_NestedKeys_Double_OnDifferentLines()
        {
            // Arrange
            var    emailKey   = "Email Name";
            string emailValue = "*****@*****.**";
            string phoneKey   = "Phone";
            string phoneValue = "5551231234";

            var content = string.Format("{1} {0} {2} {0} {3} {0} {4}",
                                        Environment.NewLine,
                                        emailKey,
                                        emailValue,
                                        phoneKey,
                                        phoneValue
                                        );

            var mappings = new List <string>();

            mappings.Add(emailKey);
            mappings.Add(phoneKey);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(emailValue, result[emailKey]);
            Assert.AreEqual(phoneValue, result[phoneKey]);
        }
Exemple #4
0
        private static string GetFieldName<T>(Expression<Func<T, object>> selector)
        {
            var visitor = new MemberAccessVisitor();
            string propName = visitor.GetMemberName(selector);

            var fieldName = FieldMapper.TranslateToFieldName(propName);

            var type = typeof(T);
            var property = type.GetProperty(propName);
            var attrs = property.GetCustomAttributes(typeof(FieldAttribute), false);

            if (attrs.Length != 0)
            {
                var attr = (FieldAttribute)attrs[0];
                if (attr.Name != null)
                    fieldName = attr.Name;
            }
            
            if (CommonHelper.IsPropertyNotMapped(property))
            {
                // allow to use FieldRef<Document>(d => d.Name)
                if (propName != "Name")
                {
                    throw new SharepointCommonException("Cannot use FieldRef<> with property marked as 'NotField'");
                }
            }

            return fieldName;
        }
Exemple #5
0
 public Either <RfcErrorInfo, T> GetFieldValue <T>(IDataContainerHandle handle, Func <Either <RfcErrorInfo, RfcFieldInfo> > func)
 {
     return(func().Bind(fieldInfo =>
     {
         Logger.IfSome(l => l.LogTrace("reading field value", new { handle, fieldInfo, TargetType = typeof(T) }));
         return FieldMapper.GetField <T>(new FieldMappingContext(this, handle, fieldInfo));
     }));
 }
Exemple #6
0
 public Either <RfcErrorInfo, Unit> SetFieldValue <T>(IDataContainerHandle handle, T value, Func <Either <RfcErrorInfo, RfcFieldInfo> > func)
 {
     return(func().Bind(fieldInfo =>
     {
         Logger.IfSome(l => l.LogTrace("setting field value", new { handle, fieldInfo, SourceType = typeof(T) }));
         return FieldMapper.SetField(value, new FieldMappingContext(this, handle, fieldInfo));
     }));
 }
Exemple #7
0
        /**
         * This console app will sync products created in the last X time
         */
        public static void Main()
        {
            _cachedEaAuthToken      = GetEaAuthToken();
            _cachedMagentoAuthToken = GetMagentoAuthToken();

            var controllerFactory = new ControllerFactory(_cachedMagentoAuthToken, _cachedEaAuthToken);

            var assetsController         = controllerFactory.CreateController(ControllerType.Assets) as AssetsController;
            var availabilityController   = controllerFactory.CreateController(ControllerType.Availability) as AvailabilityController;
            var catalogsController       = controllerFactory.CreateController(ControllerType.Catalogs) as CatalogsController;
            var entitiesController       = controllerFactory.CreateController(ControllerType.Entities) as EntitiesController;
            var fieldController          = controllerFactory.CreateController(ControllerType.FieldDefinition) as FieldDefinitionController;
            var ordersController         = controllerFactory.CreateController(ControllerType.Orders) as OrdersController;
            var pricingController        = controllerFactory.CreateController(ControllerType.Pricing) as PricingController;
            var productLibraryController = controllerFactory.CreateController(ControllerType.ProductLibrary) as ProductLibraryController;

            var cartController       = controllerFactory.CreateController(ControllerType.Cart) as CartController;
            var attributesController = controllerFactory.CreateController(ControllerType.CustomAttributes) as CustomAttributesController;
            var customerController   = controllerFactory.CreateController(ControllerType.Customer) as CustomerController;
            var productController    = controllerFactory.CreateController(ControllerType.Product) as ProductController;
            var regionController     = controllerFactory.CreateController(ControllerType.Region) as RegionController;

            _productMapper      = new ProductMapper(catalogsController, productLibraryController, productController);
            _assetMapper        = new AssetMapper(assetsController, productLibraryController, catalogsController);
            _availabilityMapper = new AvailabilityMapper(availabilityController);
            _colorMapper        = new ColorMapper(attributesController, productLibraryController);
            _fieldMapper        = new FieldMapper(productLibraryController, productController, fieldController, catalogsController, attributesController);
            _pricingMapper      = new PricingMapper(pricingController);
            _orderMapper        = new OrderMapper(ordersController, catalogsController, cartController, productController);
            _entityMapper       = new EntityMapper(entitiesController, regionController);
            _customerMapper     = new CustomerMapper(customerController);

            bool doOrderSync;
            bool productsSynced = ProductSync();

            if (productsSynced)
            {
                Console.WriteLine("Products successfully synced");
                doOrderSync = true;
            }
            else
            {
                Console.WriteLine("An error occurred while syncing products to Endless Aisle. Check errorLog.txt for more details.");
                Console.WriteLine("Continue on to synchronizing Orders to Magento?");
                doOrderSync = Console.ReadKey().ToString().Equals(UserAffirmativeString, StringComparison.OrdinalIgnoreCase);
            }

            //Order syncing
            if (doOrderSync)
            {
                bool ordersSynced = OrderSync();
                Console.WriteLine(ordersSynced
                                ? "Orders successfully synced"
                                : "An error occurred while syncing orders to Magento. Check errorLog.txt for more details.");
            }
            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
Exemple #8
0
        public void FieldMapperTests_Init_WhitespaceKeyInMappings_ShouldThrowArgumentException()
        {
            var mappings = Enumerable.Empty <string>().ToList();

            mappings.Add("      ");
            var content = "First Name: Joe";

            var parser = new FieldMapper(content, mappings);
        }
Exemple #9
0
        private string ParseBody(string message, Dictionary <Guid, RecordField> dictionary, Record record)
        {
            if (!string.IsNullOrEmpty(FieldMapper))
            {
                Hashtable ht = new Hashtable();

                string[] _fields = FieldMapper.Split(';');
                if (_fields.Length > 0)
                {
                    foreach (string field in _fields)
                    {
                        string[] vals = field.Split(',');
                        if (vals.Length == 3)
                        {
                            string formFieldId = string.Empty;
                            string alias       = vals[0];
                            string value       = string.Empty;

                            if (!string.IsNullOrEmpty(vals[1]))
                            {
                                formFieldId = vals[1];
                            }

                            if (!string.IsNullOrEmpty(formFieldId))
                            {
                                KeyValuePair <Guid, RecordField> formField = dictionary.SingleOrDefault(d => d.Key == new Guid(formFieldId));
                                if (!formField.Equals(default(KeyValuePair <Guid, RecordField>)))
                                {
                                    value = formField.Value.ValuesAsString();
                                }
                            }

                            if (!ht.ContainsKey(alias))
                            {
                                ht.Add(alias, value);
                            }
                        }
                    }

                    return(EvaluateVelocity(message, ht));
                }

                /*
                 * foreach (KeyValuePair<Guid, RecordField> keyValuePair in dictionary)
                 * {
                 *  Guid guid = keyValuePair.Key;
                 *  RecordField field = keyValuePair.Value;
                 *  Field field1 = field.Field;
                 *  Guid keyId = field.Key;
                 *  Guid recordId = field.Record;
                 *  List<object> objects = field.Values;
                 *  string asString = field.ValuesAsString();
                 * }
                 */
            }
            return(message);
        }
Exemple #10
0
        public virtual void CheckFields()
        {
            var fields = FieldMapper.ToFields <T>();

            foreach (var fieldInfo in fields)
            {
                if (List.Fields.ContainsFieldWithStaticName(fieldInfo.Name) == false)
                {
                    throw new SharepointCommonException(string.Format("List '{0}' does not contain field '{1}'", List.Title, fieldInfo.Name));
                }
            }
        }
Exemple #11
0
        public virtual void EnsureField(Expression <Func <T, object> > selector)
        {
            // get proprerty name
            var    memberAccessor = new MemberAccessVisitor();
            string propName       = memberAccessor.GetMemberName(selector);

            var prop = _entityType.GetProperty(propName);

            var fieldType = FieldMapper.ToFieldType(prop);

            EnsureFieldImpl(fieldType);
        }
Exemple #12
0
        public virtual Field GetField(Expression <Func <T, object> > selector)
        {
            var propName = CommonHelper.GetFieldInnerName(selector);

            var fieldInfo = FieldMapper.ToFields <T>().FirstOrDefault(f => f.Name.Equals(propName));

            if (fieldInfo == null)
            {
                throw new SharepointCommonException(string.Format("Field {0} not found", propName));
            }

            return(fieldInfo);
        }
Exemple #13
0
 public Presenter(IView view, IGameController gameController)
 {
     this.view            = view;
     this.gameController  = gameController;
     view.OnMove         += Move;
     view.OnMoveUndo     += UndoMove;
     view.OnPickCargo    += PickCargo;
     view.OnPickUndo     += PickUndo;
     view.OnGetCargoInfo += GetCargoInfo;
     mapper      = new FieldMapper();
     moveMapper  = new MoveParameterMapper();
     stateMapper = new StateMapper();
 }
 public void TestConstructDefault_WritingFile()
 {
     productMapper = new FieldMapper<ProductData>(new CsvFileDescription(), "test04.csv", true);
     Assert.AreEqual(productMapper.NameToInfo.Count, 11);
     Assert.AreEqual(productMapper.NameToInfo.ElementAt(0).Key, "Name");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[0].CanBeNull, true);
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo.Count(), 11);
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[1].HasColumnAttribute, true);
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[2].Name, "LaunchTime");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[3].Index, 4);
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[4].MemberInfo.MemberType.ToString(), "Property");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[5].OutputFormat, "G");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[5].Name, "Code");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[6].MemberInfo.Name, "RetailPrice");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[7].CanBeNull, true);
 }
Exemple #15
0
 public void TestConstructDefault_WritingFile()
 {
     productMapper = new FieldMapper <ProductData>(new CsvFileDescription(), "test04.csv", true);
     Assert.AreEqual(productMapper.NameToInfo.Count, 11);
     Assert.AreEqual(productMapper.NameToInfo.ElementAt(0).Key, "Name");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[0].CanBeNull, true);
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo.Count(), 11);
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[1].HasColumnAttribute, true);
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[2].Name, "LaunchTime");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[3].Index, 4);
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[4].MemberInfo.MemberType.ToString(), "Property");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[5].OutputFormat, "G");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[5].Name, "Code");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[6].MemberInfo.Name, "RetailPrice");
     Assert.AreEqual(productMapper.FieldIndexInfo.IndexToInfo[7].CanBeNull, true);
 }
Exemple #16
0
        public virtual void EnsureFields()
        {
            var fields = FieldMapper.ToFields <T>();

            foreach (var fieldInfo in fields)
            {
                if (FieldMapper.IsReadOnlyField(fieldInfo.Name) == false)
                {
                    continue;                                                        // skip fields that cant be set
                }
                if (FieldMapper.IsFieldCanBeAdded(fieldInfo.Name) == false)
                {
                    continue;
                }

                EnsureFieldImpl(fieldInfo);
            }
        }
Exemple #17
0
        public void FieldMapperTests_GetAndMap_FirstName()
        {
            // Arrange
            string key   = "First Name:";
            string value = "Joe";

            var content  = $"{key} {value}";
            var mappings = new List <string>();

            mappings.Add(key);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(value, result[key]);
        }
Exemple #18
0
        public void FieldMapperTests_ShouldReturnEmptyResultIfNoKeysFound()
        {
            // Arrange
            string key   = "First Name:";
            string value = "Joe";

            var content  = $"{value}";
            var mappings = new List <string>();

            mappings.Add(key);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(result.Count, 0);
        }
Exemple #19
0
        public void FieldMapperTests_CaseInsensitiveShouldntFindValue()
        {
            // Arrange
            string key   = "First Name:";
            string value = "Joe";

            var content  = $"FIRst NaMe: {value}";
            var mappings = new List <string>();

            mappings.Add(key);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(result.Count, 0);
        }
Exemple #20
0
        public void FieldMapperTests_LineBreakSeparatedMapping_NoSpace_CarriageReturnAndLineFeed_FirstName()
        {
            // Arrange
            string key   = "First{0}Name:";
            string value = "Joe";

            var content  = $"{string.Format(key, "\r\n")} {value}";
            var mappings = new List <string>();

            mappings.Add(string.Format(key, " "));

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(value, result[string.Format(key, " ")]);
        }
Exemple #21
0
        public void FieldMapperTests_PutMapping_ShouldThrowArgumentExceptionIfTryingToAddDuplicateKey()
        {
            // Arrange
            string key         = "First Name:";
            string value       = "Joe";
            string secondKey   = "First Name:";
            string secondValue = "Tom";

            var content  = $"{key} {value} {secondKey} {secondValue}";
            var mappings = new List <string>();

            mappings.Add(key);
            mappings.Add(secondKey);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(secondValue, result[key]);
        }
Exemple #22
0
        private bool ContainsFieldImpl(PropertyInfo prop)
        {
            var propName = prop.Name;

            var fieldAttrs = prop.GetCustomAttributes(typeof(FieldAttribute), true);

            if (fieldAttrs.Length != 0)
            {
                var spPropName = ((FieldAttribute)fieldAttrs[0]).Name;
                if (spPropName != null)
                {
                    propName = spPropName;
                }
            }
            else
            {
                propName = FieldMapper.TranslateToFieldName(propName);
            }

            return(List.Fields.ContainsFieldWithStaticName(propName));
        }
Exemple #23
0
        public void FieldMapperTests_NestedKeys_Triple_OnSameLines()
        {
            // Arrange
            string emailKey   = "Email Name";
            string phoneKey   = "Phone";
            string nameKey    = "Name";
            string zipKey     = "Zip Name";
            string cityKey    = "City Zip Name";
            string addressKey = "Address City Zip Name";

            string emailValue   = "*****@*****.**";
            string phoneValue   = "5551231234";
            string nameValue    = "Joe Moceri";
            string zipValue     = "000000";
            string cityValue    = "ExampleCity";
            string addressValue = "Example Address #123";

            var content  = string.Format("{1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12}", Environment.NewLine, emailKey, emailValue, phoneKey, phoneValue, nameKey, nameValue, zipKey, zipValue, cityKey, cityValue, addressKey, addressValue);
            var mappings = new List <string>();

            mappings.Add(emailKey);
            mappings.Add(nameKey);
            mappings.Add(phoneKey);
            mappings.Add(zipKey);
            mappings.Add(cityKey);
            mappings.Add(addressKey);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(emailValue, result[emailKey]);
            Assert.AreEqual(phoneValue, result[phoneKey]);
            Assert.AreEqual(nameValue, result[nameKey]);
            Assert.AreEqual(zipValue, result[zipKey]);
            Assert.AreEqual(cityValue, result[cityKey]);
            Assert.AreEqual(addressValue, result[addressKey]);
        }
Exemple #24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public OutputMapper mapper(Class userClass) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public virtual OutputMapper Mapper(Type userClass)
        {
            AssertIsValidRecordClass(userClass);

            IList <System.Reflection.FieldInfo> fields = InstanceFields(userClass);

            FieldSignature[] signature    = new FieldSignature[fields.Count];
            FieldMapper[]    fieldMappers = new FieldMapper[fields.Count];

            for (int i = 0; i < fields.Count; i++)
            {
                System.Reflection.FieldInfo field = fields[i];
                if (!isPublic(field.Modifiers))
                {
                    throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.TypeError, "Field `%s` in record `%s` cannot be accessed. Please ensure the field is marked as `public`.", field.Name, userClass.Name);
                }

                try
                {
                    TypeMappers.TypeChecker checker     = _typeMappers.checkerFor(field.GenericType);
                    MethodHandle            getter      = _lookup.unreflectGetter(field);
                    FieldMapper             fieldMapper = new FieldMapper(getter, checker);

                    fieldMappers[i] = fieldMapper;
                    signature[i]    = FieldSignature.outputField(field.Name, checker.Type(), field.isAnnotationPresent(typeof(Deprecated)));
                }
                catch (ProcedureException e)
                {
                    throw new ProcedureException(e.Status(), e, "Field `%s` in record `%s` cannot be converted to a Neo4j type: %s", field.Name, userClass.Name, e.Message);
                }
                catch (IllegalAccessException e)
                {
                    throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.TypeError, e, "Field `%s` in record `%s` cannot be accessed: %s", field.Name, userClass.Name, e.Message);
                }
            }

            return(new OutputMapper(signature, fieldMappers));
        }
Exemple #25
0
        private static void WriteData <T>(IEnumerable <T> values, string fileName, TextWriter stream,
                                          CsvFileDescription fileDescription)
        {
            FieldMapper <T> fm = new FieldMapper <T>(fileDescription, fileName, true);
            CsvStream       cs = new CsvStream(null, stream, fileDescription.SeparatorChar,
                                               fileDescription.IgnoreTrailingSeparatorChar);

            List <string> row = new List <string>();

            // If first line has to carry the field names, write the field names now.
            if (fileDescription.FirstLineHasColumnNames)
            {
                fm.WriteNames(row);
                cs.WriteRow(row, fileDescription.QuoteAllFields);
            }

            foreach (T obj in values)
            {
                // Convert obj to row
                fm.WriteObject(obj, row);
                cs.WriteRow(row, fileDescription.QuoteAllFields);
            }
        }
Exemple #26
0
        public virtual IEnumerable <T> ByField <TR>(Expression <Func <T, TR> > selector, TR value)
        {
            var    memberAccessor = new MemberAccessVisitor();
            string fieldName      = memberAccessor.GetMemberName(selector);


            var fieldInfo = FieldMapper.ToFields <T>().FirstOrDefault(f => f.Name.Equals(fieldName));

            if (fieldInfo == null && fieldName == "Name")
            {
                fieldInfo = new Field {
                    Type = SPFieldType.Text, Name = "FileLeafRef",
                };
            }

            if (fieldInfo == null)
            {
                throw new SharepointCommonException(string.Format("Field '{0}' not exist in '{1}'", fieldName, List.Title));
            }

            string fieldType = fieldInfo.Type.ToString();

            var camlByField = string.Empty;

            fieldName = fieldInfo.Name;

#pragma warning disable 612,618
            if (CommonHelper.IsNullOrDefault(value))
            {
                if (value is ValueType)
                {
                    camlByField = Q.Where(Q.Eq(Q.FieldRef(fieldName), Q.Value(default(TR).ToString())));
                }
                else
                {
                    camlByField = Q.Where(Q.IsNull(Q.FieldRef(fieldName)));
                }
            }
            else if (fieldInfo.Type == SPFieldType.User)
            {
                var user = value as User;
                int userId;

                if (user.Id != 0)
                {
                    userId = user.Id;
                }
                else
                {
                    var person = user as Person;
                    if (person != null)
                    {
                        try
                        {
                            var spUser = ParentWeb.Web.SiteUsers[person.Login];
                            userId = spUser.ID;
                        }
                        catch (SPException)
                        {
                            throw new SharepointCommonException(string.Format("Person {0} not found.", person.Login));
                        }
                    }
                    else
                    {
                        try
                        {
                            var group = ParentWeb.Web.SiteGroups[user.Name];
                            userId = @group.ID;
                        }
                        catch (SPException)
                        {
                            throw new SharepointCommonException(string.Format("Group {0} not found.", user.Name));
                        }
                    }
                }

                camlByField = Q.Where(Q.Eq(Q.FieldRef(fieldName, true), Q.Value(fieldType, userId.ToString())));
            }
            else if (fieldInfo.Type == SPFieldType.Lookup)
            {
                var item = value as Item;

                if (item.Id != 0)
                {
                    camlByField = Q.Where(Q.Eq(Q.FieldRef(fieldName, true), Q.Value(fieldType, item.Id.ToString())));
                }
                else if (item.Title != null)
                {
                    camlByField = Q.Where(Q.Eq(Q.FieldRef(fieldName), Q.Value(fieldType, item.Title)));
                }
                else
                {
                    throw new SharepointCommonException("Both Id and Title are null in search value");
                }
            }
            else
            {
                camlByField = Q.Where(Q.Eq(Q.FieldRef(fieldName), Q.Value(fieldType, value.ToString())));
            }
#pragma warning restore 612,618
            var itemsByField = ByCaml(List, camlByField);
            return(EntityMapper.ToEntities <T>(itemsByField));
        }
Exemple #27
0
 public void FieldMapperTests_Init_EmptyKeys_ShouldThrowArgumentException()
 {
     var content = "First Name: Joe";
     IEnumerable <string> mappings = Enumerable.Empty <string>();
     var parser = new FieldMapper(content, mappings);
 }
Exemple #28
0
 public void FieldMapperTests_Init_NullKeys_ShouldThrowArgumentException()
 {
     var content = "First Name: Joe";
     var parser  = new FieldMapper(content, null);
 }
Exemple #29
0
 public void FieldMapperTests_Init_WhitespaceContent_ShouldThrowArgumentException()
 {
     IEnumerable <string> mappings = Enumerable.Empty <string>();
     var parser = new FieldMapper("     ", mappings);
 }
Exemple #30
0
 public virtual IEnumerable <Field> GetFields(bool onlyCustom)
 {
     return(FieldMapper.ToFields(List, onlyCustom));
 }
Exemple #31
0
        private void EnsureFieldImpl(Field fieldInfo)
        {
            if (ContainsFieldImpl(fieldInfo.Property))
            {
                return;
            }

            if (fieldInfo.Type == SPFieldType.Lookup)
            {
                if (string.IsNullOrEmpty(fieldInfo.LookupList))
                {
                    throw new SharepointCommonException(string.Format("LookupList must be set for lookup fields. ({0})", fieldInfo.Name));
                }

                var lookupList = ParentWeb.Web.TryGetListByNameOrUrlOrId(fieldInfo.LookupList);

                if (lookupList == null)
                {
                    throw new SharepointCommonException(string.Format("List {0} not found on {1}", fieldInfo.LookupList, ParentWeb.Web.Url));
                }

                List.Fields.AddLookup(fieldInfo.Name, lookupList.ID, false);
            }
            else
            {
                var customPropAttrs = (CustomPropertyAttribute[])Attribute.GetCustomAttributes(fieldInfo.Property, typeof(CustomPropertyAttribute));

                var sb = new StringBuilder();
                var xv = new XmlTextWriter(new StringWriter(sb));
                xv.WriteStartElement("Field");

                xv.WriteAttributeString("ID", Guid.NewGuid().ToString());

                var type = "";
                if (fieldInfo.Type == SPFieldType.Invalid && fieldInfo.FieldAttribute.FieldProvider != null)
                {
                    type = fieldInfo.FieldAttribute.FieldProvider.FieldTypeAsString;
                }
                else
                {
                    var typeAttr = customPropAttrs.FirstOrDefault(cp => cp.Name == "Type");
                    if (typeAttr != null)
                    {
                        type = typeAttr.Value;
                    }
                    else
                    {
                        type = fieldInfo.Type.ToString();
                    }
                }
                xv.WriteAttributeString("Type", type);


                xv.WriteAttributeString("DisplayName", fieldInfo.Name);
                xv.WriteAttributeString("Name", fieldInfo.Name);

                foreach (var customProp in customPropAttrs.Where(cp => cp.Name != "Type"))
                {
                    xv.WriteAttributeString(customProp.Name, customProp.Value);
                }

                xv.WriteEndElement();

                //  Mockable.AddFieldAsXml(List.Fields, sb.ToString());
                List.Fields.AddFieldAsXml(sb.ToString());
            }

            // var field = Mockable.GetFieldByInternalName(List.Fields, fieldInfo.Name);
            var field = List.Fields.GetFieldByInternalName(fieldInfo.Name);


            //Mockable.FieldMapper_SetFieldProperties(field, fieldInfo);
            FieldMapper.SetFieldProperties(field, fieldInfo);
        }