Exemplo n.º 1
0
        /// <summary>
        /// Opens an XUK file and loads the project from this
        /// </summary>
        /// <param name="fileUri">The <see cref="Uri"/> of the source XUK file (cannot be null)</param>
        //public void OpenXuk(Uri fileUri)
        //{
        //    if (fileUri == null)
        //    {
        //        throw new exception.MethodParameterIsNullException("The source URI cannot be null");
        //    }
        //    OpenXukAction action = new OpenXukAction(this, fileUri);
        //    action.Execute();
        //}

        /// <summary>
        /// Opens an XUK file and loads the project from this.
        /// DO NOT USE ! THE STREAM IS NULL. USE THE STREAM-BASED method instead !
        /// TODO: make public once the Stream issue is fixed.
        /// </summary>
        /// <param name="fileUri">The <see cref="Uri"/> of the source XUK file (can be null)</param>
        /// <param name="reader">The <see cref="XmlReader"/> of the source XUK file (cannot be null)</param>
        //private void OpenXuk(Uri fileUri, XmlReader reader)
        //{
        //    if (reader == null)
        //    {
        //        throw new exception.MethodParameterIsNullException("The source XML reader cannot be null");
        //    }
        //    OpenXukAction action = new OpenXukAction(this, fileUri, reader);
        //    action.Execute();
        //}
        /// <summary>
        /// Saves the <see cref="Project"/> to a XUK file
        /// </summary>
        /// <param name="fileUri">The <see cref="Uri"/> of the destination XUK file</param>
        //public void SaveXuk(Uri fileUri)
        //{
        //    if (fileUri == null)
        //    {
        //        throw new exception.MethodParameterIsNullException("The destination URI cannot be null");
        //    }
        //    SaveXukAction action = new SaveXukAction(this, this, fileUri);
        //    action.Execute();
        //}

        /// <summary>
        /// Saves the <see cref="Project"/> to a XUK file
        /// </summary>
        /// <param name="fileUri">The <see cref="Uri"/> of the destination XUK file</param>
        /// <param name="writer">The <see cref="XmlWriter"/> of the destination XUK file</param>
        //public void SaveXuk(Uri fileUri, XmlWriter writer)
        //{
        //    if (writer == null)
        //    {
        //        throw new exception.MethodParameterIsNullException("The destination XML writer cannot be null");
        //    }
        //    SaveXukAction action = new SaveXukAction(this, this, fileUri, writer);
        //    action.Execute();
        //}


        /// <summary>
        /// Sets the <see cref="Presentation"/> at a given index
        /// </summary>
        /// <param name="newPres">The <see cref="Presentation"/> to set</param>
        /// <param name="index">The given index</param>
        /// <exception cref="exception.MethodParameterIsNullException">
        /// Thrown when <paramref name="newPres"/> is <c>null</c></exception>
        /// <exception cref="exception.MethodParameterIsOutOfBoundsException">
        /// Thrown when <paramref name="index"/> is not in <c>[0;this.getNumberOfPresentations()]</c>
        /// </exception>
        /// <exception cref="exception.IsAlreadyManagerOfException">
        /// Thrown when <paramref name="newPres"/> already exists in <c>this</c> with another <paramref name="index"/>
        /// </exception>
        public void SetPresentation(Presentation newPres, int index)
        {
            if (newPres == null)
            {
                throw new exception.MethodParameterIsNullException("The new Presentation can not be null");
            }
            if (index < 0 || mPresentations.Count < index)
            {
                throw new exception.MethodParameterIsOutOfBoundsException(String.Format(
                                                                              "There is no Presentation at index {0:0}, index must be between 0 and {1:0}",
                                                                              index, mPresentations.Count));
            }
            if (mPresentations.IndexOf(newPres) != -1)
            {
                if (mPresentations.IndexOf(newPres) != index)
                {
                    throw new exception.IsAlreadyManagerOfException(String.Format(
                                                                        "The new Presentation already exists in the Project at index {0:0}",
                                                                        mPresentations.IndexOf(newPres)));
                }
            }
            if (index < mPresentations.Count)
            {
                mPresentations.Remove(mPresentations.Get(index));
                newPres.Project = this;
                mPresentations.Insert(index, newPres);
            }
            else
            {
                newPres.Project = this;
                mPresentations.Insert(mPresentations.Count, newPres);
            }
        }
        private void AddManagedObject_NO_LOCK(T obj, string uid, bool safetyChecks)
        {
            obj.Uid = uid;

#if !UidStringComparisonNoHashCodeOptimization
            if (!XukAble.UsePrefixedIntUniqueHashCodes)
            {
#if DEBUG
                Debugger.Break();
#endif //DEBUG
                CheckUidHashCollision(obj.UidHash);
            }
#endif //UidStringComparisonNoHashCodeOptimization

            if (safetyChecks)
            {
                foreach (T objz in m_managedObjects.ContentsAs_Enumerable)
                {
                    if (obj == objz)
                    {
                        throw new exception.ObjectIsAlreadyManagedException(
                                  "The given object is already managed by the Manager");
                    }
#if !UidStringComparisonNoHashCodeOptimization
                    if (UidEquals(objz, obj.Uid, obj.UidHash))
#else //UidStringComparisonNoHashCodeOptimization
                    if (objz.Uid == obj.Uid)
#endif //UidStringComparisonNoHashCodeOptimization
                    {
                        throw new exception.ObjectIsAlreadyManagedException(
                                  String.Format("Another managed object exists with uid {0}", uid));
                    }
                }
            }

            if (!CanAddManagedObject(obj))
            {
                throw new CannotManageObjectException("the given object cannot be added to the Manager.");
            }

            m_managedObjects.Insert(m_managedObjects.Count, obj);
        }