Exemple #1
0
 public ModelIntegration(Donut.Models.Model model, Data.DataIntegration integration)
 {
     this.Model       = model;
     this.Integration = integration;
     //this.ModelId = model.Id;
     //this.IntegrationId = integration.Id;
 }
Exemple #2
0
        private IEnumerable <DslToken> ConstructTimeTokens(Data.DataIntegration tkTargetDataset, uint startLine, int startIndex,
                                                           int i, Stack <DslToken> output)
        {
            var matches = new List <DslToken>();

            if (output.Count > 0)
            {
                output.Pop();
            }
            var timeFn = new DslToken(TokenType.Symbol, "dstime", startLine)
            {
                Position = (uint)startIndex
            };
            var obrk = new DslToken(TokenType.OpenParenthesis, "(", startLine)
            {
                Position = (uint)startIndex + 4
            };
            var paramsVal = "";

            paramsVal += tkTargetDataset.Name;
            var dbSymbol = new DslToken(TokenType.Symbol, paramsVal, startLine)
            {
                Position = (uint)(startIndex + 5)
            };
            var cbrk = new DslToken(TokenType.CloseParenthesis, ")", startLine)
            {
                Position = (uint)(startIndex + 4 + paramsVal.Length)
            };

            matches.AddRange(new [] { timeFn, obrk, dbSymbol, cbrk });
            return(matches);
        }
Exemple #3
0
        private bool ParseParameterSubstring(List <TokenMatch> nextTokens,
                                             string nextDefVal,
                                             out Data.DataIntegration matchingIntegration,
                                             out string outputExpValue,
                                             ref int cntReadTokens)
        {
            matchingIntegration = _integrations.FirstOrDefault(x => x.Name.StartsWith(nextDefVal));
            outputExpValue      = null;
            if (matchingIntegration != null)
            {
                var isFullMatch = matchingIntegration.Name == nextDefVal;
                if (!isFullMatch && nextTokens != null && nextTokens.Count > 0)
                {
                    var strLeft = matchingIntegration.Name.Substring(nextDefVal.Length);
                    for (int intx = 0; intx < nextTokens.Count; intx++)
                    {
                        cntReadTokens++;
                        TokenMatch tokenMatch = nextTokens[intx];
                        if (strLeft.StartsWith(tokenMatch.Value))
                        {
                            strLeft = strLeft.Substring(tokenMatch.Value.Length);
                        }
                        else if (tokenMatch.Value.EndsWith(strLeft))
                        {
                            TokenMatch nextBest = null;
                            for (int xt = intx; xt < nextTokens.Count; xt++)
                            {
                                if (nextTokens[xt].Line >= tokenMatch.Line &&
                                    nextTokens[xt].StartIndex >= tokenMatch.EndIndex)
                                {
                                    cntReadTokens += xt - 1;
                                    nextBest       = nextTokens[xt];
                                    break;
                                }
                            }
                            if (nextBest == null)
                            {
                                continue;
                            }
                            outputExpValue = nextBest?.Value;
                            //outputExpValue = tokenMatch.Value;
                            break;
                        }
                        else
                        {
                            outputExpValue = tokenMatch.Value;
                            break;
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
            public static Data.DataIntegration CreateNamed(string key, string name)
            {
                var typedef = new Data.DataIntegration(name);

                typedef.APIKey = new ApiAuth()
                {
                    AppId = key
                };
                return(typedef);
            }
Exemple #5
0
        public override IIntegration ResolveIntegrationDefinition()
        {
            if (_cachedIntegration != null)
            {
                return(_cachedIntegration);
            }
            var iterator          = Formatter.GetIterator(Content, true);
            var firstInstance     = _cachedInstance = iterator.First();
            var outputIntegration = CreateIntegrationFromObj(firstInstance, null);

            return(_cachedIntegration = outputIntegration);
        }
            /// <summary>
            ///
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <returns></returns>
            public static Data.DataIntegration CreateFromType <T>(string name, ApiAuth apiObj)
            {
                var type    = typeof(T);
                var typedef = new Data.DataIntegration(type.Name);

                typedef.APIKey         = apiObj;
                typedef.DataFormatType = "dynamic";
                typedef.DataEncoding   = System.Text.Encoding.Default.CodePage;
                var properties = type.GetProperties();

                //var fields = type.GetFieldpairs();
                foreach (var member in properties)
                {
                    Type memberType      = member.PropertyType;
                    var  fieldDefinition = new FieldDefinition(member.Name, memberType);
                    typedef.Fields.Add(fieldDefinition); //member.name
                }
                typedef.Name = name;
                return(typedef);
            }
Exemple #7
0
        private string GetParameterSymbol(TokenMatch bestMatch, IGrouping <TokenPosition, TokenMatch> nextBestMatches,
                                          List <TokenMatch> nextTokens,
                                          out Data.DataIntegration dataIntegration,
                                          ref int cntReadTokens)
        {
            int offset         = 0;
            var nextDefsSorted = nextBestMatches.OrderBy(x => x.Precedence).ToList();

            dataIntegration = null;
            while ((nextDefsSorted.Count) > offset)
            {
                var nextDef    = nextDefsSorted[offset];
                var nextDefVal = nextDef.Value;
                if (offset == 0)
                {
                    var pTokenIndex = nextDefVal.IndexOf(bestMatch.Value);
                    if (pTokenIndex > 0)
                    {
                        return(null);
                    }
                    nextDefVal = nextDefVal.Substring(bestMatch.Value.Length);
                }
                string outputExpression;
                if (ParseParameterSubstring(nextTokens, nextDefVal, out dataIntegration, out outputExpression, ref cntReadTokens))
                {
                    return(outputExpression);

                    break;
                }
                offset++;
            }
            var nextBestMatch = nextBestMatches.OrderBy(x => x.Precedence).First();
            var expValue      = nextBestMatch.Value;

            expValue = expValue.Substring(bestMatch.Value.Length);
            return(expValue);
        }
Exemple #8
0
        private bool HandleExpressionSubstring(TokenMatch parent, TokenMatch child, out Data.DataIntegration targetDataSet)
        {
            targetDataSet = null;
            if (child.TokenType != TokenType.DatasetTime)
            {
                return(false);
            }
            string pValue   = parent.Value;
            var    subIndex = pValue.LastIndexOf(child.Value);

            if (subIndex != (pValue.Length - child.Value.Length))
            {
                return(false);
            }
            else
            {
                pValue = pValue.Substring(0, pValue.Length - child.Value.Length);
                var pValTokens   = Tokenize(pValue);
                var foundDataSet = false;
                foreach (var subToken in pValTokens)
                {
                    if (subToken.TokenType != TokenType.Symbol)
                    {
                        continue;
                    }
                    var dataIntegration = _integrations.FirstOrDefault(x => x.Name == subToken.Value);
                    if (dataIntegration != null)
                    {
                        targetDataSet = dataIntegration;
                        foundDataSet  = true; break;
                    }
                }
                return(foundDataSet);
            }
            return(false);
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strReader"></param>
        /// <returns></returns>
        public IEnumerable <DslToken> Tokenize(StringReader strReader, ref int cReadTokens)
        {
            var tokenMatches = FindTokenMatches(strReader).ToList();
            var definitions  = tokenMatches.GroupBy(x => new TokenPosition(x.Line, (uint)x.StartIndex),
                                                    new TokenPositionComparer())
                               .OrderBy(x => x.Key.Line)
                               .ThenBy(x => x.Key.Position)
                               .ToList();

            TokenMatch lastMatch   = null;
            var        output      = new Stack <DslToken>();
            bool       isSubstring = false;

            Data.DataIntegration matchedIntegration = null;
            for (int i = 0; i < definitions.Count; i++)
            {
                var orderedEnumerable = definitions[i].OrderBy(x => x.Precedence);
                var bestMatch         = orderedEnumerable.First();
                Data.DataIntegration tokensTargetDataset = null;
                if (lastMatch != null && bestMatch.StartIndex < lastMatch.EndIndex &&
                    bestMatch.Line == lastMatch.Line)
                {
                    //Validate if it's ok for the last expression to contain the current one;
                    var isValid = HandleExpressionSubstring(lastMatch, bestMatch, out tokensTargetDataset);
                    isSubstring = true;
                    if (!isValid)
                    {
                        continue;
                    }
                }

                if (bestMatch.TokenType == TokenType.DatasetTime)
                {
                    if (isSubstring)
                    {
                        if (tokensTargetDataset == null)
                        {
                            throw new Exception("Target DataSet not found!");
                        }
                        var timeTokens = ConstructTimeTokens(tokensTargetDataset, bestMatch.Line, bestMatch.StartIndex, i, output);
                        foreach (var tt in timeTokens)
                        {
                            output.Push(tt);
                        }
                        continue;
                    }
                    else
                    {
                        var timeTokens = ConstructTimeTokens(_currentIntegration, bestMatch.Line, bestMatch.StartIndex, i, output);
                        foreach (var tt in timeTokens)
                        {
                            output.Push(tt);
                        }
                        i += 1;
                        continue;
                    }
                }
                if (bestMatch.TokenType == TokenType.First)
                {
                    var nextBestMatch = ((definitions.Count - 1) == i) ? null : definitions[i + 1];
                    if (nextBestMatch != null)
                    {
                        var nextTokens = definitions.Skip(i + 2).Select(x => x.FirstOrDefault()).ToList();
                        var expValue   = GetParameterSymbol(bestMatch, nextBestMatch, nextTokens, out matchedIntegration, ref cReadTokens);
                        i += cReadTokens;
                        _currentIntegration = matchedIntegration;
                        if (String.IsNullOrEmpty(expValue))
                        {
                            continue;
                        }
                        //Get the subtoken
                        int iReadTokens = 0;
                        var subTokens   = ConstructFirstElementTokens(bestMatch, expValue, ref iReadTokens);
                        if (subTokens == null || subTokens.Count() == 0)
                        {
                            continue;
                        }
                        foreach (var tt in subTokens)
                        {
                            output.Push(tt);
                        }
                        //We skip the subtokens, so that we can continue.
                        i += iReadTokens;
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }


                var token = new DslToken(bestMatch.TokenType, bestMatch.Value, bestMatch.Line)
                {
                    Position = (uint)bestMatch.StartIndex
                };
                output.Push(token);
                //yield return token;

                lastMatch = bestMatch;
            }
            cReadTokens = definitions.Count;
            return(output.Reverse());
        }
Exemple #10
0
 public DatasetMember(Data.DataIntegration integration)
 {
     this.Name        = integration.Name;
     this.Integration = integration;
 }
Exemple #11
0
        /// <summary>
        /// Create a new integration from an object instance
        /// </summary>
        /// <param name="firstInstance"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected Data.DataIntegration CreateIntegrationFromObj(dynamic firstInstance, string name)
        {
            Data.DataIntegration typeDef = null;
            if (firstInstance != null)
            {
                typeDef                = new Data.DataIntegration();
                typeDef.PublicKey      = ApiAuth.Generate();
                typeDef.DataEncoding   = Encoding.CodePage;
                typeDef.DataFormatType = Formatter.Name;
                typeDef.SetFieldsFromType(firstInstance);
            }
            //Apply field options
            foreach (var fieldOpPair in FieldOptions)
            {
                FieldDefinition targetField = typeDef.Fields.FirstOrDefault(x => x.Name == fieldOpPair.Key);
                var             fieldOp     = fieldOpPair.Value;
                if (targetField == null)
                {
                    if (fieldOp.ValueEvaluater != null)
                    {
                        var targetType = fieldOp.ValueEvaluater.ReturnType;
                        var virtField  = targetField = new FieldDefinition(fieldOpPair.Key, targetType);
                        virtField.Extras = new FieldExtras()
                        {
                            IsFake = true
                        };
                        typeDef.Fields.Add(virtField);
                    }
                    else
                    {
                        continue; //Maybe throw?
                    }
                }
                if (fieldOp.IgnoreField)
                {
                    typeDef.Fields.Remove(targetField);
                    continue;
                }
                var ops        = fieldOp;
                var stringName = typeof(String).Name;
                if (ops.IsString)
                {
                    targetField.Type = stringName;
                }
                if (ops.Encoding != null)
                {
                    FieldEncoding.SetEncoding(typeDef, targetField, ops.Encoding);
                }
                if (targetField.Type == stringName && targetField.Extras == null)
                {
                    targetField.DataEncoding = FieldDataEncoding.BinaryIntId;
                    targetField.Extras       = new FieldExtras();
                    //targetField.Extras.Field = targetField;
                }

                if (ops.Duplicates.Count > 0)
                {
                    foreach (var duplicate in ops.Duplicates)
                    {
                        var dupField = new FieldDefinition(duplicate, targetField.Type);
                        typeDef.Fields.Add(dupField);
                    }
                }
            }
            return(typeDef);
        }