Example #1
0
        private string DescribeConnectionParameters(Receiver receiver)
        {
            var result = new StringBuilder();

            switch (receiver.ConnectionType)
            {
            case ConnectionType.COM:
                result.AppendFormat("{0}, {1}, {2}/{3}, {4}, {5}, \"{6}\", \"{7}\"",
                                    receiver.ComPort,
                                    receiver.BaudRate,
                                    receiver.DataBits,
                                    Describe.StopBits(receiver.StopBits),
                                    Describe.Parity(receiver.Parity),
                                    Describe.Handshake(receiver.Handshake),
                                    receiver.StartupText,
                                    receiver.ShutdownText
                                    );
                break;

            case ConnectionType.TCP:
                result.AppendFormat("{0}:{1}",
                                    receiver.Address,
                                    receiver.Port
                                    );
                break;
            }

            return(result.ToString());
        }
Example #2
0
        /// <summary>
        /// Called when the user clicks the copy to clipboard button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void View_CopySelectedItemsToClipboardClicked(object sender, EventArgs e)
        {
            var buffer = new StringBuilder();
            var events = _View.SelectedConnectorActivityEvents;

            if (events.Length == 0)
            {
                events = _View.ConnectorActivityEvents;
            }
            foreach (var activity in events)
            {
                var line = String.Format("[{0}] [{1}] [{2}] {3}",
                                         FormatTime(activity.Time),
                                         activity.ConnectorName,
                                         Describe.ConnectorActivityType(activity.Type),
                                         activity.Message
                                         );
                if (activity.Exception != null)
                {
                    line = String.Format("{0}{1}{2}", line, Environment.NewLine, Describe.ExceptionSingleLineFull(activity.Exception.Exception));
                }

                buffer.AppendLine(line);
            }

            try {
                Clipboard.SetText(buffer.ToString());
            } catch {
                // The clipboard occasionally throws some bizarro exception but even when
                // it does it's usually worked
            }
        }
        public ActionResult Get()
        {
            Describe describe = new Describe();

            JsonConvert.SerializeObject(describe);
            return(Ok(describe));
        }
Example #4
0
            /// <summary>
            /// Gets the column value to sort on.
            /// </summary>
            /// <param name="listViewItem"></param>
            /// <returns></returns>
            public override IComparable GetRowValue(ListViewItem listViewItem)
            {
                var result   = base.GetRowValue(listViewItem);
                var activity = listViewItem.Tag as ConnectorActivityEvent;

                if (activity != null)
                {
                    var column = SortColumn ?? _Parent.columnHeaderDate;
                    if (column == _Parent.columnHeaderDate)
                    {
                        result = activity.Time;
                    }
                    else if (column == _Parent.columnHeaderConnector)
                    {
                        result = activity.ConnectorName ?? "";
                    }
                    else if (column == _Parent.columnHeaderType)
                    {
                        result = Describe.ConnectorActivityType(activity.Type);
                    }
                    else if (column == _Parent.columnHeaderMessage)
                    {
                        result = activity.Message;
                    }
                }

                return(result);
            }
        /// <summary>
        /// See base docs.
        /// </summary>
        protected override void CreateBindings()
        {
            base.CreateBindings();

            var rebroadcastFormatManager = Factory.ResolveSingleton<IRebroadcastFormatManager>();

            AddControlBinder(new MasterListToListBinder<Configuration, RebroadcastSettings>(SettingsView.Configuration, listRebroadcastServers, r => r.RebroadcastSettings) {
                FetchColumns = (rebroadcastServer, e) => {
                    var receiver = SettingsView.CombinedFeed.FirstOrDefault(r => r.UniqueId == rebroadcastServer.ReceiverId);
                    var portDescription = !rebroadcastServer.IsTransmitter ? String.Format("::{0}", rebroadcastServer.Port) : String.Format("{0}:{1}", rebroadcastServer.TransmitAddress, rebroadcastServer.Port);

                    e.Checked = rebroadcastServer.Enabled;
                    e.ColumnTexts.Add(rebroadcastServer.Name);
                    e.ColumnTexts.Add(receiver == null ? "" : receiver.Name ?? "");
                    e.ColumnTexts.Add(rebroadcastFormatManager.ShortName(rebroadcastServer.Format));
                    e.ColumnTexts.Add(portDescription);
                    e.ColumnTexts.Add(Describe.DefaultAccess(rebroadcastServer.Access.DefaultAccess));
                },
                GetSortValue = (rebroadcastServer, header, defaultValue) => {
                    IComparable result = defaultValue;
                    if(header == columnHeaderUNC) {
                        if(!rebroadcastServer.IsTransmitter) result = String.Format("_{0:00000}", rebroadcastServer.Port);
                        else                                 result = String.Format("{0}:{1:00000}", rebroadcastServer.TransmitAddress, rebroadcastServer.Port);
                    }

                    return result;
                },
                AddHandler = () => SettingsView.CreateRebroadcastServer(),
                AutoDeleteEnabled = true,
                EditHandler = (rebroadcastServer) => SettingsView.DisplayPageForPageObject(rebroadcastServer),
                CheckedChangedHandler = (rebroadcastServer, isChecked) => rebroadcastServer.Enabled = isChecked,
            });
        }
Example #6
0
 internal void setDescribe(Describe de)
 {
     if (des == null)
     {
         des = de;
     }
 }
Example #7
0
        public void FeatureMatcherGeneratesCorrectMismatchDescriptionForNullValues()
        {
            var sut = Describe.Object <AnotherFlatClass>()
                      .Property(x => x.Id, new FakeMatcher <Guid>(true, "", i => ""));

            sut.ShouldHaveMismatchDescriptionForValue(null, "was null");
        }
Example #8
0
        public void FeatureMatcherGeneratesNestedMatcherMismatchDesciptionsCorrectly(
            int intVal,
            int mismatchedIntVal,
            string mismatchIntDescription)
        {
            var sut = Describe.Object <DoubleNestedClass>()
                      .Property(x => x.Nested, Describe.Object <NestedClass>()
                                .Property(x => x.InnerClass, Describe.Object <SimpleFlatClass>()
                                          .Property(x => x.IntProperty, new FakeMatcher <int>(false, "", i => i == mismatchedIntVal ? mismatchIntDescription : i.ToString()))));

            var expectedDescription = "was a(n) DoubleNestedClass where:\r\n" +
                                      "    member Nested value was a(n) NestedClass where:\r\n" +
                                      "        member InnerClass value was a(n) SimpleFlatClass where:\r\n" +
                                      "            member IntProperty value " + mismatchIntDescription;

            var mismatched = new DoubleNestedClass()
            {
                Nested = new NestedClass
                {
                    InnerClass = new SimpleFlatClass
                    {
                        IntProperty = mismatchedIntVal,
                    }
                }
            };

            sut.ShouldHaveMismatchDescriptionForValue(mismatched, expectedDescription);
        }
Example #9
0
        public async Task <object> Go(QueryContext context, ConnectionClient client, RegistryService registry)
        {
            var describe = context.Query.Split("?", StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();

            Describe describeRequest;

            if (describe.Any())
            {
                describeRequest = new Describe()
                {
                    TableName = describe[0]
                };
            }
            else
            {
                describeRequest = new Describe()
                {
                    TableName = "sqlite_master"
                };
            }

            try
            {
                var describeResponse = await client.DescribeCommandAsync(describeRequest);

                return(new DescribeResultViewModel(describeResponse, await registry.GetServices(), context.HttpContext.Request));
            }
            catch (Exception err)
            {
                return(new DescribeResultViewModel(err.Message));
            }
        }
Example #10
0
        public void FeatureMatcherGeneratesCorrectTypeNameInMismatchDescription()
        {
            var sut = Describe.Object <AnotherFlatClass>()
                      .Property(x => x.Id, new FakeMatcher <Guid>(false, "", i => ""));

            sut.ShouldHaveMismatchDescriptionForValue(new AnotherFlatClass(), Starts.With("was a(n) AnotherFlatClass where:"));
        }
Example #11
0
        public void Describe_RebroadcastSettingsCollection_Correctly_Describes_Collection()
        {
            foreach (var culture in new string[] { "en-GB", "fr-FR" })
            {
                using (var cultureSwitcher = new CultureSwitcher(culture)) {
                    Assert.AreEqual(Strings.RebroadcastServersNoneConfigured, Describe.RebroadcastSettingsCollection(null));

                    var settings = new List <RebroadcastSettings>();
                    Assert.AreEqual(Strings.RebroadcastServersNoneConfigured, Describe.RebroadcastSettingsCollection(settings));

                    settings.Add(new RebroadcastSettings()
                    {
                        Enabled = false
                    });
                    Assert.AreEqual(String.Format(Strings.RebroadcastServersDescribeSingle, 0), Describe.RebroadcastSettingsCollection(settings));

                    settings[0].Enabled = true;
                    Assert.AreEqual(String.Format(Strings.RebroadcastServersDescribeSingle, 1), Describe.RebroadcastSettingsCollection(settings));

                    settings.Add(new RebroadcastSettings()
                    {
                        Enabled = false
                    });
                    Assert.AreEqual(String.Format(Strings.RebroadcastServersDescribeMany, 2, 1), Describe.RebroadcastSettingsCollection(settings));

                    settings[1].Enabled = true;
                    Assert.AreEqual(String.Format(Strings.RebroadcastServersDescribeMany, 2, 2), Describe.RebroadcastSettingsCollection(settings));
                }
            }
        }
Example #12
0
        /// <summary>
        /// Populates the control with a list of clients.
        /// </summary>
        /// <param name="clients"></param>
        /// <param name="sessionMap"></param>
        public void Populate(IList <LogClient> clients, IDictionary <long, IList <LogSession> > sessionMap)
        {
            listView.Items.Clear();

            foreach (LogClient client in clients)
            {
                IList <LogSession> sessions;
                if (!sessionMap.TryGetValue(client.Id, out sessions))
                {
                    sessions = new List <LogSession>();
                }
                ClientAndSessions tag = new ClientAndSessions()
                {
                    Client = client, Sessions = sessions
                };
                ListViewItem item = new ListViewItem(new string[] {
                    client.IpAddress,
                    client.IsLocal ? Strings.Local : Strings.Internet,
                    client.ReverseDns,
                    tag.FirstSession.ToLocalTime().ToString(),
                    tag.LastSession.ToLocalTime().ToString(),
                    String.Format("{0:N0}", sessions.Count),
                    Describe.TimeSpan(tag.TotalDuration),
                    Describe.Bytes(tag.TotalBytesSent)
                });
                item.Tag = tag;
                listView.Items.Add(item);
            }
        }
Example #13
0
        private int BuildAirportJson(Airport sdmAirport, Dictionary <string, int> airportMap, List <ReportAirportJson> jsonList, bool preferIataCodes)
        {
            var result = -1;

            if (sdmAirport != null)
            {
                var code = preferIataCodes ? String.IsNullOrEmpty(sdmAirport.IataCode) ? sdmAirport.IcaoCode : sdmAirport.IataCode
                                           : String.IsNullOrEmpty(sdmAirport.IcaoCode) ? sdmAirport.IataCode : sdmAirport.IcaoCode;
                if (!String.IsNullOrEmpty(code))
                {
                    if (!airportMap.TryGetValue(code, out result))
                    {
                        result = jsonList.Count;
                        jsonList.Add(new ReportAirportJson()
                        {
                            Code = code,
                            Name = Describe.Airport(sdmAirport, preferIataCodes, showCode: false, showName: true, showCountry: true)
                        });
                        airportMap.Add(code, result);
                    }
                }
            }

            return(result);
        }
Example #14
0
        /// <summary>
        /// Shows the details of an exception to the user and logs it.
        /// </summary>
        /// <param name="ex"></param>
        public static void ShowException(Exception ex)
        {
            // Don't translate, I don't want to confuse things if the translation throws exceptions

            var isThreadAbort = Hierarchy.Flatten(ex, r => r.InnerException).Any(r => r is ThreadAbortException);

            if (!isThreadAbort)
            {
                var message = Describe.ExceptionMultiLine(ex, "\r\n");

                ILog log = null;
                try {
                    log = Factory.Singleton.Resolve <ILog>().Singleton;
                    if (log != null)
                    {
                        log.WriteLine(message);
                    }
                } catch { }

                try {
                    Factory.Singleton.Resolve <IMessageBox>().Show(message, "Unhandled Exception Caught");
                } catch (Exception doubleEx) {
                    Debug.WriteLine(String.Format("Program.ShowException caught double-exception: {0} when trying to display / log {1}", doubleEx.ToString(), ex.ToString()));
                    try {
                        if (log != null)
                        {
                            log.WriteLine("Caught exception while trying to show a previous exception: {0}", doubleEx.ToString());
                        }
                    } catch { }
                }
            }
        }
Example #15
0
        protected static IEnumerable <ExpectResult> CompareAssert(
            IEvent <T>[] expected,
            IEvent <T>[] actual)
        {
            var max = Math.Max(expected.Length, actual.Length);

            for (int i = 0; i < max; i++)
            {
                var ex = expected.Skip(i).FirstOrDefault();
                var ac = actual.Skip(i).FirstOrDefault();

                var expectedString = ex == null ? "No event expected" : Describe.Object(ex);
                var actualString   = ac == null ? "No event actually" : Describe.Object(ac);

                var result = new ExpectResult {
                    Expectation = expectedString
                };

                var realDiff = CompareObjects.FindDifferences(ex, ac);
                if (!string.IsNullOrEmpty(realDiff))
                {
                    var stringRepresentationsDiffer = expectedString != actualString;

                    result.Failure = stringRepresentationsDiffer ?
                                     GetAdjusted("Was:  ", actualString) :
                                     GetAdjusted("Diff: ", realDiff);
                }

                yield return(result);
            }
        }
Example #16
0
        public IActionResult Describe([FromBody] Describe describe)
        {
            return(this.Intercept(() =>
            {
                var results = new List <List <object> >();

                try
                {
                    using (var dbReader = dbConnection.ExecuteQuery($"pragma table_info({describe.TableName.TrimEnd(';')})"))
                    {
                        var reader = dbReader.Reader;
                        while (reader.Read())
                        {
                            var rowResults = new List <object>();
                            foreach (var column in Model.Describe.DescribeColumns)
                            {
                                var columnOrdinal = reader.GetOrdinal(column);
                                rowResults.Add(reader.GetValue(columnOrdinal));
                            }

                            results.Add(rowResults);
                        }

                        return Ok(DescribeResponse.Ok(describe, results));
                    }
                }
                catch (Exception err)
                {
                    return Ok(DescribeResponse.Failed(err.Message));
                }
            }));
        }
        /// <summary>
        /// Gets the filename of the aircraft's picture, if any.
        /// </summary>
        /// <param name="directoryCache"></param>
        /// <param name="icao24"></param>
        /// <param name="registration"></param>
        /// <returns></returns>
        private string GetImageFileName(IDirectoryCache directoryCache, string icao24, string registration)
        {
            string result = null;

            if (!String.IsNullOrEmpty(icao24))
            {
                result = SearchForPicture(directoryCache, icao24, "jpg") ??
                         SearchForPicture(directoryCache, icao24, "jpeg") ??
                         SearchForPicture(directoryCache, icao24, "png") ??
                         SearchForPicture(directoryCache, icao24, "gif") ??
                         SearchForPicture(directoryCache, icao24, "bmp");
            }

            if (result == null && !String.IsNullOrEmpty(registration))
            {
                var icaoCompliantRegistration = Describe.IcaoCompliantRegistration(registration);
                result = SearchForPicture(directoryCache, icaoCompliantRegistration, "jpg") ??
                         SearchForPicture(directoryCache, icaoCompliantRegistration, "jpeg") ??
                         SearchForPicture(directoryCache, icaoCompliantRegistration, "png") ??
                         SearchForPicture(directoryCache, icaoCompliantRegistration, "gif") ??
                         SearchForPicture(directoryCache, icaoCompliantRegistration, "bmp");
            }

            return(result);
        }
Example #18
0
        public void FeatureMatcherGeneratesCorrectTypeNameInDescription()
        {
            var sut = Describe.Object <AnotherFlatClass>()
                      .Property(x => x.Id, new FakeMatcher <Guid>(true, "", i => ""));

            sut.ShouldHaveDescription(Starts.With("a(n) AnotherFlatClass where:"));
        }
Example #19
0
        private static void SomeWork()
        {
            using (Describe.Step("T0 action"))
            {
                Describe.TechnicalDetails("details 0");
            }

            using (Describe.Step("T1 action"))
            {
                Describe.TechnicalDetails("details 1");
                Describe.TechnicalDetails("details 1 and2");

                using (Describe.Step("sub 1 T1 action"))
                {
                    using (Describe.Step("sub 11 T11 action"))
                    {
                        Describe.TechnicalDetails("details 22");
                        Describe.TechnicalDetails("details 222");
                        Describe.TechnicalDetails("details 2222");
                    }

                    Describe.TechnicalDetails("details 2");
                }

                Describe.TechnicalDetails("details 3")
                .PrintJson(new { xxx = "abc", yyy = "xyz" });

                using (Describe.Step("sub 2 T1 action"))
                {
                    Describe.TechnicalDetails("details 4");
                }

                Describe.TechnicalDetails("details 5");
            }
        }
Example #20
0
 public void Describe_TimeSpan_Formats_TimeSpans_Correctly()
 {
     Assert.AreEqual("00:00:00", Describe.TimeSpan(new TimeSpan()));
     Assert.AreEqual("00:00:01", Describe.TimeSpan(new TimeSpan(0, 0, 1)));
     Assert.AreEqual("00:01:59", Describe.TimeSpan(new TimeSpan(0, 1, 59)));
     Assert.AreEqual("01:59:59", Describe.TimeSpan(new TimeSpan(1, 59, 59)));
     Assert.AreEqual("100:59:59", Describe.TimeSpan(new TimeSpan(100, 59, 59)));
 }
Example #21
0
        public void Describe_Bytes_Formats_Bytes_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            using (var switcher = new CultureSwitcher(worksheet.String("Region"))) {
                Assert.AreEqual(worksheet.String("Description"), Describe.Bytes(worksheet.Long("Bytes")));
            }
        }
        public ActionResult DeleteConfirmed(string id)
        {
            Describe describe = db.Describes.Find(id);

            db.Describes.Remove(describe);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #23
0
 public EventModel(VirtualRadar.Interface.Network.ConnectorActivityEvent obj)
 {
     Id            = obj.Id;
     ConnectorName = obj.ConnectorName;
     Time          = obj.Time.ToLocalTime().ToString("dd-MMM-yyyy HH:mm:ss");
     Type          = Describe.ConnectorActivityType(obj.Type);
     Message       = obj.Message;
 }
        void ReleaseDesignerOutlets()
        {
            if (Back != null)
            {
                Back.Dispose();
                Back = null;
            }

            if (CapturedImage != null)
            {
                CapturedImage.Dispose();
                CapturedImage = null;
            }

            if (CaptureImage != null)
            {
                CaptureImage.Dispose();
                CaptureImage = null;
            }

            if (ClearPicture != null)
            {
                ClearPicture.Dispose();
                ClearPicture = null;
            }

            if (Describe != null)
            {
                Describe.Dispose();
                Describe = null;
            }

            if (Emotion != null)
            {
                Emotion.Dispose();
                Emotion = null;
            }

            if (Front != null)
            {
                Front.Dispose();
                Front = null;
            }

            if (ImageData != null)
            {
                ImageData.Dispose();
                ImageData = null;
            }

            if (OCR != null)
            {
                OCR.Dispose();
                OCR = null;
            }
        }
Example #25
0
        public void FeatureMatcherGeneratesCorrectDescriptionForAProperty(int intVal, string intDescription)
        {
            var sut = Describe.Object <SimpleFlatClass>()
                      .Property(x => x.IntProperty, new FakeMatcher <int>(true, intDescription, i => ""));

            var expectedDescription = "a(n) SimpleFlatClass where:\r\n" +
                                      "    member IntProperty value is " + intDescription;

            sut.ShouldHaveDescription(expectedDescription);
        }
        /// <summary>
        /// Updates the display of any configuration settings we're showing on the view.
        /// </summary>
        /// <returns></returns>
        private IConfigurationStorage DisplayConfigurationSettings()
        {
            var result = Factory.Singleton.Resolve <IConfigurationStorage>().Singleton;

            var configuration = result.Load();

            View.RebroadcastServersConfiguration = Describe.RebroadcastSettingsCollection(configuration.RebroadcastSettings);

            return(result);
        }
 public ActionResult Edit([Bind(Include = "NameDescribe,ContentDescribe")] Describe describe)
 {
     if (ModelState.IsValid)
     {
         db.Entry(describe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(describe));
 }
Example #28
0
        public ViewModel()
        {
            var plugin = Plugin.Singleton;

            if (plugin != null)
            {
                IndexPageAddress = plugin.GetIndexPageAddress();
            }
            EnumDefaultAccesses = EnumModel.CreateFromEnum <DefaultAccess>(r => Describe.DefaultAccess(r));
        }
Example #29
0
        public virtual async Task <DescribeResponse> DescribeCommandAsync(Describe describe)
        {
            var describeUrl = UrlBuilder.GetDescribeUrl(EndPoint);
            var response    = await client.PostAsync <DescribeResponse>(describeUrl, describe);

            if (response.StatusCode != StatusCode.Ok)
            {
                throw new ConnectionClientCommandException($"Describe failed. {response.Error}");
            }
            return(response);
        }
        public void MainPresenter_RebroadcastServerManager_Configuration_Shown_On_Initialise()
        {
            _Configuration.RebroadcastSettings.Add(new RebroadcastSettings()
            {
                Enabled = true
            });

            _Presenter.Initialise(_View.Object);

            Assert.AreEqual(Describe.RebroadcastSettingsCollection(_Configuration.RebroadcastSettings), _View.Object.RebroadcastServersConfiguration);
        }