public async Task <string> GetSymbolContent(SymbolData data)
        {
            string result;

            if (String.IsNullOrEmpty(data.SymbolZipName))
            {
                var alobj = await GetSymbolObject(data, true);

                result = ALParser.Write(alobj);
                return(await Task.FromResult(result));
            }

            using (Stream fs = File.OpenRead(data.Path))
            {
                using (var zf = new ZipFile(fs))
                {
                    int i;
                    int.TryParse(data.SymbolZipName, out i);
                    var zipEntry = zf[i];

                    using (var entryStream = zf.GetInputStream(zipEntry))
                    {
                        using (var zipStream = new StreamReader(entryStream))
                        {
                            result = zipStream.ReadToEnd();
                            return(await Task.FromResult(result));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Read_Comments_Methods()
        {
            var result = ALParser.Read(testPath);
            var actual = result.ElementAt(1).Methods.FirstOrDefault(f => f.Name == "CheckThatLabelCanBeAssignedToCustomer");

            Assert.IsTrue(actual.MethodBody.Comments.Count() == 6);
        }
Exemplo n.º 3
0
        public void Read_GlobalVariables()
        {
            var result = ALParser.Read(testPath);

            Assert.IsTrue(result.ElementAt(0).GlobalVariables.Count() == 0);
            Assert.IsTrue(result.ElementAt(1).GlobalVariables.Count() == 1);
        }
Exemplo n.º 4
0
        public void Read_Procedure_Verify_IsLocal(int index, bool expected)
        {
            var result = ALParser.ReadSingle(testPath);
            var actual = result.Methods.ElementAt(index).IsLocal == expected;

            Assert.IsTrue(actual);
        }
Exemplo n.º 5
0
        [TestCase(1, true)]  // Does not have Return Type
        public void Read_Procedure_Verify_ReturnType(int index, bool expected)
        {
            var result = ALParser.ReadSingle(testPath);
            var actual = string.IsNullOrEmpty(result.Methods.ElementAt(index).ReturnTypeDefinition.Name.Trim()) == expected;

            Assert.IsTrue(actual);
        }
Exemplo n.º 6
0
        public void Read_Comments_Object()
        {
            var result = ALParser.Read(testPath);
            var actual = result.ElementAt(1).Comments;

            Assert.IsTrue(actual.Count() > 0);
        }
Exemplo n.º 7
0
        public void Read_Sections()
        {
            var result = ALParser.Read(testPath);
            var actual = result.ElementAt(0).Sections;

            Assert.IsTrue(actual.Count() == 1);
            Assert.IsTrue(actual.ElementAt(0).Sections.Count() == 2);
        }
Exemplo n.º 8
0
        public void Read_ObjectHeaders()
        {
            var result = ALParser.ReadObjectInfos(testPath);

            Assert.AreEqual(result.Count(), 2);
            Assert.AreEqual(81000, result.ElementAt(1).Id);
            Assert.AreEqual(@"LookupValue UT Customer", result.ElementAt(1).Name);
        }
Exemplo n.º 9
0
        public void WriteBackExistingObject_UpdatedParameter()
        {
            var alobjects = ALParser.Read(testPath);
            var alobject  = alobjects.ElementAt(1);

            alobject.Methods.ElementAt(0).Parameters.ElementAt(0).Name = "UpdatedParameter_NewNameGiven";

            var result = ALParser.Write(alobjects);

            Assert.IsNotEmpty(result);
            Assert.IsTrue(result.Contains("UpdatedParameter_NewNameGiven"));
        }
Exemplo n.º 10
0
        public ICollection<CollectorItem> DiscoverLocalFiles(List<string> wkspcePaths)
        {
            var projects = ALProjectCollector.Discover(wkspcePaths);
            var srcDirs = projects.Select(s => Directory.GetParent(s.FilePath).FullName).ToArray();
            var result = new List<CollectorItem>().AsQueryable();

            foreach (var project in projects)
            {
                var path = Directory.GetParent(project.FilePath).FullName;
                var localSymbols = Directory
                    .GetDirectories(path)
                    .SelectMany(s => Directory.GetFiles(s, "*.al", SearchOption.AllDirectories))
                    .SelectMany(item =>
                    {
                        var collectorItems = new List<CollectorItem>();
                        var alobjects = ALParser.Read(item);
                        foreach (var alobject in alobjects)
                        {

                            collectorItems.Add(new CollectorItem
                            {
                                TypeId = alobject.Type,
                                Id = alobject.Id,
                                Type = $"{alobject.Type}",
                                Publisher = project.publisher,
                                //Version = project.version
                                //Symbol = item,
                                FsPath = item,
                                Name = alobject.Name,
                                Application = project.name,
                                CanExecute = (new string[] { "Table", "Page", "PageExtension", "TableExtension", "PageCustomization", "Report" }).Contains($"{alobject.Type}"),
                                CanDesign = (new string[] { "Table", "Page" }).Contains($"{alobject.Type}"),
                                CanCreatePage = (new string[] { "Table", "TableExtension" }).Contains($"{alobject.Type}"),
                                EventName = "not_an_event",
                                IsEvent = false,
                                SymbolData = new SymbolData
                                {
                                    Index = alobject.Id,
                                    Path = item,
                                    Type = alobject.Type
                                }
                            });
                        }

                        return collectorItems;
                    });

                result = result.Concat(localSymbols);
            }

            return result.ToList();
        }
        public List <CollectorItem> DiscoverLocalFile(string itemPath, ALProject project = null)
        {
            if (project is null)
            {
                project = ALProjectCollector.Discover(itemPath);
            }

            var collectorItems = new List <CollectorItem>();
            var alobjects      = ALParser.Read(itemPath);

            foreach (var alobject in alobjects)
            {
                if (alobject.Type == ALObjectType.codeunit)
                {
                    bool isTestCodeunit = alobject
                                          .Properties
                                          .Any(p => p.Name.ToLower() == "subtype" && p.Value.ToLower() == "test");

                    if (isTestCodeunit)
                    {
                        var testCodeunit = ALParser.Read <ALTestCodeunitReader>(itemPath).FirstOrDefault();

                        collectorItems.Add(new CollectorItem
                        {
                            TypeId      = alobject.Type,
                            Id          = alobject.Id,
                            Type        = $"{alobject.Type}",
                            Publisher   = project.publisher,
                            Version     = project.version.ToString(),
                            Symbol      = testCodeunit,
                            FsPath      = itemPath,
                            Name        = alobject.Name,
                            Application = project.name,
                            IsLocal     = true,
                            ProjectPath = project.FilePath,
                            SymbolData  = new SymbolData
                            {
                                Index = alobject.Id,
                                Path  = itemPath,
                                Type  = alobject.Type,
                                Name  = alobject.Name
                            }
                        });
                    }
                }
            }

            //alobjects.ToList().Clear();

            return(collectorItems);
        }
Exemplo n.º 12
0
        public void WriteBackExistingObject_NoChange()
        {
            var alobjects = ALParser.Read(testPath);

            foreach (var obj in alobjects)
            {
                var result = ALParser.Write(obj);
                Assert.IsNotEmpty(result);
            }

            var allobjStr = ALParser.Write(alobjects);

            Assert.IsNotEmpty(allobjStr);
        }
Exemplo n.º 13
0
        public async Task<IALObject> GetSymbolObject(SymbolData data)
        {
            FileInfo info = new FileInfo(data.Path);
            if (info.Extension == ".al")
            {
                var alobjects = ALParser.Read(data.Path);
                var alobject = alobjects.FirstOrDefault(f => f.Type == data.Type && f.Id == data.Index);

                return alobject;
            }

            var symbols = await GetSymbolReference(data.Path);
            var packType = ALTypeMap[data.Type];

            var objects = symbols.GetType().GetProperty(packType)?.GetValue(symbols) as IEnumerable<IALObject>;
            var result = objects.Where(w => w.Id == data.Index).FirstOrDefault();
            return result;
        }
Exemplo n.º 14
0
        public void WriteNewObject_FromALObjectClass()
        {
            var alobject = new ALCodeunit
            {
                Id      = 81000,
                Name    = "Test Codeunit",
                Methods = new List <ALMethod>()
            };

            var method = new ALMethod {
                TestMethod = true, Name = "TestMethod", MethodKind = ALMethodKind.Method
            };

            alobject.Methods.Add(method);

            var result = ALParser.Write(alobject);

            Assert.IsNotEmpty(result);
        }
        public async Task <IALObject> GetSymbolObject(SymbolData data, bool mapSourcePath = true)
        {
            FileInfo info = new FileInfo(data.Path);

            if (info.Extension == ".al")
            {
                var alobjects = ALParser.Read(data.Path);
                var alobject  = alobjects.FirstOrDefault(f => f.Type == data.Type && f.Name == data.Name);
                var project   = ALProjectCollector.Discover(data.Path);

                return(alobject);
            }

            var symbols = await GetSymbolReference(data.Path, mapSourcePath);

            var result = symbols.Symbols.Where(w => w.Type == data.Type && w.Name == data.Name).FirstOrDefault();

            return(await Task.FromResult(result));
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            var path     = args != null && args.Count() > 0 ? args[0] : @".\test_cu.al";
            var codeunit = ALParser.ReadSingle(path);

            Console.WriteLine($"Object info: {codeunit.Type} {codeunit.Id} {codeunit.Name}");
            Console.WriteLine($"Object path: {path}");
            Console.WriteLine("-----------------------------------------------------------");
            foreach (var method in codeunit.Methods)
            {
                Console.WriteLine($"Method: {method.Name} including {method.Parameters.Count()} pparameter(s)");
                Console.WriteLine();
                foreach (var param in method.Parameters)
                {
                    Console.WriteLine($"  Parameter: #{param.Name} {param.TypeDefinition?.Name}");
                }
                Console.WriteLine("-----------------------------------------------------------");
            }

            Console.ReadLine();
        }
Exemplo n.º 17
0
        public void Read_Procedure_Verify_Parameters()
        {
            var result = ALParser.ReadSingle(testPath);

            Assert.IsTrue(result.Methods.First().Parameters.Count > 0);
        }
Exemplo n.º 18
0
        public void Read_Procedure_Verify_TestAttribute()
        {
            var result = ALParser.ReadSingle(testPath);

            Assert.IsTrue(result.Methods.First().TestMethod);
        }