コード例 #1
0
ファイル: Events.cs プロジェクト: tracid56/DispatchSystem
        public static void AddOfficer(string handle, string callsign)
        {
            Player p = GetPlayerByHandle(handle);

            // checking if civ exists
            if (GetCivilian(handle) != null)
            {
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 },
                            "You cannot be a officer and a civilian at the same time.");
                return;
            }

            // check for officer existing
            if (GetOfficer(handle) == null)
            {
                Officers.Add(new Officer(p.Identifiers["ip"], callsign));                                              // adding new officer
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Assigning new officer for callsign {callsign}"); // msg
#if DEBUG
                SendMessage(p, "", new[] { 0, 0, 0 }, "Creating new Officer profile...");
#endif
            }
            else
            {
                int index = Officers.IndexOf(GetOfficer(handle));                                             // finding the index
                Officers[index] = new Officer(p.Identifiers["ip"], callsign);                                 // setting the index to the specified officer
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Changing your callsign to {callsign}"); // msg
            }
        }
コード例 #2
0
 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);
         }
     }
 }
コード例 #3
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;
            }
        }