Example #1
0
        public void SetUp()
        {
            kernel = new StandardKernel();

            tmp     = new TempDirectory();
            rootDir = new LocalFileSystemDirectory(tmp);
            using (var writer = rootDir.CreateTextFile("file1"))
                writer.WriteLine("Contents of file 1");
            using (var writer = rootDir.CreateTextFile("file2"))
                writer.WriteLine("Contents of file 2");
            using (var writer = rootDir.CreateTextFile("file3"))
                writer.WriteLine("Contents of file 3");

            sourceSet1 = new SourceSet("test1");
            sourceSet1.Add(new SuiteRelativePath("file1"));
            sourceSet1.Add(new SuiteRelativePath("file2"));

            sourceSet2 = new SourceSet("test2");
            sourceSet2.Add(new SuiteRelativePath("file1"));
            sourceSet2.Add(new SuiteRelativePath("file3"));

            kernel.Bind <IFileSystemDirectory>().ToConstant(rootDir).WhenTargetHas <SuiteRootAttribute>();

            var factoryMock = new Mock <ISourceSetFingerprintFactory>();

            factoryMock.Setup(
                f =>
                f.CreateSourceSetFingerprint(It.IsAny <IEnumerable <SuiteRelativePath> >(), It.IsAny <Func <string, bool> >(), It.IsAny <bool>()))
            .Returns <IEnumerable <SuiteRelativePath>, Func <string, bool>, bool>(
                (files, exclusions, fullDependency) => new SourceSetFingerprint(rootDir, files, exclusions, fullDependency));
            fingerprintFactory = factoryMock.Object;
        }
Example #2
0
        private IEnumerable <SourceTrack> CreateSourceTracksForFiles(
            Artist artist,
            Source dbSource,
            Vendor.ArchiveOrg.Metadata.Metadata meta,
            IEnumerable <Vendor.ArchiveOrg.Metadata.File> mp3Files,
            IDictionary <string, Vendor.ArchiveOrg.Metadata.File> flacFiles,
            SourceSet set = null
            )
        {
            var trackNum = 0;

            return(mp3Files.
                   Where(file =>
            {
                return !(
                    (file.title == null && file.original == null && file.name == null) ||
                    file.length == null ||
                    file.name == null
                    );
            }).
                   OrderBy(file => file.name).
                   Select(file =>
            {
                var r = CreateSourceTrackForFile(artist, dbSource, meta, file, trackNum, flacFiles, set);
                trackNum = r.track_position;

                return r;
            })
                   );
        }
Example #3
0
 public Realm GetActiveRealm(DateTime now)
 {
     return(SourceSet
            .Where(r => r.Beginning <= now)
            .Where(r => r.End > now)
            .SingleOrDefault());
 }
Example #4
0
        private SourceTrack CreateSourceTrackForFile(
            Artist artist,
            Source dbSource,
            Vendor.ArchiveOrg.Metadata.Metadata meta,
            Vendor.ArchiveOrg.Metadata.File file,
            int previousTrackNumber,
            IDictionary <string, Vendor.ArchiveOrg.Metadata.File> flacFiles,
            SourceSet set = null
            )
        {
            int trackNum = previousTrackNumber + 1;

            var title = !String.IsNullOrEmpty(file.title) ? file.title : file.original;

            var flac = flacFiles.GetValue(file.original);

            return(new SourceTrack()
            {
                title = title,
                track_position = trackNum,
                source_set_id = set == null ? -1 : set.id,
                source_id = dbSource.id,
                duration = file.length.
                           Split(':').
                           Reverse().
                           Select((v, k) => (int)Math.Round(Math.Max(1, 60 * k) * double.Parse(v, NumberStyles.Any))).
                           Sum(),
                slug = Slugify(title),
                mp3_url = $"https://archive.org/download/{meta.identifier}/{file.name}",
                mp3_md5 = file.md5,
                flac_url = flac == null ? null : $"https://archive.org/download/{meta.identifier}/{flac.name}",
                flac_md5 = flac?.md5,
                updated_at = dbSource.updated_at
            });
        }
Example #5
0
        public void GeneratedGuidDefinitionFileIsFiltered()
        {
            var sourceSet = new SourceSet("cpp");

            sourceSet.Add(new SuiteRelativePath("x.cpp"));
            sourceSet.Add(new SuiteRelativePath("y.h"));
            sourceSet.Add(new SuiteRelativePath("real/something.c"));
            sourceSet.Add(new SuiteRelativePath("fake/something.c"));

            const string realGuidDef = @"

/* this ALWAYS GENERATED file contains the IIDs and CLSIDs */

...";

            const string fakeGuidDef = "this is just a regular file";

            sourceSetRoot.SetFileContents("real/something.c", realGuidDef);
            sourceSetRoot.SetFileContents("fake/something.c", fakeGuidDef);
            sourceSetRoot.SetFileContents("y.h", string.Empty);

            var filteredSet = sourceSet.FilterCppSourceSet(sourceSetRoot, sourceSetRoot);

            sourceSet.Files.Should().HaveCount(4);
            filteredSet.Files.Should().HaveCount(3);

            filteredSet.Files.Should().NotContain(new SuiteRelativePath("real/something.c"));
            filteredSet.Files.Should().Contain(new SuiteRelativePath("fake/something.c"));
        }
Example #6
0
        public void GeneratedIdlHeaderIsFiltered()
        {
            var sourceSet = new SourceSet("cpp");

            sourceSet.Add(new SuiteRelativePath("x.cpp"));
            sourceSet.Add(new SuiteRelativePath("y.h"));
            sourceSet.Add(new SuiteRelativePath("real/something.h"));
            sourceSet.Add(new SuiteRelativePath("fake/something.h"));

            const string realIdlHeader = @"

/* this ALWAYS GENERATED file contains the definitions for the interfaces */

...";

            const string fakeIdlHeader = "this is just a regular file";

            sourceSetRoot.SetFileContents("real/something.h", realIdlHeader);
            sourceSetRoot.SetFileContents("fake/something.h", fakeIdlHeader);
            sourceSetRoot.SetFileContents("y.h", string.Empty);

            var filteredSet = sourceSet.FilterCppSourceSet(sourceSetRoot, sourceSetRoot);

            sourceSet.Files.Should().HaveCount(4);
            filteredSet.Files.Should().HaveCount(3);

            filteredSet.Files.Should().NotContain(new SuiteRelativePath("real/something.h"));
            filteredSet.Files.Should().Contain(new SuiteRelativePath("fake/something.h"));
        }
Example #7
0
            public async override Task <ProductMetadata> GetProductMetadataFromUrl(ChromeDriver driver, Product product)
            {
                var html = await HtmlHelpers.GetHtml(driver, product.Link);

                var images = html.QuerySelectorAll(".pDetails__slide")
                             .Select(s => {
                    var fragment = s.InnerHtml;
                    var source   = s.QuerySelectorAll("source").Last();
                    var srcset   = source.GetAttribute("srcset") ?? source.GetAttribute("data-srcset");
                    var parsed   = SourceSet.Parse(srcset);
                    return(parsed.Last().Url);
                })
                             .Where(p => p != null)
                             .ToArray();

                var tags = html.QuerySelectorAll("#pdp_details .tab__item li")
                           .Select(p => Regex.Replace(p.TextContent, @"\s+", " ").Trim())
                           .ToArray();

                return(new ProductMetadata
                {
                    Images = images,
                    Tags = tags,
                });
            }
Example #8
0
        public void GeneratedProxyStubIsFiltered()
        {
            var sourceSet = new SourceSet("cpp");

            sourceSet.Add(new SuiteRelativePath("x.cpp"));
            sourceSet.Add(new SuiteRelativePath("y.h"));
            sourceSet.Add(new SuiteRelativePath("real/something.c"));
            sourceSet.Add(new SuiteRelativePath("fake/something.c"));

            const string realProxyStub = @"

/* this ALWAYS GENERATED file contains the proxy stub code */

...";

            const string fakeProxyStub = "this is just a regular file";

            sourceSetRoot.SetFileContents("real/something.c", realProxyStub);
            sourceSetRoot.SetFileContents("fake/something.c", fakeProxyStub);
            sourceSetRoot.SetFileContents("y.h", string.Empty);

            var filteredSet = sourceSet.FilterCppSourceSet(sourceSetRoot, sourceSetRoot);

            sourceSet.Files.Should().HaveCount(4);
            filteredSet.Files.Should().HaveCount(3);

            filteredSet.Files.Should().NotContain(new SuiteRelativePath("real/something.c"));
            filteredSet.Files.Should().Contain(new SuiteRelativePath("fake/something.c"));
        }
Example #9
0
 public Player GetPlayerForRealm(Guid userId, Guid realmId)
 {
     return(SourceSet
            .Where(p => p.UserId == userId)
            .Where(p => p.RealmId == realmId)
            .SingleOrDefault());
 }
Example #10
0
        /// <summary>
        /// Gets a suitable image candidate for the provided image element.
        /// </summary>
        /// <param name="img">The element to use.</param>
        /// <returns>The possibly valid URL to the right candidate.</returns>
        public static Url GetImageCandidate(this HtmlImageElement img)
        {
            var owner   = img.Owner;
            var srcset  = new SourceSet(owner);
            var options = owner.Options;
            var sources = img.GetSources();

            while (sources.Count > 0)
            {
                var source = sources.Pop();
                var type   = source.Type;

                if (!String.IsNullOrEmpty(type) && options.GetResourceService <IImageInfo>(type) == null)
                {
                    continue;
                }

                foreach (var candidate in srcset.GetCandidates(source.SourceSet, source.Sizes))
                {
                    return(new Url(img.BaseUrl, candidate));
                }
            }

            foreach (var candidate in srcset.GetCandidates(img.SourceSet, img.Sizes))
            {
                return(new Url(img.BaseUrl, candidate));
            }

            return(Url.Create(img.Source));
        }
Example #11
0
        public async Task <SourceSet> Update(Source source, SourceSet set)
        {
            var l = new List <SourceSet>();

            l.Add(set);

            return((await UpdateAll(source, l)).FirstOrDefault());
        }
Example #12
0
        public async Task <SourceSet> Insert(SourceSet set)
        {
            var l = new List <SourceSet>();

            l.Add(set);

            return((await InsertAll(l)).FirstOrDefault());
        }
Example #13
0
        /// <summary>
        /// Recursively adds every file in a given directory to a source set (<see cref="SourceSet"/>)
        /// </summary>
        /// <param name="target">The target source set to be extended</param>
        /// <param name="dir">The root directory for the operation</param>
        private void AddAllFiles(SourceSet target, IFileSystemDirectory dir)
        {
            foreach (var fileName in dir.Files)
            {
                target.Add(new SuiteRelativePath(Path.Combine(suiteRoot.GetRelativePath(dir), fileName)));
            }

            foreach (var childDirectory in dir.ChildDirectories)
            {
                AddAllFiles(target, dir.GetChildDirectory(childDirectory));
            }
        }
Example #14
0
        /// <summary>
        /// Recursively adds every file in a given directory to a source set (<see cref="SourceSet"/>)
        /// </summary>
        /// <param name="target">The target source set to be extended</param>
        /// <param name="dir">The root directory for the operation</param>
        private void AddAllFiles(SourceSet target, IFileSystemDirectory dir)
        {
            foreach (var fileName in dir.Files)
            {
                target.Add(new SuiteRelativePath(Path.Combine(suiteRoot.GetRelativePath(dir), fileName)));
            }

            foreach (var childDirectory in dir.ChildDirectories)
            {
                AddAllFiles(target, dir.GetChildDirectory(childDirectory));
            }
        }
Example #15
0
        public void SourceSetIsNotCaseSensitive()
        {
            var set = new SourceSet("test");

            set.Add(new SuiteRelativePath("x/y/z.abc"));
            set.Add(new SuiteRelativePath("x/Y/z.abc"));
            set.Add(new SuiteRelativePath("x/y/Z.abc"));
            set.Add(new SuiteRelativePath("x/y/z.aBc"));

            set.Files.Should().HaveCount(1);
            set.Files.Should().HaveElementAt(0, new SuiteRelativePath("x/y/z.abc"));
        }
Example #16
0
        public void Add(RenoItem item, SourceSet set, bool asTemplate)
        {
            var function = set.Source.Parsed.Functions.ToArray().FirstOrDefault(f => item.id.EndsWith("." + f.Name));

            if (function != null)
            {
                sb.Append("/**" + function.Snippet.Replace("\n", "\r\n") +
                          "\r\n * @see " + item.url + "\r\n" +
                          "*/\r\n");

                var line          = "";
                var preline       = "";
                var allParameters = true;

                sb.Append("\r\n");

                if (function.Parameters.Count > 0)
                {
                    for (int i = 0; i < function.Parameters.Count; i++)
                    {
                        var parm = function.Parameters[i];

                        var actualValue = (item.parms[i].defaultData == "null"
                            ? "null"
                            : parm.Type == "string" ? ("\"" + item.parms[i].defaultData + "\"") : item.parms[i].defaultData);

                        //TODO: literal values vs. others (like document.title);

                        if (allParameters || (item.parms[i].defaultData != "" && item.parms[i].defaultData != "null"))
                        {
                            sb.Append("var " + parm.Name + " = " + actualValue + ";\r\n");
                            line   += preline + parm.Name + ", ";
                            preline = "";
                        }
                        else
                        {
                            preline += actualValue + ", ";
                        }
                    }

                    line = (function.Returns != null ? ("var " + function.Returns.Name + " = ") : "") + function.Method + "(" +
                           line.Substring(0, line.Length - 2) + ");";
                }
                else
                {
                    line = (function.Returns != null ? ("var " + function.Returns.Name + " = ") : "") + function.Method + "();";
                }


                sb.Append("\r\n" + line + "\r\n\r\n");
            }
        }
Example #17
0
        /// <summary>
        /// Recursively adds every file in a given directory to a source set (<see cref="SourceSet"/>)
        /// </summary>
        /// <param name="target">The target source set to be extended</param>
        /// <param name="dir">The root directory for the operation</param>
        /// <param name="ignoreList">Ignore list for the target source set</param>
        private void AddAllFiles(SourceSet target, IFileSystemDirectory dir, SourceSetIgnoreList ignoreList)
        {
            foreach (var fileName in dir.Files)
            {
                var suiteRelativePath = new SuiteRelativePath(Path.Combine(suiteRoot.GetRelativePath(dir), fileName));
                if (!ignoreList.IsIgnored(suiteRelativePath))
                {
                    target.Add(suiteRelativePath);
                }
            }

            foreach (var childDirectory in dir.ChildDirectories)
            {
                AddAllFiles(target, dir.GetChildDirectory(childDirectory), ignoreList);
            }
        }
Example #18
0
        /// <summary>
        /// Recursively adds every file in a given directory to a source set (<see cref="SourceSet"/>)
        /// </summary>
        /// <param name="target">The target source set to be extended</param>
        /// <param name="dir">The root directory for the operation</param>
        /// <param name="ignoreList">Ignore list for the target source set</param>
        private void AddAllFiles(SourceSet target, IFileSystemDirectory dir, SourceSetIgnoreList ignoreList)
        {
            foreach (var fileName in dir.Files)
            {
                var suiteRelativePath = new SuiteRelativePath(Path.Combine(suiteRoot.GetRelativePath(dir), fileName));
                if (!ignoreList.IsIgnored(suiteRelativePath))
                {
                    target.Add(suiteRelativePath);
                }
            }

            foreach (var childDirectory in dir.ChildDirectories)
            {
                AddAllFiles(target, dir.GetChildDirectory(childDirectory), ignoreList);
            }
        }
Example #19
0
        private void GetSource(SourceSet ss, out Column column)
        {
            switch (this.WhatPlotting)
            {
            case EPlotting.Peaks:
                column = ss._colourByPeak;
                break;

            case EPlotting.Observations:
                column = ss._colourByObervation;
                break;

            default:
                throw new SwitchException(this.WhatPlotting);
            }
        }
Example #20
0
        private void ColourBy(SourceSet ss, Column selected)
        {
            switch (this.WhatPlotting)
            {
            case EPlotting.Peaks:
                ss._colourByPeak = selected;
                break;

            case EPlotting.Observations:
                ss._colourByObervation = selected;
                break;

            default:
                throw new SwitchException(this.WhatPlotting);
            }
        }
Example #21
0
        private void _btnColour_DropDownOpening(object sender, EventArgs e)
        {
            ToolStripDropDownButton tsddb = (ToolStripDropDownButton)sender;

            IEnumerable <Column> columns;
            Column selected;

            bool isColour = tsddb == this._btnColour;

            SourceSet ss = isColour ? this._colourBy : this._regressAgainst;

            switch (this.WhatPlotting)
            {
            case EPlotting.Peaks:
                columns  = ColumnManager.GetColumns <Peak>(this._core);
                selected = ss._colourByPeak;
                break;

            case EPlotting.Observations:
                columns  = ColumnManager.GetColumns <ObservationInfo>(this._core);
                selected = ss._colourByObervation;
                break;

            default:
                throw new SwitchException(this.WhatPlotting);
            }

            selected = FrmEditColumns.Show(this, columns, selected, isColour ? "Colour by" : "Regress against");

            if (selected == null)
            {
                return;
            }

            if (isColour)
            {
                this.ColourBy(this._colourBy, selected);
                this.UpdatePlot();
            }
            else
            {
                this.ColourBy(this._regressAgainst, selected);
                this.ColourBy(this._colourBy, selected);
                this.UpdateScores();
            }
        }
        private void Add(TKey key, TSource value, IDictionary <TKey, SourceSet> addTo, IDictionary <TKey, SourceSet> other, Func <bool, SetAction> onAddedMethod)
        {
            int?insertIndex = null;
            var action      = SetAction.None;

            if (!addTo.TryGetValue(key, out SourceSet sourceSet))
            {
                int?otherIndex = null;
                if (other != null && other.TryGetValue(key, out SourceSet otherSourceSet))
                {
                    otherIndex = otherSourceSet.Index;
                }
                else
                {
                    insertIndex = _cumulativeList.Count;
                }

                sourceSet = new SourceSet(otherIndex ?? ++_nextIndex);
                addTo.Add(key, sourceSet);

                action = onAddedMethod.Invoke(otherIndex.HasValue);
            }

            if (!insertIndex.HasValue)
            {
                insertIndex = FindByIndex(_cumulativeList, sourceSet.Index) + 1;
            }

            sourceSet.IncrementCount();

            var resultSet = new ResultSet(sourceSet.Index, value);

            _cumulativeList.Insert(insertIndex.Value, resultSet);

            switch (action)
            {
            case SetAction.Add:
                AddToResultList(_cumulativeList[FindFirstByIndex(_cumulativeList, insertIndex.Value, sourceSet.Index)]);
                break;

            case SetAction.Remove:
                RemoveFromResultList(sourceSet.Index);
                break;
            }
        }
Example #23
0
        private void GetSource(SourceSet ss, out IEnumerator enSources, out Column column)
        {
            this.GetSource(ss, out column);

            switch (this.WhatPlotting)
            {
            case EPlotting.Peaks:
                enSources = this._pcaPeaks.GetEnumerator();
                break;

            case EPlotting.Observations:
                enSources = this._pcaObservations.GetEnumerator();
                break;

            default:
                throw new SwitchException(this.WhatPlotting);
            }
        }
Example #24
0
        public void FilesWithIdlExtensionAreFiltered()
        {
            var sourceSet = new SourceSet("cpp");

            sourceSet.Add(new SuiteRelativePath("x.cpp"));
            sourceSet.Add(new SuiteRelativePath("y.h"));
            sourceSet.Add(new SuiteRelativePath("a/b/c/z.c"));
            sourceSet.Add(new SuiteRelativePath("1.idl"));
            sourceSet.Add(new SuiteRelativePath("a/2.idl"));


            sourceSetRoot.SetFileContents("y.h", string.Empty);
            sourceSetRoot.SetFileContents("a/b/c/z.c", string.Empty);

            var filteredSet = sourceSet.FilterCppSourceSet(sourceSetRoot, sourceSetRoot);

            sourceSet.Files.Should().HaveCount(5);
            filteredSet.Files.Should().HaveCount(3);

            filteredSet.Files.Should().NotContain(new SuiteRelativePath("1.idl"));
            filteredSet.Files.Should().NotContain(new SuiteRelativePath("a/2.idl"));
        }
Example #25
0
        public void GeneratedDllDataCIsFiltered()
        {
            var sourceSet = new SourceSet("cpp");

            sourceSet.Add(new SuiteRelativePath("x.cpp"));
            sourceSet.Add(new SuiteRelativePath("y.h"));
            sourceSet.Add(new SuiteRelativePath("real/dlldata.c"));
            sourceSet.Add(new SuiteRelativePath("fake/dlldata.c"));

            const string realDllDataC =
                @"/*********************************************************
   DllData file -- generated by MIDL compiler 

        DO NOT ALTER THIS FILE

   This file is regenerated by MIDL on every IDL file compile.

   To completely reconstruct this file, delete it and rerun MIDL
   on all the IDL files in this DLL, specifying this file for the
   /dlldata command line option

*********************************************************/";

            const string fakeDllDataC = "this is just a regular file";

            sourceSetRoot.SetFileContents("real/dlldata.c", realDllDataC);
            sourceSetRoot.SetFileContents("fake/dlldata.c", fakeDllDataC);
            sourceSetRoot.SetFileContents("y.h", string.Empty);

            var filteredSet = sourceSet.FilterCppSourceSet(sourceSetRoot, sourceSetRoot);

            sourceSet.Files.Should().HaveCount(4);
            filteredSet.Files.Should().HaveCount(3);

            filteredSet.Files.Should().NotContain(new SuiteRelativePath("real/dlldata.c"));
            filteredSet.Files.Should().Contain(new SuiteRelativePath("fake/dlldata.c"));
        }
Example #26
0
 public static ISourceSet FilterCppSourceSet(this SourceSet sourceSet, IFileSystemDirectory sourceSetRoot, IFileSystemDirectory suiteRoot)
 {
     return(new FilterImpl(sourceSet, sourceSetRoot, suiteRoot));
 }
Example #27
0
        public void SourceSetTypeCanBeQueried()
        {
            var set = new SourceSet("abcd");

            set.Type.Should().Be(new SourceSetType("abcd"));
        }
Example #28
0
        private async Task <Source> ProcessShow(ImportStats stats, Artist artist, PhishinShow fullShow, ArtistUpstreamSource src, Source dbSource, PerformContext ctx)
        {
            dbSource.has_jamcharts = fullShow.tags.Count(t => t.name == "Jamcharts") > 0;
            dbSource = await _sourceService.Save(dbSource);

            var sets = new Dictionary <string, SourceSet>();

            foreach (var track in fullShow.tracks)
            {
                var set = sets.GetValue(track.set);

                if (set == null)
                {
                    set = new SourceSet()
                    {
                        source_id  = dbSource.id,
                        index      = SetIndexForIdentifier(track.set),
                        name       = track.set_name,
                        is_encore  = track.set[0] == 'E',
                        updated_at = dbSource.updated_at
                    };

                    // this needs to be set after loading from the db
                    set.tracks = new List <SourceTrack>();

                    sets[track.set] = set;
                }
            }

            var setMaps = (await _sourceSetService.UpdateAll(dbSource, sets.Values))
                          .GroupBy(s => s.index)
                          .ToDictionary(kvp => kvp.Key, kvp => kvp.Single());

            foreach (var kvp in setMaps)
            {
                kvp.Value.tracks = new List <SourceTrack>();
            }

            foreach (var track in fullShow.tracks)
            {
                var set = setMaps[SetIndexForIdentifier(track.set)];
                set.tracks.Add(new SourceTrack()
                {
                    source_set_id  = set.id,
                    source_id      = dbSource.id,
                    title          = track.title,
                    duration       = track.duration / 1000,
                    track_position = track.position,
                    slug           = SlugifyTrack(track.title),
                    mp3_url        = track.mp3.Replace("http:", "https:"),
                    updated_at     = dbSource.updated_at,
                    artist_id      = artist.id
                });
            }

            stats.Created += (await _sourceTrackService.InsertAll(dbSource, setMaps.SelectMany(kvp => kvp.Value.tracks))).Count();

            await ProcessSetlistShow(stats, fullShow, artist, src, dbSource, sets);

            ResetTrackSlugCounts();

            return(dbSource);
        }
Example #29
0
 /// <summary>
 ///   The copy constructor.
 /// </summary>
 /// <param name="p_tndCopy">The node to copy.</param>
 public FileSystemTreeNode(FileSystemTreeNode p_tndCopy)
     : base(p_tndCopy.Text)
 {
     Name         = p_tndCopy.Name;
     m_sstSources = new SourceSet(p_tndCopy.m_sstSources);
 }