public CloudParkingGate()
 {
     this.Config      = FileConfig.FindConfig("Parking.cfg");
     this.SecurityKey = Config.GetString("SecurityKey");
     this.Token       = String.Empty;
     this.TickThread  = new Thread(this.Tick);
 }
        public void Run()
        {
            this.Storage.Initialize();
            this.TransactionPool.WipeThread.Start();
            Log.Info(String.Format("Engine starting running(version:{0})...",
                                   Assembly.GetAssembly(this.GetType()).GetName().Version));
            //F3Gate would start after successful log in.
            this.CloudParking.Start();
            Log.Info("Engine started!");
            this.UiControl.Dispatcher.Invoke(new Action(() =>
            {
                this.UiControl.MajorWindow.Show();
                this.UiControl.MajorWindow.MainPage.ParkPage.RefreshData
                (
                    this.Storage.GetTodayParking()
                );
                this.UiControl.MajorWindow.MainPage.TicketPage.RefreshData
                (
                    this.Storage.GetTodayTicketUsed()
                );
                this.UiControl.LoginWindow.Owner = this.UiControl.MajorWindow;
                this.UiControl.LoginWindow.UserNameTextBox.Text =
                    LoginUtils.ReadPerservedAccount(
                        new FileInfo(FileConfig.FindConfig("GUI.cfg").GetString("PERSERVEACCOUNTFILENAME"))).Item1;
                this.UiControl.LoginWindow.PasswordTextBox.Password =
                    LoginUtils.ReadPerservedAccount(
                        new FileInfo(FileConfig.FindConfig("GUI.cfg").GetString("PERSERVEACCOUNTFILENAME"))).Item2;

                this.UiControl.LoginWindow.ShowDialog();
            }));
            this.UiControl.Run();
        }
Beispiel #3
0
        private void LoginSuccess(LoginResult result)
        {
            Engine.GetEngine().UiControl.LoginWindow.Dispatcher.Invoke(new Action(() =>
            {
                Engine.GetEngine().UiControl.LoginWindow.ResultString  = UI.Properties.Resources.LoginSuccess;
                Engine.GetEngine().UiControl.LoginWindow.IsLoginEnable = true;
                Engine.GetEngine().UiControl.LoginWindow.Visibility    = Visibility.Collapsed;
            }));
            Engine.GetEngine().UiControl.LoginWindow.Dispatcher.Invoke(new Action(() =>
            {
                if (Engine.GetEngine().UiControl.LoginWindow.PerserverAccount)
                {
                    LoginUtils.PerserveUserNameAndPasswordToFile(
                        new FileInfo(FileConfig.FindConfig("GUI.cfg").GetString("PERSERVEACCOUNTFILENAME")),
                        Engine.GetEngine().UiControl.LoginWindow.UserNameTextBox.Text,
                        Engine.GetEngine().UiControl.LoginWindow.PasswordTextBox.Password);
                }
                else
                {
                    LoginUtils.PerserveUserNameAndPasswordToFile(
                        new FileInfo(FileConfig.FindConfig("GUI.cfg").GetString("PERSERVEACCOUNTFILENAME")),
                        String.Empty,
                        String.Empty);
                }
            }));

            Engine.GetEngine().F3Gate.Start();
            Engine.GetEngine().CloudParking.TickThread.Start();
        }
Beispiel #4
0
 public F3Gate()
 {
     if (!HttpListener.IsSupported)
     {
         Log.Error("Windows XP SP2 or Server 2003 or upper is required to use the HttpListener class.");
         return;
     }
     this.Config     = FileConfig.FindConfig("F3.cfg");
     this.IsDebug    = this.Config.GetBoolean("IsDebug");
     this.PortNumber = this.Config.GetUInt("Port");
     this.LocalHost  = this.Config.GetString("LocalHost");
     //Init urls
     this.ParkingUrl       = this.Config.GetString("ParkingUrl");
     this.LeavingUrl       = this.Config.GetString("LeavingUrl");
     this.CouponReceiveUrl = Config.GetString("CouponReceiveUrl");
     this.UpdateUrl        = Config.GetString("UpdateUrl");
     this.ImageUpdateUrl   = Config.GetString("IMAGEUPDATE");
     //Register http window
     this.RegisterHttp(this.LocalHost, this.PortNumber);
     this.Listener = new HttpListener();
     this.Listener.Prefixes.Add(String.Format("http://{0}:{1}/", this.LocalHost, this.PortNumber));
     this.OnReceived += this.F3Gate_OnReceived;
 }
Beispiel #5
0
 public DataPool()
 {
     this.Config        = FileConfig.FindConfig("Storage.cfg");
     this.ConnectString = this.Config.GetString("DBConnectString");
 }
Beispiel #6
0
        public LeavingTransaction(String plateNumber, DateTime outTime, Byte[] outImg, Decimal copeMoney,
                                  Decimal actualMoney, UInt32 ticketId, Stream responseStream)
        {
            //TODO:Using record id which readed from db
            this.RecordId       = 0x00;
            this.PlateNumber    = plateNumber;
            this.OutTime        = outTime;
            this.OutImg         = outImg;
            this.CopeMoney      = copeMoney;
            this.ActualMoney    = actualMoney;
            this.TicketId       = ticketId;
            this.ResponseStream = responseStream;
            this.FullOutput     = FileConfig.FindConfig("Transaction.cfg").GetBoolean("FullOutput");

            this.WorkThread = new Thread(() =>
            {
                try
                {
                    DateTime start = DateTime.Now;
                    if (this.FullOutput)
                    {
                        Log.Info(String.Format("Leave started[+0ms]"));
                    }
                    //Pre-Storage messages and get record id
                    this.RecordId = Engine.GetEngine()
                                    .Storage.PreCarLeave(this.PlateNumber, this.OutTime, this.CopeMoney, this.ActualMoney,
                                                         this.TicketId);
                    if (this.FullOutput)
                    {
                        Log.Info(String.Format("Leave pre-leaved[+{0}ms]", (DateTime.Now - start).TotalMilliseconds));
                    }

                    //Calculate action
                    var successfullyChargedByUserBalance = this.RecordId != 0 &&
                                                           Engine.GetEngine()
                                                           .Storage.TryDeductBalance(this.RecordId,
                                                                                     this.ActualMoney);



                    Log.Info(String.Format("Leave Educted Balance[+{0}ms]",
                                           (DateTime.Now - start).TotalMilliseconds));



                    //Response F3!
                    String json;
                    if (successfullyChargedByUserBalance)
                    {
                        json =
                            IPSCMJsonConvert.ConvertToJson(new Result
                        {
                            ResultCode = ResultCode.Success
                        });
                    }
                    else
                    {
                        json =
                            IPSCMJsonConvert.ConvertToJson(new Result
                        {
                            ResultCode = ResultCode.SuccessButInsufficientFunds
                        });
                    }
                    StreamUtils.WriteToStreamWithUF8(this.ResponseStream, json);
                    this.ResponseStream.Flush();
                    this.ResponseStream.Close();
                    if (this.FullOutput)
                    {
                        Log.Info(String.Format("Leave responded to F3[+{0}ms]", (DateTime.Now - start).TotalMilliseconds));
                    }
                    //Used ticket
                    if (successfullyChargedByUserBalance && this.TicketId != 0)
                    {
                        Engine.GetEngine().Storage.UsedTicket(ticketId, outTime);
                    }
                    if (this.FullOutput)
                    {
                        Log.Info(String.Format("Leave ticket processed[+{0}ms]",
                                               (DateTime.Now - start).TotalMilliseconds));
                    }

                    //Send message to cloud
                    if (!successfullyChargedByUserBalance)
                    {
                        this.CopeMoney   = 0;
                        this.TicketId    = 0;
                        this.ActualMoney = 0;
                    }
                    var result = Engine.GetEngine()
                                 .CloudParking.Leaving(this.RecordId, this.PlateNumber, this.OutTime, this.OutImg, this.CopeMoney,
                                                       this.ActualMoney, this.TicketId);
                    if (this.FullOutput)
                    {
                        Log.Info(String.Format("Leave result received[+{0}ms]", (DateTime.Now - start).TotalMilliseconds));
                    }

                    switch (result.ResultCode)
                    {
                    case ResultCode.Success:
                        {
                            Engine.GetEngine().Storage.PostCarLeaved(this.PlateNumber, result);
                            break;
                        }

                    default:
                        {
                            Log.Error("Leaving transaction do not support Result code:" + result.ResultCode +
                                      " and wrong message is:" + result.ErrorMsg);
                            break;
                        }
                    }
                    this.Status = TransactionStatus.Exhausted;
                }
                catch (Exception ex)
                {
                    this.Status = TransactionStatus.Errored;
                    Log.Error("Leaving transtraction encountered a bad error!", ex);
                }
                finally
                {
                    this.ResponseStream.Flush();
                    this.ResponseStream.Close();
                }
            });
        }