예제 #1
0
        /// <summary>
        /// Does validate object.
        /// </summary>
        /// <param name="obj">Object to validation.</param>
        private void _ValidateObject(AppData.DataObject obj)
        {
            Debug.Assert(null != obj); // created

            // check geocoded point in map extent
            var geocodable = obj as IGeocodable;

            if ((null != geocodable) &&
                geocodable.IsGeocoded)
            {
                AppGeometry.Envelope extent = App.Current.Map.ImportCheckExtent;
                // geolocation is not valide
                if (!extent.IsPointIn(geocodable.GeoLocation.Value))
                {
                    // reset geolocation
                    geocodable.GeoLocation         = null;
                    geocodable.Address.MatchMethod = string.Empty;
                    // store problem description
                    string extendedFormat =
                        App.Current.FindString("ImportProcessStatusRecordOutMapExtendFormat");
                    string errorTextFormat =
                        string.Format(GEOCODE_MESSAGE_FORMAT, _objectsName, extendedFormat);
                    _details.Add(new MessageDetail(MessageType.Warning, errorTextFormat, obj));
                }
            }

            _StoreValidateResult(obj);
        }
예제 #2
0
        /// <summary>
        /// Handler begins edit item (calls BeginEditItem method of appropriate ContextHandler).
        /// </summary>
        /// <param name="sender">Data grid control sender.</param>
        /// <param name="e">Item event args.</param>
        private void _DataGridCollectionViewSourceBeginningEdit(object sender, DataGridItemCancelEventArgs e)
        {
            e.Handled = true;

            ESRI.ArcLogistics.Data.DataObject dataObject = e.Item as ESRI.ArcLogistics.Data.DataObject;
            if (dataObject != null)
            {
                // Define event args from editinf Item.
                DataObjectCanceledEventArgs args = new DataObjectCanceledEventArgs(dataObject);

                // Raise BeginningEdit event.
                if (BeginningEdit != null)
                {
                    BeginningEdit(this, args);
                }

                if (!args.Cancel)
                {
                    _handler.BeginEditItem(e); // If action wasn't cancelled - begin editing in appropriate handler.
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Removes specified data object.
        /// </summary>
        /// <param name="context">ObjectContext object</param>
        /// <param name="obj">Data object to remove</param>
        /// <returns>
        /// entity set name
        /// </returns>
        public static void RemoveObject(ObjectContext context,
            DataObject obj)
        {
            Debug.Assert(context != null);

            context.DeleteObject(DataObjectHelper.GetEntityObject(obj));
        }
예제 #4
0
        /// <summary>
        /// Updates geocodable information.
        /// </summary>
        /// <param name="needMessage">Need show message.</param>
        /// <param name="candidate">Geocoded candidate (can be NULL).</param>
        /// <param name="obj">Source object to geocoded candidate.</param>
        private void _UpdateGeocodableInfo(bool needMessage,
                                           AddressCandidate candidate,
                                           AppData.DataObject obj)
        {
            Debug.Assert(null != obj); // Created.

            IGeocodable geocodable = _GetGeocodable(obj);

            geocodable.GeoLocation = null;

            if ((null == candidate) || (candidate.Score <= App.Current.Geocoder.MinimumMatchScore))
            {
                // Not geocoded.
                geocodable.Address.MatchMethod = string.Empty;
            }
            else
            {
                GeocodeHelpers.SetCandidate(geocodable, candidate);
                ++_geocodedCount;

                // Store warning.
                if (needMessage)
                {
                    string objectName      = _informer.ObjectName;
                    string errorTextFormat =
                        App.Current.GetString("ImportProcessStatusRecordOutMapExtendGeocodedFormat",
                                              objectName.ToLower(),
                                              "{0}",
                                              objectName);
                    var description =
                        new MessageDetail(MessageType.Warning, errorTextFormat, obj);
                    _details.Add(description);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Parses batch geocoding result. Set geocode candidates values to relative object.
        /// </summary>
        /// <param name="candidates">Candidates from geocoding.</param>
        /// <param name="objects">Objects to geocoding.</param>
        private void _ParseBatchGeocodeResult(AddressCandidate[] candidates,
                                              IList <AppData.DataObject> objects)
        {
            Debug.Assert(null != objects);                    // created
            Debug.Assert(null != candidates);                 // created
            Debug.Assert(candidates.Length == objects.Count); // valid state
            Debug.Assert(null != _checker);                   // inited

            // valid check extent
            var importExtent = App.Current.Map.ImportCheckExtent;

            // init progress
            int count = objects.Count;

            for (int index = 0; index < count; ++index)
            {
                _checker.ThrowIfCancellationRequested();

                // get current object
                AppData.DataObject obj        = objects[index];
                IGeocodable        geocodable = _GetGeocodable(obj);

                bool needMessage = false;
                if (geocodable.IsGeocoded)
                {   // add message - Could not locate object using X/Y attributes.
                    // Order was located using address information instead
                    Debug.Assert(!importExtent.IsPointIn(geocodable.GeoLocation.Value));
                    needMessage = true;
                }

                AddressCandidate candidate = candidates[index];
                _UpdateGeocodableInfo(needMessage, candidate, obj);
            }
        }
예제 #6
0
 /// <summary>
 /// Raises New Object Created.
 /// </summary>
 /// <param name="obj">New object.</param>
 private void _OnNewObjectCreated(ESRI.ArcLogistics.Data.DataObject obj)
 {
     if (NewObjectCreated != null)
     {
         NewObjectCreated(this, new DataObjectEventArgs(obj));
     }
 }
예제 #7
0
        /// <summary>
        /// Updates destination object by data from source object.
        /// </summary>
        /// <typeparam name="T">The type of data objects to updating.</typeparam>
        /// <param name="sourceObj">Source object.</param>
        /// <param name="destinationObj">Destination object (object to update).</param>
        private void _UpdateObject <T>(AppData.DataObject sourceObj,
                                       AppData.DataObject destinationObj)
            where T : AppData.DataObject
        {
            Debug.Assert(null != sourceObj);      // created
            Debug.Assert(null != destinationObj); // created

            // special issue for routes: color not updated by empty value
            if (typeof(Route) == typeof(T))
            {
                var   route       = destinationObj as Route;
                Color storedColor = route.Color;
                sourceObj.CopyTo(route);
                if (route.Color.IsEmpty)
                {
                    route.Color = storedColor;
                }
            }

            // simple update data
            else
            {
                sourceObj.CopyTo(destinationObj);
            }
        }
예제 #8
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);
        }
예제 #9
0
 /// <summary>
 /// Raises EditCommited.
 /// </summary>
 /// <param name="obj">Edited object.</param>
 private void _OnEditCommited(ESRI.ArcLogistics.Data.DataObject obj)
 {
     if (EditCommitted != null)
     {
         EditCommitted(this, new DataObjectEventArgs(obj));
     }
 }
예제 #10
0
 /// <summary>
 /// Raises Bedin Edit.
 /// </summary>
 /// <param name="obj">Edited object.</param>
 private void _OnEditBegun(ESRI.ArcLogistics.Data.DataObject obj)
 {
     if (EditBegun != null)
     {
         EditBegun(this, new DataObjectEventArgs(obj));
     }
 }
예제 #11
0
 /// <summary>
 /// Raises New Object Canceled.
 /// </summary>
 /// <param name="obj">Cancelled object.</param>
 private void _OnNewObjectCanceled(ESRI.ArcLogistics.Data.DataObject obj)
 {
     if (NewObjectCanceled != null)
     {
         NewObjectCanceled(this, new ESRI.ArcLogistics.App.Pages.DataObjectEventArgs(obj));
     }
 }
예제 #12
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Gets geocodable interface from data object.
        /// </summary>
        /// <param name="obj">Data object to conversion.</param>
        /// <returns>Geocodable interface.</returns>
        private IGeocodable _GetGeocodable(AppData.DataObject obj)
        {
            var geocodable = obj as IGeocodable;

            Debug.Assert(null != geocodable); // valid type
            return(geocodable);
        }
예제 #13
0
        /// <summary>
        /// Handler raises event about editing was started.
        /// </summary>
        /// <param name="sender">Data grid control sender.</param>
        /// <param name="e">Item event args.</param>
        private void _DataGridCollectionViewSourceEditBegun(object sender, DataGridItemEventArgs e)
        {
            ESRI.ArcLogistics.Data.DataObject dataObject = e.Item as ESRI.ArcLogistics.Data.DataObject;

            if (dataObject != null)
            {
                // Raise event about item editing was started.
                _OnEditBegun(dataObject);
            }
        }
        /// <summary>
        /// Finds all routes associated with the specified object.
        /// </summary>
        /// <param name="associatedObject">The object to find routes associated with.</param>
        /// <returns>A collection of routes associated with the specified object.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="associatedObject"/> is
        /// a null reference.</exception>
        public IEnumerable<Route> FindRoutes(DataObject associatedObject)
        {
            CodeContract.RequiresNotNull("associatedObject", associatedObject);

            var tracker = default(RouteAssociationTracker);
            if (!_associationTrackers.TryGetValue(associatedObject.GetType(), out tracker))
            {
                return Enumerable.Empty<Route>();
            }

            return tracker.FindRoutes(associatedObject);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <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;
        }
예제 #16
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);
            }
        }
예제 #17
0
        /// <summary>
        /// Populate update object warning.
        /// </summary>
        /// <param name="obj">Updated object.</param>
        private void _AddUpdateObjectWarning(AppData.DataObject obj)
        {
            Debug.Assert(null != obj); // created

            IGeocodable geocodable = obj as IGeocodable;

            if (null != geocodable)
            {   // NOTE: workaround - see method comment
                CommonHelpers.FillAddressWithSameValues(geocodable.Address);
            }

            string statusText = App.Current.FindString("ImportProcessStatusUpdated");
            string textFormat = _objectsName + FORMAT_UPDATE_MESSAGE_PART + statusText;

            _details.Add(new MessageDetail(MessageType.Warning, textFormat, obj));
        }
예제 #18
0
        /// <summary>
        /// Stores validate result.
        /// </summary>
        /// <param name="obj">Object to validation.</param>
        private void _StoreValidateResult(AppData.DataObject obj)
        {
            Debug.Assert(null != obj); // created

            string error = obj.Error;

            if (string.IsNullOrEmpty(error))
            {
                ++_validCount;
            }
            else
            {
                string errorTextFormat =
                    _objectsName + FORMAT_VALIDATION_MESSAGE_PART + Environment.NewLine + error;
                _details.Add(new MessageDetail(MessageType.Warning, errorTextFormat, obj));
            }
        }
예제 #19
0
        /// <summary>
        /// Does source geocoding.
        /// </summary>
        /// <param name="objects">Objects to geocoding.</param>
        private void _SourceGeocode(IList <AppData.DataObject> objects)
        {
            Debug.Assert(null != objects);   // created
            Debug.Assert(0 < objects.Count); // not empty
            Debug.Assert(null != _checker);  // inited

            // init progress
            int count = objects.Count;

            // geocode process
            var ungeocoded = new List <AppData.DataObject>();

            for (int index = 0; index < count; ++index)
            {
                _checker.ThrowIfCancellationRequested();

                AppData.DataObject obj        = objects[index];
                IGeocodable        geocodable = _GetGeocodable(obj);

                bool isObjectGeocoded = false;
                if (geocodable.IsGeocoded)
                {
                    // check is geocodable object valid and set candidate
                    // from local geocoder if exists
                    isObjectGeocoded = _SourceGeocodedObject(geocodable);
                    if (isObjectGeocoded)
                    {
                        ++_geocodedCount;
                    }
                }

                if (!isObjectGeocoded)
                {
                    ungeocoded.Add(obj);
                }
            }

            _checker.ThrowIfCancellationRequested();

            // geocode all ungeocoded object by batch geocode
            if (0 < ungeocoded.Count)
            {
                _BatchGeocode(ungeocoded);
            }
        }
예제 #20
0
        /// <summary>
        /// Checks is object unique.
        /// </summary>
        /// <param name="obj">Object to check.</param>
        /// <param name="objects">Previous object collection.</param>
        /// <returns>Return TRUE if newObject not present in objects.</returns>
        private bool _IsObjectUnique(AppData.DataObject obj, IList <AppData.DataObject> objects)
        {
            Debug.Assert(null != obj);     // created
            Debug.Assert(null != objects); // created

            bool isUnique = true;

            foreach (var currentObj in objects)
            {
                if (_IsObjectsEquals(obj, currentObj))
                {
                    isUnique = false;
                    break; // NOTE: result founded
                }
            }

            return(isUnique);
        }
        private static List <MessageDetail> _CheckDriverSpecialties(ICollection <Route> routes, ICollection <Order> orders)
        {
            List <MessageDetail> details = new List <MessageDetail>();

            bool checkOneRoute = (1 == routes.Count);

            string format = App.Current.FindString((checkOneRoute)? "ConstraintsCheckerDriverSpecRouteMessageFmt" :
                                                   "ConstraintsCheckerDriverSpecRoutesMessageFmt");

            foreach (Order order in orders)
            {
                ICollection <DriverSpecialty> specialties = (checkOneRoute)?
                                                            _CanAccommodateOrderSpecialties(routes.First().Driver.Specialties, order.DriverSpecialties) :
                                                            _CanAccommodateOrderDriverSpecialties(routes, order);;
                if (null != specialties)
                {
                    int paramCount = 1 + specialties.Count;
                    if (checkOneRoute)
                    {
                        ++paramCount;
                    }
                    AppData.DataObject[] param = new AppData.DataObject[paramCount];

                    int index = 0;
                    if (checkOneRoute)
                    {
                        param[index++] = routes.First().Driver;
                    }
                    param[index++] = order;

                    string specialtiesFormat = ViolationsHelper.GetObjectListFormat(specialties, ref index, param);
                    string messageFormat     = (checkOneRoute) ? string.Format(format, "{0}", "{1}", specialtiesFormat) :
                                               string.Format(format, "{0}", specialtiesFormat);
                    details.Add(new MessageDetail(MessageType.Warning, messageFormat, param));
                }
            }

            return(details);
        }
예제 #22
0
        /// <summary>
        /// Adds objects to project.
        /// </summary>
        /// <param name="objects">Object collection to adding.</param>
        /// <returns>TRUE if operation ended successed.</returns>
        private bool _AddToProject(IList <AppData.DataObject> objects)
        {
            Debug.Assert(null != objects);   // created
            Debug.Assert(0 < objects.Count); // not empty

            App     currentApp = App.Current;
            Project project    = currentApp.Project;

            // store in project
            bool result = false;

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;

                // get objects type
                AppData.DataObject firstObject = objects.FirstOrDefault();

                if (firstObject == null)
                {
                    return(result);
                }

                Type type = firstObject.GetType();

                if (type == typeof(Order))
                {   // case for Orders
                    result = _AddOrdersToProject(objects, project);
                }
                else if (type == typeof(Barrier))
                {   // case for Barriers
                    result = _AddBarriersToProject(objects, project);
                }
                else if (type == typeof(Location))
                {   // case for Locations
                    result = _AddObjectsToProject(objects, project.Locations);
                }
                else if (type == typeof(Driver))
                {   // case for Drivers
                    result = _AddObjectsToProject(objects, project.Drivers);
                }
                else if (type == typeof(Vehicle))
                {   // case for Vehicles
                    result = _AddObjectsToProject(objects, project.Vehicles);
                }
                else if (type == typeof(MobileDevice))
                {   // case for MobileDevices
                    result = _AddObjectsToProject(objects, project.MobileDevices);
                }
                else if (type == typeof(Route))
                {   // case for Routes
                    // NOTE: support only for Default Routes
                    result = _AddObjectsToProject(objects, project.DefaultRoutes);
                }
                else if (type == typeof(DriverSpecialty))
                {   // case for DriverSpecialties
                    result = _AddObjectsToProject(objects, project.DriverSpecialties);
                }
                else if (type == typeof(VehicleSpecialty))
                {   // case for VehicleSpecialties
                    result = _AddObjectsToProject(objects, project.VehicleSpecialties);
                }
                else if (type == typeof(Zone))
                {   // case for Zones
                    result = _AddObjectsToProject(objects, project.Zones);
                }
                else
                {
                    Debug.Assert(false); // not supported
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }

            return(result);
        }
 public DataObjectCanceledEventArgs(DataObject obj)
 {
     _object = obj;
 }
 public DataObjectEventArgs(DataObject obj)
 {
     _object = obj;
 }
        /// <summary>
        /// Gets new name for DataObject which is not duplicated in collection.
        /// </summary>
        /// <param name="collection">Collection in which this object will be placed.</param>
        /// <param name="newItem">New object.</param>
        /// <param name="nameContainNew">If 'true' the new name will be like 'New Driver 2',otherwise
        /// it would be like 'Driver 2'.</param>
        /// <returns>New name.</returns>
        public static string GetNameForNewDataObject(IEnumerable collection,
            DataObject newItem, bool nameContainNew)
        {
            // Calculate new item's name.
            string name = newItem.TypeTitle;

            // If flag is 'true' then apply format from resources.
            if (nameContainNew)
                name = App.Current.GetString("NewItemNameFormat", name);

            return _GetUniqueNewName(collection, name, false,
                delegate(object obj)
                {
                    return (obj as DataObject).Name;
                });
        }
예제 #26
0
        /// <summary>
        /// Does deep copy without build results.
        /// </summary>
        /// <param name="obj">Object to copy values.</param>
        private void _CopyNoResults(DataObject obj)
        {
            Route route = obj as Route;
            Debug.Assert(null != route);

            route.Name = this.Name;
            route.Comment = this.Comment;
            route.Color = this.Color;
            route.MaxOrders = this.MaxOrders;
            route.MaxTotalDuration = this.MaxTotalDuration;
            route.MaxTravelDistance = this.MaxTravelDistance;
            route.MaxTravelDuration = this.MaxTravelDuration;
            route.TimeAtEnd = this.TimeAtEnd;
            route.TimeAtRenewal = this.TimeAtRenewal;
            route.TimeAtStart = this.TimeAtStart;
            route.HardZones = this.HardZones;

            route.StartLocation = this.StartLocation;
            route.EndLocation = this.EndLocation;
            route.Vehicle = this.Vehicle;
            route.Driver = this.Driver;

            if (null != this.StartTimeWindow)
                route.StartTimeWindow = this.StartTimeWindow.Clone() as TimeWindow;

            if (null != this.Breaks)
                route.Breaks = this.Breaks.Clone() as Breaks;

            route.RenewalLocations = this.RenewalLocations;

            route.Zones = this.Zones;

            route.Days = this.Days.Clone() as Days;

            if (_Entity.Default)
                route._Entity.DefaultRouteID = this.Id;
            else if (null != this.DefaultRouteID)
                route._Entity.DefaultRouteID = this.DefaultRouteID;
        }
예제 #27
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);
        }
        /// <summary>
        /// Method creates a collection of violations for collection of Violation Constraint entries.
        /// </summary>
        /// <param name="violatedConstraint">Violated constraint.</param>
        /// <param name="hresult">HResult.</param>
        /// <param name="assocObject">Associated object.</param>
        /// <param name="entries">Collection of Violation Constraint entries.</param>
        /// <returns>Collection of Violations.</returns>
        private static List<Violation> _CreateViolations(int violatedConstraint,
                                                         int hresult,
                                                         DataObject assocObject,
                                                         VCEntry[] entries)
        {
            var list = new List<Violation>();

            foreach (VCEntry entry in entries)
            {
                int naType = (int)entry.NAType;
                if ((violatedConstraint & naType) == naType)
                {
                    Violation violation = new Violation();
                    violation.ViolationType = entry.type;
                    violation.AssociatedObject = assocObject;

                    // Get extended info for HRESULT.
                    foreach (VCDesc hrDesc in entry.hrDesc)
                    {
                        if (hresult == hrDesc.HR)
                        {
                            // Override violation type.
                            violation.ViolationType = hrDesc.subType;
                            break;
                        }
                    }

                    list.Add(violation);
                }
            }

            return list;
        }
예제 #29
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copies all the object's data to the target data object.
        /// </summary>
        /// <param name="obj">Target data object.</param>
        public override void CopyTo(DataObject obj)
        {
            Debug.Assert(obj is Barrier);

            var barrier = obj as Barrier;
            barrier.Name = this.Name;
            barrier.Comment = this.Comment;

            barrier.Name = this.Name;
            barrier.StartDate = this.StartDate;
            barrier.FinishDate = this.FinishDate;
            barrier.Comment = this.Comment;

            if (null != this.Geometry)
            {
                var polygon = this.Geometry as AppGeometry.Polygon;
                if (null != polygon)
                    barrier.Geometry = polygon.Clone();
                else
                {
                    var polyline = this.Geometry as AppGeometry.Polyline;
                    if (null != polyline)
                        barrier.Geometry = polyline.Clone();
                    else
                    {
                        var point = this.Geometry as AppGeometry.Point?;
                        if (null != point)
                            barrier.Geometry = point.Value;
                        else
                        {
                            Debug.Assert(false); // NOTE: not supported
                        }
                    }
                }
            }

            if (null != this.BarrierEffect)
                barrier.BarrierEffect = this.BarrierEffect.Clone() as BarrierEffect;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        public MessageObjectContext(DataObject dataObject)
        {
            if (null == dataObject)
                throw new ArgumentException();

            _name = dataObject.ToString();
            _type = dataObject.GetType();
            _id = dataObject.Id;
        }
예제 #31
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copies all the object's data to the target data object.
        /// </summary>
        /// <param name="obj">Target data object.</param>
        public override void CopyTo(DataObject obj)
        {
            Debug.Assert(obj is Vehicle);

            Vehicle vehicle = obj as Vehicle;
            vehicle.Name = this.Name;
            vehicle.Comment = this.Comment;
            vehicle.FuelEconomy = this.FuelEconomy;
            vehicle.Capacities = (Capacities)this._capacities.Clone();
            vehicle.FixedCost = this.FixedCost;

            foreach (VehicleSpecialty spec in this.Specialties)
                vehicle.Specialties.Add(spec);

            vehicle.MobileDevice = this.MobileDevice;
            vehicle.FuelType = this.FuelType;
        }
예제 #32
0
        /// <summary>
        /// Assemblyes stop's values string.
        /// </summary>
        /// <param name="fields">Exported fields.</param>
        /// <param name="data">Data keeper.</param>
        /// <param name="scheduleId">Schedule ID.</param>
        /// <param name="obj">Stop to exporting.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <returns>Stop's values string.</returns>
        private string _AssemblyStopString(ICollection<string> fields,
                                           DataKeeper data,
                                           Guid scheduleId,
                                           DataObject obj,
                                           ICancelTracker tracker)
        {
            bool isSeparatorNeed = false;
            var sb = new StringBuilder();
            foreach (string field in fields)
            {
                _CheckCancelState(tracker);

                if (isSeparatorNeed)
                    sb.Append(_separator);

                DataWrapper value = data.GetStopFieldValue(field, scheduleId, obj);
                sb.Append(_FormatFieldValue(value));
                isSeparatorNeed = true;
            }

            return sb.ToString();
        }
예제 #33
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copies all the object's data to the target data object.
        /// </summary>
        /// <param name="obj">Target data object.</param>
        public override void CopyTo(DataObject obj)
        {
            Debug.Assert(obj is DriverSpecialty);

            DriverSpecialty spec = obj as DriverSpecialty;
            spec.Name = this.Name;
            spec.Comment = this.Comment;
        }
예제 #34
0
 private void _RemoveObject(DataObject obj)
 {
     ContextHelper.RemoveObject(_Context, obj);
 }
예제 #35
0
 ///////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Copies all the object's data to the target data object.
 /// </summary>
 /// <param name="obj">Target data object.</param>
 public virtual void CopyTo(DataObject obj)
 {
     Debug.Assert(false); // NOTE: need replace in child classes
 }
        /// <summary>
        /// Method gets details messages about successfully assigned orders during
        /// routing operation. Details message are expanded by route names.
        /// </summary>
        /// <param name="schedule">Schedule.</param>
        /// <param name="info">Operation info.</param>
        /// <returns>Collection of message details.</returns>
        private ICollection<MessageDetail> _GetSuccessfullyAssignedOrdersDetails(
            Schedule schedule, AsyncOperationInfo info)
        {
            var routedOrdersDetails = new Collection<MessageDetail>();
            ICollection<Order> ordersToAssign = _GetOrdersToAssign(info);

            if (ordersToAssign == null)
                return routedOrdersDetails;

            // Find all pairs Route & Order.
            var detailsPairs = new List<KeyValuePair<Route, Order>>();

            foreach (Order order in ordersToAssign)
                foreach (Route route in schedule.Routes)
                    foreach (Stop stop in route.Stops)
                        if (stop.AssociatedObject is Order &&
                            ((Order)stop.AssociatedObject).Equals(order))
                        {
                            var pair = new KeyValuePair<Route, Order>(
                                route, order);

                            detailsPairs.Add(pair);
                        }

            string formatString =
                (string)App.Current.FindResource(ORDERS_SUCCESSFULLY_ASSIGNED);

            // Add messages expanded by Routes.
            foreach (Route route in schedule.Routes)
                foreach (KeyValuePair<Route, Order> pair in detailsPairs)
                {
                    if (pair.Key.Name == route.Name)
                    {
                        DataObject[] parameters = new DataObject[] { pair.Value, pair.Key };
                        MessageDetail detail = new MessageDetail(MessageType.Information,
                            formatString, parameters);
                        routedOrdersDetails.Add(detail);
                    }
                }

            return routedOrdersDetails;
        }
예제 #37
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copies all the object's data to the target data object.
        /// </summary>
        /// <param name="obj">Target data object.</param>
        public override void CopyTo(DataObject obj)
        {
            System.Diagnostics.Debug.Assert(obj is Driver);

            Driver driver = obj as Driver;
            driver.Name = this.Name;
            driver.Comment = this.Comment;
            driver.FixedCost = this.FixedCost;
            driver.PerHourSalary = this.PerHourSalary;
            driver.PerHourOTSalary = this.PerHourOTSalary;
            driver.TimeBeforeOT = this.TimeBeforeOT;

            foreach (DriverSpecialty spec in this.Specialties)
                driver.Specialties.Add(spec);

            driver.MobileDevice = this.MobileDevice;
        }
예제 #38
0
 ///////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Copies all the object's data to the target data object.
 /// </summary>
 /// <param name="obj">Target data object.</param>
 public override void CopyTo(DataObject obj)
 {
     MobileDevice mobileDevice = obj as MobileDevice;
     mobileDevice.Name = this.Name;
     mobileDevice.ActiveSyncProfileName = this.ActiveSyncProfileName;
     mobileDevice.EmailAddress = this.EmailAddress;
     mobileDevice.SyncFolder = this.SyncFolder;
     mobileDevice.SyncType = this.SyncType;
 }
예제 #39
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copies all the object's data to the target data object.
        /// </summary>
        /// <param name="obj">Target data object.</param>
        public override void CopyTo(DataObject obj)
        {
            Location location = obj as Location;
            location.Name = this.Name;
            location.Comment = this.Comment;
            location.CurbApproach = this.CurbApproach;

            if (null != this.TimeWindow)
                location.TimeWindow = (TimeWindow)this.TimeWindow.Clone();

            if (null != this.TimeWindow2)
                location.TimeWindow2 = (TimeWindow)this.TimeWindow2.Clone();

            if (null != this.Address)
                location.Address = (Address)this.Address.Clone();

            if (GeoLocation.HasValue)
                location.GeoLocation = new Point(this.GeoLocation.Value.X, this.GeoLocation.Value.Y);
        }
        /// <summary>
        /// Method creates violation for restricted object according to its status.
        /// </summary>
        /// <param name="status">Object status.</param>
        /// <param name="assocObject">Associated object.</param>
        /// <returns>Violation.</returns>
        private static Violation _CreateRestrictedObjViolation(NAObjectStatus status,
                                                               DataObject assocObject)
        {
            var violation = new Violation();
            violation.AssociatedObject = assocObject;

            if (status == NAObjectStatus.esriNAObjectStatusNotLocated ||
                status == NAObjectStatus.esriNAObjectStatusElementNotLocated)
            {
                violation.ViolationType = ViolationType.TooFarFromRoad;
            }
            else if (status == NAObjectStatus.esriNAObjectStatusElementNotTraversable)
            {
                violation.ViolationType = ViolationType.RestrictedStreet;
            }
            else
                Debug.Assert(false);

            return violation;
        }
예제 #41
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copies all the object's data to the target data object.
        /// </summary>
        /// <param name="obj">Target data object.</param>
        public override void CopyTo(DataObject obj)
        {
            Debug.Assert(obj is Route);

            _CopyNoResults(obj);

            Route route = obj as Route;

            // resulting data
            route.Cost = this.Cost;
            route.StartTime = this.StartTime;
            route.EndTime = this.EndTime;
            route.Overtime = this.Overtime;
            route.TotalTime = this.TotalTime;
            route.TotalDistance = this.TotalDistance;
            route.TravelTime = this.TravelTime;
            route.ViolationTime = this.ViolationTime;
            route.WaitTime = this.WaitTime;
            route.IsLocked = this.IsLocked;
            route.IsVisible = this.IsVisible;
            route.Capacities = (Capacities)this._capacities.Clone();

            // stops
            foreach (Stop stop in this.Stops)
                route.Stops.Add((Stop)stop.Clone());
        }
예제 #42
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copies all the object's data to the target data object.
        /// </summary>
        /// <param name="obj">Target data object.</param>
        public override void CopyTo(DataObject obj)
        {
            System.Diagnostics.Debug.Assert(obj is Zone);

            Zone zone = obj as Zone;
            zone.Name = this.Name;
            zone.Comment = this.Comment;

            if (null != this.Geometry)
            {
                if (this.Geometry is Polygon)
                    zone.Geometry = (this.Geometry as Polygon).Clone();
                else if (this.Geometry is Point)
                {
                    Point? pt = this.Geometry as Point?;
                    zone.Geometry = new Point(pt.Value.X, pt.Value.Y);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false); // NOTE: not supported
                }
            }
        }
예제 #43
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copies all the object's data to the target data object.
        /// </summary>
        /// <param name="obj">Target data object.</param>
        public override void CopyTo(DataObject obj)
        {
            Debug.Assert(obj is Order);

            Order order = obj as Order;

            order.Name = this.Name;
            order.PlannedDate = this.PlannedDate;

            if (null != this.Address)
                order.Address = (Address)this.Address.Clone();

            if (GeoLocation.HasValue)
                order.GeoLocation = new Point(this.GeoLocation.Value.X, this.GeoLocation.Value.Y);
            else
                order.GeoLocation = null;

            order.Type = this.Type;
            order.Priority = this.Priority;
            order.ServiceTime = this.ServiceTime;
            order.CurbApproach = this.CurbApproach;

            if (null != this.TimeWindow)
                order.TimeWindow = (TimeWindow)this.TimeWindow.Clone();

            if (null != this.TimeWindow2)
                order.TimeWindow2 = (TimeWindow)this.TimeWindow2.Clone();

            order.Capacities = (Capacities)this._capacities.Clone();
            order.CustomProperties = (OrderCustomProperties)this._customProperties.Clone();

            order.VehicleSpecialties.Clear();
            foreach (VehicleSpecialty spec in this.VehicleSpecialties)
                order.VehicleSpecialties.Add(spec);

            order.DriverSpecialties.Clear();
            foreach (DriverSpecialty spec in this.DriverSpecialties)
                order.DriverSpecialties.Add(spec);
        }
        private void DataObjectContext_SavingChanges(object sender, EventArgs e)
        {
            IEnumerable <ObjectStateEntry> entries = this.ObjectStateManager.GetObjectStateEntries(
                EntityState.Added |
                EntityState.Modified |
                EntityState.Deleted);

            List <DataObject> addedItems    = new List <DataObject>();
            List <DataObject> modifiedItems = new List <DataObject>();
            List <DataObject> deletedItems  = new List <DataObject>();

            foreach (ObjectStateEntry entry in entries)
            {
                if (!entry.IsRelationship &&
                    entry.EntitySet.ElementType is EntityType)
                {
                    if (entry.State == EntityState.Added ||
                        entry.State == EntityState.Modified)
                    {
                        // apply database constraints
                        _ApplyConstraints(entry);

                        // check whether object can be saved
                        _CheckCanSave(entry);

                        // fill event collections
                        if (entry.State != EntityState.Detached)
                        {
                            DataObject item = DataObjectHelper.GetDataObject(
                                entry.Entity as EntityObject);

                            if (item != null)
                            {
                                if (entry.State == EntityState.Added)
                                {
                                    addedItems.Add(item);
                                }
                                else if (entry.State == EntityState.Modified)
                                {
                                    if (_IsMarkedAsDeleted(item))
                                    {
                                        deletedItems.Add(item);
                                    }
                                    else
                                    {
                                        modifiedItems.Add(item);
                                    }
                                }
                            }
                        }
                    }
                    else if (entry.State == EntityState.Deleted)
                    {
                        DataObject item = DataObjectHelper.GetDataObject(
                            entry.Entity as EntityObject);

                        if (item != null)
                        {
                            deletedItems.Add(item);
                        }
                    }
                }
            }

            _NotifySavingChanges(addedItems.AsReadOnly(),
                                 modifiedItems.AsReadOnly(),
                                 deletedItems.AsReadOnly());
        }
 /// <summary>
 /// Create import result.
 /// </summary>
 /// <param name="obj">Imported object.</param>
 /// <param name="desciptions">Collection of import value description </param>
 public ImportResult(DataObject obj, ICollection<ImportedValueInfo> desciptions)
 {
     Object = obj;
     Desciptions = desciptions;
 }