Ejemplo n.º 1
0
        /// <summary>
        /// Function to create a new content object.
        /// </summary>
        /// <param name="plugIn">The plug-in used to create the object.</param>
        /// <returns>The content object or NULL if the content object was not created.</returns>
        public static ContentObject Create(ContentPlugIn plugIn)
        {
            if (plugIn == null)
            {
                throw new ArgumentNullException("plugIn");
            }

            // Perform any set up required on the content.
            ContentSettings settings = plugIn.GetContentSettings();

            if (settings != null)
            {
                if (!settings.PerformSetup())
                {
                    return(null);
                }

                settings.CreateContent = true;
            }

            return(CreateContentObjectInstance(plugIn, settings, null, true));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to load content data from the file system.
        /// </summary>
        /// <param name="editorFile">The editor file data.</param>
        /// <param name="file">The file system file that contains the content data.</param>
        /// <param name="plugIn">The plug-in used to open the file.</param>
        /// <param name="reload">TRUE to just reload the file, FALSE to do a complete load of the content.</param>
        public static void Load(EditorFile editorFile, GorgonFileSystemFileEntry file, ContentPlugIn plugIn, bool reload = false)
        {
            ContentObject content;

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

            if (!reload)
            {
                ContentSettings settings = plugIn.GetContentSettings();                 // Get default settings.

                if (settings != null)
                {
                    // Assign the name from the file.
                    settings.Name          = file.Name;
                    settings.CreateContent = false;
                }

                content = CreateContentObjectInstance(plugIn, settings, editorFile, false);

                Debug.Assert(_currentContentObject != null, "Content should not be NULL!");
            }
            else
            {
                content = Current;
            }

            // Load the content dependencies if any exist.
            // Check for dependencies.
            if ((editorFile != null) &&
                (editorFile.DependsOn.Count > 0))
            {
                var missingDependencies = new List <string>();

                try
                {
                    LoadDependencies(content, content.EditorFile, missingDependencies);
                }
                catch
                {
                    content.Dependencies.Clear();
                    throw;
                }

                if ((missingDependencies.Count > 0) &&
                    (DependencyNotFound != null))
                {
                    DependencyNotFound(file.Name, missingDependencies);
                }
            }

            if (!reload)
            {
                LoadContentPane(content);
            }

            // Load in the content data.
            using (Stream stream = file.OpenStream(false))
            {
                content.Read(stream);
            }

            ContentFile = file;

            content.OnContentReady();
        }