public void LoadSettings()
 {
     this.UserName = BsaContext.GetUserName();
     this.Url      = $"http://{BsaContext.GetURL()}:8081";
     this.Role     = BsaContext.GetUserRole();
     this.IP       = AddressResolving.GetIp4AddressesString();
 }
 public async Task <bool> ShutDownServer(string ip, uint port)
 {
     try
     {
         Thread.Sleep(30000);
         this.Clients.All.ChangeServer(ip, port);
         Server.ShutDown();
         if (await CommunicationProxy.ConnectToServer(ip, port))
         {
             BsaContext.Initialize(ip, BsaContext.GetUserName(), ApplicationRole.Client);
             MessageBox.Show("Sie sind jetz nicht mehr Server, sondern nur noch Client!");
             return(true);
         }
         else
         {
             MessageBox.Show("Der Wechsel hat nicht funktioniert! Bitte starten Sie neu und verbinden sich manuell!");
             Cursor.Current = Cursors.Default;
             return(false);
         }
     }
     catch (SystemException e)
     {
         return(false);
     }
 }
        private void SaveToDatabase()
        {
            this.Force.History.Add(this.force.IsNew
                ? new HistoryItem(BsaContext.GetUserName(), $"Neue Einheit angelegt: {this.Force.Name}")
                : new HistoryItem(BsaContext.GetUserName(), $"Einheit {this.Force.Name} modifiziert"));

            //this.AddPersonsHistoryItems();
            this.forceService.SaveForces(this.Force);
        }
Exemplo n.º 4
0
        private void SaveToDatabase()
        {
            this.Job.History.Add(this.Job.IsNew
                ? new HistoryItem(BsaContext.GetUserName(), $"Neuer Auftrag angelegt: {this.Job.Description}")
                : new HistoryItem(BsaContext.GetUserName(), $"Auftrag {this.Job.Description} modifiziert"));
            this.jobService.SaveJob(this.Job);

            // ToDo: This does not fall within the remit of the presentation layer. Implementation should lie in an IJobService instance instead!
            ////CommunicationProxy.SendJobChange(BsaContext.GetUserName(), this.job);
        }
        public void SaveJob(Job job)
        {
            if (BsaContext.GetUserRole() != ApplicationRole.Standalone)
            {
                CommunicationProxy.SendJobChange(job);
            }

            if (BsaContext.GetUserRole() != ApplicationRole.Client)
            {
                this.SaveJobLocal(job);
            }
        }
Exemplo n.º 6
0
        public void SaveForces(Force forces)
        {
            if (BsaContext.GetUserRole() != ApplicationRole.Standalone)
            {
                CommunicationProxy.SendForceChanged(forces);
            }

            if (BsaContext.GetUserRole() != ApplicationRole.Client)
            {
                this.SaveForcesLocal(forces);
            }
        }
        private void SaveToDatabase()
        {
            //var differenceQuery = assignedForcesList.Except(SelectedJob.Forces);
            //var differenceQueryList = differenceQuery as IList<Force> ?? differenceQuery.ToList();

            //if (SelectedJob.Forces.Count == 0 && differenceQueryList.Any()
            //    && this.SelectedJob.JobStatus == JobState.NewCreated)
            //{
            //    this.SelectedJob.JobStatus = JobState.InProgress;
            //}

            //if (! differenceQueryList.Any())
            //    return;

            foreach (var force in assignedForcesList)
            {
                if (!this.SelectedJob.Forces.Contains(force.Id))
                {
                    this.SelectedJob.Forces.Add(force.Id);
                    this.selectedJob.History.Add(new HistoryItem(BsaContext.GetUserName(), $"Einheit: {force.Name} {System.Environment.NewLine} zu Auftrag: {this.selectedJob.Description} hinzugefügt"));

                    if (Properties.Settings.Default.AutomaticallySetJobInProgressAfterForceAssignment)
                    {
                        if (this.SelectedJob.Forces.Count >= 1 && this.SelectedJob.JobStatus == JobState.NewCreated)
                        {
                            this.SelectedJob.JobStatus = JobState.InProgress;
                        }
                    }

                    this.jobService.SaveJob(this.SelectedJob);
                }
            }

            foreach (var force in availableForcesList)
            {
                if (this.SelectedJob.Forces.Contains(force.Id))
                {
                    if (this.SelectedJob.Forces.Count >= 1)
                    {
                        this.SelectedJob.Forces.Remove(force.Id);
                        this.selectedJob.History.Add(new HistoryItem(BsaContext.GetUserName(), $"Einheit: {force.Name} {System.Environment.NewLine} von Auftrag: {this.selectedJob.Description} entfernt"));
                        this.jobService.SaveJob(this.SelectedJob);
                    }
                }
            }
        }
        private void AddPersonsHistoryItems()
        {
            foreach (var person in this.Force.Persons)
            {
                var unmodifiedPendant = this.personsUnmodified.FirstOrDefault(x => x.Id == person.Id);
                if (unmodifiedPendant == null)
                {
                    // the person doesn't seem to exist on the unmodified list. That means, this is a new person!
                    person.History.Add(new HistoryItem(BsaContext.GetUserName(),
                                                       $"Person {person.Prename} {person.Surname} in Einheit {this.Force.Name} erstellt"));
                    return;
                }

                var changes = Comparison.GetChanges(person, unmodifiedPendant);
                if (changes.Count > 0)
                {
                    person.History.Add(new HistoryItem(BsaContext.GetUserName(),
                                                       $"Person {unmodifiedPendant.Prename} {unmodifiedPendant.Surname} in Einheit {this.Force.Name} modifiziert"));
                }
            }
        }
Exemplo n.º 9
0
        private void SaveToDatabase()
        {
            this.forceService.SaveForces(this.SelectedForce);

            foreach (var Job in this.assignedJobsList)
            {
                if (!Job.Forces.Contains(this.selectedForce.Id))
                {
                    Job.Forces.Add(this.selectedForce.Id);
                    Job.History.Add(new HistoryItem(BsaContext.GetUserName(),
                                                    $"Auftrag: {Job.Description} {Environment.NewLine} zu Einheit: {this.selectedForce.Name} hinzugefügt"));

                    if (Settings.Default.AutomaticallySetJobInProgressAfterForceAssignment)
                    {
                        if (Job.Forces.Count >= 1 && Job.JobStatus == JobState.NewCreated)
                        {
                            Job.JobStatus = JobState.InProgress;
                        }
                    }
                    this.jobService.SaveJob(Job);
                }
            }

            foreach (var Job in this.availableJobsList)
            {
                if (Job.Forces.Contains(this.selectedForce.Id))
                {
                    if (Job.Forces.Count >= 1)
                    {
                        Job.Forces.Remove(this.selectedForce.Id);
                        Job.History.Add(new HistoryItem(BsaContext.GetUserName(),
                                                        $"Auftrag: {Job.Description} {Environment.NewLine} von Einheit: {this.selectedForce.Name} entfernt"));
                        this.jobService.SaveJob(Job);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public static bool PermitServerChange()
        {
            var user = BsaContext.GetUserName();

            return(HubProxy.Invoke <bool>("MayGetServer", user).Result);
        }
        public async void CreateDummyData()
        {
            //this.jobService.SaveJob(new Job(BSA.Database.SampleData.SampleJobs.SampleJob1));
            //this.jobService.SaveJob(new Job(BSA.Database.SampleData.SampleJobs.SampleJob2));
            //this.jobService.SaveJob(new Job(BSA.Database.SampleData.SampleJobs.SampleJob3));
            //this.LoadData();

            var randomWords = await DummyDataHelper.GetRandomWords(2000);

            var dummyDataCount = 100;
            var random         = new Random();

            for (var i = 0; i < dummyDataCount; i++)
            {
                var day = await DummyDataHelper.GetRandomNumber(1, 28, random);

                var month = await DummyDataHelper.GetRandomNumber(1, 12, random);

                var year = await DummyDataHelper.GetRandomNumber(1950, 2050, random);

                var hour = await DummyDataHelper.GetRandomNumber(0, 23, random);

                var minute = await DummyDataHelper.GetRandomNumber(0, 59, random);

                var second = await DummyDataHelper.GetRandomNumber(0, 59, random);

                var date = new DateTime(year, month, day, hour, minute, second);

                var job = new Job
                {
                    Name              = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 5, random),
                    Date              = date,
                    Messenger         = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 2, random),
                    Organization      = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 5, random),
                    Communicationtool = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 1, random),
                    Location          = new JobLocation
                    {
                        Street                = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 2, random),
                        HouseNumber           = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 1, random),
                        ZipCode               = (await DummyDataHelper.GetRandomNumber(111111, 999999, random)).ToString(),
                        City                  = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 1, random),
                        FloorLevel            = (await DummyDataHelper.GetRandomNumber(0, 50, random)).ToString(),
                        AdditionalDescription = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 20, random)
                    },
                    JobType             = DummyDataHelper.GetRandomEnumValue <JobType>(random).ToString(),
                    NumberInjuredPerson = await DummyDataHelper.GetRandomNumber(0, 250, random),
                    Description         = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 20, random),
                    JobPriority         = DummyDataHelper.GetRandomEnumValue <JobPriority>(random),
                    JobStatus           = DummyDataHelper.GetRandomEnumValue <JobState>(random)
                };

                job.History.Add(job.IsNew
                    ? new HistoryItem(BsaContext.GetUserName(), $"Neuer Auftrag angelegt: {job.Description}")
                    : new HistoryItem(BsaContext.GetUserName(), $"Auftrag #1  ({job.Description}) modifiziert"));
                this.jobService.SaveJob(job);
            }


            //var job1 = new Job
            //{
            //    Name = "This is the job name",
            //    Date = DateTime.Now,
            //    Messenger = "Leitstelle",
            //    Organization = "Microsoft",
            //    Communicationtool = "Internet",
            //    Location = new JobLocation
            //    {
            //        Street = "Schaezlerstraße",
            //        HouseNumber = "30",
            //        ZipCode = "86152",
            //        City = "Augsburg",
            //        FloorLevel = "3",
            //        AdditionalDescription = "Kein Aufzug vorhanden!"
            //    },
            //    JobType = JobType.Fire.ToString(),
            //    NumberInjuredPerson = 3,
            //    Description = "Backofen wurde nicht ausgeschaltet",
            //    JobPriority = JobPriority.High,
            //    JobStatus = JobState.InProgress
            //};

            //var job2 = new Job
            //{
            //    Name = "This is the job name",
            //    Date = DateTime.Now,
            //    Messenger = "Random person",
            //    Organization = "HS AUgsburg",
            //    Communicationtool = "Brieftaube",
            //    Location = new JobLocation
            //    {
            //        Street = "Friedberger Straße",
            //        HouseNumber = "12",
            //        ZipCode = "86150",
            //        City = "Augsburg",
            //        FloorLevel = "3",
            //        AdditionalDescription = "Raum W3.18"
            //    },
            //    JobType = JobType.Flooding.ToString(),
            //    NumberInjuredPerson = 7,
            //    Description = "Wasserflasche ist umgefallen",
            //    JobPriority = JobPriority.Medium,
            //    JobStatus = JobState.NewCreated
            //};

            //this.jobs.Add(job1);
            //this.jobs.Add(job2);
        }
            public DisconnectMessageBox()
            {
                this.reconnectButton.Text    = @"Erneut verbinden";
                this.getServerButton.Text    = @"Server werden";
                this.connectOtherButton.Text = @"Mit anderem Server verbinden";

                this.reconnectButton.Click += async(a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    var success = await CommunicationProxy.ConnectToServer(BsaContext.GetURL(), 8081);

                    if (success)
                    {
                        this.Close();
                    }

                    this.ChangeButtonIsEnabled(true);
                };

                this.getServerButton.Click += (a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    if (UacHelper.RestartWithAdminRights("") == false)
                    {
                        this.ChangeButtonIsEnabled(true);
                        return;
                    }

                    Process.GetCurrentProcess().Kill();
                };

                this.connectOtherButton.Click += async(a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    var success = await this.ConnectToServerAsync();

                    if (success == false)
                    {
                        this.ChangeButtonIsEnabled(true);
                    }
                    else
                    {
                        this.Close();
                    }
                };

                var l = new Label {
                    Text = @"Die Verbindung zum Server ist getrennt. Was möchten Sie jetzt tun?"
                };

                l.SetBounds(100, 30, 450, 50);
                this.reconnectButton.SetBounds(50, 100, 150, 50);
                this.getServerButton.SetBounds(250, 100, 150, 50);
                this.connectOtherButton.SetBounds(450, 100, 150, 50);

                this.connectOtherButton.Anchor = this.connectOtherButton.Anchor | AnchorStyles.Right;
                this.reconnectButton.Anchor    = AnchorStyles.Bottom | AnchorStyles.Right;
                this.getServerButton.Anchor    = AnchorStyles.Bottom | AnchorStyles.Right;
                this.Text       = @"Fehler";
                this.ClientSize = new Size(650, 200);
                this.Controls.AddRange(new Control[] { l, this.reconnectButton, this.getServerButton, this.connectOtherButton });
                this.FormBorderStyle = FormBorderStyle.FixedDialog;
                this.StartPosition   = FormStartPosition.CenterScreen;
                this.MinimizeBox     = false;
                this.MaximizeBox     = false;

                this.ShowDialog();
            }
Exemplo n.º 13
0
        public async void CreateDummyData()
        {
            var randomWords = await DummyDataHelper.GetRandomWords(2000);

            var dummyDataCount = 100;
            var random         = new Random();

            for (var i = 0; i < dummyDataCount; i++)
            {
                var persons     = new ObservableCollection <Person>();
                var personCount = await DummyDataHelper.GetRandomNumber(1, 50, random);

                for (var ii = 0; ii < personCount; ii++)
                {
                    var day = await DummyDataHelper.GetRandomNumber(1, 28, random);

                    var month = await DummyDataHelper.GetRandomNumber(1, 12, random);

                    var year = await DummyDataHelper.GetRandomNumber(1930, 2005, random);

                    var hour = await DummyDataHelper.GetRandomNumber(0, 23, random);

                    var minute = await DummyDataHelper.GetRandomNumber(0, 59, random);

                    var second = await DummyDataHelper.GetRandomNumber(0, 59, random);

                    var date = new DateTime(year, month, day, hour, minute, second);

                    var person = new Person
                    {
                        Prename          = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 1, random),
                        Surname          = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 1, random),
                        RadioCallName    = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 3, random),
                        BirthDate        = date,
                        Additional       = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 10, random),
                        Street           = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 5, random),
                        ZipCode          = (await DummyDataHelper.GetRandomNumber(111111, 999999, random)).ToString(),
                        Employer         = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 3, random),
                        PhoneNumber      = (await DummyDataHelper.GetRandomNumber(10000, 1000000, random)).ToString(),
                        RelativesDetails = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 20, random),
                    };
                    persons.Add(person);
                }

                var force = new Force
                {
                    Name      = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 3, random),
                    RadioName = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 3, random),
                    Leader    = persons[await DummyDataHelper.GetRandomNumber(0, persons.Count, random)],
                    Persons   = persons,
                    Vehicle   = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 5, random),
                    Notes     = await DummyDataHelper.GetRandomWordsFromList(randomWords, 1, 10, random)
                };

                force.History.Add(force.IsNew
                    ? new HistoryItem(BsaContext.GetUserName(), $"Neue Einheit angelegt: {force.Name}")
                    : new HistoryItem(BsaContext.GetUserName(), $"Einheit ({force.Name}) modifiziert"));
                this.forceService.SaveForces(force);
            }

            //var sniper = new Person {Prename = "Chris", Surname = "Kyle", RadioCallName = "Peacemaker"};
            //var diver = new Person {Prename = "Colonel", Surname = "Sanders", RadioCallName = "The chicken"};
            //var cook = new Person {Prename = "Old", Surname = "McDonald", RadioCallName = "Mealmaker"};

            //var force = new Force
            //{
            //    Name = "US Navy",
            //    RadioName = "The Sharks",
            //    Leader = sniper,
            //    Persons = new ObservableCollection<Person>{sniper, cook, diver},
            //    Vehicle = "Submarine",
            //    Notes = "Incompetent"
            //};

            //var force2Leader = new Person {Prename = "Marvin", Surname = "Reiter", RadioCallName = "Mj"};
            //var force2 = new Force
            //{
            //    Name = "Mj-petworld",
            //    RadioName = "The petguy",
            //    Leader = force2Leader,
            //    Persons = new ObservableCollection<Person> { force2Leader},
            //    Vehicle = "Chopper",
            //    Notes = "Competent"
            //};

            //this.forces.Add(force);
            //this.forces.Add(force2);

            //this.forceService.SaveForces(new Force(SampleForces.SampleForce1));
            //this.forceService.SaveForces(new Force(SampleForces.SampleForce2));
            //this.forceService.SaveForces(new Force(SampleForces.SampleForce3));
        }