Пример #1
0
        public void FindCommonParentPath()
        {
            var cr = new List <CodeRecord>();

            cr.Add(new CodeRecord()
            {
                Assembly   = this.GetType().Assembly.FullName,
                SourceFile = "/home/inb/things/sources/projects/asm1/file1.cs"
            });
            cr.Add(new CodeRecord()
            {
                Assembly   = this.GetType().Assembly.FullName,
                SourceFile = "/home/inb/things/sources/projects/asm1/file2.cs"
            });
            cr.Add(new CodeRecord()
            {
                Assembly   = this.GetType().Assembly.FullName,
                SourceFile = "/home/inb/things/sources/projects/asm1/file3.cs"
            });
            cr.Add(new CodeRecord()
            {
                Assembly   = this.GetType().Assembly.FullName,
                SourceFile = "/home/inb/things/sources/projects/asm1/subdir/file4.cs"
            });
            cr.Add(new CodeRecord()
            {
                Assembly   = this.GetType().Assembly.FullName,
                SourceFile = "/home/inb/things/sources/projects/asm1/subdir/subdir2/file5.cs"
            });

            var x      = new FilesystemMap();
            var parent = x.FindMainFolder(this.GetType().Assembly.FullName, cr);

            Assert.AreEqual("/home/inb/things/sources/projects/asm1", parent);
        }
Пример #2
0
        protected void OnRemapAssemblySource(object sender, EventArgs e)
        {
            if (records == null || records.Count == 0)
            {
                return;
            }

            var rd = new RemapSourceFoldersDialog();

            rd.Response += (o, args) => {
                rd.Hide();
            };

            var asmlist = (from x in records where true select x.Assembly).Distinct().ToArray();
            Dictionary <string, string> oldpaths = new Dictionary <string, string>();

            foreach (var asm in asmlist)
            {
                var recs       = from x in records where x.Assembly == asm select x;
                var asmrecs    = recs.ToArray();
                var parentpath = fsmap.FindMainFolder(asm, asmrecs);
                oldpaths[asm] = parentpath;
                rd.AddAssembly(asm, parentpath, null);
            }

            var rt = rd.Run();

            if (rt == (int)(ResponseType.Ok))
            {
                Dictionary <string, string> newpaths = new Dictionary <string, string>();
                foreach (var asm in asmlist)
                {
                    var p = rd.GetPathOfAssembly(asm);
                    newpaths[asm] = p;
                }

                foreach (var rec in records)
                {
                    if (newpaths.ContainsKey(rec.Assembly))
                    {
                        var oldp = oldpaths[rec.Assembly];
                        var newp = newpaths[rec.Assembly];
                        if (!string.IsNullOrEmpty(rec.SourceFile))
                        {
                            var newf = newp + "/" + rec.SourceFile.Substring(oldp.Length);
                            newf = newf.Replace("//", "/");
                            if (File.Exists(newf))
                            {
                                if (newf.Length > 3)
                                {
                                    rec.SourceFile = newf;
                                }
                            }
                        }
                    }
                }
            }
        }