コード例 #1
0
        //------------------------------------
        // Session List Management Functions
        //------------------------------------

        /// <summary>
        /// Delete session
        /// <summary>
        private async Task <bool> DeleteSession(SessionInfo session)
        {
            bool isSuccess = false;

            try
            {
                StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                string        fullpath    = Path.Combine(localFolder.Path, SiteProfileManager.GetFullPath(App.SiteProfileId, session.profilePath));

                StorageFile targetFile = await StorageFile.GetFileFromPathAsync(fullpath);

                if (targetFile != null)
                {
                    await targetFile.DeleteAsync();
                }
                sessionConfig.sessions.Remove(session);
                await SiteProfileManager.DefaultSiteProfileManager?.SaveSessionConfig();

                isSuccess = true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("DeleteSession Exception! " + ex.Message);
            }
            return(isSuccess);
        }
コード例 #2
0
        public static async Task <SiteProfileManager> Open(string profileId, bool createIfNotExist = false)
        {
            if (String.IsNullOrEmpty(profileId))
            {
                return(null);
            }

            bool isSuccess = await OpenSiteProfileFolder(profileId, createIfNotExist);

            if (isSuccess)
            {
                SiteProfileManager siteManager = new SiteProfileManager(profileId);
                isSuccess = await siteManager.LoadSessionConfig();

                if (isSuccess)
                {
                    Debug.WriteLine("InitSiteManager success!");
                }
                else
                {
                    Debug.WriteLine("InitSiteManager failed!");
                }
                return(siteManager);
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Rename session
        /// <summary>
        private async Task <bool> RenameSession(string targetName, SessionInfo session)
        {
            bool isSuccess = false;

            try
            {
                StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                string        filepath    = Path.Combine(localFolder.Path, SiteProfileManager.GetFullPath(App.SiteProfileId, session.profilePath));

                StorageFile targetFile = await StorageFile.GetFileFromPathAsync(filepath);

                string targetFilename = String.Format("session_{0}.config.json", targetName);

                if (targetFile != null)
                {
                    await targetFile.RenameAsync(targetFilename, NameCollisionOption.FailIfExists);
                }
                session.sessionName = targetName;
                session.profilePath = targetFilename;

                await SiteProfileManager.DefaultSiteProfileManager?.SaveSessionConfig();

                isSuccess = true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("RenameSession Exception! " + ex.Message);
            }
            return(isSuccess);
        }
コード例 #4
0
        /// <summary>
        /// On save button clicked
        /// -- save server connection settings and node subscription list
        ///    and exit this page, get back to main page
        /// <summary>
        private async void btnSave_Button_Click(object sender, RoutedEventArgs e)
        {
            EnableSessionOpButtons(false);
            OpcuaSessionConfig config         = null;
            var          sessionname          = m_design_session.SessionName;
            const string PROFILENAME_TEMPLATE = "session_{0}.json";

            if (sessionMgmtAction == SESSIONMGMT_ACTION.NEW)
            {
                sessionname = txtSessionName.Text;

                if (String.IsNullOrEmpty(sessionname))
                {
                    MessageDialog showDialog = new MessageDialog("Session Name must not be empty or duplicated.\nPlease enter a unique session name.");
                    showDialog.Commands.Add(new UICommand("OK")
                    {
                        Id = 1
                    });
                    showDialog.DefaultCommandIndex = 1;
                    showDialog.CancelCommandIndex  = 1;
                    var result = await showDialog.ShowAsync();

                    EnableSessionOpButtons(true);
                    return;
                }

                m_sessionConfig_full_path = Path.Combine(m_local, SiteProfileManager.GetFullPath(App.SiteProfileId, String.Format(PROFILENAME_TEMPLATE, sessionname)));
                while (File.Exists(m_sessionConfig_full_path))
                {
                    var timestamp = DateTime.Now.ToString("_yyMMddHHmmss");
                    sessionname = txtSessionName.Text + timestamp;
                    m_sessionConfig_full_path = Path.Combine(m_local, SiteProfileManager.GetFullPath(App.SiteProfileId, String.Format(PROFILENAME_TEMPLATE, sessionname)));
                }
            }
            config = SaveSessionConfig(m_sessionConfig_full_path, sessionname, m_design_session);

            if (config != null)
            {
                try
                {
                    if (sessionMgmtAction == SESSIONMGMT_ACTION.NEW)
                    {
                        sessionInfo.profilePath = String.Format(PROFILENAME_TEMPLATE, sessionname);
                        sessionInfo.sessionName = sessionname;
                        sessionInfo.sourceType  = m_design_session.Endpoint.Server.ApplicationName.ToString();
                        SiteProfileManager.DefaultSiteProfileManager.sessionConfig.sessions.Add(sessionInfo);
                        await SiteProfileManager.DefaultSiteProfileManager.SaveSessionConfig();
                    }
                    CloseSessionView_OpcuaClient();
                    Frame.Navigate(typeof(SessionMgmtPage), "RELOAD");
                }
                catch (Exception ex)
                {
                    Utils.Trace(ex, "SessionMgmt_OpcuaPage.btnSave_Button_Click() Exception: " + ex.Message);
                }
            }
            EnableSessionOpButtons(true);
        }
コード例 #5
0
        /// <summary>
        /// Load profile information from app storage
        /// </summary>
        private async Task OpenSiteProfile(bool forceRelad = false, bool createIfNotExist = false)
        {
            string             newSiteProfileId = App.SiteProfileId;
            SiteProfileManager curSiteProfile   = SiteProfileManager.DefaultSiteProfileManager;

            if (curSiteProfile != null && (forceRelad || newSiteProfileId != curSiteProfile.SiteProfileId))
            {
                SiteProfileManager.SetDefault(null);
                curSiteProfile = null;
            }
            if (curSiteProfile == null)
            {
                curSiteProfile = await SiteProfileManager.Open(newSiteProfileId, createIfNotExist);

                SiteProfileManager.SetDefault(curSiteProfile);
            }
        }
コード例 #6
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);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// On export-publishednodes button clicked
        //  -- generate "publishednodes.json" file to target file path
        /// <summary>
        private async void btnExportPublishedNodes_Click(object sender, RoutedEventArgs e)
        {
            if (sessionConfig?.sessions?.Count > 0)
            {
            }
            else
            {
                MessageDialog showDialog = new MessageDialog("No Node for Publishing!");
                showDialog.Commands.Add(new UICommand("Close")
                {
                    Id = 1
                });
                showDialog.DefaultCommandIndex = 1;
                showDialog.CancelCommandIndex  = 1;
                await showDialog.ShowAsync();

                return;
            }

            var picker = new Windows.Storage.Pickers.FileSavePicker();

            picker.SuggestedFileName      = SiteProfileManager.DEFAULT_PUBLISHEDNODESPATH;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Downloads;
            picker.FileTypeChoices.Add("JSON", new List <string>()
            {
                ".json"
            });

            StorageFile destfile = await picker.PickSaveFileAsync();

            if (destfile != null)
            {
                try
                {
                    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                    bool          isSuccess   = await SiteProfileManager.DefaultSiteProfileManager?.SavePublishedNodes();

                    if (isSuccess)
                    {
                        var         srcuri  = new Uri("ms-appdata:///local/" + SiteProfileManager.GetFullPath(App.SiteProfileId, SiteProfileManager.DEFAULT_PUBLISHEDNODESPATH));
                        StorageFile srcfile = await StorageFile.GetFileFromApplicationUriAsync(srcuri);

                        await srcfile.CopyAndReplaceAsync(destfile);

                        MessageDialog showDialog = new MessageDialog("Export PublisherNodes Done!\n" + destfile.Path);
                        showDialog.Commands.Add(new UICommand("Close")
                        {
                            Id = 1
                        });
                        showDialog.DefaultCommandIndex = 1;
                        showDialog.CancelCommandIndex  = 1;
                        await showDialog.ShowAsync();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("btnExportPublishedNodes_Click Exception! " + ex.Message);
                    MessageDialog showDialog = new MessageDialog("Export PublishedNodes Failed!\nError: " + ex.Message);
                    showDialog.Commands.Add(new UICommand("Close")
                    {
                        Id = 1
                    });
                    showDialog.DefaultCommandIndex = 1;
                    showDialog.CancelCommandIndex  = 1;
                    await showDialog.ShowAsync();
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// On page loaded
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            App.unclosedSession = this;

            sessionInfo = e.Parameter as SessionInfo;

            if (sessionInfo == null)
            {
                sessionMgmtAction         = SESSIONMGMT_ACTION.NEW;
                sessionInfo               = new SessionInfo();
                sessionInfo.sessionName   = "";
                sessionInfo.profilePath   = "";
                sessionInfo.sourceType    = "";
                m_sessionConfig_full_path = "";
                m_sessionConfig           = null;
            }
            else
            {
                m_sessionConfig_full_path = Path.Combine(m_local, SiteProfileManager.GetFullPath(App.SiteProfileId, sessionInfo.profilePath));
                // json configuration
                m_sessionConfig = OpcuaSessionConfig.LoadFromJsonFile(m_sessionConfig_full_path);
            }


            ApplicationInstance      application   = OpcuaSessionConfig.OpcuaApplication;
            ApplicationConfiguration configuration = application.ApplicationConfiguration;
            ServiceMessageContext    context       = configuration.CreateMessageContext();

            if (!configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
            {
                configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
            }

            m_context       = context;
            m_application   = application;
            m_configuration = configuration;

            SessionsCTRL.Configuration    = configuration;
            SessionsCTRL.MessageContext   = context;
            SessionsCTRL.AddressSpaceCtrl = BrowseCTRL;
            SessionsCTRL.NodeSelected    += SessionCtrl_NodeSelected;


            // disable cached endpoints from Opc.Ua.SampleClient.Config.xml
            //// get list of cached endpoints.
            //m_endpoints = m_configuration.LoadCachedEndpoints(true);
            m_endpoints = new ConfiguredEndpointCollection();
            m_endpoints.DiscoveryUrls = configuration.ClientConfiguration.WellKnownDiscoveryUrls;

            // work around to fill Configuration and DiscoveryUrls
            if (m_sessionConfig != null)
            {
                m_sessionConfig.endpoint.Configuration = EndpointConfiguration.Create(m_configuration);
                m_sessionConfig.endpoint.Description.Server.DiscoveryUrls.Add(m_sessionConfig.endpoint.EndpointUrl.AbsoluteUri.ToString());
                m_endpoints.Add(m_sessionConfig.endpoint);
            }

            // hook up endpoint selector
            EndpointSelectorCTRL.Initialize(m_endpoints, m_configuration);
            EndpointSelectorCTRL.ConnectEndpoint  += EndpointSelectorCTRL_ConnectEndpoint;
            EndpointSelectorCTRL.EndpointsChanged += EndpointSelectorCTRL_OnChange;

            BrowseCTRL.SessionTreeCtrl = SessionsCTRL;
            BrowseCTRL.NodeSelected   += BrowseCTRL_NodeSelected;

            btnDelSubscription.IsEnabled = false;
            btnAddSubscription.IsEnabled = false;

            btnDelSubscription.Click += ContextMenu_OnDelete;
            btnAddSubscription.Click += ContextMenu_OnReport;

            // exception dialog
            GuiUtils.ExceptionMessageDlg += ExceptionMessageDlg;

            EndpointSelectorCTRL.IsEnabled = false;
            BrowseCTRL.IsEnabled           = false;
            SessionsCTRL.IsEnabled         = false;

            txtSessionName.Text = sessionInfo.sessionName;

            if (sessionMgmtAction == SESSIONMGMT_ACTION.NEW)
            {
                txtSessionName.IsReadOnly      = false;
                btnReload.IsEnabled            = false;
                btnReload.Visibility           = Visibility.Collapsed;
                EndpointSelectorCTRL.IsEnabled = true;
            }
            else
            {
                if (m_sessionConfig == null)
                {
                    txtSessionName.IsReadOnly      = true;
                    EndpointSelectorCTRL.IsEnabled = true;
                    btnReload.IsEnabled            = false;
                }
                else
                {
                    txtSessionName.IsReadOnly = true;
                    btnReload.IsEnabled       = false;
                    var ignored = Task.Run(OpenSessionView_OpcuaClient);
                }
            }
        }
コード例 #9
0
        public static async Task <bool> OpenSiteProfileFolder(string profileid, bool createIfNotExist = false)
        {
            bool          isExisted  = false;
            StorageFolder baseFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

            try
            {
                if (createIfNotExist)
                {
                    StorageFolder sitesFolder = await baseFolder.CreateFolderAsync(PROFILEROOT, CreationCollisionOption.OpenIfExists);

                    StorageFolder siteFolder = await sitesFolder.CreateFolderAsync(profileid, CreationCollisionOption.OpenIfExists);

                    if (siteFolder != null)
                    {
                        StorageFile settingsFile = null;
                        try
                        {
                            settingsFile = await siteFolder.GetFileAsync(DEFAULT_SESSIONCONFIGPATH);
                        }
                        catch (Exception e)
                        {
                            Utils.Trace(e, "SiteProfileManager.OpenSiteProfileFolder() Exception: " + e.Message);
                        }

                        if (settingsFile == null)
                        {
                            SiteProfileManager siteManager = new SiteProfileManager(App.SiteProfileId);
                            await siteManager.SaveSessionConfig(null);
                        }

                        isExisted = true;
                    }
                }
                else
                {
                    StorageFolder sitesFolder = await baseFolder.GetFolderAsync(PROFILEROOT);

                    StorageFolder siteFolder = await sitesFolder.GetFolderAsync(profileid);

                    if (siteFolder != null)
                    {
                        StorageFile settingsFile = null;
                        try
                        {
                            settingsFile = await siteFolder.GetFileAsync(DEFAULT_SESSIONCONFIGPATH);

                            if (settingsFile != null)
                            {
                                isExisted = true;
                            }
                        }
                        catch (Exception e)
                        {
                            Utils.Trace(e, "SiteProfileManager.OpenSiteProfileFolder() Exception: " + e.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.Trace(ex, "SiteProfileManager.OpenSiteProfileFolder() Exception: " + ex.Message);
            }
            return(isExisted);
        }
コード例 #10
0
 public static void SetDefault(SiteProfileManager siteManager)
 {
     DefaultSiteProfileManager = siteManager;
 }