public TerminatorDataSelectorPopup(Window parent, CommMedium medium)
 {
     this.parent = parent;
     this.medium = medium;
     InitializeComponent();
     this.SizeToContent = SizeToContent.WidthAndHeight;
 }
        public void GetCodeSample(CommMedium helpType, Action <string> onSuccess, OnErrTitle onError)
        {
            ErrReport report;

            WrapErr.ToErrReport(out report, 9999,
                                () => string.Format(""),
                                () => {
                string filename = this.GetFilename(helpType);
                if (filename.Length > 0)
                {
                    // TODO - Move to cross platform access
                    if (File.Exists(filename))
                    {
                        onSuccess.Invoke(File.ReadAllText(filename));
                        return;
                    }
                }
                onError(this.GetText(MsgCode.Error), "* N/Ax *");
            });
            if (report.Code != 0)
            {
                WrapErr.SafeAction(() => {
                    onError.Invoke(this.GetText(MsgCode.Error), report.Msg);
                });
            }
        }
示例#3
0
 private CommandsPopup(Window parent, CommMedium medium)
 {
     this.parent = parent;
     this.medium = medium;
     InitializeComponent();
     this.SizeToContent = SizeToContent.WidthAndHeight;
 }
示例#4
0
        /// <summary>Do any initialization here. Should be called by window at load</summary>
        public void OnLoad(Window parent, CommMedium medium, RunPageCtrlsEnabled enableList = null)
        {
            this.parent = parent;
            this.medium = medium;
            // TODO - remove the enable list
            if (enableList != null)
            {
                this.btnInfo.SetVisualEnabled(enableList.Info);
                this.btnSettings.SetVisualEnabled(enableList.Settings);
                this.btnConnect.SetVisualEnabled(enableList.Connect);
                this.connectedOff.SetVisualEnabled(enableList.Connect);
                this.connectedOn.SetVisualEnabled(enableList.Connect);
                this.btnDisconnect.SetVisualEnabled(enableList.Disconnect);
                this.btnSend.SetVisualEnabled(enableList.Send);
            }

            this.inScroll  = this.lbIncoming.GetScrollViewer();
            this.logScroll = this.lbLog.GetScrollViewer();
            this.logSection.Collapse();
            this.SetConnectState(false);

            this.AddEventHandlers();
            DI.Wrapper.CurrentSupportedLanguage(this.SetLanguage);
            DI.Wrapper.GetCurrentTerminator(this.medium, this.SetTerminators, App.ShowMsg);
            DI.Wrapper.GetCurrentScript(this.medium, this.PopulateScriptData, App.ShowMsg);
        }
示例#5
0
 public static void Load(CommMedium commHelpType, Action <string> onSuccess, Action <string, string> onErr)
 {
     try {
         var    assembly = IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly;
         string filename = string.Format("{0}.{1}", SAMPLES_RES_PREFIX, GetSimpleFilename(commHelpType));
         Stream stream   = assembly.GetManifestResourceStream(filename);
         if (stream == null)
         {
             Log.Error(9999, "SampleLoader", "Load", () => string.Format("Not found:{0}", filename));
             onErr.Invoke(App.GetText(MsgCode.NotFound), filename);
         }
         else
         {
             using (StreamReader reader = new System.IO.StreamReader(stream)) {
                 string txt = reader.ReadToEnd();
                 if (txt.Length == 0)
                 {
                     onErr.Invoke(App.GetText(MsgCode.NotFound), filename);
                 }
                 else
                 {
                     onSuccess.Invoke(txt);
                 }
             }
         }
     }
     catch (Exception e) {
         Log.Exception(9999, "GetCodeSampleFromResources", "", e);
         onErr.Invoke(App.GetText(MsgCode.Error), App.GetText(MsgCode.LoadFailed));
     }
 }
        private void OnHasCodeSampleView(CommMedium helpType)
        {
            // This to avoid opening the code highlighted box because
            // its control malfunctions with no content
            MsgBoxCode win = new MsgBoxCode(this, helpType);

            win.ShowDialog();
        }
 public MsgBoxCode(Window parent, CommMedium helpType)
 {
     this.parent = parent;
     this.medium = helpType;
     InitializeComponent();
     this.Title = DI.Wrapper.GetText(helpType);
     WrapErr.ToErrReport(9999, () => this.Icon = helpType.ResourceWhiteBitmap());
     //this.codeBox.CurrentHighlighter = HighlighterManager.Instance.Highlighters["CPPDL"];
     this.buttonWidthManager = new ButtonGroupSizeSyncManager(this.btnCopy, this.btnExit);
     this.buttonWidthManager.PrepForChange();
 }
示例#8
0
 private CommHelpDisplay HelpItem(string name, UIIcon icon, CommMedium helpType)
 {
     return(new CommHelpDisplay()
     {
         Display = name,
         HelpType = helpType,
         IconHeight = 16,
         IconWidth = 16,
         IconSource = this.IconSource(icon),
     });
 }
示例#9
0
 private CommMedialDisplay CommItem(string name, UIIcon icon, CommMedium mediumType)
 {
     return(new CommMedialDisplay()
     {
         Display = name,
         IconHeight = 16,
         IconWidth = 16,
         IconSource = this.IconSource(icon),
         MediumType = mediumType
     });
 }
        public void GetCurrentScript(CommMedium medium, Action <ScriptDataModel> onSuccess, OnErr onError)
        {
            WrapErr.ToErrReport(9999, () => {
                ErrReport report;
                WrapErr.ToErrReport(out report, 9999, () => {
                    // Force default creation
                    var x = this.scriptStorage;
                    SettingItems items = this.settings.ReadObjectFromDefaultFile();

                    ScriptDataModel dm = null;
                    switch (medium)
                    {
                    case CommMedium.Bluetooth:
                        dm = items.CurrentScriptBT;
                        break;

                    case CommMedium.BluetoothLE:
                        dm = items.CurrentScriptBLE;
                        break;

                    case CommMedium.Ethernet:
                        dm = items.CurrentScriptEthernet;
                        break;

                    case CommMedium.Usb:
                        dm = items.CurrentScriptUSB;
                        break;

                    case CommMedium.Wifi:
                        dm = items.CurrentScriptWIFI;
                        break;

                    default:
                        dm = items.CurrentScript;
                        break;
                    }
                    if (dm == null)
                    {
                        if (items.CurrentScript == null)
                        {
                            items.CurrentScript = this.AssureScript(new ScriptDataModel());
                        }
                        dm = items.CurrentScript;
                    }
                    onSuccess(dm);
                });
                if (report.Code != 0)
                {
                    onError.Invoke(this.GetText(MsgCode.LoadFailed));
                }
            });
        }
        public void GetCurrentTerminator(CommMedium medium, Action <TerminatorDataModel> onSuccess, OnErr onError)
        {
            WrapErr.ToErrReport(9999, () => {
                ErrReport report;
                WrapErr.ToErrReport(out report, 9999, () => {
                    // Force default creation
                    var x = this.terminatorStorage;
                    SettingItems items = this.settings.ReadObjectFromDefaultFile();

                    TerminatorDataModel dm = null;
                    switch (medium)
                    {
                    case CommMedium.Bluetooth:
                        dm = items.CurrentTerminatorBT;
                        break;

                    case CommMedium.BluetoothLE:
                        dm = items.CurrentTerminatorBLE;
                        break;

                    case CommMedium.Ethernet:
                        dm = items.CurrentTerminatorEthernet;
                        break;

                    case CommMedium.Usb:
                        dm = items.CurrentTerminatorUSB;
                        break;

                    case CommMedium.Wifi:
                        dm = items.CurrentTerminatorWIFI;
                        break;

                    default:
                        dm = items.CurrentTerminator;
                        break;
                    }
                    if (dm == null)
                    {
                        this.log.Error(9999, () => string.Format("Default terminators for {0} not found", medium));
                        dm = items.CurrentTerminator;
                    }
                    dm = this.AssureTerminators(dm);
                    onSuccess(dm);
                });
                if (report.Code != 0)
                {
                    onError.Invoke(this.GetText(MsgCode.LoadFailed));
                }
            });
        }
示例#12
0
        /// <summary>Get the icon corresponding to the Communication Medium Type</summary>
        /// <param name="medium">The medium type</param>
        /// <returns>Icon source string</returns>
        public static string CommMediumSource(this CommMedium medium)
        {
            switch (medium)
            {
            case CommMedium.Bluetooth: return(BluetoothClassic);

            case CommMedium.BluetoothLE: return(BluetoothLE);

            case CommMedium.Ethernet: return(Source(UIIcon.Ethernet));

            case CommMedium.Wifi: return(Source(UIIcon.Wifi));

            default: return(Cancel);
            }
        }
        public void SetCurrentTerminators(TerminatorDataModel data, CommMedium medium, OnErr onError)
        {
            ErrReport report;

            WrapErr.ToErrReport(out report, 2000301, "Failure on SetCurrentTerminators", () => {
                this.GetSettings((settings) => {
                    EventHandler <TerminatorDataModel> ev = null;
                    switch (medium)
                    {
                    case CommMedium.Bluetooth:
                        settings.CurrentTerminatorBT = data;
                        ev = this.CurrentTerminatorChangedBT;
                        break;

                    case CommMedium.BluetoothLE:
                        settings.CurrentTerminatorBLE = data;
                        ev = this.CurrentTerminatorChangedBLE;
                        break;

                    case CommMedium.Ethernet:
                        settings.CurrentTerminatorEthernet = data;
                        ev = this.CurrentTerminatorChangedEthernet;
                        break;

                    case CommMedium.Usb:
                        settings.CurrentTerminatorUSB = data;
                        ev = this.CurrentTerminatorChangedUSB;
                        break;

                    case CommMedium.Wifi:
                        settings.CurrentTerminatorWIFI = data;
                        ev = this.CurrentTerminatorChangedWIFI;
                        break;

                    default:
                        settings.CurrentTerminator = data;
                        ev = this.CurrentTerminatorChanged;
                        break;
                    }

                    this.SaveSettings(settings, () => { ev?.Invoke(this, data); }, onError);
                }, onError);
            });
            this.RaiseIfException(report);
        }
示例#14
0
        public string GetText(CommMedium medium)
        {
            switch (medium)
            {
            case CommMedium.Bluetooth: return("Bluetooth");

            case CommMedium.BluetoothLE: return(String.Format("BLE  {0} {1}", '\u2b84', '\u2b86'));

            case CommMedium.Wifi: return("Wifi");

            case CommMedium.Ethernet: return("Ethernet");

            case CommMedium.Usb: return("USB");

            default: return("N/A");
                // TODO - others
            }
        }
示例#15
0
        public static string CommMediumSourceWhite(this CommMedium helpType)
        {
            switch (helpType)
            {
            case CommMedium.Bluetooth:
                return(BluetoothClassic_W);

            case CommMedium.BluetoothLE:
                return(BluetoothLE_W);

            case CommMedium.Ethernet:
                // TODO need white
                return(Source(UIIcon.EthernetWhite));

            case CommMedium.Wifi:
                return(Source(UIIcon.Wifi));

            default:
                return(Cancel);
            }
        }
        public void SetCurrentTerminators(IIndexItem <DefaultFileExtraInfo> index, CommMedium medium, Action onSuccess, OnErr onError)
        {
            ErrReport report;

            WrapErr.ToErrReport(out report, 2000304, "Failure on SetCurrentTerminators", () => {
                if (index == null)
                {
                    onError(this.GetText(MsgCode.NothingSelected));
                }
                else
                {
                    this.RetrieveTerminatorData(
                        index,
                        (data) => {
                        this.SetCurrentTerminators(data, medium, onError);
                        onSuccess.Invoke();
                    },
                        onError);
                }
            });
            this.RaiseIfException(report);
        }
        private string GetFilename(CommMedium medium)
        {
            switch (medium)
            {
            case CommMedium.Bluetooth:
                return(this.AssembleWithSamplePath("Samples/BTSample.txt"));

            case CommMedium.BluetoothLE:
                return(this.AssembleWithSamplePath("Samples/BLESample.txt"));

            case CommMedium.Wifi:
                return(this.AssembleWithSamplePath("Samples/WifiSample.txt"));

            case CommMedium.Usb:
                return(this.AssembleWithSamplePath("Samples/USBSample.txt"));

            case CommMedium.Ethernet:
                return(this.AssembleWithSamplePath("Samples/EthernetSample.txt"));

            default: return("");
            }
        }
示例#18
0
        private static string GetSimpleFilename(CommMedium medium)
        {
            switch (medium)
            {
            case CommMedium.Bluetooth:
                return("BTSample.txt");

            case CommMedium.BluetoothLE:
                return("BLESample.txt");

            case CommMedium.Wifi:
                return("WifiSample.txt");

            case CommMedium.Usb:
                return("USBSample.txt");

            case CommMedium.Ethernet:
                return("EthernetSample.txt");

            default:
                return("");
            }
        }
        public void HasCodeSample(CommMedium helpType, Action <CommMedium> onSuccess, OnErrTitle onError)
        {
            ErrReport report;

            WrapErr.ToErrReport(out report, 9999,
                                () => string.Format(""),
                                () => {
                string tmp = this.GetFilename(helpType);
                if (tmp.Length > 0)
                {
                    onSuccess(helpType);
                }
                else
                {
                    onError(this.GetText(MsgCode.Error), this.GetText(MsgCode.LoadFailed));
                }
            });
            if (report.Code != 0)
            {
                WrapErr.SafeAction(() => {
                    onError.Invoke(this.GetText(MsgCode.Error), report.Msg);
                });
            }
        }
示例#20
0
 public CommMedialDisplay(string display, string iconSource, CommMedium mediumType)
     : this(display, mediumType)
 {
     this.IconSource = iconSource;
 }
 private void PostSample(CommMedium commHelpType)
 {
     SampleLoader.Load(commHelpType, this.OnLoadOk, this.OnErr);
 }
示例#22
0
 public static string PacketSourceWhite(this CommMedium helpType)
 {
     return(string.Format("{0}{1}", GetIconPrefix(), IconBinder.CommMediumSourceWhite(helpType)));
 }
示例#23
0
 public static BitmapImage ResourceWhiteBitmap(this CommMedium helpType)
 {
     return(new BitmapImage(new Uri(helpType.PacketSourceWhite(), UriKind.Absolute)));
 }
示例#24
0
 public CommHelpDisplay(string display, CommMedium helpType)
 {
     this.Display  = display;
     this.HelpType = helpType;
 }
示例#25
0
 public CommHelpDisplay(string display, string iconSource, CommMedium helpType)
     : this(display, helpType)
 {
     this.IconSource = iconSource;
 }
        public static void ShowBox(Window parent, CommMedium medium)
        {
            TerminatorDataSelectorPopup win = new TerminatorDataSelectorPopup(parent, medium);

            win.ShowDialog();
        }
示例#27
0
 public CommMedialDisplay(string display, CommMedium mediumType)
 {
     this.Display    = display;
     this.MediumType = mediumType;
 }
示例#28
0
        public static void ShowBox(Window parent, CommMedium medium)
        {
            CommandsPopup win = new CommandsPopup(parent, medium);

            win.ShowDialog();
        }