/*-------------------------------------------------------------------------
 * 功能描述：ExportInstance
 * 作者：xulisong
 * 创建时间： 2019/6/13 14:46:48
 * 版本号：v1.0
 *  -------------------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RevitExport
{
    /*
     * 使用event形式，将Export和Parse关联断开
     */
    /// <summary>
    /// 导出实例
    /// </summary>
    public class ExportInstance
    {
        public ExportInstance(List<ElementWrapper> elements)
        {
            ExportElements = elements ?? new List<ElementWrapper>();
        }
        /// <summary>
        /// 待导出元素
        /// </summary>
        private List<ElementWrapper> ExportElements { get; set; }

        #region 导出逻辑相关
        public bool Export()
        {
            if (ExportElements == null)
                return false;
            for (int i = 0; i < ExportElements.Count; i++)
            {

                if (IsCancel)
                    return false;
                ElementWrapper revitElementWrapper = ExportElements[i];
                ParseElement?.Invoke(this, new ExportArgs(revitElementWrapper));
                ProcessChanged?.Invoke(i + 1);
            }
            return true;
        }
        /// <summary>
        /// 是否取消
        /// </summary>
        public bool IsCancel { get; set; }
        public event EventHandler<ExportArgs> ParseElement;
        public event Action<int> ProcessChanged;
        #endregion
    }

    public class ExportArgs : EventArgs
    {
        public ExportArgs(ElementWrapper elementWrapper)
        {
            ElementWrapper = elementWrapper;
        }
        public ElementWrapper ElementWrapper { get; private set; }
    }
}
