Пример #1
0
        /// <summary>
        /// Provides solve operation.
        /// </summary>
        /// <param name="request">Request to solver.</param>
        /// <param name="cancelTracker">Cancel tracker.</param>
        /// <returns>Function returning BatchRouteSolveResponse.</returns>
        /// <exception cref="ESRI.ArcLogistics.Routing.RouteException">If get
        /// directions operation error occurs.</exception>
        public Func <SolveOperationResult <BatchRouteSolveRequest> > Solve(
            BatchRouteSolveRequest request,
            ICancelTracker cancelTracker)
        {
            Debug.Assert(request != null);
            Debug.Assert(request.Requests != null);

            try
            {
                List <RouteSolveResponse> responses = new List <RouteSolveResponse>();
                foreach (RouteSolveRequest req in request.Requests)
                {
                    responses.Add(_context.RouteService.Solve(req,
                                                              RouteRequestBuilder.JsonTypes));
                }

                var response = new BatchRouteSolveResponse(responses.ToArray());

                return(() => new SolveOperationResult <BatchRouteSolveRequest>
                {
                    SolveResult = _ProcessSolveResult(response),
                    NextStepOperation = null,
                });
            }
            catch (RestException e)
            {
                throw SolveHelper.ConvertServiceException(
                          Properties.Messages.Error_GetDirections, e);
            }
        }
        public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            throw new NotImplementedException();
            //if (_fdb == null) return;
            //try
            //{
            //    DataTable tab = _fdb._conn.Select("IMAGE,X,Y,dx1,dx2,dy1,dy2", _dsname + "_IMAGE_DATA", "ID=" + _ID);
            //    if (tab == null) return;
            //    if (tab.Rows.Count != 1) return;
            //    DataRow row = tab.Rows[0];

            //    _bm = (System.Drawing.Bitmap)ImageFast.FromStream((byte[])row["IMG"]);
            //    _X = (double)tab.Rows[0]["X"];
            //    _Y = (double)tab.Rows[0]["Y"];
            //    _dx_X = (double)tab.Rows[0]["dx1"];
            //    _dx_Y = (double)tab.Rows[0]["dx2"];
            //    _dy_X = (double)tab.Rows[0]["dy1"];
            //    _dy_Y = (double)tab.Rows[0]["dy2"];
            //    _iWidth = _bm.Width;
            //    _iHeight = _bm.Height;
            //}
            //catch
            //{
            //    EndPaint(cancelTracker);
            //}
        }
Пример #3
0
        /// <summary>
        /// Runs solve operation passed to the class constructor.
        /// </summary>
        /// <param name="cancellationTracker">Cancellation tracker to be used for cancelling running
        /// solve operation.</param>
        /// <returns>A function returning asynchronous solve task result.</returns>
        public Func <SolveTaskResult> Run(ICancelTracker cancellationTracker)
        {
            if (_operation.CanGetResultWithoutSolve)
            {
                return(() =>
                {
                    var result = _operation.CreateResultWithoutSolve();
                    // we must have a result if CanGetResultWithoutSolve is true
                    Debug.Assert(result != null);

                    return new SolveTaskResult
                    {
                        SolveResult = result,
                        NextTask = null,
                    };
                });
            }
            else
            {
                var request        = _operation.CreateRequest();
                var resultProvider = _operation.Solve(request, cancellationTracker);

                return(() => this._ProcessSolveResult(resultProvider));
            }
        }
Пример #4
0
        public FDBImport(int featureBufferSize = 1000)
        {
            _cancelTracker = new CancelTracker();
            ((CancelTracker)_cancelTracker).Reset();

            this.FeatureBufferSize = featureBufferSize > 0 ? featureBufferSize : 1000;
        }
Пример #5
0
 public void FinishDrawing(IDisplay disp, ICancelTracker cancelTracker)
 {
     if (_renderer != null)
     {
         _renderer.FinishDrawing(disp, cancelTracker);
     }
 }
Пример #6
0
        public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
        {
            if (_fdb == null)
            {
                return;
            }
            try
            {
                DataTable tab = _fdb._conn.Select("IMAGE,X,Y,dx1,dx2,dy1,dy2", _dsname + "_IMAGE_DATA", "ID=" + _ID);
                if (tab == null)
                {
                    return;
                }
                if (tab.Rows.Count != 1)
                {
                    return;
                }
                DataRow row = tab.Rows[0];

                _bm      = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(new MemoryStream((byte[])row["IMG"]));
                _X       = (double)tab.Rows[0]["X"];
                _Y       = (double)tab.Rows[0]["Y"];
                _dx_X    = (double)tab.Rows[0]["dx1"];
                _dx_Y    = (double)tab.Rows[0]["dx2"];
                _dy_X    = (double)tab.Rows[0]["dy1"];
                _dy_Y    = (double)tab.Rows[0]["dy2"];
                _iWidth  = _bm.Width;
                _iHeight = _bm.Height;
            }
            catch
            {
                EndPaint(cancelTracker);
            }
        }
Пример #7
0
        /// <summary>
        /// Writes stops content.
        /// </summary>
        /// <param name="data">Data keeper.</param>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="fields">Exported fields.</param>
        /// <param name="writeOnlyOrders">Write only orders flag.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <param name="sw">Export writer.</param>
        private void _WriteStopsContent(DataKeeper data,
                                        ICollection <Schedule> schedules,
                                        ICollection <string> fields,
                                        bool writeOnlyOrders,
                                        ICancelTracker tracker,
                                        StreamWriter sw)
        {
            foreach (Schedule schedule in schedules)
            {
                Guid scheduleID = schedule.Id;
                foreach (Route route in schedule.Routes)
                {   // stops
                    IDataObjectCollection <Stop> stops = route.Stops;
                    foreach (Stop stop in stops)
                    {
                        _CheckCancelState(tracker);

                        if (!writeOnlyOrders ||
                            (writeOnlyOrders && (stop.StopType == StopType.Order)))
                        {
                            string exportString = _AssemblyStopString(fields,
                                                                      data,
                                                                      scheduleID,
                                                                      stop,
                                                                      tracker);
                            Debug.Assert(!string.IsNullOrEmpty(exportString));
                            sw.WriteLine(exportString);
                        }
                    }
                }

                _WriteUnassignedOrdersContent(data, schedule, fields, tracker, sw);
            }
        }
Пример #8
0
        /// <summary>
        /// Writes export data content.
        /// </summary>
        /// <param name="type">Table type.</param>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="fields">Exported fields.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <param name="sw">Export writer.</param>
        private void _WriteContent(TableType type,
                                   ICollection <Schedule> schedules,
                                   ICollection <string> fields,
                                   ICancelTracker tracker,
                                   StreamWriter sw)
        {
            TableDescription tableDescription = _structureKeeper.GetTableDescription(type);
            var data = new DataKeeper(_listSeparator, tableDescription);

            switch (type)
            {
            case TableType.Routes:
                _WriteRoutesContent(data, schedules, fields, tracker, sw);
                break;

            case TableType.Stops:
                _WriteStopsContent(data, schedules, fields, false, tracker, sw);
                break;

            case TableType.Orders:
                _WriteStopsContent(data, schedules, fields, true, tracker, sw);
                break;

            default:
                Debug.Assert(false);     // NOTE: not supported
                break;
            }
        }
Пример #9
0
        /// <summary>
        /// Writes routes content.
        /// </summary>
        /// <param name="data">Data keeper.</param>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="fields">Exported fields.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <param name="sw">Export writer.</param>
        private void _WriteRoutesContent(DataKeeper data,
                                         ICollection <Schedule> schedules,
                                         ICollection <string> fields,
                                         ICancelTracker tracker,
                                         StreamWriter sw)
        {
            foreach (Schedule schedule in schedules)
            {
                Guid scheduleID = schedule.Id;
                foreach (Route route in schedule.Routes)
                {
                    _CheckCancelState(tracker);

                    if ((null == route.Stops) || (0 == route.Stops.Count))
                    {
                        continue; // NOTE: skip empty routes
                    }
                    string exportString = _AssemblyRouteString(fields,
                                                               data,
                                                               scheduleID,
                                                               route,
                                                               tracker);

                    Debug.Assert(!string.IsNullOrEmpty(exportString));
                    sw.WriteLine(exportString);
                }
            }
        }
Пример #10
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());
        }
Пример #11
0
            public FeatureClassImportProgressReporter(object import, IFeatureClass source)
            {
                if (import == null)
                {
                    return;
                }

                if (import is FDBImport)
                {
                    _cancelTracker = ((FDBImport)import).CancelTracker;

                    if (source != null)
                    {
                        _report.featureMax = source.CountFeatures;
                    }
                    ((FDBImport)import).ReportAction   += new FDBImport.ReportActionEvent(FeatureClassImportProgressReporter_ReportAction);
                    ((FDBImport)import).ReportProgress += new FDBImport.ReportProgressEvent(FeatureClassImportProgressReporter_ReportProgress);
                    ((FDBImport)import).ReportRequest  += new FDBImport.ReportRequestEvent(FeatureClassImportProgressReporter_ReportRequest);
                }
                if (import is FeatureImport)
                {
                    _cancelTracker = ((FeatureImport)import).CancelTracker;

                    if (source != null)
                    {
                        _report.featureMax = source.CountFeatures;
                    }
                    ((FeatureImport)import).ReportAction   += new FeatureImport.ReportActionEvent(import_ReportAction);
                    ((FeatureImport)import).ReportProgress += new FeatureImport.ReportProgressEvent(import_ReportProgress);
                    ((FeatureImport)import).ReportRequest  += new FeatureImport.ReportRequestEvent(import_ReportRequest);
                }
            }
Пример #12
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Does export routine.
        /// </summary>
        /// <param name="filePath">Export file path.</param>
        /// <param name="tables">Table definitions.</param>
        /// <param name="schedules">Shedules to export.</param>
        /// <param name="routes">Routes to export (can be null).</param>
        /// <param name="imageExporter">Map's image exporter (can be null).</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <remarks>Routes must belong to the <c>schedule</c>. If <c>routes</c> collection
        /// is empty, Generator will use all the routes from the <c>schedules</c>.</remarks>
        public void DoExport(string filePath,
                             ICollection <ITableDefinition> tables,
                             ICollection <Schedule> schedules,
                             ICollection <Route> routes,
                             MapImageExporter imageExporter,
                             ICancelTracker tracker)
        {
            Debug.Assert(!string.IsNullOrEmpty(filePath));

            Debug.Assert(null != tables);
            Debug.Assert(null != schedules);
            Debug.Assert((null == routes) || ((null != routes) && (1 == schedules.Count)));

            try
            {
                _CreateDatabase(filePath, tables);

                _CheckCancelState(tracker);

                _WriteContent(filePath, tables, schedules, routes, imageExporter, tracker);
            }
            catch (Exception ex)
            {
                if (!(ex is UserBreakException))
                {
                    Logger.Error(ex);
                }

                _DeleteFile(filePath);

                throw; // exception
            }
        }
Пример #13
0
 private static void _CheckCancelState(ICancelTracker tracker)
 {
     if (tracker != null && tracker.IsCancelled)
     {
         throw new UserBreakException();
     }
 }
Пример #14
0
        /// <summary>
        /// Writes routes.
        /// </summary>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="routes">Routes to export.</param>
        /// <param name="fields">Fields to export.</param>
        /// <param name="data">Data keeper.</param>
        /// <param name="imageExporter">Map image exporter.</param>
        /// <param name="table">Table to data writing.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        private void _WriteRoutes(ICollection <Schedule> schedules,
                                  ICollection <Route> routes,
                                  ICollection <string> fields,
                                  DataKeeper data,
                                  MapImageExporter imageExporter,
                                  DataTable table,
                                  ICancelTracker tracker)
        {
            foreach (Schedule schedule in schedules)
            {
                _CheckCancelState(tracker);

                Guid scheduleID = schedule.Id;

                foreach (Route route in schedule.Routes)
                {
                    _CheckCancelState(tracker);

                    if ((null != routes) && !routes.Contains(route))
                    {
                        continue; // NOTE: skeep not selected
                    }
                    if ((null == route.Stops) || (0 == route.Stops.Count))
                    {
                        continue; // NOTE: skeep empty routes
                    }
                    DataRow dr = table.NewRow();
                    foreach (string field in fields)
                    {
                        if ("OverviewMap" == field)
                        { // special routine
                            Debug.Assert(null != imageExporter);

                            _CheckCancelState(tracker);

                            Image image = imageExporter.GetRouteImage(route,
                                                                      ROUTE_MAP_IMAGE_SIZE_X,
                                                                      ROUTE_MAP_IMAGE_SIZE_Y,
                                                                      IMAGE_DPI);
                            dr[field] = _ConvertImageToBlob(image);
                            if (null != image)
                            {
                                image.Dispose();
                                image = null;
                            }
                        }
                        else
                        {
                            Debug.Assert("PlannedDate" != field); // NOTE: do not supported

                            dr[field] = _FormatFieldValue(data.GetRouteFieldValue(field,
                                                                                  scheduleID,
                                                                                  route));
                        }
                    }
                    table.Rows.Add(dr);
                }
            }
        }
Пример #15
0
 public void BeginPaint(gView.Framework.Carto.IDisplay display, ICancelTracker cancelTracker)
 {
     if (_stream != null)
     {
         EndPaint(cancelTracker);
     }
     _stream = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
 }
Пример #16
0
 public void EndPaint(ICancelTracker cancelTracker)
 {
     if (_stream != null)
     {
         _stream.Close();
         _stream = null;
     }
 }
Пример #17
0
 public void EndPaint(ICancelTracker cancelTracker)
 {
     if (_bitmap != null)
     {
         _bitmap.Dispose();
         _bitmap = null;
     }
 }
 public void EndPaint(ICancelTracker cancelTracker)
 {
     if (_bm != null)
     {
         _bm.Dispose();
         _bm = null;
     }
 }
Пример #19
0
        override protected void DrawRasterParentLayer(IParentRasterLayer rLayer, ICancelTracker cancelTracker, IRasterLayer rootLayer)
        {
            if (rLayer is ILayer && ((ILayer)rLayer).Class is IRasterClass)
            {
                ((IRasterClass)((ILayer)rLayer).Class).BeginPaint(this.Display, cancelTracker);
            }
            else if (rLayer is IRasterClass)
            {
                ((IRasterClass)rLayer).BeginPaint(this.Display, cancelTracker);
            }
            string filterClause = String.Empty;

            if (rootLayer is IRasterCatalogLayer)
            {
                filterClause = ((((IRasterCatalogLayer)rootLayer).FilterQuery != null) ?
                                ((IRasterCatalogLayer)rootLayer).FilterQuery.WhereClause : String.Empty);
            }

            using (IRasterLayerCursor cursor = ((IParentRasterLayer)rLayer).ChildLayers(this, filterClause))
            {
                ILayer child;

                while ((child = cursor.NextRasterLayer) != null)
                //foreach (ILayer child in ((IParentRasterLayer)rLayer).ChildLayers(this, filterClause))
                {
                    if (!cancelTracker.Continue)
                    {
                        break;
                    }
                    if (child.Class is IParentRasterLayer)
                    {
                        DrawRasterParentLayer((IParentRasterLayer)child.Class, cancelTracker, rootLayer);
                        continue;
                    }
                    if (!(child is IRasterLayer))
                    {
                        continue;
                    }
                    IRasterLayer cLayer = (IRasterLayer)child;

                    RenderRasterLayerThread rlt = new RenderRasterLayerThread(this, cLayer, rootLayer, cancelTracker);
                    rlt.Render();

                    if (child.Class is IDisposable)
                    {
                        ((IDisposable)child.Class).Dispose();
                    }
                }
            }
            if (rLayer is ILayer && ((ILayer)rLayer).Class is IRasterClass)
            {
                ((IRasterClass)((ILayer)rLayer).Class).EndPaint(cancelTracker);
            }
            else if (rLayer is IRasterClass)
            {
                ((IRasterClass)rLayer).EndPaint(cancelTracker);
            }
        }
Пример #20
0
        public RenderLabel(Map map, IFeatureLayer layer, ICancelTracker cancelTracker, FeatureCounter counter)
        {
            _map           = map;
            _layer         = layer;
            _cancelTracker = ((cancelTracker == null) ? new CancelTracker() : cancelTracker);

            _counter         = counter;
            _counter.Counter = 0;
        }
Пример #21
0
        public static bool Canceled(ICancelTracker cancelTracker)
        {
            if (cancelTracker != null && !cancelTracker.Continue)
            {
                return(true);
            }

            return(false);
        }
Пример #22
0
        public void FinishDrawing(IDisplay disp, ICancelTracker cancelTracker)
        {
            if (cancelTracker == null)
            {
                cancelTracker = new CancelTracker();
            }

            if (_actualCartoMethod == CartographicMethod.SymbolOrder && cancelTracker.Continue)
            {
                ISymbolCollection sColl = (ISymbolCollection)_symbol;
                foreach (ISymbolCollectionItem symbolItem in sColl.Symbols)
                {
                    if (symbolItem.Visible == false || symbolItem.Symbol == null)
                    {
                        continue;
                    }

                    ISymbol symbol      = symbolItem.Symbol;
                    bool    isRotatable = symbol is ISymbolRotation;

                    int counter = 0;
                    if (!cancelTracker.Continue)
                    {
                        break;
                    }

                    foreach (IFeature feature in _features)
                    {
                        if (_rotate && isRotatable)
                        {
                            object rot = feature[_symbolRotation.RotationFieldName];
                            if (rot != null && rot != DBNull.Value)
                            {
                                ((ISymbolRotation)symbol).Rotation = (float)_symbolRotation.Convert2DEGAritmetic(Convert.ToDouble(rot));
                            }
                            else
                            {
                                ((ISymbolRotation)symbol).Rotation = 0;
                            }
                        }
                        disp.Draw(symbol, feature.Shape);

                        counter++;
                        if (counter % 100 == 0 && !cancelTracker.Continue)
                        {
                            break;
                        }
                    }
                }
            }

            if (_features != null)
            {
                _features.Clear();
            }
            _features = null;
        }
Пример #23
0
        async public Task <IRasterPaintContext> BeginPaint(IDisplay display, ICancelTracker cancelTracker)
        {
            if (!cancelTracker.Continue)
            {
                return(null);
            }

            return(await GetImage());
        }
Пример #24
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Checks cancel state.
        /// </summary>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <remarks>If cancelled throw UserBreakException.</remarks>
        private void _CheckCancelState(ICancelTracker tracker)
        {
            if (tracker != null)
            {
                if (tracker.IsCancelled)
                {
                    throw new UserBreakException(); // exception
                }
            }
        }
Пример #25
0
        public void Draw(IDisplay display, ICancelTracker cancelTracker)
        {
            try
            {
                display.GraphicsContext.DrawImage(_bm, new PointF(0, 0));

                //_bm.Save(@"c:\temp\label.png", System.Drawing.Imaging.ImageFormat.Png);
            }
            catch { }
        }
Пример #26
0
 public void FinishDrawing(IDisplay disp, ICancelTracker cancelTracker)
 {
     foreach (IFeatureRenderer renderer in _renderers)
     {
         if (renderer != null)
         {
             renderer.FinishDrawing(disp, cancelTracker);
         }
     }
 }
Пример #27
0
 public RenderFeatureLayer(Map map, IDatasetCachingContext datasetCachingContext, IFeatureLayer layer, ICancelTracker cancelTracker, FeatureCounter counter)
 {
     _map = map;
     _datasetCachingContext = datasetCachingContext;
     _isServiceMap          = map is IServiceMap;
     _layer           = layer;
     _cancelTracker   = ((cancelTracker == null) ? new CancelTracker() : cancelTracker);
     _counter         = counter;
     _counter.Counter = 0;
 }
Пример #28
0
        public void Draw(IDisplay display, ICancelTracker cancelTracker)
        {
            try
            {
                display.Canvas.DrawBitmap(_bitmap, new GraphicsEngine.CanvasPoint(0, 0));

                //_bm.Save(@"c:\temp\label.png", System.Drawing.Imaging.ImageFormat.Png);
            }
            catch { }
        }
Пример #29
0
        public FormTaskProgress(IProgressReporter reporter, Task task)
            : this(task)
        {
            _cancelTracker    = reporter.CancelTracker;
            btnCancel.Visible = (_cancelTracker != null);

            if (reporter != null)
            {
                reporter.ReportProgress += new ProgressReporterEvent(HandleProgressEvent);
            }
        }
Пример #30
0
        public FormProgress(IProgressReporter reporter, Thread thread)
            : this(thread)
        {
            _cancelTracker    = reporter.CancelTracker;
            btnCancel.Visible = (_cancelTracker != null);

            if (reporter != null)
            {
                reporter.ReportProgress += new ProgressReporterEvent(progressEvent);
            }
        }
Пример #31
0
        /// <summary>
        /// Writes schedules.
        /// </summary>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="fields">Fields to export.</param>
        /// <param name="data">Data keeper.</param>
        /// <param name="table">Table to data writing.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        private void _WriteSchedules(ICollection<Schedule> schedules,
                                     ICollection<string> fields,
                                     DataKeeper data,
                                     DataTable table,
                                     ICancelTracker tracker)
        {
            foreach (Schedule schedule in schedules)
            {
                _CheckCancelState(tracker);

                DataRow dr = table.NewRow();
                foreach (string field in fields)
                    dr[field] = _FormatFieldValue(data.GetScheduleFieldValue(field, schedule));

                table.Rows.Add(dr);
            }
        }
Пример #32
0
        /// <summary>
        /// Write database content.
        /// </summary>
        /// <param name="filePath">Export file path.</param>
        /// <param name="tables">Table definitions.</param>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="routes">Routes to export.</param>
        /// <param name="imageExporter">Map image exporter.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        private void _WriteContent(string filePath,
                                   ICollection<ITableDefinition> tables,
                                   ICollection<Schedule> schedules,
                                   ICollection<Route> routes,
                                   MapImageExporter imageExporter,
                                   ICancelTracker tracker)
        {
            OleDbConnection connection = new OleDbConnection(_GetConnectionString(filePath));

            try
            {
                foreach (ITableDefinition tableDef in tables)
                {
                    _CheckCancelState(tracker);

                    TableDescription tableDescription =
                        _structureKeeper.GetTableDescription(tableDef.Type);
                    DataKeeper data = new DataKeeper(_listSeparator, tableDescription);
                    ICollection<string> fields = tableDef.Fields;

                    string tableName = tableDef.Name;

                    // obtain dataset
                    string selectCommand = string.Format(SQL_SELECT_COMMAND_FORMAT, tableName);
                    OleDbCommand accessCommand = new OleDbCommand(selectCommand, connection);

                    OleDbDataAdapter dataAdapter = new OleDbDataAdapter(accessCommand);
                    DataSet dataSet = new DataSet(tableName);
                    dataAdapter.Fill(dataSet, tableName);

                    // select table
                    DataTable table = dataSet.Tables[tableName];

                    // write data to table
                    switch (tableDef.Type)
                    {
                        case TableType.Schedules:
                            _WriteSchedules(schedules, fields, data, table, tracker);
                            break;

                        case TableType.Routes:
                            {
                                _WriteRoutes(schedules,
                                             routes,
                                             fields,
                                             data,
                                             imageExporter,
                                             table,
                                             tracker);
                                break;
                            }

                        case TableType.Stops:
                            {
                                _WriteStops(schedules,
                                            routes,
                                            fields,
                                            data,
                                            imageExporter,
                                            table,
                                            tracker);
                                break;
                            }

                        case TableType.Schema:
                            _WriteSchema(fields, table, tracker);
                            break;

                        default:
                            Debug.Assert(false); // NOTE: not supported
                            break;
                    }

                    _CheckCancelState(tracker);

                    // set insert command
                    OleDbCommand insertCommand = _CreateInsertCommand(tableName,
                                                                      tableDescription,
                                                                      fields);
                    insertCommand.Connection = connection;
                    dataAdapter.InsertCommand = insertCommand;

                    // store changes
                    dataAdapter.Update(table);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                connection.Close();
            }
        }
Пример #33
0
        /// <summary>
        /// Writes routes.
        /// </summary>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="routes">Routes to export.</param>
        /// <param name="fields">Fields to export.</param>
        /// <param name="data">Data keeper.</param>
        /// <param name="imageExporter">Map image exporter.</param>
        /// <param name="table">Table to data writing.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        private void _WriteRoutes(ICollection<Schedule> schedules,
                                  ICollection<Route> routes,
                                  ICollection<string> fields,
                                  DataKeeper data,
                                  MapImageExporter imageExporter,
                                  DataTable table,
                                  ICancelTracker tracker)
        {
            foreach (Schedule schedule in schedules)
            {
                _CheckCancelState(tracker);

                Guid scheduleID = schedule.Id;

                foreach (Route route in schedule.Routes)
                {
                    _CheckCancelState(tracker);

                    if ((null != routes) && !routes.Contains(route))
                        continue; // NOTE: skeep not selected

                    if ((null == route.Stops) || (0 == route.Stops.Count))
                        continue; // NOTE: skeep empty routes

                    DataRow dr = table.NewRow();
                    foreach (string field in fields)
                    {
                        if ("OverviewMap" == field)
                        { // special routine
                            Debug.Assert(null != imageExporter);

                            _CheckCancelState(tracker);

                            Image image = imageExporter.GetRouteImage(route,
                                                                      ROUTE_MAP_IMAGE_SIZE_X,
                                                                      ROUTE_MAP_IMAGE_SIZE_Y,
                                                                      IMAGE_DPI);
                            dr[field] = _ConvertImageToBlob(image);
                            if (null != image)
                            {
                                image.Dispose();
                                image = null;
                            }
                        }
                        else
                        {
                            Debug.Assert("PlannedDate" != field); // NOTE: do not supported

                            dr[field] = _FormatFieldValue(data.GetRouteFieldValue(field,
                                                                                  scheduleID,
                                                                                  route));
                        }
                    }
                    table.Rows.Add(dr);
                }
            }
        }
Пример #34
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Does export routine.
        /// </summary>
        /// <param name="filePath">Export file path.</param>
        /// <param name="tables">Table definitions.</param>
        /// <param name="schedules">Shedules to export.</param>
        /// <param name="routes">Routes to export (can be null).</param>
        /// <param name="imageExporter">Map's image exporter (can be null).</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <remarks>Routes must belong to the <c>schedule</c>. If <c>routes</c> collection
        /// is empty, Generator will use all the routes from the <c>schedules</c>.</remarks>
        public void DoExport(string filePath,
                             ICollection<ITableDefinition> tables,
                             ICollection<Schedule> schedules,
                             ICollection<Route> routes,
                             MapImageExporter imageExporter,
                             ICancelTracker tracker)
        {
            Debug.Assert(!string.IsNullOrEmpty(filePath));

            Debug.Assert(null != tables);
            Debug.Assert(null != schedules);
            Debug.Assert((null == routes) || ((null != routes) && (1 == schedules.Count)));

            try
            {
                _CreateDatabase(filePath, tables);

                _CheckCancelState(tracker);

                _WriteContent(filePath, tables, schedules, routes, imageExporter, tracker);
            }
            catch (Exception ex)
            {
                if ( !(ex is UserBreakException) )
                    Logger.Error(ex);

                _DeleteFile(filePath);

                throw; // exception
            }
        }
Пример #35
0
 /// <summary>
 /// Checks cancel state.
 /// </summary>
 /// <param name="tracker">Cancel tracker (can be null).</param>
 /// <remarks>If cancelled throw UserBreakException.</remarks>
 private void _CheckCancelState(ICancelTracker tracker)
 {
     if (tracker != null)
     {
         if (tracker.IsCancelled)
             throw new UserBreakException(); // exception
     }
 }
Пример #36
0
        /// <summary>
        /// Writes unassigned orders content.
        /// </summary>
        /// <param name="data">Data keeper.</param>
        /// <param name="schedule">Schedule to export.</param>
        /// <param name="fields">Exported fields.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <param name="sw">Export writer.</param>
        private void _WriteUnassignedOrdersContent(DataKeeper data,
                                                   Schedule schedule,
                                                   ICollection<string> fields,
                                                   ICancelTracker tracker,
                                                   StreamWriter sw)
        {
            Guid scheduleID = schedule.Id;

            IDataObjectCollection<Order> orders = schedule.UnassignedOrders;
            if (null != orders)
            {   // unassigned orders
                foreach (Order order in orders)
                {
                    _CheckCancelState(tracker);

                    string exportString = null;
                    exportString = _AssemblyStopString(fields, data, scheduleID, order, tracker);

                    Debug.Assert(!string.IsNullOrEmpty(exportString));
                    sw.WriteLine(exportString);
                }
            }
        }
Пример #37
0
        /// <summary>
        /// Writes stops content.
        /// </summary>
        /// <param name="data">Data keeper.</param>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="fields">Exported fields.</param>
        /// <param name="writeOnlyOrders">Write only orders flag.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <param name="sw">Export writer.</param>
        private void _WriteStopsContent(DataKeeper data,
                                        ICollection<Schedule> schedules,
                                        ICollection<string> fields,
                                        bool writeOnlyOrders,
                                        ICancelTracker tracker,
                                        StreamWriter sw)
        {
            foreach (Schedule schedule in schedules)
            {
                Guid scheduleID = schedule.Id;
                foreach (Route route in schedule.Routes)
                {   // stops
                    IDataObjectCollection<Stop> stops = route.Stops;
                    foreach (Stop stop in stops)
                    {
                        _CheckCancelState(tracker);

                        if (!writeOnlyOrders ||
                            (writeOnlyOrders && (stop.StopType == StopType.Order)))
                        {
                            string exportString = _AssemblyStopString(fields,
                                                                      data,
                                                                      scheduleID,
                                                                      stop,
                                                                      tracker);
                            Debug.Assert(!string.IsNullOrEmpty(exportString));
                            sw.WriteLine(exportString);
                        }
                    }
                }

                _WriteUnassignedOrdersContent(data, schedule, fields, tracker, sw);
            }
        }
Пример #38
0
        /// <summary>
        /// Writes routes content.
        /// </summary>
        /// <param name="data">Data keeper.</param>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="fields">Exported fields.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <param name="sw">Export writer.</param>
        private void _WriteRoutesContent(DataKeeper data,
                                         ICollection<Schedule> schedules,
                                         ICollection<string> fields,
                                         ICancelTracker tracker,
                                         StreamWriter sw)
        {
            foreach (Schedule schedule in schedules)
            {
                Guid scheduleID = schedule.Id;
                foreach (Route route in schedule.Routes)
                {
                    _CheckCancelState(tracker);

                    if ((null == route.Stops) || (0 == route.Stops.Count))
                        continue; // NOTE: skip empty routes

                   string exportString = _AssemblyRouteString(fields,
                                                              data,
                                                              scheduleID,
                                                              route,
                                                              tracker);

                    Debug.Assert(!string.IsNullOrEmpty(exportString));
                    sw.WriteLine(exportString);
                }
            }
        }
Пример #39
0
        /// <summary>
        /// Write schema.
        /// </summary>
        /// <param name="fields">Fields to export.</param>
        /// <param name="table">Table to data writing.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        private void _WriteSchema(ICollection<string> fields,
                                  DataTable table,
                                  ICancelTracker tracker)
        {
            TableDescription description = _structureKeeper.GetTableDescription(TableType.Schema);

            // Capacities
            var capacitiesSpecFields = new List<string> ();
            CapacitiesInfo capacitiesInfo = _structureKeeper.CapacitiesInfo;
            for (int index = 0; index < capacitiesInfo.Count; ++index)
            {
                string relativeName = description.ValidateRelativeName(capacitiesInfo[index].Name);
                capacitiesSpecFields.Add(relativeName);
            }

            _CheckCancelState(tracker);

            // add text Capacities
            if (0 < capacitiesSpecFields.Count)
                _AddSchemaRow(fields, SCHEMA_TABLE_TYPE_CAPACITIES,
                              capacitiesSpecFields.AsReadOnly(), table);

            // CustomOrderProperties
            var textCustomPropSpecFields = new List<string>();
            var numericCustomPropSpecFields = new List<string>();
            OrderCustomPropertiesInfo customOrderPropsInfo =
                _structureKeeper.OrderCustomPropertiesInfo;
            for (int index = 0; index < customOrderPropsInfo.Count; ++index)
            {
                var name = description.ValidateRelativeName(customOrderPropsInfo[index].Name);
                if (customOrderPropsInfo[index].Type == OrderCustomPropertyType.Text)
                    textCustomPropSpecFields.Add(name);
                else
                {   // numeric
                    Debug.Assert(customOrderPropsInfo[index].Type == OrderCustomPropertyType.Numeric);
                    numericCustomPropSpecFields.Add(name);
                }
            }

            _CheckCancelState(tracker);

            // add text CustomOrderProperties
            if (0 < textCustomPropSpecFields.Count)
                _AddSchemaRow(fields, SCHEMA_TABLE_TYPE_CUSTOMPROP_TEXT,
                              textCustomPropSpecFields.AsReadOnly(), table);

            _CheckCancelState(tracker);

            // add numeric CustomOrderProperties
            if (0 < numericCustomPropSpecFields.Count)
                _AddSchemaRow(fields, SCHEMA_TABLE_TYPE_CUSTOMPROP_NUMERIC,
                              numericCustomPropSpecFields.AsReadOnly(), table);
        }
Пример #40
0
        /// <summary>
        /// Writes export data content.
        /// </summary>
        /// <param name="type">Table type.</param>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="fields">Exported fields.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        /// <param name="sw">Export writer.</param>
        private void _WriteContent(TableType type,
                                   ICollection<Schedule> schedules,
                                   ICollection<string> fields,
                                   ICancelTracker tracker,
                                   StreamWriter sw)
        {
            TableDescription tableDescription = _structureKeeper.GetTableDescription(type);
            var data = new DataKeeper(_listSeparator, tableDescription);

            switch (type)
            {
                case TableType.Routes:
                    _WriteRoutesContent(data, schedules, fields, tracker, sw);
                    break;

                case TableType.Stops:
                    _WriteStopsContent(data, schedules, fields, false, tracker, sw);
                    break;

                case TableType.Orders:
                    _WriteStopsContent(data, schedules, fields, true, tracker, sw);
                    break;

                default:
                    Debug.Assert(false); // NOTE: not supported
                    break;
            }
        }
Пример #41
0
        /// <summary>
        /// Writes stops.
        /// </summary>
        /// <param name="schedules">Schedules to export.</param>
        /// <param name="routes">Routes to export.</param>
        /// <param name="fields">Fields to export.</param>
        /// <param name="data">Data keeper.</param>
        /// <param name="imageExporter">Map image exporter.</param>
        /// <param name="table">Table to data writing.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        private void _WriteStops(ICollection<Schedule> schedules,
                                 ICollection<Route> routes,
                                 ICollection<string> fields,
                                 DataKeeper data,
                                 MapImageExporter imageExporter,
                                 DataTable table,
                                 ICancelTracker tracker)
        {
            foreach (Schedule schedule in schedules)
            {
                _CheckCancelState(tracker);

                // stops
                Guid scheduleId = schedule.Id;
                foreach (Route route in schedule.Routes)
                {
                    _CheckCancelState(tracker);

                    if ((null != routes) && !routes.Contains(route))
                        continue; // NOTE: skeep not selected

                    IDataObjectCollection<Stop> stops = route.Stops;
                    for (int index = 0; index < stops.Count; ++index)
                    {
                        _CheckCancelState(tracker);

                        // write stop
                        Stop stop = stops[index];

                        DataRow dr = table.NewRow();
                        foreach (string field in fields)
                        {
                            if (field == "StopVicinityMap")
                            { // NOTE: special routine
                                Debug.Assert(null != imageExporter);

                                _CheckCancelState(tracker);

                                Image image = imageExporter.GetStopImage(route,
                                                                         stop,
                                                                         STOP_MAP_RADIUS,
                                                                         STOP_MAP_IMAGE_SIZE_X,
                                                                         STOP_MAP_IMAGE_SIZE_Y,
                                                                         IMAGE_DPI);
                                dr[field] = _ConvertImageToBlob(image);
                                if (null != image)
                                {
                                    image.Dispose();
                                    image = null;
                                }
                            }
                            else if (field == "Directions")
                            { // NOTE: special routine
                                System.Text.UnicodeEncoding encoding =
                                    new System.Text.UnicodeEncoding();
                                dr[field] = encoding.GetBytes(_GetDirectionsText(stop.Directions));
                            }
                            else
                            {
                                dr[field] = _FormatFieldValue(data.GetStopFieldValue(field,
                                                                                     scheduleId,
                                                                                     stop));
                            }
                        }

                        table.Rows.Add(dr);
                    }
                }

                _CheckCancelState(tracker);

                // unassigned orders
                IDataObjectCollection<Order> orders = schedule.UnassignedOrders;
                if (null != orders)
                {
                    foreach (Order order in orders)
                    {
                        _CheckCancelState(tracker);

                        DataRow dr = table.NewRow();
                        foreach (string field in fields)
                        {
                            DataWrapper wrapper = data.GetStopFieldValue(field, scheduleId, order);
                            dr[field] = _FormatFieldValue(wrapper);
                        }

                        table.Rows.Add(dr);
                    }
                }
            }
        }
Пример #42
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();
        }
Пример #43
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Does export.
        /// </summary>
        /// <param name="filePath">Export file path.</param>
        /// <param name="table">Export table description.</param>
        /// <param name="schedules">Schedules to exporting.</param>
        /// <param name="tracker">Cancel tracker (can be null).</param>
        public void DoExport(string filePath,
                             ITableDefinition table,
                             ICollection<Schedule> schedules,
                             ICancelTracker tracker)
        {
            Debug.Assert(!string.IsNullOrEmpty(filePath));
            Debug.Assert(null != table);
            Debug.Assert(null != schedules);
            Debug.Assert((TableType.Routes == table.Type) ||
                         (TableType.Stops == table.Type) ||
                         (TableType.Orders == table.Type));

            try
            {
                // create file
                using (var fs = new FileStream(filePath, FileMode.Create))
                {
                    using (var sw = new StreamWriter(fs))
                    {
                        sw.AutoFlush = true;

                        ICollection<string> fields = table.Fields;
                        Debug.Assert(0 < table.Fields.Count);

                        // write header
                        sw.WriteLine(_AssemblyHeaderString(table, fields));

                        _CheckCancelState(tracker);

                        _WriteContent(table.Type, schedules, fields, tracker, sw);
                    }
                }
            }
            catch(Exception e)
            {
                if (File.Exists(filePath))
                    File.Delete(filePath);

                throw (e);
            }
        }
 /// <summary>
 /// Runs function passed to the class constructor.
 /// </summary>
 /// <param name="cancellationTracker">Cancellation tracker to be used for cancelling running
 /// solve operation.</param>
 /// <returns>A function returning asynchronous solve task result.</returns>
 public Func<SolveTaskResult> Run(ICancelTracker cancellationTracker)
 {
     return _taskFunction(cancellationTracker);
 }