예제 #1
0
        public KeyValuePairCollection Reduce(KeyValuePairCollection inputKeyValuePairs)
        {
            var reducedMostAccidentProne = new Dictionary <string, AccidentStats>();

            inputKeyValuePairs.ForEach(x =>
            {
                var mostAccidentProneKvp = (MostAccidentProneKvp)x;

                if (!reducedMostAccidentProne.ContainsKey(mostAccidentProneKvp.Key))
                {
                    reducedMostAccidentProne.Add(mostAccidentProneKvp.Key, new AccidentStats());
                }

                reducedMostAccidentProne[mostAccidentProneKvp.Key] =
                    ReduceAccidentStats(reducedMostAccidentProne[mostAccidentProneKvp.Key], mostAccidentProneKvp.Value);
            });

            var keyValuePairs = new KeyValuePairCollection();

            reducedMostAccidentProne
            .ToList()
            .ForEach(x => keyValuePairs.Add(new MostAccidentProneKvp(x.Key, x.Value)));

            keyValuePairs.Sort(CompareMostAccidentProneKvps);

            return(keyValuePairs);
        }
        public void Write__KeyValuePairCollection__KeysAreAligned()
        {
            var ow = new StringObjectWriter();

            var kvpc = new KeyValuePairCollection();

            kvpc.Add(new KeyValuePair("1", " "));
            kvpc.Add(new KeyValuePair("12", " "));
            kvpc.Add(new KeyValuePair("1234", " "));
            kvpc.Add(new KeyValuePair("12345", " "));
            kvpc.Add(new KeyValuePair("1234567890", " "));
            kvpc.Add(new KeyValuePair("123456789012345678901", " "));

            var r = ow.Write(kvpc);

            var expected =
                 "1\t\t\t\t\t\t:\t "
                + Environment.NewLine
                + "12\t\t\t\t\t\t:\t "
                + Environment.NewLine
                +"1234\t\t\t\t\t:\t "
                + Environment.NewLine
                + "12345\t\t\t\t\t:\t "
                + Environment.NewLine
                + "1234567890\t\t\t\t:\t "
                + Environment.NewLine
                + "123456789012345678901\t:\t ";

            Assert.AreEqual(expected, r);
        }
예제 #3
0
        /// <summary>
        /// Handles click event of OK button
        /// </summary>
        /// <param name="sender">Object that fired the event</param>
        /// <param name="e">.NET supplied event parameters</param>
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            primaryColumnData = cbxSelectedTableInformation.SelectedItem.ToString();

            kvPairs           = new KeyValuePairCollection();
            kvPairs.Delimiter = CharLiterals.SPACE;

            for (int index = 0; index < lbxAssociatedLinkedFields.Items.Count; index++)
            {
                kvPairs.Add(ParseLinkedFields(lbxAssociatedLinkedFields.Items[index].ToString()));
            }

            this.DialogResult = DialogResult.OK;
            this.Hide();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="caCertificatePath"></param>
        /// <param name="clientCertificatePath"></param>
        /// <param name="clientCertificatePassword"></param>
        public MqttTlsCertificates(string caCertificatePath     = null,
                                   string clientCertificatePath = null, string clientCertificatePassword = null)
        {
            m_caCertificatePath         = caCertificatePath ?? "";
            m_clientCertificatePath     = clientCertificatePath ?? "";
            m_clientCertificatePassword = clientCertificatePassword ?? "";

            if (!string.IsNullOrEmpty(m_caCertificatePath))
            {
                m_caCertificate = X509Certificate.CreateFromCertFile(m_caCertificatePath);
            }
            if (!string.IsNullOrEmpty(clientCertificatePath))
            {
                m_clientCertificate = new X509Certificate2(clientCertificatePath, m_clientCertificatePassword);
            }

            m_keyValuePairs = new KeyValuePairCollection();

            QualifiedName qCaCertificatePath = EnumMqttClientConfigurationParameters.TlsCertificateCaCertificatePath.ToString();

            m_keyValuePairs.Add(new KeyValuePair {
                Key = qCaCertificatePath, Value = m_caCertificatePath
            });

            QualifiedName qClientCertificatePath = EnumMqttClientConfigurationParameters.TlsCertificateClientCertificatePath.ToString();

            m_keyValuePairs.Add(new KeyValuePair {
                Key = qClientCertificatePath, Value = m_clientCertificatePath
            });

            QualifiedName qClientCertificatePassword = EnumMqttClientConfigurationParameters.TlsCertificateClientCertificatePassword.ToString();

            m_keyValuePairs.Add(new KeyValuePair {
                Key = qClientCertificatePassword, Value = m_clientCertificatePassword
            });
        }
        public void Write__KeyValuePairCollection__MultiLineValuesAreHandled()
        {
            var ow = new StringObjectWriter();

            var kvpc = new KeyValuePairCollection();

            kvpc.Add(new KeyValuePair("key", "_line1_" + Environment.NewLine + "_line2_"));
            kvpc.Add(new KeyValuePair("key_0123456", " "));

            var r = ow.Write(kvpc);

            var expected =
                 "key\t\t\t:"
                + Environment.NewLine
                + "-------------"
                + Environment.NewLine
                + "\t_line1_"
                + Environment.NewLine
                + "\t_line2_"
                + Environment.NewLine
                + "key_0123456\t:\t ";

            Assert.AreEqual(expected, r);
        }
 /// <inheritdoc/>
 private void EncodeBinary(IEncoder encoder)
 {
     encoder.WriteUInt32("ContentMask", MessageContentMask);
     if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.NodeId) != 0)
     {
         encoder.WriteString(nameof(MonitoredItemMessageContentMask.NodeId), NodeId);
     }
     if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.EndpointUrl) != 0)
     {
         encoder.WriteString(nameof(MonitoredItemMessageContentMask.EndpointUrl), EndpointUrl);
     }
     if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ApplicationUri) != 0)
     {
         encoder.WriteString(nameof(MonitoredItemMessageContentMask.ApplicationUri), ApplicationUri);
     }
     if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.DisplayName) != 0)
     {
         encoder.WriteString(nameof(MonitoredItemMessageContentMask.DisplayName), DisplayName);
     }
     if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.Timestamp) != 0)
     {
         encoder.WriteDateTime(nameof(MonitoredItemMessageContentMask.Timestamp), Timestamp);
     }
     encoder.WriteDataValue("Value", Value);
     if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.SequenceNumber) != 0)
     {
         encoder.WriteUInt32(nameof(MonitoredItemMessageContentMask.SequenceNumber), SequenceNumber);
     }
     if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ExtensionFields) != 0)
     {
         if (ExtensionFields != null)
         {
             var dictionary = new KeyValuePairCollection();
             foreach (var item in ExtensionFields)
             {
                 dictionary.Add(new Ua.KeyValuePair()
                 {
                     Key   = item.Key,
                     Value = item.Value
                 });
             }
             encoder.WriteEncodeableArray("ExtensionFields", dictionary.ToArray(), typeof(Ua.KeyValuePair));
         }
     }
 }
예제 #7
0
        /// <inheritdoc/>
        public void Encode(IEncoder encoder)
        {
            encoder.WriteUInt32("ContentMask", MessageContentMask);
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.NodeId) != 0)
            {
                encoder.WriteExpandedNodeId(nameof(MonitoredItemMessageContentMask.NodeId), NodeId);
            }
            // todo check why Value is not encoded as DataValue type
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ServerTimestamp) != 0)
            {
                encoder.WriteDateTime(nameof(MonitoredItemMessageContentMask.ServerTimestamp),
                                      Value?.ServerTimestamp ?? DateTime.MinValue);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ServerPicoSeconds) != 0)
            {
                encoder.WriteUInt16(nameof(MonitoredItemMessageContentMask.ServerPicoSeconds),
                                    Value?.ServerPicoseconds ?? 0);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.SourceTimestamp) != 0)
            {
                encoder.WriteDateTime(nameof(MonitoredItemMessageContentMask.SourceTimestamp),
                                      Value?.SourceTimestamp ?? DateTime.MinValue);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.SourcePicoSeconds) != 0)
            {
                encoder.WriteUInt16(nameof(MonitoredItemMessageContentMask.SourcePicoSeconds),
                                    Value?.SourcePicoseconds ?? 0);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.StatusCode) != 0)
            {
                encoder.WriteStatusCode(nameof(MonitoredItemMessageContentMask.StatusCode),
                                        Value?.StatusCode ?? StatusCodes.BadNoData);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.Status) != 0)
            {
                encoder.WriteString(nameof(MonitoredItemMessageContentMask.Status),
                                    Value == null ? "" : StatusCode.LookupSymbolicId(Value.StatusCode.Code));
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.EndpointUrl) != 0)
            {
                encoder.WriteString(nameof(MonitoredItemMessageContentMask.EndpointUrl), EndpointUrl);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.SubscriptionId) != 0)
            {
                encoder.WriteString(nameof(MonitoredItemMessageContentMask.SubscriptionId), SubscriptionId);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ApplicationUri) != 0)
            {
                encoder.WriteString(nameof(MonitoredItemMessageContentMask.ApplicationUri), ApplicationUri);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.DisplayName) != 0)
            {
                encoder.WriteString(nameof(MonitoredItemMessageContentMask.DisplayName), DisplayName);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.Timestamp) != 0)
            {
                encoder.WriteDateTime(nameof(MonitoredItemMessageContentMask.Timestamp), DateTime.UtcNow);
            }
            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.PicoSeconds) != 0)
            {
                encoder.WriteUInt16(nameof(MonitoredItemMessageContentMask.PicoSeconds), 0);
            }

            if (Value?.WrappedValue != null)
            {
                encoder.WriteVariant("Value", Value.WrappedValue);
            }
            else
            {
                encoder.WriteVariant("Value", Variant.Null);
            }

            if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ExtraFields) != 0)
            {
                if (ExtensionFields != null)
                {
                    var dictionary = new KeyValuePairCollection();
                    foreach (var item in ExtensionFields)
                    {
                        dictionary.Add(new Ua.KeyValuePair()
                        {
                            Key   = item.Key,
                            Value = item.Value
                        });
                    }
                    encoder.WriteEncodeableArray("ExtensionFields", dictionary.ToArray(), typeof(Ua.KeyValuePair));
                }
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="certificates">The certificates used for encrypted communication including the CA certificate</param>
        /// <param name="sslProtocolVersion">The preferred version of SSL protocol</param>
        /// <param name="allowUntrustedCertificates">Specifies if untrusted certificates should be accepted in the process of certificate validation</param>
        /// <param name="ignoreCertificateChainErrors">Specifies if Certificate Chain errors should be validated in the process of certificate validation</param>
        /// <param name="ignoreRevocationListErrors">Specifies if Certificate Revocation List errors should be validated in the process of certificate validation</param>
        /// <param name="trustedIssuerCertificates">The trusted issuer certifficates store identifier</param>
        /// <param name="trustedPeerCertificates">The trusted peer certifficates store identifier</param>
        /// <param name="rejectedCertificateStore">The rejected certifficates store identifier</param>
        public MqttTlsOptions(MqttTlsCertificates certificates  = null,
                              SslProtocols sslProtocolVersion   = SslProtocols.Tls12,
                              bool allowUntrustedCertificates   = false,
                              bool ignoreCertificateChainErrors = false,
                              bool ignoreRevocationListErrors   = false,
                              CertificateStoreIdentifier trustedIssuerCertificates = null,
                              CertificateStoreIdentifier trustedPeerCertificates   = null,
                              CertificateStoreIdentifier rejectedCertificateStore  = null
                              )
        {
            m_certificates                 = certificates;
            m_SslProtocolVersion           = sslProtocolVersion;
            m_allowUntrustedCertificates   = allowUntrustedCertificates;
            m_ignoreCertificateChainErrors = ignoreCertificateChainErrors;
            m_ignoreRevocationListErrors   = ignoreRevocationListErrors;

            m_trustedIssuerCertificates = trustedIssuerCertificates;
            m_trustedPeerCertificates   = trustedPeerCertificates;
            m_rejectedCertificateStore  = rejectedCertificateStore;

            m_keyValuePairs = new KeyValuePairCollection();

            if (m_certificates != null)
            {
                m_keyValuePairs.AddRange(m_certificates.KeyValuePairs);
            }

            KeyValuePair kvpTlsProtocolVersion = new KeyValuePair();

            kvpTlsProtocolVersion.Key   = EnumMqttClientConfigurationParameters.TlsProtocolVersion.ToString();
            kvpTlsProtocolVersion.Value = (int)m_SslProtocolVersion;
            m_keyValuePairs.Add(kvpTlsProtocolVersion);
            KeyValuePair kvpAllowUntrustedCertificates = new KeyValuePair();

            kvpAllowUntrustedCertificates.Key   = EnumMqttClientConfigurationParameters.TlsAllowUntrustedCertificates.ToString();
            kvpAllowUntrustedCertificates.Value = m_allowUntrustedCertificates;
            m_keyValuePairs.Add(kvpAllowUntrustedCertificates);
            KeyValuePair kvpIgnoreCertificateChainErrors = new KeyValuePair();

            kvpIgnoreCertificateChainErrors.Key   = EnumMqttClientConfigurationParameters.TlsIgnoreCertificateChainErrors.ToString();
            kvpIgnoreCertificateChainErrors.Value = m_ignoreCertificateChainErrors;
            m_keyValuePairs.Add(kvpIgnoreCertificateChainErrors);
            KeyValuePair kvpIgnoreRevocationListErrors = new KeyValuePair();

            kvpIgnoreRevocationListErrors.Key   = EnumMqttClientConfigurationParameters.TlsIgnoreRevocationListErrors.ToString();
            kvpIgnoreRevocationListErrors.Value = m_ignoreRevocationListErrors;
            m_keyValuePairs.Add(kvpIgnoreRevocationListErrors);

            KeyValuePair kvpTrustedIssuerCertificatesStoreType = new KeyValuePair();

            kvpTrustedIssuerCertificatesStoreType.Key   = EnumMqttClientConfigurationParameters.TrustedIssuerCertificatesStoreType.ToString();
            kvpTrustedIssuerCertificatesStoreType.Value = m_trustedIssuerCertificates?.StoreType;
            m_keyValuePairs.Add(kvpTrustedIssuerCertificatesStoreType);
            KeyValuePair kvpTrustedIssuerCertificatesStorePath = new KeyValuePair();

            kvpTrustedIssuerCertificatesStorePath.Key   = EnumMqttClientConfigurationParameters.TrustedIssuerCertificatesStorePath.ToString();
            kvpTrustedIssuerCertificatesStorePath.Value = m_trustedIssuerCertificates?.StorePath;
            m_keyValuePairs.Add(kvpTrustedIssuerCertificatesStorePath);

            KeyValuePair kvpTrustedPeerCertificatesStoreType = new KeyValuePair();

            kvpTrustedPeerCertificatesStoreType.Key   = EnumMqttClientConfigurationParameters.TrustedPeerCertificatesStoreType.ToString();
            kvpTrustedPeerCertificatesStoreType.Value = m_trustedPeerCertificates?.StoreType;
            m_keyValuePairs.Add(kvpTrustedPeerCertificatesStoreType);
            KeyValuePair kvpTrustedPeerCertificatesStorePath = new KeyValuePair();

            kvpTrustedPeerCertificatesStorePath.Key   = EnumMqttClientConfigurationParameters.TrustedPeerCertificatesStorePath.ToString();
            kvpTrustedPeerCertificatesStorePath.Value = m_trustedPeerCertificates?.StorePath;
            m_keyValuePairs.Add(kvpTrustedPeerCertificatesStorePath);

            KeyValuePair kvpRejectedCertificateStoreStoreType = new KeyValuePair();

            kvpRejectedCertificateStoreStoreType.Key   = EnumMqttClientConfigurationParameters.RejectedCertificateStoreStoreType.ToString();
            kvpRejectedCertificateStoreStoreType.Value = m_rejectedCertificateStore?.StoreType;
            m_keyValuePairs.Add(kvpRejectedCertificateStoreStoreType);
            KeyValuePair kvpRejectedCertificateStoreStorePath = new KeyValuePair();

            kvpRejectedCertificateStoreStorePath.Key   = EnumMqttClientConfigurationParameters.RejectedCertificateStoreStorePath.ToString();
            kvpRejectedCertificateStoreStorePath.Value = m_rejectedCertificateStore?.StorePath;
            m_keyValuePairs.Add(kvpRejectedCertificateStoreStorePath);
        }
        public void Write__KeyValuePairCollection__ValueIsKeyValuePairCollection()
        {
            var ow = new StringObjectWriter();

            var kvpc = new KeyValuePairCollection();

            var value = new KeyValuePairCollection();

            value.Add(new KeyValuePair("key_1", "value_1"));
            value.Add(new KeyValuePair("key_2", "value_2"));

            kvpc.Add("item", value);

            var r = ow.Write(kvpc);

            var expected =
                 "item\t:"
                + Environment.NewLine
                + "---------"
                + Environment.NewLine
                + "\tkey_1\t:\tvalue_1"
                + Environment.NewLine
                + "\tkey_2\t:\tvalue_2";

            Assert.AreEqual(expected, r);
        }
예제 #10
0
        /// <summary>
        /// Builds the command text
        /// </summary>
        protected override void GenerateCommand()
        {
            Configuration          config  = Configuration.GetNewInstance();
            KeyValuePairCollection kvPairs = new KeyValuePairCollection();

            kvPairs.Delimiter = CharLiterals.SPACE;

            if ((cmbYesAs.Text != config.Settings.RepresentationOfYes) || (hasYesAsChanged))
            {
                kvPairs.Add(new KeyValuePair(ShortHands.YES, Util.InsertInDoubleQuotes(cmbYesAs.Text)));
            }
            if ((cmbNoAs.Text != config.Settings.RepresentationOfNo) || (hasNoAsChanged))
            {
                kvPairs.Add(new KeyValuePair(ShortHands.NO, Util.InsertInDoubleQuotes(cmbNoAs.Text)));
            }
            if ((cmbMissingAs.Text != config.Settings.RepresentationOfMissing) || (hasMissingAsChanged))
            {
                kvPairs.Add(new KeyValuePair(ShortHands.MISSING, Util.InsertInDoubleQuotes(cmbMissingAs.Text)));
            }
            if ((cbxGraphics.Checked != config.Settings.ShowGraphics) || (hasShowGraphicChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.FREQGRAPH,
                                             Epi.Util.GetShortHand(cbxGraphics.Checked)));
            }
            if ((cbxHyperlinks.Checked != config.Settings.ShowHyperlinks) || (hasShowHyperlinkChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.HYPERLINKS,
                                             Epi.Util.GetShortHand(cbxHyperlinks.Checked)));
            }
            if ((cbxPercents.Checked != config.Settings.ShowPercents) || (hasShowPercentsChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.PERCENTS,
                                             Epi.Util.GetShortHand(cbxPercents.Checked)));
            }
            if ((cbxSelectCriteria.Checked != config.Settings.ShowSelection) || (hasShowSelectChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.SELECT,
                                             Epi.Util.GetShortHand(cbxSelectCriteria.Checked)));
            }
            if ((cbxShowPrompt.Checked != config.Settings.ShowCompletePrompt) || (hasShowPromptChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.SHOWPROMPTS,
                                             Epi.Util.GetShortHand(cbxShowPrompt.Checked)));
            }
            if ((cbxTablesOutput.Checked != config.Settings.ShowTables) || (hasShowTablesChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.TABLES,
                                             Epi.Util.GetShortHand(cbxTablesOutput.Checked)));
            }
            if ((cbxIncludeMissing.Checked != config.Settings.IncludeMissingValues) || (hasIncludeMissingChanged))
            {
                kvPairs.Add(new KeyValuePair(CommandNames.MISSING,
                                             Epi.Util.GetShortHand(cbxIncludeMissing.Checked)));
            }
            if (hasStatisticsLevelChanged)
            {
                StatisticsLevel levelIdSelected  = (StatisticsLevel)short.Parse(WinUtil.GetSelectedRadioButton(gbxStatistics).Tag.ToString());
                string          levelTagSelected = AppData.Instance.GetStatisticsLevelById(levelIdSelected).Tag;
                kvPairs.Add(new KeyValuePair(CommandNames.STATISTICS, levelTagSelected));
            }
            if (hasProcessRecordsChanged)
            {
                RecordProcessingScope scopeIdSelected = (RecordProcessingScope)short.Parse(WinUtil.GetSelectedRadioButton(gbxProcessRecords).Tag.ToString());
                string scopeTagSelected = AppData.Instance.GetRecordProcessessingScopeById(scopeIdSelected).Tag;
                kvPairs.Add(new KeyValuePair(CommandNames.PROCESS, scopeTagSelected));
            }

            WordBuilder command = new WordBuilder();

            //Generate command only if there are key value pairs
            if (kvPairs.Count > 0)
            {
                if (!this.isDialogMode)
                {
                    command.Append(CommandNames.SET);
                }
                command.Append(kvPairs.ToString());
                if (!this.isDialogMode)
                {
                    command.Append(" END-SET\n");
                }
                this.CommandText = command.ToString();
            }
            else
            {
                this.CommandText = string.Empty;
            }
        }