/// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 4
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <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());
        }
Esempio n. 6
0
 /// <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;
        }
Esempio n. 10
0
        /// <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);
        }
Esempio n. 11
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <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);
        }