void OnListItemClick(object sender, AdapterView.ItemClickEventArgs e) { View selectedItem = profilesListView.GetChildAt(e.Position); SyncProfile selectedProfile = SyncProfilesHandler.AvailableProfilesList[e.Position]; var menu = new PopupMenu(this, selectedItem); menu.Inflate(Resource.Layout.popup_menu); menu.MenuItemClick += (s, a) => { switch (a.Item.ItemId) { case Resource.Id.pop_button1: SyncProfilesHandler.DeleteProfile(selectedProfile.ProfileName); profilesListView.Adapter = new ProfilesListAdapter(this, SyncProfilesHandler.AvailableProfilesList); break; case Resource.Id.pop_button2: if (SyncProfilesHandler.SelectedProfilesList.Any( profile => profile.ProfileName == selectedProfile.ProfileName)) { SyncProfilesHandler.SelectedProfilesList.Remove(selectedProfile); selectedItem.SetBackgroundColor(Color.Black); } else { SyncProfilesHandler.SelectedProfilesList.Add(selectedProfile); selectedItem.SetBackgroundColor(Color.Gray); } break; } }; menu.Show(); }
public void ProcessingProfile(SyncProfile profile) { //streamHandler.SendString(profile.ProfileName); syncService = new Synchroniser(new FolderHandler(profile.ProfileSyncFolderPath)); syncService.Synchronise(streamHandler); SyncProfilesHandler.UpdateProfile(profile); }
/// <summary> /// Creates new sync profile using entered name and selected folder. /// </summary> static public bool AddNewProfile(string name, string path) { SyncProfile newProfile = new SyncProfile(name, path, DateTime.Now.ToString()); SaveProfile(newProfile); LoadProfiles(); return(true); }
/// <summary> /// Saves new created profile to local store. /// </summary> static void SaveProfile(SyncProfile profile) { string profileInfo = profile.ProfileName + "|" + profile.ProfileSyncFolderPath + "|" + profile.SyncDateTime + Environment.NewLine; if (File.Exists(syncProfilesStore)) { File.AppendAllText(syncProfilesStore, profileInfo, Encoding.UTF8); } else { File.WriteAllText(syncProfilesStore, profileInfo, Encoding.UTF8); } }
/// <summary> /// Creates new sync profile using entered name and selected folder. /// </summary> static public bool AddNewProfile(string name, string path, Activity currentActivity) { SyncProfile newProfile = new SyncProfile(name, path, DateTime.Now.ToString()); if (CheckInputData(newProfile, currentActivity)) { LoadProfiles(); return(true); } else { return(false); } }
/// <summary> /// Validates input name and folder to avoid the similar profiles. /// </summary> static bool CheckInputData(SyncProfile newProfile, Activity currentActivity) { if (newProfile.ProfileName == "" || newProfile.ProfileSyncFolderPath == "") { MessageDisplayer.ShowAlertMessage(currentActivity, "Ошибка добавления профиля", "Попытка создать профиль с пустым именем и/или пустым каталогом."); return(false); } else { if (AvailableProfilesList.Count != 0) { if (AvailableProfilesList.Any(profile => profile.ProfileName == newProfile.ProfileName)) { MessageDisplayer.ShowAlertMessage(currentActivity, "Ошибка добавления профиля", "Профиль с введеным именем уже существует.Пожалуйста, введите другое имя."); return(false); } else if (AvailableProfilesList.Any(profile => profile.ProfileSyncFolderPath == newProfile.ProfileSyncFolderPath)) { MessageDisplayer.ShowAlertMessage(currentActivity, "Ошибка добавления профиля", "Профиль с выбранным каталогом уже существует.Пожалуйста, выберите другой каталог."); return(false); } else { SaveProfile(newProfile); return(true); } } else { SaveProfile(newProfile); return(true); } } }
/// <summary> /// Updates profile's date and time of the synchronization. /// </summary> static public void UpdateProfile(SyncProfile profile) { DeleteProfile(profile.ProfileName); AddNewProfile(profile.ProfileName, profile.ProfileSyncFolderPath); }