public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node)
        {
            CheckCastContex(node);
            CheckParenthesizeContex(node);

            var newNode = SyntaxFactoryExtensions.DataCodeVirtualAccess();

            string      name        = node.Identifier.Text;
            string      typeText    = "";
            bool        found       = false;
            VirtualData virtualData = null;

            foreach (var data in _virtualizationContext.data)
            {
                if (data.Name.Equals(name))
                {
                    typeText    = data.Type;
                    found       = true;
                    virtualData = data;
                    break;
                }
            }
            if (!found)
            {
                return(node);
            }

            newNode = newNode.WithAdditionalAnnotations(virtualData.Annotations);

            var newExpression = newNode;

            if (CastEnabled)
            {
                newExpression = SyntaxFactory.CastExpression(SyntaxFactory.IdentifierName
                                                             (
                                                                 @"" + typeText
                                                             ),
                                                             newNode
                                                             );
            }
            if (ParenthesizeEnabled)
            {
                newExpression = SyntaxFactory.ParenthesizedExpression(newExpression);
            }

            newExpression = newExpression.WithLeadingTrivia(node.GetLeadingTrivia())
                            .WithTrailingTrivia(node.GetTrailingTrivia())
            ;

            return(newExpression);
        }
Exemplo n.º 2
0
        public void ValidateVirtualDataAllProperties()
        {
            VirtualData <Sequence> vdObj = new VirtualData <Sequence>();

            Assert.AreEqual(0, vdObj.BlockSize);
            Assert.AreEqual(0, vdObj.Count);
            Assert.AreEqual(0, vdObj.BlockSize);
            Assert.IsFalse(vdObj.IsReadOnly);

            // Logs to the NUnit GUI (Console.Out) window
            Console.WriteLine(
                "Virtual Data BVT : Successfully validated all the properties.");
            ApplicationLog.WriteLine(
                "Virtual Data BVT : Successfully validated all the properties.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the MBF.IO.FileVirtualQualitativeSequenceProvider
        /// class to hold a sequence pointer with a parser.
        /// </summary>
        /// <param name="parser">A virtual parser object.</param>
        /// <param name="pointer">The sequence pointer.</param>
        public FileVirtualQualitativeSequenceProvider(IVirtualSequenceParser parser, SequencePointer pointer)
        {
            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            if (pointer == null)
            {
                throw new ArgumentNullException("pointer");
            }

            _parser = parser;
            _count  = (int)(pointer.IndexOffsets[1] - pointer.IndexOffsets[0]);
            SequencePointerInstance = pointer;

            //set the default DV properties.
            _virtualData = new VirtualData <Sequence>
            {
                BlockSize         = FileLoadHelper.DefaultBlockSize,
                MaxNumberOfBlocks = FileLoadHelper.DefaultMaxNumberOfBlocks
            };
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the MBF.IO.FileVirtualSequenceProvider
        /// class to hold a sequence pointer with a parser.
        /// </summary>
        /// <param name="parser">A virtual parser object.</param>
        /// <param name="pointer">The sequence pointer.</param>
        public FileVirtualSequenceProvider(IVirtualSequenceParser parser, SequencePointer pointer)
        {
            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            if (pointer == null)
            {
                throw new ArgumentNullException("pointer");
            }

            _parser = parser;
            _count  = (int)(pointer.IndexOffsets[1] - pointer.IndexOffsets[0]);
            SequencePointerInstance = pointer;
            _alphabet = Alphabets.All.FirstOrDefault(A => A.Name.Equals(pointer.AlphabetName));

            //set the default DV properties.
            _virtualData = new VirtualData <byte[]>
            {
                BlockSize         = FileLoadHelper.DefaultBlockSize,
                MaxNumberOfBlocks = FileLoadHelper.DefaultMaxNumberOfBlocks
            };
        }
        public override SyntaxNode VisitPrefixUnaryExpression(PrefixUnaryExpressionSyntax node)
        {
            if (node.Kind() != SyntaxKind.UnaryMinusExpression)
            {
                return(base.VisitPrefixUnaryExpression(node));
            }
            var expression = node.Operand;

            if (expression.Kind() != SyntaxKind.NumericLiteralExpression)
            {
                return(base.VisitPrefixUnaryExpression(node));
            }

            CheckCastContex(node);

            string      value    = node.ToString();
            bool        found    = false;
            VirtualData constant = null;

            foreach (var data in _virtualizationContext.data)
            {
                if (value.Equals(data.Name))
                {
                    found    = true;
                    constant = data;
                    break;
                }
            }
            if (!found)
            {
                int              index          = _virtualizationContext.DataIndex;
                string           name           = value;
                SyntaxAnnotation indexMarker    = new SyntaxAnnotation("index", index + "");
                SyntaxAnnotation nameMarker     = new SyntaxAnnotation("name", name);
                SyntaxAnnotation constantMarker = new SyntaxAnnotation("type", "constant");
                SyntaxAnnotation codeMarker     = new SyntaxAnnotation("code", "undefined");
                SyntaxAnnotation uniqueMarker   = new SyntaxAnnotation("unique", "" + VirtualizationContext.UniqueId);

                constant       = new VirtualData();
                constant.Index = index;
                constant.Name  = name;
                var typeInfo = _virtualizationContext.semanticModel.GetTypeInfo(node);
                var info     = typeInfo.Type.ToString();
                constant.Type         = info;
                constant.Node         = node;
                constant.DefaultValue = node;
                constant.Annotations.Add(indexMarker);
                constant.Annotations.Add(nameMarker);
                constant.Annotations.Add(constantMarker);
                constant.Annotations.Add(codeMarker);
                constant.Annotations.Add(uniqueMarker);
                _virtualizationContext.data.Add(constant);
            }

            //            constants.Add(node);



            ExpressionSyntax newNode = SyntaxFactoryExtensions.DataCodeVirtualAccess();

            newNode = newNode.WithAdditionalAnnotations(constant.Annotations);
            ExpressionSyntax newExpression;

            if (CastEnabled)
            {
                newExpression = SyntaxFactory.CastExpression(SyntaxFactory.IdentifierName
                                                             (
                                                                 @"" + constant.Type
                                                             ),
                                                             newNode
                                                             );
            }
            else
            {
                newExpression = newNode;
            }

            //TODO: add annotations + comments
            newExpression = newExpression.WithLeadingTrivia(node.GetLeadingTrivia())
                            .WithTrailingTrivia(node.GetTrailingTrivia())
            ;

            return(newExpression);
        }
        public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
        {
            var kind = node.Kind();

            if ((kind != SyntaxKind.NumericLiteralExpression) &&
                (kind != SyntaxKind.StringLiteralExpression) &&
                (kind != SyntaxKind.FalseLiteralExpression) &&
                (kind != SyntaxKind.TrueLiteralExpression) &&
                (kind != SyntaxKind.CharacterLiteralExpression)
                )
            {
                return(node);
            }

            CheckCastContex(node);

            string      value        = node.ToString();
            bool        found        = false;
            VirtualData constant     = null;
            string      requiredType = GetRequiredType(node); //in the case of return statements

            if (requiredType.Equals("void"))
            {
                requiredType = ""; // return statement was added as a refactoring "hack"
            }
            var typeInfo     = _virtualizationContext.semanticModel.GetTypeInfo(node);
            var declaredType = typeInfo.Type.ToString();

            foreach (var data in _virtualizationContext.data)
            {
                if (value.Equals(data.Name))
                {
                    if (requiredType.Equals("") && declaredType.Equals(data.Type))
                    {
                        found        = true;
                        constant     = data;
                        requiredType = declaredType;
                        break;
                    }
                    if (requiredType.Equals(data.Type))
                    {
                        found    = true;
                        constant = data;
                        break;
                    }
                }
            }
            if (!found)
            {
                if (requiredType.Equals(""))
                {
                    requiredType = declaredType;
                }

                int              index           = _virtualizationContext.DataIndex;
                string           name            = value;
                SyntaxAnnotation dataIndexMarker = new SyntaxAnnotation("index", index + "");
                SyntaxAnnotation nameMarker      = new SyntaxAnnotation("name", name);
                SyntaxAnnotation constantMarker  = new SyntaxAnnotation("type", "constant");
                SyntaxAnnotation codeIndexMarker = new SyntaxAnnotation("code", "undefined");
                SyntaxAnnotation uniqueMarker    = new SyntaxAnnotation("unique", "" + VirtualizationContext.UniqueId);

                constant       = new VirtualData();
                constant.Index = index;
                constant.Name  = name;
                var info = requiredType;

                constant.Type         = info;
                constant.Node         = node;
                constant.DefaultValue = node;
                constant.Annotations.Add(dataIndexMarker);
                constant.Annotations.Add(nameMarker);
                constant.Annotations.Add(constantMarker);
                constant.Annotations.Add(codeIndexMarker);
                constant.Annotations.Add(uniqueMarker);
                _virtualizationContext.data.Add(constant);
            }



            ExpressionSyntax newNode = SyntaxFactoryExtensions.DataCodeVirtualAccess();

            newNode = newNode.WithAdditionalAnnotations(constant.Annotations);
            ExpressionSyntax newExpression;

            if (CastEnabled)
            {
                newExpression = SyntaxFactory.CastExpression(SyntaxFactory.IdentifierName
                                                             (
                                                                 @"" + constant.Type
                                                             ),
                                                             newNode
                                                             );
            }
            else
            {
                newExpression = newNode;
            }

            //TODO: add annotations + comments
            newExpression = newExpression.WithLeadingTrivia(node.GetLeadingTrivia())
                            .WithTrailingTrivia(node.GetTrailingTrivia())
            ;

            return(newExpression);
        }
Exemplo n.º 7
0
        /// <summary>
        /// General method to validate virtual data class.
        /// <param name="addParam">Additional parameter.</param>
        /// </summary>
        static void ValidateGeneralVirtualDataTestCases(AdditionalParameters addParam)
        {
            VirtualData <Sequence> vdObj = new VirtualData <Sequence>();

            // Sets the Initial Properties and required Cache box
            vdObj.MaxNumberOfBlocks = 5;
            vdObj.BlockSize         = 5;
            CacheBox <Sequence> cb1 = new CacheBox <Sequence>(11);

            cb1.StartRange = 0;
            cb1.EndRange   = 10;
            cb1.Data       = new Sequence(Alphabets.DNA, "GGGGGGGGGGGGG");

            CacheBox <Sequence> cb2 = new CacheBox <Sequence>(11);

            cb2.StartRange = 0;
            cb2.EndRange   = 10;
            cb2.Data       = new Sequence(Alphabets.DNA, "TTTTTTTTTTTTT");

            CacheBox <Sequence> cb3 = new CacheBox <Sequence>(11);

            cb3.StartRange = 0;
            cb3.EndRange   = 10;
            cb3.Data       = new Sequence(Alphabets.DNA, "CCCCCCCCCCCCC");

            CacheBox <Sequence> cb4 = new CacheBox <Sequence>(11);

            cb4.StartRange = 0;
            cb4.EndRange   = 10;
            cb4.Data       = new Sequence(Alphabets.DNA, "AAAAAAAAAAAAAA");

            List <CacheBox <Sequence> > cbList = new List <CacheBox <Sequence> >();

            cbList.Add(cb1);
            cbList.Add(cb2);
            cbList.Add(cb3);
            cbList.Add(cb4);

            switch (addParam)
            {
            case AdditionalParameters.Add:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Add() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Add() method.");
                break;

            case AdditionalParameters.AddData:
                vdObj.AddData(new Sequence(Alphabets.DNA, "GGGGGGGGGGGGG"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "TTTTTTTTTTTTT"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "CCCCCCCCCCCCC"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "AAAAAAAAAAAAAA"), 0, 10);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data.ToString(), vdObj[i].Data.ToString());
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the AddData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the AddData() method.");
                break;

            case AdditionalParameters.AddDelay:
                vdObj.MaxNumberOfBlocks = 2;
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                // Sleep for 20 seconds so that the cache box would be cleared
                // and the count of items in the VirtualData would be reduced
                Thread.Sleep(20000);
                vdObj.Add(cb3);
                vdObj.Add(cb4);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i + 2].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Add() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Add() method.");
                break;

            case AdditionalParameters.AddDataDelay:
                vdObj.MaxNumberOfBlocks = 2;
                vdObj.AddData(new Sequence(Alphabets.DNA, "GGGGGGGGGGGGG"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "TTTTTTTTTTTTT"), 0, 10);
                // Sleep for 20 seconds so that the cache box would be cleared
                // and the count of items in the VirtualData would be reduced
                Thread.Sleep(20000);
                vdObj.AddData(new Sequence(Alphabets.DNA, "CCCCCCCCCCCCC"), 0, 10);
                vdObj.AddData(new Sequence(Alphabets.DNA, "AAAAAAAAAAAAAA"), 0, 10);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i + 2].Data.ToString(), vdObj[i].Data.ToString());
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the AddData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the AddData() method.");
                break;

            case AdditionalParameters.Clear:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                vdObj.Clear();
                Assert.AreEqual(0, vdObj.Count);
                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Clear() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Clear() method.");
                break;

            case AdditionalParameters.ClearStaleData:
                vdObj.MaxNumberOfBlocks = 2;
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                // Sleep for 20 seconds so that the cache box would be cleared
                // and the count of items in the VirtualData would be reduced
                Thread.Sleep(20000);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                Assert.IsTrue(3 > vdObj.Count);
                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the ClearStaleData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the ClearStaleData() method.");
                break;

            case AdditionalParameters.GetAllData:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                // Gets all the data in Virtual data object
                IList <Sequence> allSeqData = vdObj.GetAllData();
                for (int i = 0; i < allSeqData.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data.ToString(), allSeqData[i].ToString());
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetAllData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetAllData() method.");
                break;

            case AdditionalParameters.GetData:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                // Gets the data in Virtual data object
                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data.ToString(), vdObj.GetData(i).ToString());
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetData() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetData() method.");
                break;

            case AdditionalParameters.GetEnumerator:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                IEnumerator <CacheBox <Sequence> > enumObj = vdObj.GetEnumerator();
                Assert.IsTrue(null != enumObj);
                Assert.AreEqual(cb1, vdObj.FirstOrDefault(C => 0 >= C.StartRange && 0 <= C.EndRange));
                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetEnumerator() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the GetEnumerator() method.");
                break;

            case AdditionalParameters.Insert:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                // Inserts the cache box in Virtual data object
                vdObj.Insert(3, cb4);
                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Insert() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Insert() method.");
                break;

            case AdditionalParameters.Remove:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);

                // Add a Cache Box and remove the same
                CacheBox <Sequence> cb5 = new CacheBox <Sequence>(11);
                cb5.StartRange = 0;
                cb5.EndRange   = 10;
                cb5.Data       = new Sequence(Alphabets.DNA, "AAAAAATTTTTTT");
                vdObj.Add(cb5);
                vdObj.Remove(cb5);
                // Removes the cache box from the virtual data list
                for (int i = 0; i < cbList.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Remove() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Remove() method.");
                break;

            case AdditionalParameters.RemoveAt:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);

                // Add a Cache Box and remove the same
                CacheBox <Sequence> cbRemove = new CacheBox <Sequence>(11);
                cbRemove.StartRange = 0;
                cbRemove.EndRange   = 10;
                cbRemove.Data       = new Sequence(Alphabets.DNA, "AAAAAATTTTTTT");
                vdObj.Add(cbRemove);
                vdObj.RemoveAt(4);

                for (int i = 0; i < cbList.Count; i++)
                {
                    Assert.AreEqual(cbList[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the RemoveAt() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the RemoveAt() method.");
                break;

            case AdditionalParameters.Contains:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                // Validates the contains block
                Assert.IsTrue(vdObj.Contains(cb4));

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the Contains() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the Contains() method.");
                break;

            case AdditionalParameters.CopyTo:
                vdObj.Add(cb1);
                vdObj.Add(cb2);
                vdObj.Add(cb3);
                vdObj.Add(cb4);
                CacheBox <Sequence>[] cbArray = new CacheBox <Sequence> [vdObj.Count];
                vdObj.CopyTo(cbArray, 0);

                for (int i = 0; i < vdObj.Count; i++)
                {
                    Assert.AreEqual(cbArray[i].Data, vdObj[i].Data);
                }

                // Logs to the NUnit GUI (Console.Out) window
                Console.WriteLine(
                    "Virtual Data BVT : Successfully validated the CopyTo() method.");
                ApplicationLog.WriteLine(
                    "Virtual Data BVT : Successfully validated the CopyTo() method.");
                break;

            default:
                break;
            }
        }