Exemple #1
0
        public GameSession()
        {
            _dataKeeper = new DataKeeper();
            _dataKeeper.Load();

            Initialize();
        }
        /// <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);
            }
        }
Exemple #3
0
        void init()
        {
            DataKeeper = new DataKeeper();
            Devices    = new Devices();

            var device = DataKeeper.device();

            if (device == null)
            {
                disConnected();
                return;
            }
            try
            {
                bIsConnected   = axCZKEM1.Connect_Net(device.DeviceIp, Convert.ToInt32(device.DevicePort));
                iMachineNumber = 1;
                axCZKEM1.RegEvent(iMachineNumber, 65535);

                connected();
            }
            catch
            {
                MessageBox.Show("There is a small issue conntecting with device \n Please report Developer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        public void OutNow()
        {
            using (var Data = new DataKeeper())
            {
                foreach (var a in Data.Keepers)
                {
                    Console.WriteLine(a);
                }
                Console.WriteLine();
                foreach (var a in Data.Actors)
                {
                    Console.WriteLine(a);
                }
                Console.WriteLine();
                foreach (var a in Data.Enitities)
                {
                    //Console.WriteLine("{0} {1} {2} {3} {4}", a.GetType().ToString(), a.Name, a.EnitityKeeper.Name, a.Position.X, a.Position.Y);
                    Console.WriteLine(a.ToString());
                }

                Console.WriteLine("Resourses");
                foreach (var r in Data.Resourses)
                {
                    Console.WriteLine(r.ResourseId.ToString() + " " + r.ResourseType + " ");
                }
            }
        }
        /// <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;
            }
        }
Exemple #6
0
        //      private static string GetShortInfoAD(IEnumerable<AD> list, int maxCount)
        //{
        //	string s = "";
        //	int i = 0;
        //	foreach (AD ad in list)
        //	{
        //		s += ad.title + Environment.NewLine + "Цена: " + ad.price + " " + ad.currency;
        //		if (maxCount != -1 && ++i >= maxCount)
        //			break;
        //	}
        //	return s;
        //}
        #endregion
        //      public static List<AdOlxDirty> DirtParceOlx(IConnectionStringBuilder conn, ICPath path)
        //{
        //	List<AdOlxDirty> listAdDirty = new List<AdOlxDirty>();
        //          ParcerProduct paserProduct = new ParcerProduct(listAdDirty);
        //	paserProduct.SetConnection(conn);
        //	paserProduct.Select(path);
        //          return listAdDirty;
        //}
        //      public static List<AdPrepared1> DirtyToPreparedAd1(List<AdOlxDirty> listAdDirty)
        //      {
        //          List<AdPrepared1> listAdPrepared1 = listAdDirty.Select(a => Preparer1Ad.Prepare(a)).ToList();
        //          return listAdPrepared1;
        //      }
        #region OldFunc
        //public static void OldFunc(List<AdPrepared1> listAdPrepared1)
        //{
        //    var comparer = new AdPrepared1Comparer();
        //    HashSet<AdPrepared1> distinctAD = new HashSet<AdPrepared1>(listAdPrepared1, comparer);

        //    XmlAdMapper<AdPrepared1> mapper = new XmlAdMapper<AdPrepared1>(Directory.GetCurrentDirectory() + "\\storage.xml");
        //    HashSet<AdPrepared1> storedListAD = new HashSet<AdPrepared1>(comparer);

        //    foreach (AdPrepared1 o in mapper.ReadAll())
        //        storedListAD.Add(o);

        //    distinctAD = new HashSet<AdPrepared1>(distinctAD.Except(storedListAD, comparer), comparer);

        //    if (storedListAD.SequenceEqual(storedListAD.Union(distinctAD, comparer), comparer) == false)
        //    {
        //        //				ShowBalloon("Новые товары", GetShortInfoAD(distinctAD, 3));
        //        foreach (AdPrepared1 ad in distinctAD)
        //            Console.WriteLine(ad);
        //        listAdPrepared1 = storedListAD.Union(distinctAD).ToList();
        //        mapper.WriteAll(listAdPrepared1);
        //    }
        //}
        #endregion
        public static void Main(string[] args)
        {
            #region test google
            //Data.GoogleSheetProvider<People> provider = new Data.GoogleSheetProvider<People>("My Project 72320", "client_secret.json", "1kE61PAN5zG_Ygx98PmaRxKZp0L1_NxSelEfOFC2owJs");
            //var p = new People { Age = 44, Name = "Solovian Andrev" };
            //provider.Insert(new List<object>() { p.Name, p.Age }, "Class Data!A1:B");

            //foreach (var a in provider.Get("Class Data!A1:B"))
            //{
            //    Console.WriteLine($"age: {a.Age} people: {a.Name}");
            //}
            //Console.ReadKey();
            #endregion

            ConcurrentQueue <AdPrepared1>   buffer   = new ConcurrentQueue <AdPrepared1>();
            IEqualityComparer <AdPrepared1> comparer = new AdPrepared1Comparer();

            GoogleSheetProvider <AdPrepared1> repository = new GoogleSheetProvider <AdPrepared1>("My Project 72320", "client_secret.json", "1kE61PAN5zG_Ygx98PmaRxKZp0L1_NxSelEfOFC2owJs", "Классификатор - розетка!A1:F");
            DataKeeper <AdPrepared1>          dataKeeper = new DataKeeper <AdPrepared1>(repository, buffer, comparer);

            IEnumerable <AdOlxDirty>  parcerDirtProduct = new ParcerProduct(new Connection("https://www.olx.ua"), new CPath("/elektronika/kompyutery-i-komplektuyuschie/komplektuyuschie-i-aksesuary/videokarty/dnepr/"));
            IEnumerable <AdPrepared1> parcer            = new OlxPreparerProductDecorator(parcerDirtProduct);
            ParcerRobot <AdPrepared1> robo = new ParcerRobot <AdPrepared1>(parcer, dataKeeper, buffer);
            robo.Run();
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
        /// <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);
                }
            }
        }
        /// <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());
        }
        /// <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);
                }
            }
        }
Exemple #10
0
        public MainWindow()
        {
            InitializeComponent();

            TBDatabaseKeeper tbKeeper   = new TBDatabaseKeeper();
            DataKeeper       dataKeeper = new DataKeeper(tbKeeper);

            InitializeController(tbKeeper, dataKeeper);
        }
Exemple #11
0
 void Awake()
 {
     if (dk == null) {
         DontDestroyOnLoad(gameObject);
         dk = this;
     } else if(dk != this){
         Destroy(gameObject);
     }
 }
Exemple #12
0
        static void Main(string[] args)
        {
            DataKeeper.Init();
            var MainTread = new Thread(new ThreadStart(MainTreadWorker));
            var OutTread  = new Thread(new ThreadStart(OutTreadWorker));

            MainTread.Start();
            OutTread.Start();
        }
Exemple #13
0
        public void OneTact()
        {
            Console.WriteLine("Doo tact");
            var keepers      = new List <Keeper>();
            var allEnitities = new List <BaseMapEnitity>();

            using (var data = new DataKeeper())
            {
                _visitor.Data = data;
                keepers.AddRange(data.Keepers);
                allEnitities.AddRange(data.Enitities);

                foreach (var keeper in keepers)
                {
                    var keepresEnitity   = new List <BaseMapEnitity>();
                    var detectedEnitity  = new HashSet <BaseMapEnitity>();
                    var collisionEnitity = new HashSet <BaseMapEnitity>();

                    keepresEnitity.AddRange(allEnitities.Where(e => e.EnitityKeeper.KeeperId == keeper.KeeperId));
                    foreach (var enitity in keepresEnitity)
                    {
                        foreach (var detected in allEnitities.Where(e => enitity.IsDetected(e) && e.KeeperId != keeper.KeeperId))
                        {
                            detectedEnitity.Add(detected);
                        }
                        foreach (var Collided in allEnitities.Where(e => enitity.IsCollided(e) && e.KeeperId != keeper.KeeperId))
                        {
                            collisionEnitity.Add(Collided);
                        }
                    }

                    foreach (var o in keepresEnitity)
                    {
                        o.Visit(_visitor, detectedEnitity);
                    }

                    /*
                     * foreach (var o in keepresEnitity)
                     * {
                     *  o.Visit(_visitor, detectedEnitity);
                     *  Console.WriteLine("\n"+o.ToString() + "\n\n");
                     * }
                     * Console.WriteLine();
                     * foreach (var o in detectedEnitity)
                     *  Console.WriteLine(o.ToString() + "\n");
                     * Console.WriteLine();
                     * foreach (var o in collisionEnitity)
                     *  Console.WriteLine(o.ToString() + "\n");
                     * Console.WriteLine();
                     *
                     * Console.WriteLine();
                     */
                }
                data.SaveChanges();
            }
        }
Exemple #14
0
    private void Start()
    {
        if (m_Real == null)
        {
            m_Real = this;
        }
        else if (m_Real != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);
    }
 void Awake()
 {
     DontDestroyOnLoad(gameObject);
     if (instance == null)
     {
         instance = this;
     }
     if (items == null)
     {
         items     = _items;
         locations = _locations;
         hand      = _hand;
     }
 }
Exemple #16
0
    private void SpawnAllTanks()
    {
        DataKeeper dk        = FindObjectOfType <DataKeeper>();
        int        tankColor = -1;

        for (int i = 0; i < m_Tanks.Length; i++)
        {
            m_Tanks[i].m_Instance =
                Instantiate(m_TankPrefab, m_Tanks[i].m_SpawnPoint.position, m_Tanks[i].m_SpawnPoint.rotation) as GameObject;
            m_Tanks[i].m_PlayerNumber = i + 1;
            for (int j = 0; j < dk.m_ChosenTanks.Length; j++)
            {
                if (dk.m_ChosenTanks[j] == i + 1)
                {
                    tankColor = j;
                    break;
                }
            }

            switch (tankColor)
            {
            case 0:
                m_Tanks[i].m_PlayerColor = Color.black;
                m_Tanks[i].m_Instance.GetComponent <TankShooting>().m_PowerUpLength = 5;
                m_Tanks[i].m_Instance.GetComponent <TankShooting>().m_PowerUpType   = PowerType.Black_Hole;
                break;

            case 1:
                m_Tanks[i].m_PlayerColor = Color.yellow;
                m_Tanks[i].m_Instance.GetComponent <TankShooting>().m_PowerUpLength = 10;
                m_Tanks[i].m_Instance.GetComponent <TankShooting>().m_PowerUpType   = PowerType.Lightning;
                break;

            case 2:
                m_Tanks[i].m_PlayerColor = Color.red;
                m_Tanks[i].m_Instance.GetComponent <TankShooting>().m_PowerUpLength = 20;
                m_Tanks[i].m_Instance.GetComponent <TankShooting>().m_PowerUpType   = PowerType.Fire;
                break;

            case 3:
                m_Tanks[i].m_PlayerColor = Color.blue;
                m_Tanks[i].m_Instance.GetComponent <TankShooting>().m_PowerUpLength = 20;
                m_Tanks[i].m_Instance.GetComponent <TankShooting>().m_PowerUpType   = PowerType.Ice;
                break;
            }

            m_Tanks[i].Setup();
        }
    }
Exemple #17
0
        static void Main(string[] args)
        {
            ConcurrentQueue <ProductPrepared1>   buffer   = new ConcurrentQueue <ProductPrepared1>();
            IEqualityComparer <ProductPrepared1> comparer = new ProductPrepared1Comparer();

            GoogleSheetProvider <ProductPrepared1> repository = new GoogleSheetProvider <ProductPrepared1>("My Project 72320", "client_secret.json", "1kE61PAN5zG_Ygx98PmaRxKZp0L1_NxSelEfOFC2owJs", "Классификатор - розетка!A1:F");
            DataKeeper <ProductPrepared1>          dataKeeper = new DataKeeper <ProductPrepared1>(repository, buffer, comparer);

            IEnumerable <ProductDirty>     parcerDirtProduct = new RozetkaProductParcer(new Connection("https://hard.rozetka.com.ua"), new CPath("/videocards/c80087/"));
            IEnumerable <ProductPrepared1> parcer            = new RozetkaPreparerProductDecorator(parcerDirtProduct);
            ParcerRobot <ProductPrepared1> robo = new ParcerRobot <ProductPrepared1>(parcer, dataKeeper, buffer);

            robo.Run();
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Exemple #18
0
        static void Main(string[] args)
        {
            DataKeeper.SetConfigFile("Calibration.xml");

            string teststring = string.Empty;
            double testnumber = 0;

            //  DataKeeper.Read("/CONFIG/DEVICE/INIT_ORDER/", out teststring);
            //  DataKeeper.Read("/CONFIG/DEVICE/INIT_ORDER/", out testnumber);
            //  DataKeeper.Write("/aa/bb/cc///", "coucou");
            //  DataKeeper.Write("/aa/bb/dd///", 1234567890);
            //  DataKeeper.Write("/aa/bb/ee///", false);
            DataKeeper.Read("CONFIG/CALIBRATION/PERTEL1", out testnumber);
            DataKeeper.Write("CONFIG/CALIBRATION/PERTEL1", testnumber * 2);
            Console.WriteLine(teststring);
            Console.WriteLine(testnumber);
            Console.ReadKey();
        }
        /// <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);
            }
        }
Exemple #20
0
    //if baitSetAt < 60 seconds, spawn the bait
    //else if baitSetAt < 15 minutes, spawn the bait plus the spider
    //if there's already a spider saved, spawn that one
    //if not, pick one and save it
    //else if baitSetAt < 2 hours, spawn just the spider
    //if there is bait but no spider, spawn the bait, then the spider, then clean up the bait
    //if there is spider, spawn it and clean up the bait
    //else clean up
    //delete baitSetAt
    //clear mybait + playerpref
    //clear myspider + playerpref

    void LoadSpiderSpawners()
    {
        if (spiderSpawners != null)
        {
            for (int i = 0; i < spiderSpawners.Length; i++)
            {
                TimeSpan timeSinceBaitSet = DataKeeper.getTimeSinceStamp(spiderSpawners[i].gameObject.name + ".baitSetAt");
                if (timeSinceBaitSet.TotalSeconds > 0)                    // Should only ever be 0 if the stamp isn't set
                {
                    SpiderSpawner spiderSpawnerScript = spiderSpawners[i].GetComponent <SpiderSpawner>();
                    string        spiderSpawnerName   = spiderSpawners[i].gameObject.name;
                    if (timeSinceBaitSet.TotalSeconds < secondsBetweenBaitPlacingAndEating)                        // bait sitting out
                    {
                        spawnBait(spiderSpawnerName, spiderSpawnerScript);
                    }
                    else if (timeSinceBaitSet.TotalSeconds < secondsBetweenEatingAndChilling)                           // spider nomming bait
                    {
                        spawnBait(spiderSpawnerName, spiderSpawnerScript);
                        spawnSpider(spiderSpawnerName, spiderSpawnerScript);
                    }
                    else if (timeSinceBaitSet.TotalSeconds < secondsBetweenChillingAndLeaving)                         // spider chilling
                    {
                        spawnBait(spiderSpawnerName, spiderSpawnerScript);
                        spawnSpider(spiderSpawnerName, spiderSpawnerScript);
                        cleanUpBait(spiderSpawnerScript);
                    }
                    else                          // clean up and note how many times it has visited
                    {
                        spawnBait(spiderSpawnerName, spiderSpawnerScript);
                        spawnSpider(spiderSpawnerName, spiderSpawnerScript);
                        updateSpiderVisits(spiderSpawnerName);
                        cleanUpBait(spiderSpawnerScript);
                        cleanUpSpider(spiderSpawnerName, spiderSpawnerScript);
                        PlayerPrefs.DeleteKey(spiderSpawnerName + ".baitSetAt");
                    }
                }
            }
        }
    }
        /// <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);
                }
            }
        }
        /// <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();
            }
        }
Exemple #23
0
 public ParcerRobot(IEnumerable <T> preparerProduct, DataKeeper <T> dataKeeper, ConcurrentQueue <T> buffer)
 {
     _preparerProduct = preparerProduct;
     _dataKeeper      = dataKeeper;
     _buffer          = buffer;
 }
        /// <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);
                }
            }
        }
        /// <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);
            }
        }
        /// <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();
            }
        }
Exemple #27
0
 public void InitializeController(IDatabaseKeeper tbKeeper, DataKeeper dataKeeper)
 {
     databaseController = new DatabaseController(tbKeeper, dataKeeper);
 }
        /// <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;
            }
        }
        /// <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);
                }
            }
        }
        /// <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);
            }
        }
Exemple #31
0
 private void Awake()
 {
     dataKeeper = FindObjectOfType <DataKeeper>();
 }
        public ActionResult GetCategories()
        {
            keeper = new DataKeeper();

            return(View(_mapper.Mapper.Map <List <Category> >(_categoryService.Get())));
        }
        public void TerminalCommand(String command)
        {
            Console.WriteLine(command);
            try
            {
                command = command.ToLower();
                if (String.IsNullOrEmpty(command) || String.IsNullOrWhiteSpace(command))
                {
                    Console.WriteLine("That's not a valid command... Type \'help\' if you don\'t know what command to use.");
                    return;
                }
                String[] commands = command.Split(' ');
                String   head     = commands[0];



                if (head == "neuralnetwork")
                {
                    Model network = NeuralNetworkHandler.network;
                    if (commands.Length == 1)
                    {
                        if (network == null)
                        {
                            Console.WriteLine("There is no Network currently loaded.");
                        }
                        else
                        {
                            String message =
                                "Current loaded network:\n" +
                                "\tName:\t" + network.Name + "\n" +
                                "\tType:\t" + network.Type;
                            Console.WriteLine(message);
                        }
                    }
                    else if (commands[1] == "create")
                    {
                        if (network == null)
                        {
                            List <LayerBase> layers = new List <LayerBase>();

                            for (int i = 4; i < commands.Length; i += 2)
                            {
                                LayerBase l = null;
                                if (commands[i] == "input")
                                {
                                    l = new InputLayer();
                                }
                                else if (commands[i] == "lrelu")
                                {
                                    l = new LeakyReluLayer();
                                }
                                else if (commands[i] == "sigmoid")
                                {
                                    l = new SigmoidLayer();
                                }
                                else
                                {
                                    Console.Error.WriteLine(String.Format("Layer type {0} does not exist.", commands[i]));
                                    return;
                                }
                                l.nodes = int.Parse(commands[i + 1]);
                                layers.Add(l);
                            }
                            NeuralNetworkHandler.CreateNetwork(layers.ToArray(), commands[2], commands[3]);
                            Console.WriteLine("Neural Network successfully created.");
                            return;
                        }
                    }
                    else if (commands[1] == "load")
                    {
                        Console.WriteLine(NeuralNetworkHandler.LoadNetwork(commands[2]));
                    }
                    else if (commands[1] == "save")
                    {
                        if (commands.Length == 2)
                        {
                            Console.WriteLine(NeuralNetworkHandler.SaveNetwork());
                        }
                        else
                        {
                            Console.WriteLine(NeuralNetworkHandler.SaveNetwork(commands[2]));
                        }
                    }
                    else if (commands[1] == "randomize")
                    {
                        Console.WriteLine(NeuralNetworkHandler.RandomizeNetwork());
                    }
                    else if (commands[1] == "train")
                    {
                        if (network == null)
                        {
                            Console.Error.WriteLine("No network loaded.");
                            return;
                        }
                        if (NeuralNetworkHandler.keeper == null)
                        {
                            Console.Error.WriteLine("No dataset loaded.");
                            return;
                        }

                        int epochs = 1;
                        if (commands.Length != 2)
                        {
                            epochs = int.Parse(commands[2]);
                        }
                        NeuralNetworkHandler.train = new Thread(() => NeuralNetworkHandler.TrainNetwork(epochs));
                        NeuralNetworkHandler.train.IsBackground = true;
                        NeuralNetworkHandler.train.Name         = "Training Thread";


                        NeuralNetworkHandler.train.Start();
                    }
                    else if (commands[1] == "learningrate")
                    {
                        if (commands.Length == 2)
                        {
                            Console.WriteLine("Learning rate: " + Model.LearningRate);
                        }
                        else
                        {
                            Model.LearningRate = float.Parse(commands[2]);
                        }
                    }
                }
                else if (head == "test")
                {
                    Data[] data = new Data[3600];

                    float x = 0;

                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i]        = new Data();
                        data[i].Inputs = new Matrix(1, 1)
                        {
                            data = new float[, ] {
                                { (1f / 360f) * x }
                            }
                        };
                        data[i].Targets = new Matrix(1, 1)
                        {
                            data = new float[, ] {
                                { (float)Math.Sin(x * (Math.PI / 180)) }
                            }
                        };
                        x += 0.1f;
                    }

                    NeuralNetworkHandler.keeper         = new DataKeeper();
                    NeuralNetworkHandler.keeper.DataSet = data;
                    NeuralNetworkHandler.keeper.Name    = "sinusfunction";
                }
                else if (head == "dataset")
                {
                    if (commands.Length == 1)
                    {
                        if (NeuralNetworkHandler.keeper == null)
                        {
                            Console.WriteLine("There is no dataset loaded yet.");
                        }
                        else
                        {
                            Console.WriteLine(String.Format("The dataset with the name {0} is currently loaded.", NeuralNetworkHandler.keeper.Name));
                        }
                    }
                    else if (commands[1] == "load")
                    {
                        Console.WriteLine(DataKeeper.LoadDataSet(commands[2]));
                    }
                    else if (commands[1] == "save")
                    {
                        if (commands.Length == 2)
                        {
                            Console.WriteLine(DataKeeper.SaveDataSet());
                        }
                        else
                        {
                            Console.WriteLine(DataKeeper.SaveDataSet(commands[2]));
                        }
                    }
                    else if (commands[1] == "unload")
                    {
                        NeuralNetworkHandler.keeper = null;
                    }
                    else if (commands[1] == "view")
                    {
                        if (NeuralNetworkHandler.keeper == null)
                        {
                            Console.Error.WriteLine("No dataset loaded.");
                            return;
                        }
                        for (int i = 0; i < NeuralNetworkHandler.keeper.DataSet.Length; i++)
                        {
                            Console.WriteLine("Data " + i + ":");
                            Console.WriteLine("Inputs:");
                            Console.WriteLine(NeuralNetworkHandler.keeper.DataSet[i].getInputString());
                            Console.WriteLine("Targets:");
                            Console.WriteLine(NeuralNetworkHandler.keeper.DataSet[i].getTargetsString());
                            Console.WriteLine("");
                        }
                    }
                }
                else if (head == "googledrive")
                {
                    if (commands[1] == "login")
                    {
                        GoogleDriveHandler.GoogleDriveLogin(HttpRuntime.AppDomainAppPath + "/credentials.json");
                        Console.WriteLine("Successfully logged in on Google Drive.");
                    }
                    else if (commands[1] == "logout")
                    {
                        GoogleDriveHandler.GoogleDriveLogout("credentials.json");
                        Console.WriteLine("Successfully logged out from Google Drive.");
                    }
                    else if (commands[1] == "list")
                    {
                        IList <Google.Apis.Drive.v3.Data.File> list = GoogleDriveHandler.GetFileList();

                        foreach (var file in list)
                        {
                            Console.WriteLine(String.Format("{0} ({1})", file.Name, file.Id));
                        }
                    }
                }
                else
                {
                    Console.Error.WriteLine("That's not a valid command... Type \'help\' if you don\'t know what command to use.");
                }
            } catch (Exception e)
            {
                Console.Error.WriteLine("Command resolved in an error.");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }
        }
        /// <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);
                    }
                }
            }
        }
        /// <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();
        }
        /// <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);
                }
            }
        }
 void setBaitAndTimestamp(string baitName)
 {
     DataKeeper.getAndUpdateStamp(gameObject.name + ".baitSetAt");
     placeBait(baitName);
 }
        /// <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);
                    }
                }
            }
        }
Exemple #39
0
 public IpForm()
 {
     InitializeComponent();
     datakeeper = new DataKeeper();
 }