Esempio n. 1
0
        /// <summary>
        /// On delete-session menu item clicked
        /// -- confirm to delete target session
        /// <summary>
        private async void DeleteSession_Click(object sender, RoutedEventArgs e)
        {
            MenuFlyoutItem    itemViewDetail    = sender as MenuFlyoutItem;
            SessionStatusInfo sessionStatusInfo = itemViewDetail.DataContext as SessionStatusInfo;

            MessageDialog showDialog = new MessageDialog("This will delete settings in this session.\nAre you sure to delete session - '" + sessionStatusInfo.Name + "' ?");

            showDialog.Commands.Add(new UICommand("Delete")
            {
                Id = 0
            });
            showDialog.Commands.Add(new UICommand("Cancel")
            {
                Id = 1
            });
            showDialog.DefaultCommandIndex = 1;
            showDialog.CancelCommandIndex  = 1;
            var result = await showDialog.ShowAsync();

            if ((int)result.Id == 0)
            {
                bool isDeleted = await DeleteSession(sessionStatusInfo.Session);

                if (isDeleted)
                {
                    int delIndex = listviewSessionStatus.SelectedIndex;
                    listviewSessionStatus.SelectedIndex = delIndex - 1;
                    listviewSessionStatus.Items.RemoveAt(delIndex);
                    listviewSessionStatus.UpdateLayout();

                    listSessionStatus.Remove(sessionStatusInfo);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// On menu button clicked
        /// -- show flyout menu function
        /// <summary>
        private async void Menu_Click(object sender, RoutedEventArgs e)
        {
            Button btnMenu = sender as Button;

            //ListViewItem thisItem = FindVisualParent<ListViewItem>(sender as Button);
            listviewSessionStatus.SelectedItem = btnMenu.DataContext as SessionStatusInfo;

            if ((btnMenu.Tag as string) == "Save")
            {
                btnMenu.Flyout.Hide();

                SessionStatusInfo sessionStatusInfo = btnMenu.DataContext as SessionStatusInfo;
                TextBox           txtSessionName    = RenameSessionEnable(false, sessionStatusInfo);

                string targetName = txtSessionName?.Text;
                if (targetName == sessionStatusInfo.Name)
                {
                    return;
                }

                await RenameSessionSave(targetName, sessionStatusInfo);
            }
            else
            {
                btnMenu.Flyout.ShowAt(btnMenu);
            }
        }
Esempio n. 3
0
        //----------------------
        // UI Event Handlers
        //----------------------

        /// <summary>
        /// On view-session-detail/edit-session menu item clicked
        /// -- navigate to Opcua session page for detail viewing & editing
        /// <summary>
        private void ViewSessionDetail_Click(object sender, RoutedEventArgs e)
        {
            MenuFlyoutItem    itemViewDetail    = sender as MenuFlyoutItem;
            SessionStatusInfo sessionStatusInfo = itemViewDetail.DataContext as SessionStatusInfo;

            Frame.Navigate(typeof(SessionMgmt_OpcuaPage), sessionStatusInfo.Session);
        }
Esempio n. 4
0
        /// <summary>
        /// Enable selected session on UI to allow session rename
        /// <summary>
        private TextBox RenameSessionEnable(bool enable, SessionStatusInfo sessionStatusInfo)
        {
            ListViewItem curItem = null;

            foreach (ListViewItem item in listviewSessionStatus.ItemsPanelRoot.Children)
            {
                if (item.Content.Equals(sessionStatusInfo))
                {
                    curItem = item;
                    break;
                }
            }

            if (curItem != null)
            {
                TextBox tbSessionName = null;
                Button  btnFunc       = null;
                foreach (UIElement uielem in (curItem.ContentTemplateRoot as Grid).Children)
                {
                    if ((uielem as TextBox)?.Name == "tbSessionName")
                    {
                        tbSessionName = uielem as TextBox;
                    }
                    else if ((uielem as Button)?.Name == "btnFunc")
                    {
                        btnFunc = uielem as Button;
                    }
                }
                if (enable)
                {
                    if (btnFunc != null)
                    {
                        btnFunc.Tag = "Save";
                        ToolTipService.SetToolTip(btnFunc, "Save");
                        (btnFunc.Content as FontIcon).Glyph = "\uE28F"; // save
                    }
                    if (tbSessionName != null)
                    {
                        tbSessionName.IsReadOnly = false;
                        tbSessionName.Focus(FocusState.Pointer);
                    }
                }
                else
                {
                    if (btnFunc != null)
                    {
                        btnFunc.Tag = "Menu";
                        ToolTipService.SetToolTip(btnFunc, "Function Menu");
                        (btnFunc.Content as FontIcon).Glyph = "\uE10C"; // menu
                    }
                    if (tbSessionName != null)
                    {
                        tbSessionName.IsReadOnly = true;
                    }
                }
                return(tbSessionName);
            }
            return(null);
        }
Esempio n. 5
0
        //----------------------
        // UI Helper Functions
        //----------------------

        /// <summary>
        /// Rename session
        /// <summary>
        private async Task <bool> RenameSessionSave(string targetName, SessionStatusInfo sessionStatusInfo)
        {
            bool hasNameConflict = false;

            foreach (var item in listSessionStatus)
            {
                if (item.Name == targetName && item.Name != sessionStatusInfo.Name)
                {
                    hasNameConflict = true;
                }
            }

            bool isRenamed = false;

            if (hasNameConflict)
            {
                MessageDialog showDialog = new MessageDialog("Session name conflicts with other session!");
                showDialog.Commands.Add(new UICommand("Close")
                {
                    Id = 1
                });
                showDialog.DefaultCommandIndex = 1;
                showDialog.CancelCommandIndex  = 1;
                await showDialog.ShowAsync();
            }
            else
            {
                // confirm rename
                MessageDialog showDialog = new MessageDialog("This will rename this session, and SiteProfile content could be inconsistent.\nAre you sure to rename session from '" + sessionStatusInfo.Name + "' to '" + targetName + "'?");
                showDialog.Commands.Add(new UICommand("Rename")
                {
                    Id = 0
                });
                showDialog.Commands.Add(new UICommand("Cancel")
                {
                    Id = 1
                });
                showDialog.DefaultCommandIndex = 1;
                showDialog.CancelCommandIndex  = 1;
                var result = await showDialog.ShowAsync();

                if ((int)result.Id == 0)
                {
                    isRenamed = await RenameSession(targetName, sessionStatusInfo.Session);

                    if (isRenamed)
                    {
                        sessionStatusInfo.UpdateSessionName(targetName);
                    }
                }
            }
            return(isRenamed);
        }
Esempio n. 6
0
        /// <summary>
        /// On session name textbox got focus
        /// <summary>
        private void tbSessionName_GotFocus(object sender, RoutedEventArgs e)
        {
            TextBox           tbSessionName     = sender as TextBox;
            SessionStatusInfo sessionStatusInfo = tbSessionName.DataContext as SessionStatusInfo;

            Debug.WriteLine("[" + sessionStatusInfo.Name + "] Got Focus " + tbSessionName.IsReadOnly + ", " + tbSessionName.FocusState);

            if (!tbSessionName.IsReadOnly && tbSessionName.FocusState != FocusState.Unfocused && String.IsNullOrEmpty(tbSessionName.Tag as string))
            {
                tbSessionName.LostFocus += tbSessionName_LostFocus;
                tbSessionName.Tag        = "Editing";
                Debug.WriteLine("[" + sessionStatusInfo.Name + "] Enable LostFocus Handler");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// On losing focus at name textbox
        /// -- require user confirmation to save this change or discard the change
        /// <summary>
        private async void tbSessionName_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox           tbSessionName     = sender as TextBox;
            SessionStatusInfo sessionStatusInfo = tbSessionName.DataContext as SessionStatusInfo;

            Debug.WriteLine("[" + sessionStatusInfo.Name + "] Lost Focus " + tbSessionName.IsReadOnly + ", " + tbSessionName.FocusState);
            if (tbSessionName.IsReadOnly)
            {
                return;
            }

            RenameSessionEnable(false, sessionStatusInfo);
            tbSessionName.LostFocus -= tbSessionName_LostFocus;
            tbSessionName.Tag        = null;

            string targetName = tbSessionName.Text;

            if (sessionStatusInfo.Name == targetName)
            {
                return;
            }
            else
            {
                // confirm rename
                MessageDialog showDialog = new MessageDialog("Would you like to save the change?");
                showDialog.Commands.Add(new UICommand("Yes")
                {
                    Id = 0
                });
                showDialog.Commands.Add(new UICommand("No")
                {
                    Id = 1
                });
                showDialog.DefaultCommandIndex = 1;
                showDialog.CancelCommandIndex  = 1;
                var result = await showDialog.ShowAsync();

                if ((int)result.Id == 1)
                {
                    tbSessionName.Text = sessionStatusInfo.Name;
                    return;
                }
            }
            await RenameSessionSave(targetName, sessionStatusInfo);
        }
Esempio n. 8
0
        /// <summary>
        /// On page loaded
        /// <summary>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            SiteProfileManager siteManager = SiteProfileManager.DefaultSiteProfileManager;

            if (siteManager == null)
            {
                siteManager = await SiteProfileManager.Open(App.SiteProfileId);

                SiteProfileManager.SetDefault(siteManager);
            }
            else
            {
                var action = e.Parameter as string;
                if (!String.IsNullOrEmpty(action) && action == "RELOAD")
                {
                    await siteManager.LoadSessionConfig();
                }
            }

            listviewSessionStatus.Items.Clear();

            if (siteManager?.sessionConfig?.sessions != null)
            {
                sessionConfig = siteManager.sessionConfig;
                foreach (var session in sessionConfig.sessions)
                {
                    SessionStatusInfo sessionInfoItem = new SessionStatusInfo()
                    {
                        Name        = session.sessionName,
                        SourceUrl   = String.Format("{0}", session.sourceType.ToString()),
                        Description = String.Empty,
                        Status      = 0,
                        IsActive    = false,
                        Session     = session,
                    };

                    listSessionStatus.Add(sessionInfoItem);
                    listviewSessionStatus.Items.Add(sessionInfoItem);
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// On rename-session menu item clicked
        /// -- allow edit session name on UI (require explicit "save" confirm by user to commit name change)
        /// <summary>
        private void RenameSession_Click(object sender, RoutedEventArgs e)
        {
            SessionStatusInfo sessionStatusInfo = (sender as MenuFlyoutItem).DataContext as SessionStatusInfo;

            RenameSessionEnable(true, sessionStatusInfo);
        }