public ICmsMedia ResolveMedia(string mediaUrl)
        {
            IMedia imedia = MediaResolver.ResolveMedia(mediaUrl);

            if (imedia != null)
            {
                return(this.CmsEntityFactory.CreateCmsMedia((object)imedia));
            }
            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Media item could not be resolved, checking stand alone register.", (Exception)null);
            string standaloneMediaId = MediaResolver.GetStandaloneMediaId(mediaUrl);

            return((ICmsMedia) new UmbracoMedia()
            {
                Id = standaloneMediaId
            });
        }
Esempio n. 2
0
        private static int Main(string[] args)
        {
            void Configuration(ParserSettings with)
            {
                with.EnableDashDash            = true;
                with.CaseInsensitiveEnumValues = true;
                with.AutoHelp   = true;
                with.HelpWriter = null;
            }

            var parser = new Parser(Configuration);

            var parsed = parser.ParseArguments <HtmlDumpOptions, JsonDumpOptions, MediaDumpOptions>(args);

            var result = 0;

            try
            {
                var         resolveMedia = false;
                BaseOptions baseOpts     = null;
                var         processors   = new List <IProcessor>();

                parsed
                .WithParsed <HtmlDumpOptions>(opts =>
                {
                    processors.Add(new HtmlGeneratorProcessor(
                                       opts.OutputDirectory,
                                       !opts.DontIncludeCustomPosterNames,
                                       !opts.DontUseColoredNames,
                                       !opts.DontIncludeSameFagCount,
                                       opts.Style,
                                       opts.Prettify));

                    baseOpts     = opts;
                    resolveMedia = !opts.DontResolveMedia;
                })
                .WithParsed <JsonDumpOptions>(opts =>
                {
                    processors.Add(new JsonSerializerProcessor(opts.OutputDirectory, opts.Formatted));

                    baseOpts     = opts;
                    resolveMedia = !opts.DontResolveMedia;
                })
                .WithParsed <MediaDumpOptions>(opts =>
                {
                    baseOpts     = opts;
                    resolveMedia = true;
                })
                .WithNotParsed(errs =>
                {
                    var helpText = HelpText.AutoBuild(parsed, h =>
                    {
                        h                   = HelpText.DefaultParsingErrorsHandler(parsed, h);
                        h.Copyright         = "";
                        h.Heading           = "";
                        h.AutoVersion       = false;
                        h.AddDashesToOption = true;
                        return(h);
                    }, e => e, true, 190);

                    Console.WriteAscii("Mitsuba Archivizer", Color.DodgerBlue);

                    Console.WriteFormatted("commit {0} @ {1}",
                                           new Formatter(ThisAssembly.Git.Commit, Color.Crimson),
                                           new Formatter(ThisAssembly.Git.Branch, Color.Chartreuse), Color.White);

                    Console.Write(helpText);

                    result = 1;
                });

                if (result != 1)
                {
                    var postCount         = 0;
                    var cursorBackupTop1  = -1;
                    var cursorBackupLeft1 = -1;

                    ThreadParser.OnPostCount   += count => postCount = count;
                    ThreadParser.OnPostParsing += idx =>
                    {
                        if (cursorBackupTop1 == -1 || cursorBackupLeft1 == -1)
                        {
                            cursorBackupTop1  = Console.CursorTop;
                            cursorBackupLeft1 = Console.CursorLeft;
                        }

                        Console.SetCursorPosition(cursorBackupLeft1, cursorBackupTop1);
                        Console.Write(new string(' ', Console.WindowWidth));
                        Console.SetCursorPosition(cursorBackupLeft1, cursorBackupTop1);
                        Console.WriteLine("Parsing post: ({0}/{1})", idx + 1, postCount);
                    };

                    var resolver = new MediaResolver(
                        resolveMedia,
                        baseOpts.OutputDirectory,
                        !baseOpts.DontSeperateMediaByExtension,
                        !baseOpts.DontDownloadThumbnails,
                        baseOpts.AllowedMediaExtensions,
                        baseOpts.AllowedThumbnailExtensions);

                    var mediaCount        = 0;
                    var cursorBackupTop2  = -1;
                    var cursorBackupLeft2 = -1;

                    resolver.OnPostWithMediaCount  += count => mediaCount = count;
                    resolver.OnProcessingPostMedia += (post, idx) =>
                    {
                        if (cursorBackupTop2 == -1 || cursorBackupLeft2 == -1)
                        {
                            cursorBackupTop2  = Console.CursorTop;
                            cursorBackupLeft2 = Console.CursorLeft;
                        }

                        Console.SetCursorPosition(cursorBackupLeft2, cursorBackupTop2);
                        Console.Write(new string(' ', Console.WindowWidth));
                        Console.SetCursorPosition(cursorBackupLeft2, cursorBackupTop2);
                        Console.WriteLine("Downloading media: {0} ({1}/{2})", post.File.FileName, idx + 1, mediaCount);
                    };

                    var pipeline = new ProcessorPipeline(processors, resolver);

                    pipeline.OnProcessorInvoked += name => Console.WriteLine("{0} is working...", name);

                    foreach (var input in baseOpts.InputSeq)
                    {
                        var thread = ThreadParser.TryParse(input).Result;
                        pipeline.Process(thread).Wait();
                    }

                    Console.WriteLine("Done!");
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                result = 1;
            }

            return(result);
        }
Esempio n. 3
0
        private async Task <MediaItem> SearchMedia()
        {
            var resolver = MediaResolver.Create(ParseResult);

            return(await resolver.ResolveMedia());
        }
        public string GetPropertyValue(object cmsPropertyValue)
        {
            if (cmsPropertyValue == null)
            {
                return(string.Empty);
            }
            string xml = cmsPropertyValue.ToString();

            if (string.IsNullOrEmpty(xml))
            {
                return(string.Empty);
            }
            string[] strArray = CurrentConfiguration.SearchSettings.RichTextFileTypes.Split(new string[1]
            {
                ","
            }, StringSplitOptions.RemoveEmptyEntries);
            string empty = string.Empty;

            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(xml);
                XmlNodeList source1 = xmlDocument.SelectNodes("//link[@type='media']");
                if (source1 != null && source1.Count > 0)
                {
                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Detected native related links property, found {0} media links in property", (object)source1.Count), (Exception)null);
                    foreach (XmlNode xmlNode in source1.Cast <XmlNode>())
                    {
                        IMedia media = MediaResolver.GetMedia(Convert.ToInt32(xmlNode.Attributes["link"].Value));
                        string str1  = xmlNode.Attributes["title"].Value;
                        object obj   = ((KeyedCollection <string, Umbraco.Core.Models.Property>)((IContentBase)media).Properties)["umbracoFile"];
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Found media item with path {0} and title {1}", obj, (object)str1), (Exception)null);
                        string str2 = Path.GetExtension(obj.ToString()).Trim('.');
                        if (((IEnumerable <string>)strArray).Contains <string>(str2))
                        {
                            empty += string.Format("<a href=\"{0}\">{1}</a>", obj, (object)str1);
                        }
                        else
                        {
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("File extension {0} is not to be index according to configuration, skipping", (object)str2), (Exception)null);
                        }
                    }
                }
                XmlNodeList source2 = xmlDocument.SelectNodes("//url-picker[@mode='Media']");
                if (source2 != null && source2.Count > 0)
                {
                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Detected uComponents Multi-URL picker, found {0} media links in property", (object)source2.Count), (Exception)null);
                    foreach (XmlNode xmlNode in source2.Cast <XmlNode>())
                    {
                        string innerText = xmlNode.SelectSingleNode("./url").InnerText;
                        string str1      = xmlNode.SelectSingleNode("./link-title").InnerText;
                        if (string.IsNullOrEmpty(str1))
                        {
                            str1 = innerText;
                        }
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Found media item with path {0} and title {1}", (object)innerText, (object)str1), (Exception)null);
                        string str2 = Path.GetExtension(innerText).Trim('.');
                        if (((IEnumerable <string>)strArray).Contains <string>(str2))
                        {
                            empty += string.Format("<a href=\"{0}\">{1}</a>", (object)innerText, (object)str1);
                        }
                        else
                        {
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("File extension {0} is not to be index according to configuration, skipping", (object)str2), (Exception)null);
                        }
                    }
                }
                XmlNodeList source3 = xmlDocument.SelectNodes("//DAMP/mediaItem");
                if (source3 != null)
                {
                    if (source3.Count > 0)
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Detected Digibiz Advanced media picker, found {0} media links in property", (object)source3.Count), (Exception)null);
                        foreach (XmlNode xmlNode in source3.Cast <XmlNode>())
                        {
                            string innerText = xmlNode.SelectSingleNode("./File/umbracoFile").InnerText;
                            string str1      = innerText;
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Found media item with path {0} and title {1}", (object)innerText, (object)str1), (Exception)null);
                            string str2 = Path.GetExtension(innerText).Trim('.');
                            if (((IEnumerable <string>)strArray).Contains <string>(str2))
                            {
                                empty += string.Format("<a href=\"{0}\">{1}</a>", (object)innerText, (object)str1);
                            }
                            else
                            {
                                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("File extension {0} is not to be index according to configuration, skipping", (object)str2), (Exception)null);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Related links property not xml format, trying to parse Media id:s from string", (Exception)null);
                string str1    = xml;
                char[] chArray = new char[1] {
                    ','
                };
                foreach (string str2 in str1.Split(chArray))
                {
                    int result;
                    if (int.TryParse(str2, out result))
                    {
                        IMedia media = MediaResolver.GetMedia(result);
                        if (media == null)
                        {
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Id {0} found, but is not detected as media item, skipping", (object)str2), (Exception)null);
                        }
                        else
                        {
                            object obj1 = ((KeyedCollection <string, Umbraco.Core.Models.Property>)((IContentBase)media).Properties)["umbracoFile"];
                            object obj2 = obj1;
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Found media item with path {0} and title {1}", obj1, obj2), (Exception)null);
                            string str3 = Path.GetExtension(obj1.ToString()).Trim('.');
                            if (((IEnumerable <string>)strArray).Contains <string>(str3))
                            {
                                empty += string.Format("<a href=\"{0}\">{1}</a>", obj1, obj2);
                            }
                            else
                            {
                                this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("File extension {0} is not to be index according to configuration, skipping", (object)str3), (Exception)null);
                            }
                        }
                    }
                    else if (str2.Length > 0 && str2.Contains("/media/"))
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Media item is not numeric, assuming path to media item {0}", (object)str2), (Exception)null);
                        IMedia imedia = MediaResolver.ResolveMedia(str2);
                        if (imedia != null)
                        {
                            object obj = ((KeyedCollection <string, Umbraco.Core.Models.Property>)((IContentBase)imedia).Properties)["umbracoFile"];
                            empty += string.Format("<a href=\"{0}\">{1}</a>", obj, obj);
                        }
                        else
                        {
                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Media item not found in media library, assuming upload property type, file existence will be verified."), (Exception)null);
                            if (!str2.StartsWith("/media/") ? System.IO.File.Exists(str2) : System.IO.File.Exists(HttpContext.Current.Server.MapPath(str2)))
                            {
                                empty += string.Format("<a href=\"{0}\">{1}</a>", (object)str2, (object)str2);
                            }
                        }
                    }
                    else
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Cannot resolve value {0} to media id, skipping.", (object)str2), (Exception)null);
                    }
                }
            }
            return(empty);
        }
Esempio n. 5
0
        private async void archivizeButton_Click(object sender, EventArgs e)
        {
            if (!threadListTextBox.Lines.Any())
            {
                return;
            }

            threadListTextBox.Enabled     = false;
            mediaGroupBox.Enabled         = false;
            jsonGroupBox.Enabled          = false;
            htmlGroupBox.Enabled          = false;
            archivizeButton.Enabled       = false;
            outputDirectoryButton.Enabled = false;

            var processors = new List <IProcessor>();

            if (jsonEnabledCheckbox.Checked)
            {
                processors.Add(new JsonSerializerProcessor(outputDirTextbox.Text, formattedCheckbox.Checked));
            }

            if (htmlEnabledCheckbox.Checked)
            {
                processors.Add(new HtmlGeneratorProcessor(outputDirTextbox.Text, namesCheckbox.Checked, coloredNamesCheckbox.Checked, samefagCheckbox.Checked, (string)styleComboBox.SelectedItem, prettifyCheckbox.Checked));
            }

            MediaResolver resolver;

            if (mediaEnabledCheckbox.Checked)
            {
                var exts      = mediaExtTextbox.Text.Split(',');
                var thumbExts = thumbnailExtTextBox.Text.Split(',');

                resolver = new MediaResolver(true, outputDirTextbox.Text, groupByExtensionsCheckbox.Checked, thumbnailsEnabledCheckbox.Checked, exts, thumbExts);
                resolver.OnPostWithMediaCount  += Resolver_OnPostWithMediaCount;
                resolver.OnProcessingPostMedia += Resolver_OnProcessingPostMedia;
            }
            else
            {
                resolver = new MediaResolver();
            }

            var pipeline = new ProcessorPipeline(processors, resolver);

            pipeline.OnProcessorInvoked += Pipeline_OnProcessorInvoked;

            foreach (var line in threadListTextBox.Lines)
            {
                try
                {
                    statusTextLabel.Text = "Parsing posts...";

                    var thread = await ThreadParser.TryParse(line);

                    if (mediaEnabledCheckbox.Checked)
                    {
                        statusTextLabel.Text = "Resolving media...";

                        foreach (var post in thread.Posts)
                        {
                            if (post.File != null)
                            {
                                _total++;

                                if (resolver.DownloadThumbnails && !string.IsNullOrEmpty(post.File.FileThumbUrl))
                                {
                                    _total++;
                                }
                            }
                        }
                    }

                    await pipeline.Process(thread);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), $"Exception thrown while processing {line}", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }

            Reset();
        }