/// <summary>
        /// Parses string and split it to properties values.
        /// </summary>
        /// <param name="value">DB barrier's type properties string.</param>
        /// <returns>Parsed barrier's type.</returns>
        internal static BarrierEffect CreateFromDBString(string value)
        {
            var obj = new BarrierEffect();

            if (null != value)
            {
                char[] valuesSeparator = new char[1] {
                    CommonHelpers.SEPARATOR
                };
                string[] values;
                values = value.Split(valuesSeparator, StringSplitOptions.None);
                System.Diagnostics.Debug.Assert(4 == values.Length);

                CultureInfo cultureInfo = CultureInfo.GetCultureInfo(CommonHelpers.STORAGE_CULTURE);
                // 0. Current version - Now ignored
                int index = 0;
                // 1. BlockTravel
                obj.BlockTravel = bool.Parse(values[++index]);
                // 2. DelayTime
                obj.DelayTime = double.Parse(values[++index], cultureInfo);
                // 3. SpeedFactor
                obj.SpeedFactorInPercent = double.Parse(values[++index], cultureInfo);
            }

            return(obj);
        }
        /// <summary>
        /// Create and initializes a instance of the <c>Barrier</c> class.
        /// </summary>
        /// <param name="entity">Entity for initialization.</param>
        internal Barrier(DataModel.Barriers entity)
            : base(entity)
        {
            Debug.Assert(0 < entity.CreationTime); // NOTE: must be inited

            _barrierEffect = BarrierEffect.CreateFromDBString(entity.BarrierType);

            _barrierEffect.PropertyChanged +=
                new PropertyChangedEventHandler(_BarrierEffect_PropertyChanged);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Clones the <c>BarierType</c> object.
        /// </summary>
        /// <returns>Cloned object.</returns>
        public object Clone()
        {
            var obj = new BarrierEffect();

            obj.BlockTravel          = this.BlockTravel;
            obj.DelayTime            = this.DelayTime;
            obj.SpeedFactorInPercent = this.SpeedFactorInPercent;

            return(obj);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Create a new instance of the <c>Barrier</c> class.
        /// </summary>
        public Barrier(DateTime startDate, DateTime endTime)
            : base(DataModel.Barriers.CreateBarriers(Guid.NewGuid(), startDate, endTime))
        {
            base.SetCreationTime();

            _barrierEffect = new BarrierEffect();
            _UpdateBarrierEffectEntityData();

            _barrierEffect.PropertyChanged +=
                new PropertyChangedEventHandler(_BarrierEffect_PropertyChanged);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Puts barrier's type to string.
        /// </summary>
        /// <param name="obj">Break values.</param>
        /// <returns>Barrier's type values string.</returns>
        internal static string AssemblyDBString(BarrierEffect obj)
        {
            var result = new StringBuilder();

            CultureInfo cultureInfo = CultureInfo.GetCultureInfo(CommonHelpers.STORAGE_CULTURE);

            // 0. Current version
            result.Append(VERSION_CURR.ToString());
            // 1. BlockTravel
            result.Append(CommonHelpers.SEPARATOR);
            result.Append(obj.BlockTravel);
            // 2. DelayTime
            result.Append(CommonHelpers.SEPARATOR);
            result.Append(obj.DelayTime.ToString(cultureInfo));
            // 3. SpeedFactor
            result.Append(CommonHelpers.SEPARATOR);
            result.Append(obj.SpeedFactorInPercent.ToString(cultureInfo));

            return(result.ToString());
        }
 /// <summary>
 /// Updates barrier type to enty data.
 /// </summary>
 private void _UpdateBarrierEffectEntityData()
 {
     _Entity.BarrierType = BarrierEffect.AssemblyDBString(_barrierEffect);
 }
        /// <summary>
        /// Parses string and split it to properties values.
        /// </summary>
        /// <param name="value">DB barrier's type properties string.</param>
        /// <returns>Parsed barrier's type.</returns>
        internal static BarrierEffect CreateFromDBString(string value)
        {
            var obj = new BarrierEffect();
            if (null != value)
            {
                char[] valuesSeparator = new char[1] { CommonHelpers.SEPARATOR };
                string[] values;
                values = value.Split(valuesSeparator, StringSplitOptions.None);
                System.Diagnostics.Debug.Assert(4 == values.Length);

                CultureInfo cultureInfo = CultureInfo.GetCultureInfo(CommonHelpers.STORAGE_CULTURE);
                // 0. Current version - Now ignored
                int index = 0;
                // 1. BlockTravel
                obj.BlockTravel = bool.Parse(values[++index]);
                // 2. DelayTime
                obj.DelayTime = double.Parse(values[++index], cultureInfo);
                // 3. SpeedFactor
                obj.SpeedFactorInPercent = double.Parse(values[++index], cultureInfo);
            }

            return obj;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Puts barrier's type to string.
        /// </summary>
        /// <param name="obj">Break values.</param>
        /// <returns>Barrier's type values string.</returns>
        internal static string AssemblyDBString(BarrierEffect obj)
        {
            var result = new StringBuilder();

            CultureInfo cultureInfo = CultureInfo.GetCultureInfo(CommonHelpers.STORAGE_CULTURE);
            // 0. Current version
            result.Append(VERSION_CURR.ToString());
            // 1. BlockTravel
            result.Append(CommonHelpers.SEPARATOR);
            result.Append(obj.BlockTravel);
            // 2. DelayTime
            result.Append(CommonHelpers.SEPARATOR);
            result.Append(obj.DelayTime.ToString(cultureInfo));
            // 3. SpeedFactor
            result.Append(CommonHelpers.SEPARATOR);
            result.Append(obj.SpeedFactorInPercent.ToString(cultureInfo));

            return result.ToString();
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Clones the <c>BarierType</c> object.
        /// </summary>
        /// <returns>Cloned object.</returns>
        public object Clone()
        {
            var obj = new BarrierEffect();
            obj.BlockTravel = this.BlockTravel;
            obj.DelayTime = this.DelayTime;
            obj.SpeedFactorInPercent = this.SpeedFactorInPercent;

            return obj;
        }
        /// <summary>
        /// Create and initializes a instance of the <c>Barrier</c> class.
        /// </summary>
        /// <param name="entity">Entity for initialization.</param>
        internal Barrier(DataModel.Barriers entity)
            : base(entity)
        {
            Debug.Assert(0 < entity.CreationTime); // NOTE: must be inited

            _barrierEffect = BarrierEffect.CreateFromDBString(entity.BarrierType);

            _barrierEffect.PropertyChanged +=
                new PropertyChangedEventHandler(_BarrierEffect_PropertyChanged);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Create a new instance of the <c>Barrier</c> class.
        /// </summary>
        public Barrier(DateTime startDate, DateTime endTime)
            : base(DataModel.Barriers.CreateBarriers(Guid.NewGuid(), startDate, endTime))
        {
            base.SetCreationTime();

            _barrierEffect = new BarrierEffect();
            _UpdateBarrierEffectEntityData();

            _barrierEffect.PropertyChanged +=
                new PropertyChangedEventHandler(_BarrierEffect_PropertyChanged);
        }
        /// <summary>
        /// Initialize popup editor.
        /// </summary>
        /// <param name="barrier"></param>
        /// <param name="popup"></param>
        public void Initialize(Barrier barrier, Popup popup)
        {
            _barrier = barrier;
            BarrierEditor.Barrier = barrier;
            _popup = popup;

            // Save initial barrier effect.
            _initialBarrierEffect = barrier.BarrierEffect.Clone() as BarrierEffect;

            App.Current.MainWindow.PreviewMouseDown += new MouseButtonEventHandler(_MainWindowPreviewMouseDown);
            App.Current.MainWindow.Deactivated += new System.EventHandler(_MainWindowDeactivated);
            this.KeyDown += new KeyEventHandler(_BarrierPopupEditorKeyDown);
        }