Esempio 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 string GetUidOfManagedObject_NO_LOCK(T obj)
        //{
        //    foreach (T objz in m_managedObjects.ContentsAs_Enumerable)
        //    {
        //        if (objz == obj) return objz.Uid;
        //    }

        //    throw new exception.IsNotManagerOfException("The given object is not managed by this Manager");
        //}

        //public string GetUidOfManagedObject(T obj)
        //{
        //    if (obj == null)
        //    {
        //        throw new exception.MethodParameterIsNullException("channel parameter is null");
        //    }
        //    if (m_managedObjects.UseLock)
        //    {
        //        lock (LOCK)
        //        {
        //            return GetUidOfManagedObject_NO_LOCK(obj);
        //        }
        //    }
        //    else
        //    {
        //        return GetUidOfManagedObject_NO_LOCK(obj);
        //    }
        //}


        //public void SetUidOfManagedObject_NO_LOCK(T obj, string uid)
        //{
        //    foreach (T objz in m_managedObjects.ContentsAs_Enumerable)
        //    {
        //        if (UidEquals(objz, uid) && objz != obj)
        //        {
        //            throw new exception.ObjectIsAlreadyManagedException(
        //                String.Format("Another managed object exists with uid {0}", uid));
        //        }
        //        if (objz == obj)
        //        {
        //            if (UidEquals(objz, obj.Uid))
        //            {
        //                return;
        //            }

        //            CheckUidHashCollision_(obj.UidHash);
        //            obj.Uid = uid;
        //            CheckUidHashCollision(obj.UidHash);
        //            return;
        //        }
        //    }

        //    throw new exception.IsNotManagerOfException("The given object is not managed by this Manager");
        //}


        //public void SetUidOfManagedObject(T obj, string uid)
        //{
        //    if (obj == null)
        //    {
        //        throw new exception.MethodParameterIsNullException("channel parameter is null");
        //    }

        //    if (string.IsNullOrEmpty(uid))
        //    {
        //        throw new exception.MethodParameterIsEmptyStringException("uid parameter cannot be null or empty string");
        //    }
        //    if (m_managedObjects.UseLock)
        //    {
        //        lock (LOCK)
        //        {
        //            SetUidOfManagedObject_NO_LOCK(obj, uid);
        //        }
        //    }
        //    else
        //    {
        //        SetUidOfManagedObject_NO_LOCK(obj, uid);
        //    }
        //}

        private void RemoveManagedObject_NO_LOCK(T obj)
        {
            T objectToRemove = null;

            foreach (T objz in m_managedObjects.ContentsAs_Enumerable)
            {
                if (objz == obj)
                {
                    objectToRemove = obj;
                    break;
                }
            }
            if (objectToRemove != null)
            {
                m_managedObjects.Remove(objectToRemove);


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

                    CheckUidHashCollision_(objectToRemove.UidHash);
                }
#endif //UidStringComparisonNoHashCodeOptimization
                return;
            }

            throw new exception.IsNotManagerOfException("The given object is not managed by this Manager");
        }