Exemplo n.º 1
0
        private async Task ReloadProfileListAsync(ProfilesFile.SelectedProfile selectedProfile = ProfilesFile.SelectedProfile.Current)
        {
            var selectedIndex = Profiles.SelectedProfileIndex;

            await Profiles.ReloadAsync(selectedProfile);

            if (Controls.Count == 0)
            {
                return;
            }

            ComboBox_CurrentProfile.DataSource = Profiles.ToArray();
            switch (selectedProfile)
            {
            case ProfilesFile.SelectedProfile.Current:
                ComboBox_CurrentProfile.SelectedIndex = selectedIndex;
                break;

            case ProfilesFile.SelectedProfile.First:
                ComboBox_CurrentProfile.SelectedIndex = Profiles.Any() ? 0 : -1;
                break;

            case ProfilesFile.SelectedProfile.Last:
                ComboBox_CurrentProfile.SelectedIndex = Profiles.Any() ? Profiles.Count() - 1 : -1;
                break;
            }
        }
Exemplo n.º 2
0
        public void AddNewProfileHandler()
        {
            var profilename = Microsoft.VisualBasic.Interaction.InputBox("Profile Name", "Add a new profile");

            if (string.IsNullOrEmpty(profilename) || Profiles.Any(x => x.Name == profilename))
            {
                return;
            }

            var newprofile = new Profile {
                Name = profilename
            };

            Profiles.Add(newprofile);

            var model = new TeamNotifierModel {
                AutoDelete            = Model.AutoDelete,
                MaxMessages           = Model.MaxMessages, User = Model.User,
                SoundNotificationType = Model.SoundNotificationType, Room = ""
            };
            var commands = new ObservableCollectionEx <CommandViewModel>();

            lock (m_ConfigurationLock)
                SaveConfiguration(newprofile.Name, model, commands);

            SelectedProfile = newprofile;
        }
Exemplo n.º 3
0
        public void AddProfile(TwitterProfile profile, int occurrence)
        {
            if (Profiles.Any(p => p.Name == profile.Name))
            {
                return;
            }

            ProfileOccurances.Add(new ProfileOccurrance(profile, this, occurrence));
        }
Exemplo n.º 4
0
 private void UpdateAddProfileCommandCanExecute()
 {
     if (!string.IsNullOrEmpty(_newProfileName) && !Profiles.Any(prof => prof.NameProfile == _newProfileName))
     {
         AddProfileCommand.CanBeExecuted = true;
     }
     else
     {
         AddProfileCommand.CanBeExecuted = false;
     }
 }
        public void CreateNewProfile(string name)
        {
            if (Profiles.Any(e => e.Name == name))
            {
                return;
            }
            MouseProfileModel profile = Service.GetDefaultMouseProfile();

            profile.Name = name;
            Profiles.Add(profile);
        }
Exemplo n.º 6
0
 public bool AddNewProfile(MyomiProfile toAdd)
 {
     //first, check to see if there are duplicated names
     if (Profiles.Any(profile => profile.Key == toAdd.Name))
     {
         return(false);
     }
     this.Profiles.Add(toAdd.Name, toAdd.ID);
     //after we add it, we would like to set the focus to this profile
     this.CurrentProfile = toAdd;
     return(true);
 }
Exemplo n.º 7
0
        public async Task <SshProfile> SelectProfile()
        {
            if (!Profiles.Any())
            {
                await _dialogService.ShowMessageDialogAsnyc("SSH Profile Selection", "There are no saved SSH Profiles.",
                                                            DialogButton.OK);

                return(null);
            }

            return(await ShowAsync() == ContentDialogResult.Primary ? SelectedProfile : null);
        }
Exemplo n.º 8
0
        public LoadOnceTag()
        {
            if (Profiles == null)
            {
                Profiles = new List <LoadProfileOnce>();
            }
            else if (!Profiles.Any())
            {
                Profiles = new List <LoadProfileOnce>();
            }

            GameEvents.OnGameJoined += TrinityLoadOnce_OnGameJoined;
        }
Exemplo n.º 9
0
        private void UpdateXmlFromData(PomXmlDocument pom)
        {
            var root = pom.Root;

            base.SaveToElement(root);

            pom.SetElementValue("packaging", Packaging);
            pom.SetElementValue("name", Name);
            pom.SetElementValue("modelVersion", ModelVersion);

            //writing parent
            var parentNode = pom.ReadOrCreateElement("parent");

            if (Parent == null)
            {
                parentNode.Remove();
            }
            else
            {
                ((ParentReference)Parent).SaveToElement(parentNode);
            }

            _container.SaveToElement(root);

            //writing profiles
            var profileNode = pom.ReadOrCreateElement("profiles");

            if (!Profiles.Any())
            {
                profileNode.Remove();
            }
            else
            {
                HashSet <PomXmlElement> usedElements = new HashSet <PomXmlElement>();
                foreach (Profile prof in Profiles)
                {
                    var profElement = profileNode.Elements.FirstOrDefault(e => e.ReadElementValue("id") == prof.Id) ??
                                      profileNode.CreateElement("profile");

                    usedElements.Add(profElement);
                    prof.SaveToElement(profElement);
                }

                //delete all profiles elements which are not in the Profiles array
                foreach (var profElem in profileNode.Elements.Where(e => !usedElements.Contains(e)))
                {
                    profElem.Remove();
                }
            }
        }
Exemplo n.º 10
0
        private void _settings(object parameter)
        {
            SettingsViewModel SettingsVM = new SettingsViewModel(SelectedProfile);

            OnPropertyChanged("Profiles");
            if (SelectedProfile != null)
            {
                if (!Profiles.Any(x => x.Id == SelectedProfile.Id))
                {
                    SelectedProfile = null;
                }
            }


            _mainWindow.Topmost = Configuration.Instance.AlwaysOnTop;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the profiles for the user
        /// </summary>
        /// <returns></returns>
        public async Task GetProfilesAsync()
        {
            IsBusy = true;

            // Call the api and get some data!
            try
            {
                var resp = await KryptPadApi.GetProfilesAsync();

                // Create instance to credential locker
                var locker = new PasswordVault();

                // Clear the profiles list
                Profiles.Clear();
                // Add the profiles to the list
                foreach (var profile in resp.Profiles)
                {
                    var profileModel = new ProfileModel(profile)
                    {
                        WindowsHelloEnabled = HasSavedPassphrase(locker, profile.Id.ToString())
                    };

                    // Add profile to list
                    Profiles.Add(profileModel);
                }

                // Set the selected profile.
                // TODO: Make this restore last selected profile... somehow
                //SelectedProfile = Profiles.FirstOrDefault();

                // If we don't have any profiles, hide the selection
                ProfileSelectionVisible = Profiles.Any() ? Visibility.Visible : Visibility.Collapsed;
            }
            catch (WebException ex)
            {
                // Something went wrong in the api
                await DialogHelper.ShowMessageDialogAsync(ex.Message);
            }
            catch (Exception ex)
            {
                // Failed
                await DialogHelper.ShowGenericErrorDialogAsync(ex);
            }

            IsBusy = false;
        }
        /// <summary>
        /// A helper method to subscribe to MVVM events
        /// </summary>
        private void SubscribeEvents()
        {
            // Subscribe to adding event
            _eventAggregator.GetEvent <AddHotspotUserProfileEvent>().Subscribe(async vm =>
            {
                // Check if the profile is already exists
                if (Profiles.Any(p => p.Name == vm.Name))
                {
                    _eventAggregator.GetEvent <NotificationEvent>().Publish(new NotificationEventArgs("This profile is already exists!"));
                    return;
                }

                // Set the commands
                vm.SelectionChangedCommand = SharedItemSelectionChangedCommand;
                vm.DeleteProfileCommand    = SharedDeleteProfileCommand;

                // Adding local method
                Task <bool> Add() => _hotspotClient.AddProfileAsync(vm.UserProfileModel);

                // Executing the local method and get the result
                var done = await Add();
                var msg  = done ? "Profile Add Successfully!" : "Unable To Add The Profile!";

                // Show a notification
                _eventAggregator.GetEvent <NotificationEvent>().Publish
                (
                    new NotificationEventArgs
                    (
                        msg, done ? "DISMISS" : "RETRY",
                        done ? null : new Action(async() => await Add()),
                        new SideNotificationViewModel("Hotspot User Profiles", msg)
                    )
                );

                // Add the profile to the list
                if (done)
                {
                    Profiles.Add(vm);
                }
            });
        }
Exemplo n.º 13
0
        public bool Add(Profile input)
        {
            if (input != null)
            {
                var var1 = new DirectoryInfo(input.GameFolder.FullName);
                var var2 = new DirectoryInfo(input.StorageFolder.FullName);
                if (var1.Exists && var2.Exists)
                {
                    if (!Profiles.Any(item => item.ProfileName == input.ProfileName))
                    {
                        Profiles.Add(input);
                        ActiveProfile = input;
                    }
                    else
                    {
                        int index = -1;
                        foreach (Profile p in Profiles)
                        {
                            if (p.ProfileName == input.ProfileName)
                            {
                                index = Profiles.IndexOf(p);
                            }
                        }
                        if (index >= 0)
                        {
                            Profiles.RemoveAt(index);
                            Profiles.Add(input);
                            ActiveProfile = input;
                        }
                    }
                    if (ChangedProfilesEvent != null)
                    {
                        ChangedProfilesEvent();
                    }
                    SaveProfilesToConfig();

                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 14
0
        public async Task LoadProfilesAsync(bool isLatest)
        {
            lock (_locker)
            {
                if (IsLoading.Value)
                {
                    return;
                }

                IsLoading.TurnOn();
            }

            Debug.WriteLine("Load start!");

            try
            {
                var oldProfileIndices = Enumerable.Range(0, Profiles.Count).Reverse().ToList();                 // Reverse method is to start removing from the tail.
                var newProfiles       = new List <ProfileItem>();

                foreach (var newProfile in await _worker.GetProfilesAsync(isLatest, _loadingTimeoutDuration))
                {
                    var isExisting = false;

                    for (int index = 0; (index < Profiles.Count) && !isExisting; index++)
                    {
                        var oldProfile = Profiles[index];
                        if (!oldProfile.Id.Equals(newProfile.Id, StringComparison.Ordinal))
                        {
                            continue;
                        }

                        // Copy changeable values.
                        oldProfile.Position    = newProfile.Position;
                        oldProfile.IsAutomatic = newProfile.IsAutomatic;
                        oldProfile.Signal      = newProfile.Signal;
                        oldProfile.IsConnected = newProfile.IsConnected;

                        oldProfileIndices.Remove(index);
                        isExisting = true;
                    }

                    if (!isExisting)
                    {
                        newProfiles.Add(newProfile);
                    }
                }

                oldProfileIndices.ForEach(x => Profiles.RemoveAt(x));
                newProfiles.ForEach(x => Profiles.Add(x));

                // Calculate count of positions for each interface.
                Profiles
                .GroupBy(x => x.InterfaceId)
                .ToList()
                .ForEach(profilesGroup =>
                {
                    var count = profilesGroup.Count();

                    foreach (var profile in profilesGroup)
                    {
                        profile.PositionCount = count;
                    }
                });

                Debug.WriteLine(Profiles.Any()
                                        ? Profiles
                                .Select(x => $"Profile {x.Name} -> Position: {x.Position}, AutoConnection {x.IsAutomatic}, Signal: {x.Signal}, IsConnected {x.IsConnected}")
                                .Aggregate((work, next) => work + Environment.NewLine + next)
                                        : "No Profile");
            }
            finally
            {
                IsLoading.TurnOff();
            }
        }
Exemplo n.º 15
0
 public bool IsInProfile(string profile)
 {
     return(Profiles.Any() && Profiles.Any(x => x.Trim().Equals(profile.Trim(), StringComparison.CurrentCultureIgnoreCase)));
 }
Exemplo n.º 16
0
 public bool HasProfile(int profileid)
 {
     return(Profiles.Any() && Profiles.Contains(profileid.ToString()));
 }
Exemplo n.º 17
0
        private async Task LoadProfilesBaseAsync()
        {
            var oldProfileIndices = Enumerable.Range(0, Profiles.Count).ToList();
            var newProfiles       = new List <ProfileItem>();

            foreach (var newProfile in await _worker.GetProfilesAsync())
            {
                var isExisting = false;

                foreach (int index in oldProfileIndices)
                {
                    var oldProfile = Profiles[index];
                    if (string.Equals(oldProfile.Id, newProfile.Id, StringComparison.Ordinal))
                    {
                        isExisting = true;
                        oldProfile.Copy(newProfile);
                        oldProfileIndices.Remove(index);
                        break;
                    }
                }

                if (!isExisting)
                {
                    newProfiles.Add(newProfile);
                }
            }

            if ((oldProfileIndices.Count > 0) || (newProfiles.Count > 0))
            {
                lock (_profilesLock)
                {
                    oldProfileIndices.Reverse();                     // Reverse indices to start removing from the tail.
                    oldProfileIndices.ForEach(x => Profiles.RemoveAt(x));
                    newProfiles.ForEach(x => Profiles.Add(x));
                }

                // Calculate count of positions for each interface.
                Profiles
                .GroupBy(x => x.InterfaceId)
                .ToList()
                .ForEach(subProfiles =>
                {
                    var count = subProfiles.Count();

                    foreach (var profile in subProfiles)
                    {
                        profile.PositionCount = count;
                    }
                });
            }

            Debug.WriteLine(Profiles.Any()
                                ? Profiles
                            .Select(x => $"Profile {x.Name} -> AutoConnect: {x.IsAutoConnectEnabled}, AutoSwitch: {x.IsAutoSwitchEnabled}, Position: {x.Position}, IsRadioOn: {x.IsRadioOn}, Signal: {x.Signal}, IsConnected {x.IsConnected}")
                            .Aggregate((work, next) => work + Environment.NewLine + next)
                                : "No Profile");

            if (EngagesPriority.Value)
            {
                var targetProfiles = Profiles
                                     .GroupBy(x => x.InterfaceId)
                                     .Where(subProfiles => subProfiles.All(x => !x.IsConnected || x.IsAutoSwitchEnabled))
                                     .Select(subProfiles => subProfiles
                                             .Where(x => x.IsAutoSwitchEnabled && (Settings.Current.SignalThreshold <= x.Signal))
                                             .OrderBy(x => x.Position)
                                             .FirstOrDefault())
                                     .Where(x => (x != null) && !x.IsConnected)
                                     .ToArray();

                if (targetProfiles.Length > 0)
                {
                    await Task.WhenAll(targetProfiles.Select(x => ConnectNetworkAsync(x, false)));
                }
            }
        }
Exemplo n.º 18
0
        public async Task SeedProfiles()
        {
            if (!Profiles.Any())
            {
                var user = await this.Users.FirstAsync(u => u.Email == "*****@*****.**");

                if (user != null)
                {
                    var locality = Localities.FirstOrDefault(l => l.Name == "București, sector 2");

                    var profile = new Profile()
                    {
                        Id        = user.Id,
                        BirthDate = new DateTime(1975, 3, 14),
                        FirstName = "Răzvan Daniel",
                        LastName  = "Ștefănescu",
                        PhoneNo   = "+40726767769",
                    };

                    var address1 = new Address()
                    {
                        Profile   = profile,
                        Contact   = "Răzvan Ștefănescu",
                        IsDefault = true,
                        Locality  = locality,
                        Text      = "Șos. Ștefan cel Mare nr. 48, bl. 35A, sc. A, et. 2, ap. 7",
                        Latitude  = 44.4525947,
                        Longitude = 26.1141650
                    };

                    var address2 = new Address()
                    {
                        Profile   = profile,
                        Contact   = "Răzvan Ștefănescu",
                        IsDefault = true,
                        Locality  = locality,
                        Text      = "Bd. Dimitrie Pompeiu nr. 6E, et. 5",
                        Latitude  = 44.4811764,
                        Longitude = 26.1188864,
                    };

                    Addresses.AddRange(address1, address2);
                    Profiles.Add(profile);
                }

                user = await this.Users.FirstAsync(u => u.Email == "*****@*****.**");

                if (user != null)
                {
                    var profile = new Profile()
                    {
                        Id        = user.Id,
                        BirthDate = new DateTime(1990, 4, 14),
                        FirstName = "Petru Mihail",
                        LastName  = "Marincea",
                        PhoneNo   = "++40754025905",
                    };

                    var locality = Localities.FirstOrDefault(l => l.Name == "București, sector 3");

                    var address1 = new Address()
                    {
                        Profile   = profile,
                        Contact   = "Mihai Marincea",
                        IsDefault = true,
                        Locality  = locality,
                        Text      = "Str. Vlad Județul nr. 8, bl. V11",
                        Latitude  = 44.4196964,
                        Longitude = 26.1276043,
                    };

                    locality = Localities.FirstOrDefault(l => l.Name == "București, sector 2");

                    var address2 = new Address()
                    {
                        Profile   = profile,
                        Contact   = "Mihai Marincea",
                        IsDefault = true,
                        Locality  = locality,
                        Text      = "Bd. Dimitrie Pompeiu nr. 6E, et. 5",
                        Latitude  = 44.4811764,
                        Longitude = 26.1188864,
                    };

                    Addresses.AddRange(address1, address2);
                    Profiles.Add(profile);
                }
            }
        }