Esempio n. 1
0
        public void ExecutePostConnectionTask()
        {
            context = AzusaContext.GetInstance();

            int forbidUpload = context.ReadIniKey("gps", "forbidUpload", 1);

            if (forbidUpload == 1)
            {
                return;
            }

            DirectoryInfo tourDir = new DirectoryInfo("tours");

            if (!tourDir.Exists)
            {
                tourDir.Create();
                tourDir.Refresh();
            }
            foreach (FileInfo fi in tourDir.GetFiles("*.csv"))
            {
                if (IsStringNumeric(Path.GetFileNameWithoutExtension(fi.Name)))
                {
                    continue;
                }

                FileStream fs          = fi.OpenRead();
                ByteBuffer checkBuffer = new ByteBuffer(512);
                int        readResult  = fs.Read(checkBuffer.Data, 0, 512);
                fs.Close();
                if (readResult != 512)
                {
                    continue;
                }

                if (TourService.IsTourKnown(checkBuffer.Hash))
                {
                    fi.Delete();
                    ExecutePostConnectionTask();
                    return;
                }

                if (context.DatabaseDriver.TransactionSupported)
                {
                    context.DatabaseDriver.BeginTransaction();
                    StreamReader sr    = fi.OpenText();
                    string       magic = sr.ReadLine();
                    if (magic != "Azusa Warwalking Tour")
                    {
                        sr.Dispose();
                        continue;
                    }

                    DateTime recordingStarting     = new DateTime(Convert.ToInt64(sr.ReadLine()));
                    int      utimeRecordingStarted = recordingStarting.ToUnixTime();
                    int      tourId = TourService.CreateTour(checkBuffer.Hash, utimeRecordingStarted,
                                                             Path.GetFileNameWithoutExtension(fi.Name));
                    context.Splash.SetLabel(String.Format("Lade WarWalking Tour hoch: {0}", fi.Name));
                    ProcessTour(sr, tourId);
                    context.DatabaseDriver.EndTransaction(true);
                }
            }
        }