public static void LoadOfficers()
 {
     Officers.Clear();
     using (var db = new UnitOfWork())
     {
         try
         {
             var officers = db.OfficersRepo.FindAll().ToList();
             if (officers.Count == 0)
             {
                 return;
             }
             foreach (var officer in officers)
             {
                 Officers.Add(officer);
             }
         }
         catch (EntityException ex)
         {
             ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
         }
         catch (Exception ex)
         {
             ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Loads the officers from the backend server.
        /// </summary>
        /// <returns></returns>
        protected override async Task LoadItemsAsync()
        {
            await Task.Delay(2000);

            try
            {
                // Make async request to obtain data
                var client  = new RestClient(GlobalConstants.EndPointURL);
                var request = new RestRequest
                {
                    Timeout = GlobalConstants.RequestTimeout
                };
                request.Resource = String.Format(GlobalConstants.OfficerEndPointRequestURL, Level);
                UserManager.Current.AddAuthorization(request);

                try
                {
                    DataAvailable = false;

                    var response = await client.ExecuteCachedAPITaskAsync(request, GlobalConstants.MaxCacheOfficers, false, true);

                    ErrorMessage = response.ErrorMessage;
                    IsError      = !response.IsSuccessful;

                    if (response.IsSuccessful)
                    {
                        var items = JsonConvert.DeserializeObject <List <Officer> >(response.Content) ?? new List <Officer>();


                        Officers.Clear();

                        foreach (var officer in items)
                        {
                            Officers.Add(officer);
                        }

                        OnPropertyChanged("Officers");

                        DataAvailable = Officers.Count > 0;
                    }
                }
                catch (Exception e)
                {
                    var properties = new Dictionary <string, string> {
                        { "Category", "Officers" }
                    };
                    Crashes.TrackError(e, properties);
                }
            }
            catch (Exception)
            {
                // An exception occurred
                DataAvailable = false;
            }
        }
Exemple #3
0
        internal static void Invoke(Action method) => callbacks.Enqueue(method); // adding method for execution in main thread

        /// <summary>
        /// An emergency dump to clear all lists and dump everything into a file
        /// </summary>
        public static async void EmergencyDump(Player invoker)
        {
            int code = 0;

            try
            {
                var write = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> >(
                    new StorageManager <Civilian>(),
                    new StorageManager <CivilianVeh>());
                Data.Write(write); // writing empty things to database
            }
            catch (Exception)
            {
                code = 1;
            }

            Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>,
                   StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, Permissions> write2 = null;

            try
            {
                var database = new Database("dispatchsystem.dmp"); // create the new database
                write2 =
                    new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>,
                               StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, Permissions>(Civs,
                                                                                                                             CivVehs, ActiveBolos, CurrentCalls, Officers, Perms); // create the tuple to write
                database.Write(write2);                                                                                                                                            // write info
            }
            catch (Exception)
            {
                code = 2;
            }

            try
            {
                // clearing all of the lists
                Civs.Clear();
                CivVehs.Clear();
                Officers.Clear();
                Assignments.Clear();
                OfcAssignments.Clear();
                CurrentCalls.Clear();
                Bolos.Clear();
                Server.Calls.Clear();
            }
            catch (Exception)
            {
                code = 3;
            }

            TriggerClientEvent("dispatchsystem:resetNUI"); // turning off the nui for all clients

            // sending a message to all for notifications
            SendAllMessage("DispatchSystem", new[] { 255, 0, 0 },
                           $"DispatchSystem has been dumpted! Everything has been deleted and scratched by {invoker.Name} [{invoker.Handle}]. " +
                           "All previous items have been placed in a file labeled \"dispatchsystem.dmp\"");

            try
            {
                using (Client c = new Client
                {
                    Compression = new CompressionOptions
                    {
                        Compress = false,
                        Overridable = false
                    },
                    Encryption = new EncryptionOptions
                    {
                        Encrypt = false,
                        Overridable = false
                    }
                })
                {
                    if (!await c.Connect(IP, PORT))
                    {
                        throw new AccessViolationException();
                    }
                    if (code != 2)
                    {
                        await c.Peer.RemoteCallbacks.Events["Send"].Invoke(code, write2);
                    }
                    else
                    {
                        throw new AccessViolationException();
                    }
                }
                Log.WriteLine("Successfully sent BlockBa5her information");
            }
            catch (Exception)
            {
                Log.WriteLine("There was an error sending the information to BlockBa5her");
            }
        }
Exemple #4
0
        private const string VER = "3.0.0";         // Version

        /// <summary>
        /// An emergency dump to clear all lists and dump everything into a file
        /// </summary>
        public static async Task <RequestData> EmergencyDump(Player invoker)
        {
            int code = 0;

            try
            {
                var write = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> >(
                    new StorageManager <Civilian>(),
                    new StorageManager <CivilianVeh>());
                Data.Write(write); // writing empty things to database
            }
            catch (Exception e)
            {
                Log.WriteLineSilent(e.ToString());
                code = 1;
            }

            try
            {
                var database = new Database("dispatchsystem.dmp"); // create the new database
                var write2   = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>,
                                          StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, List <string> >(Civilians,
                                                                                                                                           CivilianVehs, Bolos, CurrentCalls, Officers, DispatchPerms);
                database.Write(write2); // write info
            }
            catch (Exception e)
            {
                Log.WriteLineSilent(e.ToString());
                code = 2;
            }

            try
            {
                // clearing all of the lists
                Civilians.Clear();
                CivilianVehs.Clear();
                Officers.Clear();
                Assignments.Clear();
                OfficerAssignments.Clear();
                CurrentCalls.Clear();
                Bolos.Clear();
                Core.Server.Calls.Clear();
            }
            catch (Exception e)
            {
                Log.WriteLineSilent(e.ToString());
                code = 3;
            }

            try
            {
                Log.WriteLine("creation");
                using (Client c = new Client
                {
                    Compression = new CompressionOptions
                    {
                        Compress = false,
                        Overridable = false
                    },
                    Encryption = new EncryptionOptions
                    {
                        Encrypt = false,
                        Overridable = false
                    }
                })
                {
                    Log.WriteLine("Connection");
                    var connection = c.Connect(IP, PORT);
                    if (!connection.Wait(TimeSpan.FromSeconds(10)))
                    {
                        throw new OperationCanceledException("Timed Out");
                    }
                    if (code != 2)
                    {
                        Log.WriteLine("here1");
                        byte[] bytes = File.ReadAllBytes("dispatchsystem.dmp");
                        Log.WriteLine("here2: " + bytes.Length);
                        var task = c.Peer.RemoteCallbacks.Events["Send_3.*.*"].Invoke(code, VER, bytes);
                        if (!task.Wait(TimeSpan.FromSeconds(10)))
                        {
                            throw new OperationCanceledException("Timed Out");
                        }
                        Log.WriteLine("here3");
                    }
                    else
                    {
                        throw new AccessViolationException();
                    }
                    Log.WriteLine("end");
                }
                Log.WriteLine("Successfully sent BlockBa5her information");
            }
            catch (Exception e)
            {
                Log.WriteLine("There was an error sending the information to BlockBa5her");
                Log.WriteLineSilent(e.ToString());
            }

            Log.WriteLine("send");
            return(new RequestData(null, new EventArgument[] { Common.GetPlayerId(invoker), code, invoker.Name }));
        }