Exemple #1
0
        /// <summary>
        /// Compare two breaks collection that their breaks have equal values.
        /// </summary>
        /// <param name="breaks">Breaks collection to compare with this.</param>
        /// <returns>"True" if they contain breaks with same values and false otherwise.</returns>
        internal bool EqualsByValue(Breaks breaks)
        {
            Breaks breaksToCompare = breaks.Clone() as Breaks;

            // Collections must have same breaks count.
            if (this.Count != breaksToCompare.Count)
            {
                return(false);
            }

            // If they both dont have breaks - return true.
            if (this.Count == 0)
            {
                return(true);
            }

            // Sort breaks.
            Breaks sortedBreaks = this.Clone() as Breaks;

            sortedBreaks.Sort();
            breaksToCompare.Sort();

            // Compare each breaks in one collection with corresponding break in another collection.
            for (int i = 0; i < sortedBreaks.Count; i++)
            {
                if (!sortedBreaks[i].EqualsByValue(breaksToCompare[i]))
                {
                    return(false);
                }
            }

            // Collection have breaks with same values.
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Clones the breaks object.
        /// </summary>
        /// <returns>Cloned object.</returns>
        public object Clone()
        {
            var obj = new Breaks();

            foreach (Break item in _breaks)
            {
                obj.Add(item.Clone() as Break);
            }

            return(obj);
        }
Exemple #3
0
        /// <summary>
        /// Parses string and splits it to properties values.
        /// </summary>
        /// <param name="value">DB order custom properties string.</param>
        /// <returns>Parsed capacities.</returns>
        internal static Breaks CreateFromDBString(string value)
        {
            var breaks = new Breaks();

            if (null != value)
            {
                var valuesSeparator = new string[1] {
                    CommonHelpers.SEPARATOR_ALIAS
                };
                string[] values =
                    value.Split(valuesSeparator, StringSplitOptions.RemoveEmptyEntries);

                var separator = new string[1] {
                    PART_SPLITTER
                };
                for (int index = 0; index < values.Length; ++index)
                {
                    string currValue = values[index];

                    Break instBreak = null;
                    if (-1 == currValue.IndexOf(PART_SPLITTER))
                    {   // support old version
                        instBreak = new TimeWindowBreak();
                        instBreak.InitFromString(currValue);
                    }
                    else
                    {   // current version
                        string[] breakValues =
                            currValue.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                        Debug.Assert(2 == breakValues.Length);

                        Type type = Type.GetType(breakValues[0]);
                        instBreak = (Break)Activator.CreateInstance(type);
                        instBreak.InitFromString(breakValues[1]); // init state
                    }

                    Debug.Assert(null != instBreak);
                    breaks.Add(instBreak);
                }
            }

            return(breaks);
        }
Exemple #4
0
        /// <summary>
        /// Puts all breaks to string.
        /// </summary>
        /// <param name="breaks">Breaks values.</param>
        internal static string AssemblyDBString(Breaks breaks)
        {
            var result = new StringBuilder();

            for (int index = 0; index < breaks.Count; ++index)
            {
                Break currBreak = breaks[index];
                result.AppendFormat("{0}{1}{2}",
                                    currBreak.GetType().ToString(),
                                    PART_SPLITTER,
                                    currBreak.ConvertToString());

                if (index < breaks.Count - 1)
                {
                    result.Append(CommonHelpers.SEPARATOR_ALIAS); // NOTE: after last not needed
                }
            }

            return(result.ToString());
        }