Exemplo n.º 1
0
 public ItemVersion(ItemVersions container, CrawlType crawlType, DateTime asOfDate)
 {
     this.LocationType = container.LocationType;
     this.Name         = container.Name;
     this.CrawlType    = crawlType;
     this.AsOfDate     = asOfDate;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Returns result type of binary expression. This may be the error type.
        /// </summary>
        public static CrawlType EvaluateBinaryType(CrawlType operand1, ExpressionType oprator, CrawlType operand2)
        {
            //Valid binary expressions are stored in BinaryExpressionDict.
            //To avoid redundancy, {tal > kommatal => bool} is saved,
            //but {kommatal > tal => bool} is not.
            //Instead we check if either of the two possible combinations
            //of two operators are stored in the dictionary.

            var firstPossibleMatch =
                new Tuple <CrawlType, CrawlType, ExpressionType>(operand1, operand2, oprator);

            if (BinaryExpressionDict.ContainsKey(firstPossibleMatch))
            {
                return(BinaryExpressionDict[firstPossibleMatch]);
            }

            var secondPossibleMatch =
                new Tuple <CrawlType, CrawlType, ExpressionType>(operand2, operand1, oprator);

            if (BinaryExpressionDict.ContainsKey(secondPossibleMatch))
            {
                return(BinaryExpressionDict[secondPossibleMatch]);
            }
            else
            {
                return(CrawlType.ErrorType);
            }
        }
Exemplo n.º 3
0
 public ItemVersion(LocationType locationType, string tableName, CrawlType crawlType, DateTime asOfDate)
 {
     this.LocationType = locationType;
     this.Name         = tableName;
     this.CrawlType    = crawlType;
     this.AsOfDate     = asOfDate;
 }
        protected override CrawlSyntaxNode VisitSingleVariableDecleration(SingleVariableDeclerationNode singleVariableDecleration)
        {
            var          node          = (SingleVariableDeclerationNode)base.VisitSingleVariableDecleration(singleVariableDecleration);
            CrawlType    resultType    = node.DefaultValue?.ResultType ?? node.Identifier.ResultType;
            VariableNode newIdentifier = (VariableNode)node.Identifier.WithResultType(resultType);

            return(node.WithIdentifier(newIdentifier));
        }
Exemplo n.º 5
0
 public TypeInformation(CrawlType type, ProtectionLevel protectionLevel, int declarationLocation, DeclaringScope declaringScope = DeclaringScope.MethodLike, NeedsABetterNameType needsABetterNameType = NeedsABetterNameType.Variable)
 {
     Type                 = type;
     ProtectionLevel      = protectionLevel;
     DeclarationLocation  = declarationLocation;
     DeclaringScope       = declaringScope;
     NeedsABetterNameType = needsABetterNameType;
 }
Exemplo n.º 6
0
        public static CrawlType UnaryNot(CrawlType operand)
        {
            if (operand.Equals(CrawlSimpleType.Bool))
            {
                return(CrawlSimpleType.Bool);
            }

            return(CrawlType.ErrorType);
        }
Exemplo n.º 7
0
 public static CrawlType UnaryNegate(CrawlType operand)
 {
     //If operand is tal, return tal; if operand is kommatal, return kommatal
     if (operand.Equals(CrawlSimpleType.Tal) || operand.Equals(CrawlSimpleType.Kommatal))
     {
         return(operand);
     }
     return(CrawlType.ErrorType);
 }
        protected override CrawlSyntaxNode VisitVariable(VariableNode variable)
        {
            var       expr       = (VariableNode)base.VisitVariable(variable);
            CrawlType resultType = expr.FindFirstScope().FindSymbol(variable.Name)?.FirstOrDefault()?.Type;

            var result = expr.WithResultType(resultType ?? CrawlType.ErrorType);

            return(result);
        }
        protected override CrawlSyntaxNode VisitCall(CallNode call)
        {
            CallNode         expr             = (CallNode)base.VisitCall(call);
            CrawlType        resultType       = CrawlType.ErrorType;
            List <CrawlType> actualParameters = expr.Arguments.Select(x => x.Value.ResultType).ToList();

            //Three posibilities exist:


            //Method type is provided as method name in specific scope.
            MemberAccessNode asMem = expr.Target as MemberAccessNode;
            //Method type is provided as a method name. Find candidates and choose best fit.
            VariableNode asVar = expr.Target as VariableNode;

            if (expr.Target.ResultType is CrawlStatusType)
            {
                return(expr.WithResultType(expr.Target.ResultType));
            }
            else if (asVar != null)
            {
                var foo = asVar
                          .FindFirstScope();
                var bar = foo
                          .FindSymbol(asVar.Name);
                List <CrawlMethodType> candidates = bar
                                                    .SelectMany(GetMethodTypesFromTypeInformation)
                                                    .ToList();

                resultType = BestParameterMatch(candidates, actualParameters);
            }
            else if (asMem != null)
            {
                List <CrawlMethodType> candidates = asMem
                                                    .Target.ResultType
                                                    .FindSymbol(asMem.Member.Value)
                                                    .SelectMany(GetMethodTypesFromTypeInformation)
                                                    .ToList();

                resultType = BestParameterMatch(candidates, actualParameters);
            }

            //Method type is provided by some other expression. In this case it either matches or does not.
            else
            {
                CrawlMethodType methodSignature = expr.Target.ResultType as CrawlMethodType;

                if (methodSignature != null)
                {
                    resultType = Call(methodSignature, actualParameters);
                }
            }

            return(expr.WithResultType(resultType));
        }
Exemplo n.º 10
0
 public IEnumerable <ItemVersion> VersionsInRange(CrawlType crawlType, DateTime startDateTime, DateTime asOfDateTime, bool startInclusive = false)
 {
     if (startInclusive)
     {
         return(this.Versions.Where((v) => (v.CrawlType == crawlType && v.AsOfDate >= startDateTime && v.AsOfDate <= asOfDateTime)));
     }
     else
     {
         return(this.Versions.Where((v) => (v.CrawlType == crawlType && v.AsOfDate > startDateTime && v.AsOfDate <= asOfDateTime)));
     }
 }
        protected override CrawlSyntaxNode VisitBinaryExpression(BinaryExpressionNode binaryExpression)
        {
            BinaryExpressionNode newExpressoinNode = (BinaryExpressionNode)(base.VisitBinaryExpression(binaryExpression));
            CrawlType            leftOperand       = newExpressoinNode.LeftHandSide.ResultType;
            CrawlType            rightOperand      = newExpressoinNode.RightHandSide.ResultType;
            ExpressionType       oprator           = newExpressoinNode.ExpressionType;

            CrawlType       expressionTypeResult = EvaluateBinaryType(leftOperand, oprator, rightOperand);
            CrawlSyntaxNode result = newExpressoinNode.WithResultType(expressionTypeResult);

            return(result);
        }
Exemplo n.º 12
0
        private static CrawlType ParseCrawlTypeOrDefault(string[] args, int index, CrawlType defaultValue)
        {
            if (args.Length <= index)
            {
                return(defaultValue);
            }

            CrawlType type;

            if (!Enum.TryParse <CrawlType>(args[index], out type))
            {
                throw new UsageException($"Unknown SourceType '{args[index]}'; valid types: {String.Join(", ", Enum.GetValues(typeof(CrawlType)))}.");
            }

            return(type);
        }
        protected override CrawlSyntaxNode VisitType(TypeNode type)
        {
            IScope scope = type.FindFirstScope();

            try
            {
                CrawlType actualType = CrawlType.ParseDecleration(scope, type.TypeName);

                var v = type.WithActualType(actualType);
                return(v);
            }
            catch (TypeNotFoundException tnfe)
            {
                _messages.Add(CompilationMessage.Create(_tokens, type.Interval, MessageCode.TypeNotFound, _file));
                return(type);
            }
        }
        protected override CrawlSyntaxNode VisitMemberAccess(MemberAccessNode memberAccess)
        {
            var expr = (MemberAccessNode)base.VisitMemberAccess(memberAccess);

            if (expr.Target.ResultType is CrawlStatusType)
            {
                return(expr.WithResultType(expr.Target.ResultType));
            }
            var results = expr.Target.ResultType.FindSymbol(expr.Member.Value);

            if (results == null || results.Length == 0)
            {
                return(expr.WithResultType(CrawlType.ErrorType));
            }

            CrawlType resultType = expr.Target.ResultType.FindSymbol(expr.Member.Value)[0].Type;

            return(expr.WithResultType(resultType));
        }
Exemplo n.º 15
0
        private void AddVersions(ItemVersions versions, CrawlType crawlType)
        {
            string sourceFullPath = this.Path(versions.LocationType, versions.Name, crawlType);

            foreach (StreamAttributes version in Enumerate(sourceFullPath, EnumerateTypes.Folder, false))
            {
                DateTime versionAsOf;

                // If it's not a DateTime folder, it's not a table version
                if (!DateTime.TryParseExact(System.IO.Path.GetFileName(version.Path), StreamProviderExtensions.DateTimeFolderFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out versionAsOf))
                {
                    continue;
                }

                // If we're looking at tables, verify there's a Schema.csv
                if (versions.LocationType == LocationType.Table && !Attributes(Path.Combine(version.Path, "Schema.csv")).Exists)
                {
                    continue;
                }

                versions.AddVersion(crawlType, versionAsOf);
            }
        }
Exemplo n.º 16
0
 public IEnumerable <ItemVersion> VersionsInRange(CrawlType crawlType, DateTime startDateTime, DateTime asOfDateTime)
 {
     return(this.Versions.Where((v) => (v.CrawlType == crawlType && v.AsOfDate > startDateTime && v.AsOfDate <= asOfDateTime)));
 }
Exemplo n.º 17
0
 public ItemVersion LatestBeforeCutoff(CrawlType crawlType, DateTime cutoff)
 {
     return(this.Versions.LastOrDefault((v) => (v.CrawlType == crawlType && v.AsOfDate <= cutoff)));
 }
Exemplo n.º 18
0
 public void AddVersion(CrawlType crawlType, DateTime asOfDate)
 {
     this.Versions.Add(new ItemVersion(this, crawlType, asOfDate));
 }
Exemplo n.º 19
0
 public override int GetHashCode()
 {
     return(LocationType.GetHashCode() ^ Name.GetHashCode() ^ CrawlType.GetHashCode() ^ AsOfDate.GetHashCode());
 }
        public static void Add(this IStreamProvider streamProvider, string sourceFileOrFolderPath, string tableName, CrawlType crawlType, DateTime asOfDateTime = default(DateTime))
        {
            // If the 'asOfDateTime' wasn't passed, use the File Write Time
            if (asOfDateTime == default(DateTime))
            {
                asOfDateTime = File.GetLastWriteTimeUtc(sourceFileOrFolderPath);
            }

            string desiredFolderPath = streamProvider.Path(LocationType.Source, tableName, crawlType, asOfDateTime);

            if (Directory.Exists(sourceFileOrFolderPath))
            {
                foreach (string filePath in Directory.GetFiles(sourceFileOrFolderPath, "*.*", SearchOption.AllDirectories))
                {
                    streamProvider.Copy(File.OpenRead(filePath), System.IO.Path.Combine(desiredFolderPath, System.IO.Path.GetFileName(filePath)));
                }
            }
            else
            {
                streamProvider.Copy(File.OpenRead(sourceFileOrFolderPath), System.IO.Path.Combine(desiredFolderPath, System.IO.Path.GetFileName(sourceFileOrFolderPath)));
            }
        }
 public static string Path(this IStreamProvider streamProvider, LocationType type, string tableName, CrawlType crawlType, DateTime version)
 {
     return(System.IO.Path.Combine(type.ToString(), tableName, crawlType.ToString(), version.ToUniversalTime().ToString(DateTimeFolderFormat)));
 }
 public static string Path(this IStreamProvider streamProvider, LocationType type, string tableName, CrawlType crawlType)
 {
     return(System.IO.Path.Combine(type.ToString(), tableName, crawlType.ToString()));
 }