Exemplo n.º 1
0
        /// <summary>
        /// Checks need object skip.
        /// </summary>
        /// <param name="result">Import process result.</param>
        /// <param name="currentNumber">Current record number.</param>
        private void _IsObjectSkipped(ImportResult result, int currentNumber)
        {
            // get object name
            AppData.DataObject obj = result.Object;
            Debug.Assert(null != obj); // created

            string importedObjName = null;

            if (!string.IsNullOrEmpty(obj.ToString()))
            {
                importedObjName = obj.ToString().Trim();
            }

            string text = null;

            if (string.IsNullOrEmpty(importedObjName))
            {   // import object with empty name - skip
                text = App.Current.GetString("ImportProcessStatusRecordSkiped", currentNumber);
                ++_skippedCount;
            }
            else if (_IsImportDataSourceInvalid(result, currentNumber))
            {   // import object convert with error - skip
                ++_skippedCount;
            }
            else
            {   // ignore object with equals names
                //  for Order and Barrier special routine: they can be have different PlannedDate
                //  and name don't check
                if ((obj is Order) ||
                    (obj is Barrier) ||
                    _IsObjectUnique(obj, _importedObjects))
                {
                    _importedObjects.Add(obj);
                }
                else
                {   // ignore object with dublicated names from resource - skip
                    text = App.Current.GetString("ImportProcessStatusSkiped",
                                                 _informer.ObjectName,
                                                 importedObjName,
                                                 currentNumber);
                    ++_skippedCount;
                }
            }

            // store description
            if (!string.IsNullOrEmpty(text))
            {
                var description = new MessageDetail(MessageType.Warning, text);
                _details.Add(description);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks is objects equals.
        /// </summary>
        /// <param name="object1">First object to checking.</param>
        /// <param name="object2">Second object to checking.</param>
        /// <returns>Return TRUE if objects is equals</returns>
        private bool _IsObjectsEquals(AppData.DataObject object1, AppData.DataObject object2)
        {
            Debug.Assert(null != object1); // created
            Debug.Assert(null != object2); // created

            bool isEquals = false;
            var  order1   = object1 as Order;

            // special check for Orders
            if (null != order1)
            {
                // check by Name and PlannedDate
                var order2 = object2 as Order;
                isEquals = _IsOrdersEquals(order1, order2);
            }

            else
            {   // special check for Barrires
                var barrier1 = object1 as Barrier;
                if (null != barrier1)
                {   // check by Name, StartDate and FinishDate
                    var barrier2 = object2 as Barrier;
                    isEquals = _IsBarriersEquals(barrier1, barrier2);
                }
                // all other objects - check by Name
                else
                {
                    string object1Name = object1.ToString().Trim();
                    isEquals = (object1Name.Equals(object2.ToString().Trim(),
                                                   StringComparison.OrdinalIgnoreCase));
                }
            }

            return(isEquals);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Convert <see cref="DataObject"/> to object name.
        /// </summary>
        /// <param name="value"><see cref="DataObject"/> (<see cref="Driver"/>, <see cref="Vehicle"/>, etc.).</param>
        /// <param name="targetType">Ignored.</param>
        /// <param name="parameter">Ignored.</param>
        /// <param name="culture">Ignored.</param>
        /// <returns>Driver name.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string result = string.Empty;

            _object = value as AppData.DataObject;
            Debug.Assert(_object != null);

            if (null != _object)
                // get object name.
                result = _object.ToString();

            return result;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        public MessageObjectContext(DataObject dataObject)
        {
            if (null == dataObject)
                throw new ArgumentException();

            _name = dataObject.ToString();
            _type = dataObject.GetType();
            _id = dataObject.Id;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds objects to project.
        /// </summary>
        /// <typeparam name="T">The type of data objects to collection adding.</typeparam>
        /// <param name="objects">Object collection.</param>
        /// <param name="appObjects">Application's object collection.</param>
        private bool _AddObjectsToProject <T>(IList <AppData.DataObject> objects, IList <T> appObjects)
            where T : AppData.DataObject
        {
            Debug.Assert(null != objects);                   // created
            Debug.Assert(0 < objects.Count);                 // not empty
            Debug.Assert(null != appObjects);                // created
            Debug.Assert(typeof(T) == objects[0].GetType()); // some types

            bool result = false;

            try
            {
                // NOTE: if object with this name present in application - need replace data
                for (int index = 0; index < objects.Count; ++index)
                {
                    AppData.DataObject obj = objects[index];

                    // find equals object in application
                    bool isUpdated = false;
                    for (int appObjIndex = 0; appObjIndex < appObjects.Count; ++appObjIndex)
                    {
                        // update application object by object data
                        if (obj.ToString() == appObjects[appObjIndex].ToString())
                        {
                            AppData.DataObject updatedObject = appObjects[appObjIndex];
                            _UpdateObject <T>(obj, updatedObject);
                            _AddUpdateObjectWarning(updatedObject);
                            _ValidateObject(updatedObject);

                            // store in updated
                            if (!_updatedObjects.Contains(updatedObject))
                            {
                                _updatedObjects.Add(updatedObject); // only unique
                            }
                            isUpdated = true;
                            break; // NOTE: process done
                        }
                    }

                    // add new object
                    if (!isUpdated)
                    {
                        CreateHelpers.SpecialInit(appObjects, obj);
                        appObjects.Add((T)obj);
                        _ValidateObject(obj);
                        ++_createdCount;

                        _updatedObjects.Add(obj);
                    }
                }

                // store changes
                App.Current.Project.Save();
                result = true;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                _updatedObjects.Clear();
            }

            return(result);
        }