Exemplo n.º 1
0
        private void buttonTijd_Click(object sender, EventArgs e)
        {
            int seconds = (int.Parse(textBox1.Text.Split(':')[0]) * 60) + int.Parse(textBox1.Text.Split(':')[1]);

            MainClient.SendNetCommand(new NetCommand(NetCommand.ValueType.TIME, seconds, Session));
            textBox1.Text = "";
        }
Exemplo n.º 2
0
        private void TakeItem(dynamic _data, CallbackDelegate _callback)
        {
            //Send container id and item id that we wanna take
            MainClient.TriggerServerEvent("Laced:TakeContainerItem", SessionManager.PlayerSession.getSessionKey(), _data.ContainerID, _data.ItemID, new Action <bool, string, int>(TakeItemCallback));

            _callback(new { ok = true });
        }
Exemplo n.º 3
0
        private bool switchclient(Arguments arg)
        {
            if (arg.Count == 0)
            {
                foreach (var item in MainClients.Clients)
                {
                    CurrentIO.WriteColor("", ConsoleColor.Gray, false);
                    CurrentIO.WriteColor(LANG_COMMANDS_CLIENT_NAME, ConsoleColor.Cyan, false, false);
                    CurrentIO.WriteColor(item.ClientName.PadRight(18), ConsoleColor.White, false, false);
                    CurrentIO.WriteColor(LANG_COMMANDS_CLIENT_AUTHOR, ConsoleColor.DarkCyan, false, false);
                    CurrentIO.WriteColor(item.Author, ConsoleColor.White, true, false);
                }

                CurrentIO.WriteColor(string.Format(LANG_COMMANDS_CURRENT, MainClient.Client.ClientName), ConsoleColor.Green);
            }
            else
            {
                if (MainClients.Clients.FirstOrDefault(p => p.ClientName == arg[0]) == null)
                {
                    return(false);
                }
                Configuration.Client = arg[0];
                MainClient.ResetClient();
            }
            return(true);
        }
Exemplo n.º 4
0
        public void RegisterNUICallbacks()
        {
            MainClient.GetInstance().RegisterNUICallback("laced_inventory_close", CloseInventory);

            MainClient.GetInstance().RegisterNUICallback("laced_inventory_use", UseItem);
            MainClient.GetInstance().RegisterNUICallback("laced_inventory_take", TakeItem);
        }
Exemplo n.º 5
0
 public CommandManager()
 {
     MainClient.GetInstance().RegisterEventHandler("Laced:AdminSpawnVehicle", new Action <string, string>(AdminSpawnVehicle));
     MainClient.GetInstance().RegisterEventHandler("Laced:ChangeCharacter", new Action <string, string>(ChangeCharacter));
     MainClient.GetInstance().RegisterEventHandler("Laced:GetCharacterPosition", new Action <string>(GetCharacterPosition));
     MainClient.GetInstance().RegisterEventHandler("Laced:AdminGiveWeapon", new Action <string, string>(AdminGiveWeapon));
 }
        public VehicleModule(MainClient client)
        {
            Client = client;

            Client.AddCommand("vehicle", VehicleCommand);
            Client.AddCommand("dv", RemoveVehicleCommand);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            MainClient mainClient = new MainClient();

            mainClient.ConnectToServer();
            mainClient.BeginCommandProcessing();
        }
Exemplo n.º 8
0
 private void btnLogin_Click(object sender, RoutedEventArgs e)
 {
     if (tb_account.Text.Trim() == "" || tb_password.Password.Trim() == "")
     {
         MessageBox.Show("账号或密码为空,请输入");
     }
     else
     {
         SignalCore.UserInfo user = new SignalCore.UserInfo();
         user.UserAccount = tb_account.Text.Trim();
         user.UserPwd     = tb_password.Password.Trim();
         foreach (var currentUser in userList)
         {
             if (currentUser.UserAccount == user.UserAccount)
             {
                 if (currentUser.UserPwd == user.UserPwd)
                 {
                     MainClient.currentUser = currentUser;
                     MainClient mainWin = new MainClient();
                     this.Close();
                     mainWin.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("密码错误");
                 }
                 return;
             }
         }
         MessageBox.Show("该账户不存在");
     }
 }
Exemplo n.º 9
0
 public void Start()
 {
     using (ClientTaskQueue = new MessageQueue <ClientTask>())
     {
         SetupHostConnection();
         GetParameters();
         while (!Exit)
         {
             var task = ClientTaskQueue.GetMessageOrTimeout(MillisecondsToWait);
             if (task != null)
             {
                 CurrentTask = task;
                 InitializeParameters(task);
                 MainClient.Start();
                 task.Result = RetrieveValue == null ? float.NaN : RetrieveValue();
                 ToHost.SendCustomMessage(task, ResultChannel);
                 if (ClientTaskQueue.Count == 0)
                 {
                     ToHost.SendCustomMessage(null, RequestJobChannel);
                 }
                 CurrentTask = null;
                 GC.Collect();
             }
             else
             {
                 ToHost.SendCustomMessage(null, RequestJobChannel);
             }
         }
     }
 }
Exemplo n.º 10
0
        private async void OnClientResourceStart(string _resourceName)
        {
            if (_resourceName == MainClient.ResourceName())
            {
                Utils.DebugLine("Resource Started!", "CSessionManager");

                MainClient.GetInstance().SetNUIFocus(false, false);
                int maxThreshhold = 2000;
                int timeStamp     = Game.GameTime;

                Screen.LoadingPrompt.Show("Loading Interface", LoadingSpinnerType.Clockwise3);

                Game.Player.CanControlCharacter = false;
                Game.Player.IsInvincible        = true;
                do
                {
                    await BaseScript.Delay(1000);
                } while ((timeStamp + maxThreshhold) > Game.GameTime);
                do
                {
                    await BaseScript.Delay(1000);
                } while (!NUIReady);
                Screen.LoadingPrompt.Hide();

                API.ShutdownLoadingScreen();

                Game.Player.CanControlCharacter = true;
                Game.Player.IsInvincible        = false;

                MainClient.TriggerServerEvent("Laced:CreateSession");
            }
        }
Exemplo n.º 11
0
        public static MainClient GetMainClient(Miljoe miljoe)
        {
            MainClient client = new MainClient();

            client.Endpoint.Address = new System.ServiceModel.EndpointAddress(RKNet_Utils.GetEndpointAddress(miljoe));
            return(client);
        }
Exemplo n.º 12
0
        public TestListOfMessages(MainClient session, TestPage currentWorkSpace)
        {
            InitializeComponent();
            CurrentWorkSpace     = currentWorkSpace;
            Session              = session;
            listOfCachedMessages = session.GetCachedMessages();
            var listOfMessages = session.GetMyMails(true);

            foreach (var message in listOfMessages)
            {
                if (listOfCachedMessages != null)
                {
                    if (message.Id == listOfCachedMessages[0].Id)
                    {
                        break;
                    }
                    else
                    {
                        MessagesPanel.Children.Add(new MessageLayout(message));
                    }
                }
                else
                {
                    MessagesPanel.Children.Add(new MessageLayout(message));
                }
            }
            if (listOfCachedMessages != null)
            {
                foreach (var message in listOfCachedMessages)
                {
                    MessagesPanel.Children.Add(new MessageLayout(message));
                }
            }
        }
Exemplo n.º 13
0
        protected void sendTradeOffer_click(Object sender, EventArgs e)
        {
            Dictionary <ResourceType, int> sell = new Dictionary <ResourceType, int>();

            sell.Add(ResourceType.Wood, Int32.Parse(woodOffer.Value));
            sell.Add(ResourceType.Wool, Int32.Parse(woolOffer.Value));
            sell.Add(ResourceType.Clay, Int32.Parse(clayOffer.Value));
            sell.Add(ResourceType.Stone, Int32.Parse(stoneOffer.Value));
            sell.Add(ResourceType.Straw, Int32.Parse(strawOffer.Value));
            sell.Add(ResourceType.Iron, Int32.Parse(ironOffer.Value));
            sell.Add(ResourceType.Food, Int32.Parse(foodOffer.Value));

            Dictionary <ResourceType, int> buy = new Dictionary <ResourceType, int>();

            buy.Add(ResourceType.Wood, Int32.Parse(woodReceive.Value));
            buy.Add(ResourceType.Wool, Int32.Parse(woolReceive.Value));
            buy.Add(ResourceType.Clay, Int32.Parse(clayReceive.Value));
            buy.Add(ResourceType.Stone, Int32.Parse(stoneReceive.Value));
            buy.Add(ResourceType.Straw, Int32.Parse(strawReceive.Value));
            buy.Add(ResourceType.Iron, Int32.Parse(ironReceive.Value));
            buy.Add(ResourceType.Food, Int32.Parse(foodReceive.Value));
            TradeOffer to = new TradeOffer(MainClient.player.Name, tradeOfferReceiver.SelectedValue, sell, buy);

            MainClient.SendTradeOfferToPlayer(to);
        }
Exemplo n.º 14
0
        private async Task Draw3DMarkers()
        {
            if (Game.PlayerPed.IsAlive && Game.PlayerPed.IsVisible)
            {
                foreach (Marker m in MarkerList)
                {
                    if (World.GetDistance(Game.PlayerPed.Position, m.MarkerPos) < 25.0f)
                    {
                        Helpers.Draw3DText(m.MarkerPos, Color.FromArgb(255, 255, 255), m.MarkerName, CitizenFX.Core.UI.Font.ChaletComprimeCologne, 1);

                        World.DrawMarker(MarkerType.VerticalCylinder, m.MarkerPos, Vector3.Zero, Vector3.Zero, new Vector3(1.5f, 1.5f, 1.5f), Color.FromArgb(255, 200, 200, 200), false, true);
                    }

                    if (World.GetDistance(Game.PlayerPed.Position, m.MarkerPos) < 2.0f)
                    {
                        if (API.IsControlJustReleased(0, 46))
                        {
                            Action <Marker> markerAction = GetMarkerAction(m.MarkerAction);

                            markerAction(m);

                            await MainClient.Delay(500);
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        private async void AdminSpawnVehicle(string _seshKey, string _vehicleModel)
        {
            if (!Helpers.CheckSessionKey(_seshKey))
            {
                MainClient.TriggerServerEvent("Laced:SessionKeyError"); return;
            }
            uint vehicleHash = Helpers.GetVehicleHashFromString(_vehicleModel);

            Utils.WriteLine(vehicleHash.ToString());
            if (!API.IsModelInCdimage(vehicleHash) || !API.IsModelAVehicle(vehicleHash))
            {
                Utils.WriteLine("Model doesn't exist!");
                return;
            }

            API.RequestModel(vehicleHash);

            while (!API.HasModelLoaded(vehicleHash))
            {
                Utils.DebugLine("Waiting for model to load!", "CCommandManager");
                await MainClient.Delay(500);
            }

            int     playerPedID = API.PlayerPedId();
            Vector3 plyPos      = Game.PlayerPed.Position;

            int vehicle = API.CreateVehicle(vehicleHash, plyPos.X, plyPos.Y, plyPos.Z, API.GetEntityHeading(playerPedID), true, false);
            await MainClient.Delay(50);

            API.SetPedIntoVehicle(playerPedID, vehicle, -1);

            API.SetEntityAsNoLongerNeeded(ref vehicle);

            API.SetModelAsNoLongerNeeded(vehicleHash);
        }
Exemplo n.º 16
0
        private static async void NUIDisconnect(dynamic _data, CallbackDelegate _callback)
        {
            await MainClient.Delay(500);

            UnregisterCharacterNUICallbacks();
            _ = _callback(new { ok = true });
        }
Exemplo n.º 17
0
        public void Connect(string ip, int port, string AP)
        {
            if (String.IsNullOrEmpty(ip))
            {
                return;
            }
            var       IPs = Dns.GetHostAddresses(ip);
            IPAddress IP  = IPs.Where(x => x.AddressFamily == AddressFamily.InterNetwork).FirstOrDefault();
            var       ep  = new IPEndPoint(IP, port);

            try
            {
                MainClient.Connect(ep);
            }
            catch
            {
                return;
            }

            ns = new NetworkStream(MainClient);
            Thread thread = new Thread(o => ReceiveData((Socket)o));

            thread.Start(MainClient);
            MainClient.Send(Encoding.UTF8.GetBytes(AP));
        }
Exemplo n.º 18
0
 public static void OnClientLoaded(MainClient c)
 {
     if (ClientLoaded_Event != null)
     {
         ClientLoaded_Event(null, c);
     }
 }
Exemplo n.º 19
0
        public async static void SellVehicle(Marker _marker)
        {
            if (_marker == null)
            {
                return;
            }

            if (Game.Player.IsAlive && Game.Player.Character.IsInVehicle())
            {
                Vehicle plyVeh    = Game.Player.Character.CurrentVehicle;
                int     vehHandle = plyVeh.Handle;

                foreach (GarageItem gI in SessionManager.PlayerSession.getSelectedCharacter().Garage.garageItems)
                {
                    if (gI.vehicleNetworkID == plyVeh.NetworkId)
                    {
                        MainClient.TriggerServerEvent("Laced:SellCardealerVehicle", SessionManager.PlayerSession.getSessionKey(), JsonConvert.SerializeObject(gI), new Action <bool, string, int>((_sold, _garageItem, _price) =>
                        {
                            if (_sold)
                            {
                                Utils.WriteLine("Selling vehicle!");
                                GarageItem garageItem = JsonConvert.DeserializeObject <GarageItem>(_garageItem);
                                SessionManager.PlayerSession.getSelectedCharacter().SellVehicle(garageItem);
                                Utils.WriteLine("Removed vehicle!");
                                SessionManager.PlayerSession.getSelectedCharacter().SellItem(_price);
                                Utils.WriteLine("Sold vehicle!");
                                API.DeleteEntity(ref vehHandle);
                            }
                        }));
                    }
                }
            }
        }
Exemplo n.º 20
0
        public void setupcon(string ip, int port, string uname, string upass, bool reg)
        {
            try
            {
                _user     = uname;
                _pass     = upass;
                _reg      = reg;
                client    = new TcpClient(ip, port);
                netstream = client.GetStream();
                ssl       = new SslStream(netstream, false, new RemoteCertificateValidationCallback(ValidateCert));
                ssl.AuthenticateAsClient("ChitChat");


                br = new BinaryReader(ssl, Encoding.UTF8);
                bw = new BinaryWriter(ssl, Encoding.UTF8);

                int hello = br.ReadInt32();

                if (hello == Client.IM_Hello)
                {
                    bw.Write(Client.IM_Hello);
                    bw.Write(_reg ? Client.IM_Login : Client.IM_Register);
                    bw.Write(_user);
                    bw.Write(_pass);
                    bw.Flush();

                    int  a   = br.PeekChar() + 1; // I am not sure if this is correct but it works. Prevent to have a -1 value.
                    byte ans = br.ReadByte();

                    if (ans == Client.IM_OK)
                    {
                        if (reg)
                        {
                            Logger.Write("Success");
                            HideFormLogin();
                            MainClient m = new MainClient();
                            m.ShowDialog();
                        }
                    }
                    else if (ans == Client.IM_WrongPass)
                    {
                        Logger.Write("Wrong Password, Please try again.");
                        _closeform = false;
                    }
                    else if (ans == Client.IM_NoExists)
                    {
                        Logger.Write("We cannot validate your logins. Please try again.", ChitChatAPI.Enums.LogLevel.Error, ConsoleColor.Red);
                    }
                    else if (ans == Client.IM_SomeoneLoggedIn)
                    {
                        Logger.Write("Someone Logged-In to your account.Please log In again.", ChitChatAPI.Enums.LogLevel.Error, ConsoleColor.Red);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write(ex.Message);
            }
        }
Exemplo n.º 21
0
 void OnGUI()
 {
     GUILayout.BeginArea(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
     stringHost   = GUILayout.TextField(stringHost);
     stringPseudo = GUILayout.TextField(stringPseudo);
     if (GUILayout.Button("Login"))
     {
         if (stringHost.Length > 0)
         {
             if (stringPseudo.Length > 0)
             {
                 string[] c    = stringHost.Split(':');
                 string   host = "";
                 int      port = 9999;
                 if (c.Length == 1)
                 {
                     host = c[0];
                     MainClient.connect(host, port, stringPseudo);
                     winID      = 6;
                     windowOpen = true;
                 }
                 else
                 {
                     host = c[0];
                     if (Int32.TryParse(c[1], out port))
                     {
                         MainClient.connect(host, port, stringPseudo);
                         winID      = 6;
                         windowOpen = true;
                     }
                     else
                     {
                         winID      = 1;
                         windowOpen = true;
                     }
                 }
             }
             else
             {
                 winID      = 2;
                 windowOpen = true;
             }
         }
         else
         {
             winID      = 3;
             windowOpen = true;
         }
     }
     GUILayout.EndArea();
     if (windowOpen)
     {
         GUI.Box(windowRect, "");
         GUI.Box(windowRect, "");
         GUI.Box(windowRect, "");
         GUI.Box(windowRect, "");
         windowRect = GUILayout.Window(winID, windowRect, connectedWindow, "Information");
     }
 }
Exemplo n.º 22
0
 protected void declineTradeOffer_click(Object sender, EventArgs e)
 {
     //MainClient.DeclineTradeOffer(Int32.Parse((string)e.CommandArgument));
     //MainClient.AcceptTradeOffer(Int32.Parse(tradeOfferId.Value));
     allYourRecievedTradeOffers = DatabaseInterface.ReadAllTradeOffers(MainClient.player.Name);
     MainClient.AcceptTradeOffer(allYourRecievedTradeOffers.ElementAt(0).Id);
     RenderTradeOffers();
 }
Exemplo n.º 23
0
        private static async void CreateCharacter(dynamic _data, CallbackDelegate _callback)
        {
            await MainClient.Delay(50);

            MainClient.TriggerServerEvent("Laced:CreateCharacter", _data.firstName, _data.lastName, _data.gender);

            _ = _callback(new { ok = true });
        }
Exemplo n.º 24
0
        private void CloseInventory(dynamic _data, CallbackDelegate _callback)
        {
            MainClient.GetInstance().SetNUIFocus(false, false);

            UnregisterNUICallbacks();

            _callback(new { ok = true });
        }
Exemplo n.º 25
0
        private static async void DeleteCharacter(dynamic _data, CallbackDelegate _callback)
        {
            await MainClient.Delay(500);

            MainClient.TriggerServerEvent("Laced:DeleteCharacter", _data.id);

            _ = _callback(new { ok = true });
        }
Exemplo n.º 26
0
 public ClientControl(MainClient client)
 {
     Messages = new List <MessageEntry>();
     Client   = client;
     InitializeComponent();
     Client.Network.ClientMessageReceived += ClientMessageReceived;
     Client.Network.ServerMessageReceived += ServerMessageReceived;
 }
Exemplo n.º 27
0
        private void button1_Click(object sender, EventArgs e)
        {
            MainClient mc = new MainClient(userID);

            this.Hide();
            mc.ShowDialog();
            this.Close();
        }
 public ContainerLogger(RichTextBox container, bool isConsole, bool saveLogs, MainClient client = null)
 {
     Container = container;
     LogCount  = 0;
     IsConsole = isConsole;
     SaveLogs  = saveLogs;
     Client    = client;
 }
Exemplo n.º 29
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(this.gameObject);
     }
 }
Exemplo n.º 30
0
 //
 // GET: /Gallery/
 public ActionResult Index()
 {
     List<Cake> cakeList;
     using (MainClient service = new MainClient())
     {
         cakeList = service.GetAllCakes();
     }
     return View(cakeList);
 }
 public ClientNetwork(Socket sock, MainClient client, uint _instance = 0)
 {
     Sock     = sock;
     Client   = client;
     Frames   = new Dictionary <int, List <MonitorPacketDelegate> >();
     Ticket   = false;
     Instance = _instance;
     Rnd      = new Random();
 }
Exemplo n.º 32
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            txtAmount.Text = "1000";
            //txtPhone.Text = "0932130483";
            txtContent.Text = "0932130483*12345*500000*0939146267*500000";
            txtMessage.Text = "";

            rdoLocalhost.IsChecked = true;

            mainClient = new MainClient("BasicHttpBinding_IMain");
        }
Exemplo n.º 33
0
        // [HttpPost]
        public ActionResult CakeCart(int cakeID)
        {
            Cake cake;
            List<Ingredient> ingredientList;
            using(MainClient service = new MainClient())
            {
                cake = service.GetCakeByID(cakeID);
                ingredientList = service.GetIngredientsByCakeID(cakeID);

                cake.Ingredient = ingredientList;
            }
            return View(cake);
        }
            private void LoadLiveTransactions(int budgetId, Action<Exception> callback)
            {
                try
                {
                    var client = new MainClient();
                    if (budgetId == 0)
                    {
                        latestState = Guid.NewGuid().ToString();

                        client.GetLatestTransactionsCompleted +=  async (sender, completedEventArgs) => 
                        {
                            if (completedEventArgs.Error == null)
                            {
                                await StorageUtility.DeleteAllItems(TRANSACTIONS_FOLDER, App.Instance.User.UserName);
                                //await delete;
                               //var test = await StorageUtility.ListItems(TRANSACTIONS_FOLDER, App.Instance.User.UserName);

                                await SetupTransactionList(completedEventArgs.Result, true);
                                //await setup;

                                //test = await StorageUtility.ListItems(TRANSACTIONS_FOLDER, App.Instance.User.UserName);


                                callback(null);
                            }
                            else
                                callback(completedEventArgs.Error);
                        };
                        client.GetLatestTransactionsAsync(App.Instance.User.UserId, latestState);
                    }
                    else
                    {
                        //client.GetTransactionsForBudgetCompleted += new EventHandler<GetTransactionsForBudgetCompletedEventArgs>(client_GetTransactionsForBudgetCompleted);
                        client.GetTransactionsForBudgetAsync(budgetId);
                    }
                }
                catch (Exception ex)
                {
                    //var msg = string.Format("There was an error accessing the weather service.\n\r{0}", ex.Message);
                    callback(ex);
                }
            }
Exemplo n.º 35
0
 private void rdoTest_Checked(object sender, RoutedEventArgs e)
 {
     mainClient = new MainClient("BasicHttpBinding_IMain");
 }
 private void LoadLiveBudgets(Action<Exception> callback)
 {
     try
     {
         latestState = Guid.NewGuid().ToString();
         var client = new MainClient();
         client.GetAllBudgetsCompleted += async (sender, e) =>
             {
                 if (e.Error == null)
                 {
                     await StorageUtility.DeleteAllItems(BUDGETS_FOLDER, App.Instance.User.UserName);
                     await SetupBudgetList(e.Result, true);
                 }
                 callback(e.Error);
             };
         client.GetAllBudgetsAsync(App.Instance.User.UserId);
     }
     catch (Exception ex)
     {
         //var msg = string.Format("There was an error accessing the weather service.\n\r{0}", ex.Message);
         callback(ex);
     }
 }
            private void LoadLiveReportTransactionAmount(DateTime dateFrom, DateTime dateTo, int transTypeId, double amountFrom, double amountTo,
                                                            Action<ObservableCollection<Transaction>, Exception> callback)
            {
                try
                {
                    var client = new MainClient();
                    client.ReportTransactionAmountAsync(dateFrom, dateTo, transTypeId, amountFrom, amountTo, App.Instance.User.UserId);

                    client.ReportTransactionAmountCompleted += (sender, e) =>
                    {
                        if (e.Error == null)
                            callback(e.Result, null);
                        else
                            callback(null, e.Error);
                    };
                }
                catch (Exception)
                {

                    throw;
                }
            }
            public void LoadAllTransactionImages(int transactionId, Action<Exception> callback)
            {
                //ICollection<TransactionImage> existing = null;

                App.Instance.StaticDataOnlineStatus = App.Instance.StaticServiceData.SetServerStatus(status =>
                {
                    if (status != Model.StaticServiceData.ServerStatus.Ok)
                    {
                        //## doesn't need to get anything from cache. Images are retrieved by the transaction
                        callback(null);
                    }
                    else
                    {
                        try
                        {
                            var client = new MainClient();
                            latestState = Guid.NewGuid().ToString();

                            client.GetImagesForTransactionCompleted += (sender, completedEventArgs) =>
                            {
                                if (completedEventArgs.Error == null)
                                    SetupTransactionImageList(completedEventArgs.Result, transactionId);

                                callback(completedEventArgs.Error);
                            };
                            client.GetImagesForTransactionAsync(transactionId, latestState);
                        }
                        catch (Exception ex)
                        {
                            //var msg = string.Format("There was an error accessing the weather service.\n\r{0}", ex.Message);
                            callback(ex);
                        }
                    }
                });
            }
            public void GetLatestTransactionDate(Action<DateTime, Exception> callback)
            {
                try
                {
                    var client = new MainClient();
                    client.GetLatestTransactionDateAsync();

                    client.GetLatestTransactionDateCompleted += (sender, e) =>
                    {
                        if (e.Error == null)
                            callback(e.Result, null);
                        else
                            callback(DateTime.Now, e.Error);
                    };
                }
                catch (Exception ex)
                {
                    callback(DateTime.Now, ex);
                }
            }
            public void SyncBudgets(Action<Exception> callback)
            {
                try
                {
                    BudgetList.Clear();

                    App.Instance.ServiceData.LoadCachedBudgets((cachedBudgets, error) =>
                        {
                            var budgetList = cachedBudgets.Where(x => x.ModifiedDate > App.Instance.LastSyncDate).ToObservableCollection();

                            var client = new MainClient();

                            client.SyncBudgetsAsync(budgetList);

                            client.SyncBudgetsCompleted += async (sender, e) =>
                            {
                                if (e.Error == null)
                                    await SetupBudgetList(e.Result, true);

                                callback(e.Error);
                            };
                        });
                }
                catch (Exception ex)
                {
                    callback(ex);
                }
            }
            public void SaveTransactionImages(ObservableCollection<TransactionImage> transactionImages)
            {
                App.Instance.StaticServiceData.SetServerStatus(status =>
                {
                    //continue with local if status is ok but is pending Sync
                    if (status != Model.StaticServiceData.ServerStatus.Ok || !App.Instance.IsSync)
                    {
                        foreach (var item in TransactionImageList.Where(x => x.HasChanges))
                            item.HasChanges = false;

                        //await UpdateCacheTransactionImages();

                        App.Instance.IsSync = false;
                    }
                    else
                    {
                        var client = new MainClient();
                        client.SaveTransactionImagesAsync(transactionImages);
                        client.SaveTransactionImagesCompleted += (sender, completedEventArgs) =>
                        {
                            if (completedEventArgs.Error == null)
                            {
                                //SetupTransactionImageList(completedEventArgs.Result);
                                
                                //Only update sync when offline and in login and main pages
                                //App.Instance.IsSync = true;
                            }
                        };
                    }
                });
            }
            public void SaveBudgets(ObservableCollection<Budget> budgets, Action<Exception> callback)
            {
                App.Instance.StaticServiceData.SetServerStatus(async status =>
                {
                    //continue with local if status is ok but is pending Sync
                    if (status != Model.StaticServiceData.ServerStatus.Ok || !App.Instance.IsSync)
                    {
                        try
                        {
                            foreach (var item in BudgetList.Where(x => x.HasChanges))
                                item.HasChanges = false;

                            await SetupBudgetList(budgets, false);

                            App.Instance.IsSync = false;

                            callback(null);
                        }
                        catch (Exception ex)
                        {
                            callback(ex);
                        }
                    }
                    else
                    {
                        var client = new MainClient();
                        client.SaveBudgetsAsync(budgets);
                        client.SaveBudgetsCompleted += async (sender, completedEventArgs) =>
                        {
                            if (completedEventArgs.Error == null)
                            {
                                await SetupBudgetList(completedEventArgs.Result, true);

                                //Only update sync when offline and in login and main pages
                                //App.Instance.IsSync = true;

                                callback(null);
                            }
                            else
                                callback(completedEventArgs.Error);
                        };
                    }
                });
            }
            private void LoadLiveReportTransactionByPeriod(DateTime dateFrom, DateTime dateTo, int transTypeId, Const.ReportPeriod period,
                                                            Action<Dictionary<int, double>, Exception> callback)
            {
                try
                {
                    var client = new MainClient();
                    client.ReportTransactionByPeriodAsync(dateFrom, dateTo, transTypeId, period, App.Instance.User.UserId);

                    client.ReportTransactionByPeriodCompleted += (sender, e) =>
                    {
                        if (e.Error == null)
                            callback(e.Result, null);
                        else
                            callback(null, e.Error);
                    };
                }
                catch (Exception)
                {
                    throw;
                }
            }
            public void GetLatestTransactionDateDouble(Action<double, Exception> callback)
            {
                try
                {
                    var client = new MainClient();
                    client.GetLatestTransactionDateDoubleAsync(App.Instance.User.UserId);

                    client.GetLatestTransactionDateDoubleCompleted += (sender, e) =>
                    {
                        callback(e.Result, e.Error);
                    };
                }
                catch (Exception)
                {

                    throw;
                }
            }
            public ServerStatus SetServerStatus(Action<ServerStatus> callback)
            {
                var result = ServerStatus.Communicating;
                try
                {
                    var client = new MainClient();
                    client.GetDBStatusAsync();
                    client.GetDBStatusCompleted += (sender, e) =>
                    {
                        if (e.Error != null)
                            result = ServerStatus.Error;
                        else if (e.Result)
                            result = ServerStatus.Ok;
                        else
                            result = ServerStatus.Error;

                        callback(result);
                    };
                }
                catch (Exception)
                {
                    //throw;
                    result = ServerStatus.Error;
                }
                return result;
            }