Example #1
0
        protected override void PerformIndexAll(string type)
        {
            if (!SupportedTypes.Contains(type))
            {
                return;
            }

            var xPath = "//*[(number(@id) > 0 and (@isDoc or @nodeTypeAlias)){0}]"; //we'll add more filters to this below if needed

            var sb = new StringBuilder();

            //create the xpath statement to match node type aliases if specified
            if (IndexerData.IncludeNodeTypes.Any())
            {
                sb.Append("(");
                foreach (var field in IndexerData.IncludeNodeTypes)
                {
                    //this can be used across both schemas
                    const string nodeTypeAlias = "(@nodeTypeAlias='{0}' or (count(@nodeTypeAlias)=0 and name()='{0}'))";

                    sb.Append(string.Format(nodeTypeAlias, field));
                    sb.Append(" or ");
                }
                sb.Remove(sb.Length - 4, 4); //remove last " or "
                sb.Append(")");
            }

            //create the xpath statement to match all children of the current node.
            if (IndexerData.ParentNodeId.HasValue && IndexerData.ParentNodeId.Value > 0)
            {
                if (sb.Length > 0)
                {
                    sb.Append(" and ");
                }
                sb.Append("(");
                sb.Append("contains(@path, '," + IndexerData.ParentNodeId.Value + ",')"); //if the path contains comma - id - comma then the nodes must be a child
                sb.Append(")");
            }

            //create the full xpath statement to match the appropriate nodes. If there is a filter
            //then apply it, otherwise just select all nodes.
            var filter = sb.ToString();

            xPath = string.Format(xPath, filter.Length > 0 ? " and " + filter : "");

            //raise the event and set the xpath statement to the value returned
            var args = new IndexingNodesEventArgs(IndexerData, xPath, type);

            OnNodesIndexing(args);
            if (args.Cancel)
            {
                return;
            }

            xPath = args.XPath;

            DataService.LogService.AddVerboseLog(-1, string.Format("({0}) PerformIndexAll with XPATH: {1}", this.Name, xPath));

            AddNodesToQueue(xPath, type);
        }
        public virtual int TypeCompliance(Type targetType)
        {
            // Determine compliance as inheritance distance
            var compliance = PerfectMatch;
            var current    = targetType;

            do
            {
                if (SupportedTypes.Contains(current))
                {
                    return(compliance);
                }

                current = current.BaseType;
                compliance++;
            } while (DerivedTypes & current != null);

            // Use full distance if it is an interface match
            if (targetType.GetInterfaces().Any(SupportedTypes.Contains))
            {
                return(compliance);
            }

            // Otherwise it is no match
            return(BadCompliance);
        }
Example #3
0
 private static void CheckFieldType(Type type)
 {
     if (!SupportedTypes.Contains(type) && !IsTypeRowList(type))
     {
         throw new InvalidCastException($"Unsupported type: '{type.FullName}'");
     }
 }
Example #4
0
 private static void ValidateSupportedType <T>()
 {
     if (!SupportedTypes.Contains(typeof(T)))
     {
         throw new NotSupportedException("Parsing to " + typeof(T).ToString() + "is not supported yet");
     }
 }
Example #5
0
 public Parameter(ParameterInfo parameter)
 {
     ParameterType        = parameter.ParameterType;
     IsOptional           = parameter.IsOptional;
     Name                 = parameter.Name;
     IsValidParameterType = SupportedTypes.Contains(ParameterType);
 }
        public override void ReIndexNode(XElement node, string type)
        {
            if (CanInitialize())
            {
                if (!SupportedTypes.Contains(type))
                {
                    return;
                }

                base.ReIndexNode(node, type);
            }
        }
 public static bool IsValid(Type type)
 {
     if (type.IsPrimitive)
     {
         return(true);
     }
     if (type.IsEnum)
     {
         return(true);
     }
     return(SupportedTypes.Contains(type));
 }
Example #8
0
 /// <summary>
 /// Reindexes a node
 /// </summary>
 /// <param name="node">
 /// The node.
 /// </param>
 /// <param name="type">
 /// The type.
 /// </param>
 public override void ReIndexNode(XElement node, string type)
 {
     if (!SupportedTypes.Contains(type))
     {
         return;
     }
     //try
     //{
     base.ReIndexNode(node, type);
     //}
     //catch (Exception ex)
     //{
     //    LogHelper.Error<BaseMerchelloIndexer>("Failed to index node of type: " + type, ex);
     //}
 }
Example #9
0
        protected override void PerformIndexAll(string type)
        {
            if (!SupportedTypes.Contains(type))
            {
                return;
            }

            var invoices      = DataService.InvoiceDataService.GetAll();
            var invoicesArray = invoices as IInvoice[] ?? invoices.ToArray();

            if (!invoicesArray.Any())
            {
                return;
            }
            var nodes = invoicesArray.Select(i => i.SerializeToXml().Root).ToList();

            AddNodesToIndex(nodes, IndexTypes.Invoice);
        }
Example #10
0
        protected override void PerformIndexAll(string type)
        {
            if (!SupportedTypes.Contains(type))
            {
                return;
            }

            var orders      = DataService.OrderDataService.GetAll();
            var ordersArray = orders as IOrder[] ?? orders.ToArray();

            if (!ordersArray.Any())
            {
                return;
            }
            var nodes = ordersArray.Select(o => o.SerializeToXml().Root).ToList();

            AddNodesToIndex(nodes, IndexTypes.Order);
        }
Example #11
0
        public static bool TryParse(string str, Type type, out object value)
        {
            if (str == null)
            {
                value = null;
                return(false);
            }

            if (type == typeof(string))
            {
                value = str;
                return(true);
            }

            if (type.IsEnum)
            {
                try
                {
                    value = Enum.Parse(type, str, true);
                    return(true);
                }
                catch (ArgumentException)
                {
                    value = null;
                    return(false);
                }
            }

            if (!SupportedTypes.Contains(type))
            {
                value = null;
                return(false);
            }

            var parameters  = new object[] { str, null };
            var parseMethod = type.GetMethod("TryParse", new [] { typeof(string), type.MakeByRefType() });
            var result      = (bool)parseMethod.Invoke(null, parameters);

            value = parameters[1];
            return(result);
        }
Example #12
0
        /// <summary>
        /// Adds all product variants to the index
        /// </summary>
        /// <param name="type"></param>
        protected override void PerformIndexAll(string type)
        {
            if (!SupportedTypes.Contains(type))
            {
                return;
            }

            var products      = DataService.ProductDataService.GetAll();
            var productsArray = products as IProduct[] ?? products.ToArray();

            if (!productsArray.Any())
            {
                return;
            }
            var nodes = new List <XElement>();

            foreach (var p in productsArray)
            {
                nodes.AddRange(p.SerializeToXml().Descendants("productVariant"));
            }

            AddNodesToIndex(nodes, IndexTypes.ProductVariant);
        }
Example #13
0
 public bool IsSupportedDateType(Type type)
 => SupportedTypes.Contains(type);
Example #14
0
 /// <summary>
 /// Indicates whether or not this instance validates an argument type.
 /// </summary>
 /// <param name="type">The argument type.</param>
 /// <returns>An indicator as to whether or not this instance validates <paramref name="type"/>.</returns>
 internal bool Validates(Type type)
 {
     return(SupportedTypes == null ? true : SupportedTypes.Contains(type));
 }
Example #15
0
        public List <T> GetList <T>()
        {
            var type = typeof(T);

            if (!SupportedTypes.Contains(type))
            {
                throw new ArgumentException($"Type {typeof(T)} is not supported by BVector collections.");
            }

            if (!Get1())
            {
                return(new List <T>());
            }
            var code   = Type.GetTypeCode(type);
            var len    = _GetObjectLen();
            var result = new List <T>(len);

            switch (code)
            {
            case TypeCode.Boolean:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(Get1(), type));
                }
                break;

            case TypeCode.Byte:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetByte(), type));
                }
                break;

            case TypeCode.Char:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetChar(), type));
                }
                break;

            case TypeCode.DateTime:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetDateTime(), type));
                }
                break;


            case TypeCode.Decimal:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetDecimal(), type));
                }
                break;

            case TypeCode.Double:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetDouble(), type));
                }
                break;

            case TypeCode.Int16:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetShort(), type));
                }
                break;

            case TypeCode.Int32:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetInt(), type));
                }
                break;

            case TypeCode.Int64:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetLong(), type));
                }
                break;

            case TypeCode.SByte:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetSByte(), type));
                }
                break;

            case TypeCode.Single:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetFloat(), type));
                }
                break;

            case TypeCode.String:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetString(), type));
                }
                break;

            case TypeCode.UInt16:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetUShort(), type));
                }
                break;

            case TypeCode.UInt32:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetUInt(), type));
                }
                break;

            case TypeCode.UInt64:
                for (var i = 0; i < len; i++)
                {
                    result.Add((T)Convert.ChangeType(GetULong(), type));
                }
                break;
            }


            return(result);
        }
Example #16
0
        public void Add <T>(List <T> list)
        {
            var type = typeof(T);

            if (!SupportedTypes.Contains(type))
            {
                throw new ArgumentException($"Type {typeof(T)} is not supported by BVector collections.");
            }
            var count = list.Count;

            if (count == 0)
            {
                Add1(false);
                return;
            }
            Add1(true);
            var code     = Type.GetTypeCode(type);
            var itemSize = GetSize(code);

            _AddObjectLen((uint)list.Count, itemSize);
            switch (code)
            {
            case TypeCode.Boolean:
                foreach (var item in list)
                {
                    Add1((bool)(Convert.ChangeType(item, typeof(bool))));
                }
                break;

            case TypeCode.Byte:
                foreach (var item in list)
                {
                    Add((byte)(Convert.ChangeType(item, typeof(byte))));
                }
                break;

            case TypeCode.Char:
                foreach (var item in list)
                {
                    Add((char)(Convert.ChangeType(item, typeof(char))));
                }
                break;

            case TypeCode.DateTime:
                foreach (var item in list)
                {
                    Add((DateTime)(Convert.ChangeType(item, typeof(DateTime))));
                }
                break;


            case TypeCode.Decimal:
                foreach (var item in list)
                {
                    Add((decimal)(Convert.ChangeType(item, typeof(decimal))));
                }
                break;

            case TypeCode.Double:
                foreach (var item in list)
                {
                    Add((double)(Convert.ChangeType(item, typeof(double))));
                }
                break;

            case TypeCode.Int16:
                foreach (var item in list)
                {
                    Add((short)(Convert.ChangeType(item, typeof(short))));
                }
                break;

            case TypeCode.Int32:
                foreach (var item in list)
                {
                    Add((int)(Convert.ChangeType(item, typeof(int))));
                }
                break;

            case TypeCode.Int64:
                foreach (var item in list)
                {
                    Add((long)(Convert.ChangeType(item, typeof(long))));
                }
                break;

            case TypeCode.SByte:
                foreach (var item in list)
                {
                    Add((sbyte)(Convert.ChangeType(item, typeof(sbyte))));
                }
                break;

            case TypeCode.Single:
                foreach (var item in list)
                {
                    Add((float)(Convert.ChangeType(item, typeof(float))));
                }
                break;

            case TypeCode.String:
                foreach (var item in list)
                {
                    Add((string)(Convert.ChangeType(item, typeof(string))));
                }
                break;

            case TypeCode.UInt16:
                foreach (var item in list)
                {
                    Add((ushort)(Convert.ChangeType(item, typeof(ushort))));
                }
                break;

            case TypeCode.UInt32:
                foreach (var item in list)
                {
                    Add((uint)(Convert.ChangeType(item, typeof(uint))));
                }
                break;

            case TypeCode.UInt64:
                foreach (var item in list)
                {
                    Add((ulong)(Convert.ChangeType(item, typeof(ulong))));
                }
                break;
            }
        }