Exemple #1
0
        public IComponentDescriptor AddNewComponent(IndexSpec index)
        {
            var compo = new Component();

            compo.Descriptor.Nest(this, index);
            return(compo.Descriptor);
        }
Exemple #2
0
        /// <summary>
        /// Constructs a signal reference literal.
        /// </summary>
        /// <param name="desc">referenced descriptor</param>
        /// <param name="prop">referenced signal property</param>
        public SignalRef(ISignalOrPortDescriptor desc, EReferencedProperty prop)
        {
            Contract.Requires(desc != null);

            Desc          = desc;
            Prop          = prop;
            Indices       = new List <Expression[]>();
            IndexSample   = new IndexSpec();
            IsStaticIndex = true;
        }
 public static IndexSpec[] JsonToIndexSpecCollection(string json)
 {
     var jarray = JArray.Parse(json);
     List<IndexSpec> specs = new List<IndexSpec>();
     foreach (JObject next in jarray)
     {
         var indexSpec = new IndexSpec(next.ExtractValue<string>("path"), new SmartStoreType(next.ExtractValue<string>("type")));
         specs.Add(indexSpec);
     }
     return specs.ToArray();
 }
Exemple #4
0
        /// <summary>
        /// Returns the signal reference which results from applying an index to this one.
        /// </summary>
        /// <param name="index">index specifier to apply</param>
        /// <returns>the indexed reference</returns>
        public SignalRef ApplyIndex(IndexSpec index)
        {
            if (!IsStaticIndex)
            {
                throw new InvalidOperationException("Only applicable to static indices");
            }

            var asmRef      = AssimilateIndices();
            var resultIndex = index.Project(asmRef.IndexSample);

            return(new SignalRef(asmRef.Desc, Prop, resultIndex.AsExpressions(), resultIndex, true));
        }
Exemple #5
0
        /// <summary>
        /// Constructs a signal reference literal.
        /// </summary>
        /// <param name="desc">referenced descriptor</param>
        /// <param name="prop">referenced signal property</param>
        /// <param name="indices">indices to apply</param>
        /// <param name="indexSample">sample index</param>
        /// <param name="isStaticIndex">whether the indices are static (i.e.) constant, in which case the sample index can be taken
        /// for granted</param>
        public SignalRef(ISignalOrPortDescriptor desc, EReferencedProperty prop,
                         IEnumerable <Expression[]> indices, IndexSpec indexSample, bool isStaticIndex)
        {
            Contract.Requires(desc != null);
            Contract.Requires(indices != null);
            Contract.Requires(indexSample != null);
            Contract.Requires(indices.Count() == indexSample.Indices.Length);

            Desc          = desc;
            Prop          = prop;
            Indices       = indices.ToList();
            IndexSample   = indexSample;
            IsStaticIndex = isStaticIndex;
        }
Exemple #6
0
        public async Task <IndexerStatus> IndexAndWait(IndexSpec indexSpec, TimeSpan maxWait)
        {
            var timer = new Timer(maxWait.TotalMilliseconds);

            timer.Elapsed += (sender, args) => { ((Timer)sender).Stop(); };
            timer.Start();

            var id = await Index(indexSpec);

            IndexerStatus status;

            do
            {
                status = await Status(id);
            } while (status == IndexerStatus.Running && timer.Enabled);

            return(status == IndexerStatus.Running ? IndexerStatus.Pending : status);
        }
Exemple #7
0
        private void PopulateIndexList(List <Expression[]> result, IndexSpec indexSpec, TypeDescriptor elemType)
        {
            int count  = indexSpec.Indices.Length;
            var curSeq = indexSpec.Indices.Reverse();

            while (curSeq.Any())
            {
                var seq = curSeq.Take(elemType.Rank).Reverse();
                result.Add(seq
                           .Select(ds => ds.Kind == DimSpec.EKind.Index ?
                                   LiteralReference.CreateConstant((int)ds) :
                                   LiteralReference.CreateConstant((Range)ds))
                           .ToArray());
                if (seq.Any(ds => ds.Kind == DimSpec.EKind.Range))
                {
                    break;
                }
                curSeq   = curSeq.Skip(elemType.Rank);
                elemType = elemType.Element0Type;
            }
        }
Exemple #8
0
            protected override void DeclareAlgorithm()
            {
                var srCur = SignalRef.Create(_taSite._portSignal, SignalRef.EReferencedProperty.Cur);
                var lrCur = new LiteralReference(srCur);

                if (_taSite._portSignal.ElementType.CILType.Equals(typeof(StdLogic)))
                {
                    var index = new IndexSpec((DimSpec)0);
                    var srSLV = new SignalRef(
                        _taSite._slvSignal,
                        SignalRef.EReferencedProperty.Next,
                        index.AsExpressions(),
                        index, true);
                    Store(srSLV, lrCur);
                }
                else
                {
                    var convFn = IntrinsicFunctions.Cast(lrCur,
                                                         _taSite._portSignal.ElementType.CILType,
                                                         _taSite._slvSignal.ElementType);
                    var srSLV = SignalRef.Create(_taSite._slvSignal, SignalRef.EReferencedProperty.Next);
                    Store(srSLV, convFn);
                }
            }
Exemple #9
0
        /// <summary>
        /// Constructs a signal reference literal.
        /// </summary>
        /// <param name="desc">referenced descriptor</param>
        /// <param name="prop">referenced signal property</param>
        /// <param name="indices">indices to apply</param>
        /// <param name="indexSample">sample index</param>
        /// <param name="isStaticIndex">whether the indices are static (i.e.) constant, in which case the sample index can be taken
        /// for granted</param>
        public SignalRef(ISignalOrPortDescriptor desc, EReferencedProperty prop, 
            IEnumerable<Expression[]> indices, IndexSpec indexSample, bool isStaticIndex)
        {
            Contract.Requires(desc != null);
            Contract.Requires(indices != null);
            Contract.Requires(indexSample != null);
            Contract.Requires(indices.Count() == indexSample.Indices.Length);

            Desc = desc;
            Prop = prop;
            Indices = indices.ToList();
            IndexSample = indexSample;
            IsStaticIndex = isStaticIndex;
        }
Exemple #10
0
 private void PopulateIndexList(List<Expression[]> result, IndexSpec indexSpec, TypeDescriptor elemType)
 {
     int count = indexSpec.Indices.Length;
     var curSeq = indexSpec.Indices.Reverse();
     while (curSeq.Any())
     {
         var seq = curSeq.Take(elemType.Rank).Reverse();
         result.Add(seq
                 .Select(ds => ds.Kind == DimSpec.EKind.Index ?
                         LiteralReference.CreateConstant((int)ds) :
                         LiteralReference.CreateConstant((Range)ds))
                 .ToArray());
         if (seq.Any(ds => ds.Kind == DimSpec.EKind.Range))
             break;
         curSeq = curSeq.Skip(elemType.Rank);
         elemType = elemType.Element0Type;
     }
 }
Exemple #11
0
        /// <summary>
        /// Constructs a signal reference literal.
        /// </summary>
        /// <param name="desc">referenced descriptor</param>
        /// <param name="prop">referenced signal property</param>
        public SignalRef(ISignalOrPortDescriptor desc, EReferencedProperty prop)
        {
            Contract.Requires(desc != null);

            Desc = desc;
            Prop = prop;
            Indices = new List<Expression[]>();
            IndexSample = new IndexSpec();
            IsStaticIndex = true;
        }
Exemple #12
0
 public IndexSpecBuilder(string dataSource)
 {
     _spec = new IndexSpec();
     _spec.Spec.DataSchema.DataSource = dataSource;
     _spec.Type = _spec.Spec.TuningConfig.Type = _spec.Spec.IoConfig.Type = IndexType;
 }
 public IndexDetail(IndexSpec index)
     : base(index)
 {
 }
        public override bool Rewrite(
            CodeDescriptor decompilee,
            MethodBase callee,
            StackElement[] args,
            IDecompiler stack,
            IFunctionBuilder builder)
        {
            if (args.Length < 2)
                throw new InvalidOperationException("The attribute SignalIndexer was applied to the wrong method");

            LiteralReference refExpr = args[0].Expr as LiteralReference;
            if (refExpr == null)
                throw new InvalidOperationException("Unable to resolve port/signal reference expression");

            DimSpec[] dimSamples = new DimSpec[args.Length - 1];
            Expression[] indices = args.Skip(1).Select(arg => arg.Expr).ToArray();
            bool isStatic = true;
            for (int i = 1; i < args.Length; i++)
            {
                var convidx = TypeConversions.ConvertValue(args[i].Sample, typeof(int));
                if (convidx != null)
                {
                    dimSamples[i - 1] = (int)convidx;
                }
                else if (args[i].Sample is Range)
                {
                    dimSamples[i - 1] = (Range)args[i].Sample;
                }
                else
                {
                    dimSamples = null;
                    break;
                }

                // EVariability.LocalVariable is not static as well, since variables
                // inside for loops will have that variability.
                if (args[i].Variability != EVariability.Constant)
                    isStatic = false;
            }
            IndexSpec indexSpec = null;
            indexSpec = new IndexSpec(dimSamples);

            SignalRef sigRef = null;
            LambdaLiteralVisitor llv = new LambdaLiteralVisitor()
            {
                OnVisitConstant = x =>
                {
                    sigRef = new SignalRef(
                        ((SignalBase)x.ConstantValue).Descriptor,
                        SignalRef.EReferencedProperty.Instance,
                        new Expression[][] { indices }, indexSpec, isStatic);
                },
                OnVisitFieldRef = x => { throw new InvalidOperationException(); },
                OnVisitSignalRef = x =>
                {
                    sigRef = new SignalRef(
                        x.Desc,
                        x.Prop,
                        x.Indices.Concat(new Expression[][] { indices }),
                        indexSpec.Project(x.IndexSample),
                        x.IsStaticIndex && isStatic);
                },
                OnVisitVariable = x => { throw new InvalidOperationException(); },
                OnVisitThisRef = x => { throw new InvalidOperationException(); }
            };
            refExpr.ReferencedObject.Accept(llv);

            object rsample = null;

            Type[] argTypes = args
                .Skip(1)
                .Select(a => a.Expr.ResultType.CILType)
                .ToArray();
            object[] argSamples = args
                .Select(a => a.Sample)
                .ToArray();
            MethodInfo indexerSampleMethod = callee.DeclaringType.GetMethod(
                "GetIndexerSample",
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                argTypes,
                null);
            if (indexerSampleMethod != null && argSamples.All(a => a != null))
            {
                rsample = indexerSampleMethod.Invoke(argSamples);
            }
            else
            {
                try
                {
                    rsample = callee.Invoke(args.Select(x => x.Sample).ToArray());
                }
                catch (TargetInvocationException)
                {
                }
            }
            stack.Push(sigRef, rsample);
            return true;
        }
 public DescriptorNestingByIndex(IndexSpec index)
 {
     _index = index;
 }
Exemple #16
0
 public PrimaryKeyDetail(IndexSpec index)
     : base(index)
 {
 }
 public DescriptorNestingByNameAndIndex(string name, IndexSpec index) :
     base(index)
 {
     _name = name;
 }
Exemple #18
0
 public virtual void Nest(IDescriptor owner, IndexSpec index)
 {
     owner.AddChild(this);
     Owner           = owner;
     _implementation = new DescriptorNestingByIndex(index);
 }
 public DescriptorNestingByNameAndIndex(string name, IndexSpec index) :
     base(index)
 {
     _name = name;
 }
        /// <summary>
        /// Builds the schema
        /// </summary>
        /// <param name="dbStore"></param>
        private void Build(DbStore dbStore)
        {
            // Get all "tables"
            var storeSchemaProperties = this.GetType().GetProperties()
                                        .Where(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericTypeDefinition() == typeof(IndexedSet <>));

            // For all tables
            foreach (var schemaProperty in storeSchemaProperties)
            {
                // Create schema
                var schema = new StoreSchema()
                {
                    Name    = schemaProperty.Name,
                    Indexes = new List <IndexSpec>(),
                };

                // Get generic parameter of list<T> (type T, only supports IndexedSet<T> ergo 1 parameter)
                var propertyType = schemaProperty.PropertyType.GetGenericArguments()[0];

                // Get all properties of the generic type T
                var properties = propertyType.GetProperties();

                Dictionary <string, List <string> > compoundIndices = new Dictionary <string, List <string> >();

                foreach (var property in properties)
                {
                    // If any non supported object is used throw exception here
                    if (property.PropertyType.IsGenericType && !property.PropertyType.Namespace.StartsWith("System"))
                    {
                        throw new NotSupportedException(property.PropertyType.FullName);
                    }

                    // Get attributes from the entity property, ergo column
                    var attributes = property.CustomAttributes;

                    var id            = false;
                    var unique        = false;
                    var autoIncrement = false;
                    var foreignKey    = false;
                    var multiEntry    = false;

                    // Check for settings via attributes here (additonal attributes have to be checked here)
                    if (attributes.Any(x => x.AttributeType == typeof(KeyAttribute)))
                    {
                        id = true;
                    }
                    if (attributes.Any(x => x.AttributeType == typeof(UniqueAttribute)))
                    {
                        unique = true;
                    }
                    if (attributes.Any(x => x.AttributeType == typeof(MultiEntryAttribute)))
                    {
                        multiEntry = true;
                    }
                    if (attributes.Any(x => x.AttributeType == typeof(AutoIncrementAttribute)))
                    {
                        autoIncrement = true;
                    }
                    if (attributes.Any(x => x.AttributeType == typeof(ForeignKeyAttribute)))
                    {
                        if (id)
                        {
                            throw new NotSupportedException("PK cannot be FK");
                        }

                        foreignKey = true;
                    }

                    var columnName = this.FirstToLower(property.Name);

                    foreach (var attributeData in attributes.Where(x => x.AttributeType == typeof(CompoundIndexAttribute)))
                    //foreach (var attribute in attributes.OfType<CompoundIndexAttribute>())
                    {
                        var name = attributeData.ConstructorArguments[0].Value as string;
                        name = this.FirstToLower(name);
                        compoundIndices.TryGetValue(name, out var list);
                        if (list == null)
                        {
                            list = new List <string>();
                        }
                        list.Add(columnName);
                        compoundIndices[name] = list;
                        Debug.WriteLine($"{nameof(IndexedDb)} -Compound key detected: {name}:{columnName}={string.Join(",",list)}");
                    }


                    // Define index
                    var index = new IndexSpec {
                        Name = columnName, KeyPath = columnName, Auto = autoIncrement, Unique = unique, MultiEntry = multiEntry
                    };

                    // Register index
                    if (id)
                    {
                        // Throw invalid operation when index has already been defined
                        if (schema.PrimaryKey != null)
                        {
                            throw new InvalidOperationException("PK already defined");
                        }

                        Debug.WriteLine($"{nameof(IndexedDb)} - {schemaProperty.Name} - PK-> {columnName}");

                        index.Auto        = true;
                        schema.PrimaryKey = index;
                    }
                    else if (!foreignKey)
                    {
                        Debug.WriteLine($"{nameof(IndexedDb)} - {schemaProperty.Name} - Property -> {columnName}");

                        schema.Indexes.Add(index);
                    }
                }

                foreach (var compound in compoundIndices)
                {
                    Debug.WriteLine($"{nameof(IndexedDb)} -Compound key queued: {compound.Key} : {string.Join(",", compound.Value)}");
                    var index = new IndexSpec {
                        Name = compound.Key, KeyPaths = compound.Value.ToArray(), Compound = true                          /*Unique = unique, MultiEntry = multiEntry*/
                    };
                    schema.Indexes.Add(index);
                }

                // Create PK when not defined
                if (schema.PrimaryKey == null)
                {
                    var idPropertyName = "Id";
                    var idColumnName   = this.FirstToLower(idPropertyName);

                    // Check for registered id property without declared key attribute
                    if (properties.Any(x => x.Name == idPropertyName))
                    {
                        var idProperty = schema.Indexes.Single(x => x.Name == idColumnName);

                        // Remove from schema
                        schema.Indexes.Remove(idProperty);

                        // And set as primary key
                        schema.PrimaryKey = idProperty;

                        // Set to auto, default setting
                        schema.PrimaryKey.Auto = true;
                    }
                    else
                    {
                        throw new NotSupportedException("Missing id property");
                        // Not supported because no implementation for changed check when deleted (missing id to resolve object in store)
                        //schema.PrimaryKey = new IndexSpec { Name = idColumnName, KeyPath = idColumnName, Auto = true };
                    }
                }

                // Add schema to registered schemas
                dbStore.Stores.Add(schema);
            }
            Debug.WriteLine($"{nameof(IndexedDb)} - Schema has been built");
        }
Exemple #21
0
 public async Task <string> Index(IndexSpec indexSpec)
 {
     return((await GetIndexer().Index(indexSpec)).Task);
 }
Exemple #22
0
 public UniqueKeyDetail(IndexSpec index) : base(index)
 {
 }
Exemple #23
0
        /// <summary>
        /// Returns the signal reference which results from applying an index to this one.
        /// </summary>
        /// <param name="index">index specifier to apply</param>
        /// <returns>the indexed reference</returns>
        public SignalRef ApplyIndex(IndexSpec index)
        {
            if (!IsStaticIndex)
                throw new InvalidOperationException("Only applicable to static indices");

            var asmRef = AssimilateIndices();
            var resultIndex = index.Project(asmRef.IndexSample);
            return new SignalRef(asmRef.Desc, Prop, resultIndex.AsExpressions(), resultIndex, true);
        }
Exemple #24
0
 /// <summary>
 /// Converts an index specifier to an array of expressions.
 /// </summary>
 /// <param name="indexSpec">index specifier to convert</param>
 /// <returns>nested array of expressions, each representing an individual index</returns>
 public static Expression[][] AsExpressions(this IndexSpec indexSpec)
 {
     return(indexSpec.Indices.Select(idx => new Expression[] { idx.AsExpression() }).ToArray());
 }
Exemple #25
0
 public IndexBasedConstraintDetail(IndexSpec index) : base(index.ConstraintName, index.DatabaseName, index.SchemaName, index.TableName)
 {
     _index = index;
 }
 public IndexGetSuffix(IndexSpec indexSpec) => this.indexSpec = indexSpec;
 internal static SDK.SmartStore.Store.IndexSpec[] ConvertToSdkIndexSpecs(IndexSpec[] indexSpecs)
 {
     var specs = from n in indexSpecs select n._indexSpec;
     return specs.ToArray();
 }
 public DescriptorNestingByIndex(IndexSpec index)
 {
     _index = index;
 }