示例#1
0
        /// <summary>
        /// Does import object.
        /// </summary>
        /// <param name="references">Dictionary property name to field position in data source.</param>
        /// <param name="currentNumber">Current record number.</param>
        private void _ImportObject(Dictionary <string, int> references, int currentNumber)
        {
            Debug.Assert(null != _profile);     // inited
            Debug.Assert(null != _provider);    // inited
            Debug.Assert(null != _projectData); // inited
            Debug.Assert(null != references);   // created

            try
            {
                ImportType   type = _profile.Type;
                ImportResult res  = CreateHelpers.Create(type,
                                                         references,
                                                         _provider,
                                                         _projectData,
                                                         _defaultDate);
                _IsObjectSkipped(res, currentNumber);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                // store problem description
                string text =
                    App.Current.GetString("ImportProcessStatusRecordFailed",
                                          _informer.ObjectName,
                                          currentNumber);
                var description = new MessageDetail(MessageType.Warning, text);
                _details.Add(description);
                ++_failedCount;
            }
        }
示例#2
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);
        }