Esempio n. 1
0
        /// <summary>
        /// Allows user to progress to a previous page or if at the first page, a previous tab
        /// </summary>
        private async Task Backward()
        {
            var pages   = CurrentTab.Pages;
            var current = CurrentTab.CurrentPage;
            var idx     = pages.IndexOf(current);

            // If not currently on first page for tab then go back one page
            if (idx > 0)
            {
                await CurrentTab.StopAsync();

                CurrentTab.CurrentPage = pages[idx - 1];
                CurrentTab.StartAsync();
                ModifyNavigation();
            }
            // If currently on first page of tab, then go back to the first tab
            // only if user is currently not on first tab
            else if (CurrentTab.Name != "Serial Connection")
            {
                await CurrentTab.StopAsync();

                CurrentTab = _tabs[0];
                CurrentTab.StartAsync();
                ModifyNavigation();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new meter tab, enables backward button to allow user to get back to Serial Page
        /// Enables forward button because first page is Configuration page and can have no modifications
        /// </summary>
        /// <param name="objects">Tuple containing the serial port index and meter serial number</param>
        public void CreateTab(Tuple <string, string> objects)
        {
            // If the tab does not exist, create one otherwise re-open the tab
            var tab = _tabs.Where(x => x.SerialIdx == objects.Item1 && x.MeterSerialNo == objects.Item2).FirstOrDefault();

            if (tab == null)
            {
                Application.Current.Dispatcher.Invoke(async() =>
                {
                    _tabs.Add(new ContentTabViewModel(objects.Item1, objects.Item2));
                    await CurrentTab.StopAsync();
                    CurrentTab = _tabs.Last();
                    CurrentTab.StartAsync();
                    ModifyNavigation();
                    ModifyTabs();
                });
            }
            else
            {
                Application.Current.Dispatcher.Invoke(async() =>
                {
                    tab.Visible = true;
                    await CurrentTab.StopAsync();
                    CurrentTab = tab;
                    CurrentTab.StartAsync();
                    ModifyNavigation();
                    ModifyTabs();
                });
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Progresses the window forward one page or progresses user to different tab in tab control
        /// </summary>
        private async Task Forward()
        {
            // The first tab is a control tab thus it's forward operations are different
            if (_tabs.IndexOf(CurrentTab) == 0)
            {
                // if there are more tabs visible than just the first tab
                // go to the next visible tab
                if (_tabs.Where(x => x.Visible == true).Count() > 1)
                {
                    await CurrentTab.StopAsync();

                    CurrentTab = _tabs[1];
                    CurrentTab.StartAsync();
                    ModifyNavigation();
                }

                // If there are no other visible tabs then assuming that the user now wants to
                // input their credentials into the login screen so they can upload into CRM
                else
                {
                    var pages = CurrentTab.Pages;
                    var page  = CurrentTab.CurrentPage;
                    var idx   = pages.IndexOf(page);

                    if (idx < pages.Count - 1)
                    {
                        await CurrentTab.StopAsync();

                        CurrentTab.CurrentPage = pages[idx + 1];
                        CurrentTab.StartAsync();
                        ModifyNavigation();
                    }
                }
            }
            // if user is on any other tab but the first tab, go to the next page if there are additional pages
            // if user is at last page for this tab, close the tab and progress to login screen if there are no
            // more tabs besides the first tab otherwise do nothing
            else
            {
                var pages   = CurrentTab.Pages;
                var current = CurrentTab.CurrentPage;
                var idx     = pages.IndexOf(current);

                if (idx < pages.Count - 1)
                {
                    await CurrentTab.StopAsync();

                    CurrentTab.CurrentPage = pages[idx + 1];
                    CurrentTab.StartAsync();
                    ModifyNavigation();
                }
                else
                {
                    // Close this tab if we are finished commissioning this meter.
                    await CloseTab(new Tuple <string, string>(CurrentTab.SerialIdx, CurrentTab.MeterSerialNo), true);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Used to start the upload to crm process if the meters have already been commissioned but an
        /// internet connection was not available on site
        /// </summary>
        private async Task StartCRM()
        {
            if (CurrentTab.Name == "Serial Connection")
            {
                var pages   = CurrentTab.Pages;
                var current = CurrentTab.CurrentPage;
                var idx     = pages.IndexOf(current);

                await CurrentTab.StopAsync();

                CurrentTab.CurrentPage = pages[idx + 1];
                CurrentTab.StartAsync();
                ModifyNavigation();
            }
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// Closes the tab that is associated with the serial port that was recently closed
        /// and removes the serial and meter object from the collections that are hosting them
        /// simultaneously saves the meter object. Modifies collections used to control visible
        /// menu tabs
        /// </summary>
        /// <param name="args"></param>
        public async Task CloseTab(Tuple <string, string> args, bool complete = false)
        {
            // Close the comm port if the complete arg is true
            var comms = Globals.Serials;

            if (complete)
            {
                comms[args.Item1].Close();
            }

            // Retrieves the index for the tab in the underlying collection
            var idx = _tabs.FindIndex(t => t.MeterSerialNo == args.Item2);
            var tab = _tabs[idx];

            // Do not remove the first tab if there are other tabs open
            if (_tabs.Where(x => x.Visible == true).Count() > 1 && idx == 0)
            {
                return;
            }

            // "Close" (Hide) the desired tab
            tab.Visible = false;

            // If there are no more visible tabs, close the application and save meter data
            if (_tabs.Where(x => x.Visible == true).Count() == 0)
            {
                ShutdownProcedure();
            }
            // If the current tab is a meter tab and user is viewing this tab
            // Shift to the next open tab and save the meter data for this tab
            else if (CurrentTab == tab)
            {
                string id = CurrentTab.MeterSerialNo;
                await CurrentTab.StopAsync();

                CurrentTab = _tabs[idx - 1];
                CurrentTab.StartAsync();
                ModifyNavigation();
                var meters = Globals.Meters;
                if (complete)
                {
                    meters[id].Commissioned = true;
                }
                meters[id].Save(_toUploadDir);
            }

            ModifyTabs();
        }
Esempio n. 6
0
        /// <summary>
        /// Opens a tab once the user clicks on the tab from the menu
        /// </summary>
        /// <param name="p"></param>
        private async Task OpenTab(string p)
        {
            // Iterates over each tab and once the tab is located sets that tab
            // as the CurrentTab and changes it's visibility value as well as
            // modifying the collections that control which tabs are viewable
            // in the menu and to the user for interaction
            foreach (var tab in _tabs)
            {
                if (tab.MeterSerialNo == p)
                {
                    // Re-establish serial connection, if port is closed
                    var comms = Globals.Serials;
                    foreach (var comm in comms)
                    {
                        if (comm.Value.SerialNo == tab.MeterSerialNo)
                        {
                            if (!comm.Value.IsOpen)
                            {
                                await comm.Value.SetupSerial(comm.Key);
                            }
                            break;
                        }
                    }


                    // Work on visual display for user
                    tab.Visible = true;
                    await CurrentTab.StopAsync();

                    CurrentTab = tab;
                    CurrentTab.StartAsync();
                    ModifyNavigation();
                    ModifyTabs();
                    break;
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Switches the active meter tab after a user has moved the optical port to a different meter
        /// </summary>
        /// <returns></returns>
        public async Task SwitchMeters()
        {
            // Retrieves the serial number of the meter currently attached to the serial port
            string serialIdx    = CurrentTab.SerialIdx;
            string currSerialNo = Serial[serialIdx].SerialNo;
            var    tabs         = _tabs.Where(x => x.MeterSerialNo == currSerialNo);

            CurrentTab.Visible = false;

            // If the meter exists and there is a tab already created for it then switch to that tab
            // and change to Commissioning page
            if (Meters.ContainsKey(currSerialNo) && tabs.Count() == 1)
            {
                await CurrentTab.StopAsync();

                var tab = tabs.ElementAt(0);
                CurrentTab      = tab;
                tab.Visible     = true;
                tab.CurrentPage = tab.Pages[1];
            }
            // If the meter exists (imported) but there is not a tab created for it then create the tab
            // and change to the Commissioning page
            else if (Meters.ContainsKey(currSerialNo))
            {
                await CurrentTab.StopAsync();

                CreateTab(new Tuple <string, string>(serialIdx, currSerialNo));
                CurrentTab.CurrentPage = CurrentTab.Pages[1];
            }
            // If the meter does not exist, create a new meter and a new tab
            // then change to the Commissioning page
            else
            {
                Meter m = new Meter();
                m.ID = currSerialNo;
                Meters.Add(currSerialNo, m);

                // Sets the size of the meter based on the type of meter connected
                string   version = await Serial[serialIdx].GetVersion();
                string[] lines   = version.Split(new char[] { '\n', '\r' }, System.StringSplitOptions.RemoveEmptyEntries);
                if (lines[2].Split(new char[0], System.StringSplitOptions.RemoveEmptyEntries)[1].StartsWith("593"))
                {
                    string[] serials = (await Serial[serialIdx].GetChildSerial()).Split(',');
                    for (int i = 0; i < 12; i++)
                    {
                        m.Channels.Add(new Channel(i + 1));
                        m.Channels[i].Serial = serials[i];
                    }
                }

                await CurrentTab.StopAsync();

                CreateTab(new Tuple <string, string>(serialIdx, currSerialNo));
                CurrentTab.CurrentPage = CurrentTab.Pages[1];
            }

            // Initiate the async processes for the current page and modify navigation buttons
            CurrentTab.StartAsync();
            ModifyNavigation();

            // Modifies the collections that represent which tabs should be visible in the menu and which tabs
            // are present in the tab control for user interaction
            Application.Current.Dispatcher.Invoke(() =>
            {
                ModifyTabs();
            });
        }