public XElement GetAssetMetadata(string path)
        {
            MetadataExtractor mex = new MetadataExtractor(path);

            return(mex.GetXml().Root);
        }
Example #2
0
        private void DoProcessing()
        {
            string inputPath = InputPath.Trim();

            if (string.IsNullOrEmpty(inputPath))
            {
                string error = string.Format("Input file path is empty.  Processing ignored. File: {0}", inputPath);
                AddLogEntry(error, LogEntryTarget.Database);
                m_Logger.Error(error);
                throw new FileNotFoundException("File not found. Input path is empty");
            }

            if (!File.Exists(inputPath))
            {
                string error = string.Format("Input file not found.  Processing ignored. File: {0}", inputPath);
                AddLogEntry(error, LogEntryTarget.Database);
                m_Logger.Error(error);
                throw new FileNotFoundException("File not found", inputPath);
            }

            try
            {
                // Plugin to be used for processing
                PluginInfo pluginInfo = PluginManager.Instance.GetPluginInfo(PluginName, PathUtils.GetExtension(inputPath));

                // Get the actual plugin to do the processing
                PluginBase plugin = pluginInfo.GetAssetProcessingPlugin();

                // Do any setup stuff
                plugin.Setup();

                // Set the plugin actually used for processing
                PluginUsed = pluginInfo.Name;

                AddLogEntry("Plugin to be used for processing: " + PluginUsed);

                // Set required properties
                plugin.InputPath     = inputPath;
                plugin.WatermarkPath = WatermarkPath;
                plugin.ThumbnailSize = (OverrideWidth > 0 && OverrideHeight > 0) ? new Size(OverrideWidth, OverrideHeight) : new Size(100, 100);
                plugin.PreviewSize   = (OverrideWidth > 0 && OverrideHeight > 0) ? new Size(OverrideWidth, OverrideHeight) : new Size(320, 300);

                m_Logger.DebugFormat("Dimensions to be used - thumbnail: {0}(w)x{1}h, preview: {2}(w)x{3}h", plugin.ThumbnailSize.Width, plugin.ThumbnailSize.Height, plugin.PreviewSize.Width, plugin.PreviewSize.Height);

                try
                {
                    plugin.BeforeProcessing();

                    m_Logger.InfoFormat("Processing {0}.  Preview: {1} (Watermark: {2}).  Thumbnail: {3}", inputPath, CreatePreview, (!String.IsNullOrEmpty(WatermarkPath)).ToString().ToLower(), CreateThumbnail);

                    if (CreatePreview)
                    {
                        if (plugin.CanGeneratePreview)
                        {
                            PreviewPath = plugin.GeneratePreview();

                            if (!String.IsNullOrEmpty(PreviewPath) && !File.Exists(PreviewPath))
                            {
                                m_Logger.WarnFormat("Plugin reports that the preview file has been created, but file does not exist: {0}", PreviewPath);
                            }

                            AddLogEntry("Generated preview: " + PreviewPath);
                        }
                        else
                        {
                            const string message = "Preview generation requested, but plugin cannot generate preview";

                            AddLogEntry(message, LogEntryTarget.Database);

                            m_Logger.Warn(message);
                        }
                    }
                }
                catch (NotImplementedException)
                {
                    const string error = "Preview not created: plugin does not support this feature";

                    AddLogEntry(error, LogEntryTarget.Database);

                    m_Logger.Error(error);
                }
                catch (Exception e)
                {
                    LogError("Error creating preview", e);
                }

                try
                {
                    if (CreateThumbnail)
                    {
                        if (plugin.CanGenerateThumbnail)
                        {
                            ThumbnailPath = plugin.GenerateThumbnail();

                            if (!String.IsNullOrEmpty(ThumbnailPath) && !File.Exists(ThumbnailPath))
                            {
                                m_Logger.WarnFormat("Plugin reports thumbnail has been created, but file does not exist: {0}", ThumbnailPath);
                            }

                            AddLogEntry("Generated thumbnail: " + ThumbnailPath);
                        }
                        else
                        {
                            const string message = "Thumbnail generation requested, but plugin cannot generate thumbnail";

                            AddLogEntry(message, LogEntryTarget.Database);

                            m_Logger.Warn(message);
                        }
                    }
                }
                catch (NotImplementedException)
                {
                    const string error = "Thumbnail not created: plugin does not support this feature";

                    AddLogEntry(error, LogEntryTarget.Database);

                    m_Logger.Error(error);
                }
                catch (Exception e)
                {
                    LogError("Error creating thumbnail", e);
                }

                // Add any other data to be posted back by plugin
                foreach (var item in plugin.FileDataItems)
                {
                    FileDataItems[item.Key] = item.Value;
                }

                // Do any cleanup stuff
                plugin.Cleanup();
            }
            catch (PluginNotFoundException ex)
            {
                LogError("Plugin not found or not available", ex);
            }

            try
            {
                MetadataExtractor mex = new MetadataExtractor(inputPath);
                MetadataXml = mex.GetXml();
                AddLogEntry("Got file metadata XML");
            }
            catch (Exception ex)
            {
                LogError("Error getting metadata XML", ex);
            }
        }