Esempio n. 1
0
        public virtual IEnumerable <T> GetObject()
        {
            if (string.IsNullOrEmpty(paths))
            {
                return(Enumerable.Empty <T>());
            }

            var ps = paths.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            List <DirectoryInfo> dirs = new List <DirectoryInfo>();

            foreach (var p in ps)
            {
                dirs.AddRange(fileProvider.GetPaths(p, false));
            }
            List <T> objs = new List <T>();

            dirs.GetFiles(fileName, false)
            .ForEach(f =>
            {
                string json = File.ReadAllText(f.FullName);
                if (!string.IsNullOrEmpty(json))
                {
                    IEnumerable <T> os = jsonSerializer.Deserialize <IEnumerable <T> >(json);
                    foreach (var obj in os)
                    {
                        InitializeObject(obj);
                        AddToList(objs, obj);
                    }
                }
            });
            return(objs);
        }
Esempio n. 2
0
        protected virtual void LoadResources(string[] paths)
        {
            if (paths == null || paths.Length <= 0)
            {
                return;
            }

            List <DirectoryInfo> dirs = new List <DirectoryInfo>();

            foreach (var p in paths)
            {
                dirs.AddRange(fileProvider.GetPaths(p, false));
            }
            dirs.GetFiles("*.js", false)
            .ForEach(o =>
            {
                JsonResource jr = new JsonResource();
                jr.FileName     = o.FullName;

                string[] fiNames = o.FileNameWithoutExtension().Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (fiNames.Length == 2)
                {
                    jr.NameSpace       = fiNames[0];
                    jr.CultureInfoName = fiNames[1];
                }
                else if (fiNames.Length == 1)
                {
                    jr.NameSpace       = fiNames[0];
                    jr.CultureInfoName = string.Empty;
                }

                string json = File.ReadAllText(o.FullName);

                jr.Resources = jsonSerializer.Deserialize <SerializableDictionary>(json);
                if (jr.Resources == null)
                {
                    jr.Resources = new SerializableDictionary();
                }

                jsonResources.Add(jr);
            });
        }
Esempio n. 3
0
        public static List <string> GetNotExistingFilesInOtherQuery(this List <FileQuery> queries, List <FileQuery> otherQueries)
        {
            if (queries == null)
            {
                throw new ArgumentNullException("queries");
            }

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

            HashSet <string> query1 = new HashSet <string>(queries.GetFiles(), new FileNameComparer());
            HashSet <string> query2 = new HashSet <string>(otherQueries.GetFiles(), new FileNameComparer());

            var removedFiles = new HashSet <string>(query1, new FileNameComparer());

            removedFiles.ExceptWith(query2);
            return(removedFiles.ToList());
        }
Esempio n. 4
0
        protected virtual void LoadResources(string[] paths)
        {
            if (paths == null || paths.Length <= 0)
                return;

            List<DirectoryInfo> dirs = new List<DirectoryInfo>();
            foreach (var p in paths)
            {
                dirs.AddRange(fileProvider.GetPaths(p, false));
            }
            dirs.GetFiles("*.js", false)
            .ForEach(o =>
            {
                JsonResource jr = new JsonResource();
                jr.FileName = o.FullName;

                string[] fiNames = o.FileNameWithoutExtension().Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (fiNames.Length == 2)
                {
                    jr.NameSpace = fiNames[0];
                    jr.CultureInfoName = fiNames[1];
                }
                else if (fiNames.Length == 1)
                {
                    jr.NameSpace = fiNames[0];
                    jr.CultureInfoName = string.Empty;
                }

                string json = File.ReadAllText(o.FullName);

                jr.Resources = jsonSerializer.Deserialize<SerializableDictionary>(json);
                if (jr.Resources == null)
                    jr.Resources = new SerializableDictionary();

                jsonResources.Add(jr);
            });
        }
Esempio n. 5
0
 /// <summary>
 /// Retrieves files from a file directory
 /// </summary>
 /// <param name="directoryObjectList">Directory list to retrieve files from</param>
 /// <param name="boolRecurse">Flag that determines whether files are retrieved recursively including files from sub-directories</param>
 /// <returns></returns>
 public static FileObjectList GetFiles(this List <DirectoryObject> directoryObjectList, bool boolRecurse)
 {
     return(directoryObjectList.GetFiles("*", boolRecurse));
 }
Esempio n. 6
0
        public void Can_Search_In_Gac()
        {
            List <FileQuery> queries = FileQuery.ParseQueryList("GAC:\\mscorlib.dll");

            Assert.AreEqual(1, queries.GetFiles().Count());
        }
        public static List<string> GetNotExistingFilesInOtherQuery(this List<FileQuery> queries, List<FileQuery> otherQueries)
        {
            if (queries == null)
            {
                throw new ArgumentNullException("queries");
            }

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

            var query1 = new HashSet<string>(queries.GetFiles(), new FileNameComparer());
            var query2 = new HashSet<string>(otherQueries.GetFiles(), new FileNameComparer());

            var removedFiles = new HashSet<string>(query1, new FileNameComparer());
            removedFiles.ExceptWith(query2);

            return removedFiles.ToList();
        }
        public AssemblyDiffCollection Execute(List <FileQuery> oldFiles, List <FileQuery> newFiles)
        {
            using (var t = new Tracer(MyType, "Execute"))
            {
                //var removedTypes = 0;
                //var changedTypes = 0;

                var removedFiles = oldFiles.GetNotExistingFilesInOtherQuery(newFiles);

                if (removedFiles.Count > 0)
                {
                    foreach (var str in removedFiles)
                    {
                        Console.WriteLine("\t{0}", Path.GetFileName(str));
                    }
                }

                var oldFilesQuery = new HashSet <string>(oldFiles.GetFiles(), new FileNameComparer());
                var newFilesQuery = new HashSet <string>(newFiles.GetFiles(), new FileNameComparer());

                // Get files which are present in one set and the other
                oldFilesQuery.IntersectWith(newFilesQuery);
                //DiffPrinter printer = new DiffPrinter(Out);

                var result = new AssemblyDiffCollection();

                foreach (var fileName1 in oldFilesQuery)
                {
                    if (fileName1.EndsWith(".XmlSerializers.dll", StringComparison.OrdinalIgnoreCase))
                    {
                        t.Info("Ignore xml serializer dll {0}", fileName1);
                        continue;
                    }

                    var fileName2 = newFiles.GetMatchingFileByName(fileName1);

                    var assemblyV1 = AssemblyLoader.LoadCecilAssembly(fileName1);
                    var assemblyV2 = AssemblyLoader.LoadCecilAssembly(fileName2);

                    if (assemblyV1 != null && assemblyV2 != null)
                    {
                        var differ      = new AssemblyDiffer(assemblyV1, assemblyV2);
                        var differences = differ.GenerateTypeDiff(QueryAggregator.PublicApiQueries);
                        result.AddedRemovedTypes.AddRange(differences.AddedRemovedTypes);
                        result.ChangedTypes.AddRange(differences.ChangedTypes);

                        //removedTypes += differences.AddedRemovedTypes.RemovedCount;
                        //changedTypes += differences.ChangedTypes.Count;

                        /*if (diff.AddedRemovedTypes.Count > 0 || diff.ChangedTypes.Count > 0)
                         * {
                         *  // Out.WriteLine("{0} has {1} changes", Path.GetFileName(fileName1), diff.AddedRemovedTypes.Count + diff.ChangedTypes.Sum(type => type.Events.Count + type.Fields.Count + type.Interfaces.Count + type.Methods.Count));
                         *
                         *  // printer.Print(diff);
                         *  // Out.WriteLine("From {0} assemblies were {1} types removed and {2} changed.", myParsedArgs.Queries1.GetFiles().Count(), removedTypes, changedTypes);
                         *
                         * }*/
                    }
                }

                return(result);
            }
        }