Example #1
0
        public async Task ExecuteAsync(BatchMapDataCommand command)
        {
            var mapperFunc = (IMapperFunc)_serviceProvider.GetService(_config.MapperFuncType);

            var keyValuePairCollection = new KeyValuePairCollection();

            foreach (var line in command.Lines)
            {
                keyValuePairCollection.AddRange(mapperFunc.Map(line));
            }

            var resultOfMap2 = new List <CompressedMostAccidentProneData>();

            foreach (var kvp in keyValuePairCollection)
            {
                var mostAccidentProneKvp = kvp as MostAccidentProneKvp;
                resultOfMap2.Add(new CompressedMostAccidentProneData
                {
                    M = mostAccidentProneKvp.Key,
                    S = new CompressedAccidentStats
                    {
                        A = mostAccidentProneKvp.Value.NoOfAccidents,
                        C = mostAccidentProneKvp.Value.NoOfCarsRegistered,
                        R = mostAccidentProneKvp.Value.RegistrationsPerAccident
                    }
                });
            }

            await _commandDispatcher.DispatchAsync(new WriteMappedDataCommand
            {
                ContextQueueMessage = command.ContextQueueMessage,
//                ResultOfMap = keyValuePairCollection,
                ResultOfMap2 = resultOfMap2
            });
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="keyValuePairs"></param>
        public MqttTlsCertificates(KeyValuePairCollection keyValuePairs)
        {
            m_caCertificatePath = "";
            QualifiedName qCaCertificatePath = EnumMqttClientConfigurationParameters.TlsCertificateCaCertificatePath.ToString();

            m_caCertificatePath = keyValuePairs.Find(kvp => kvp.Key.Name.Equals(qCaCertificatePath.Name))?.Value.Value as string;

            m_clientCertificatePath = "";
            QualifiedName qClientCertificatePath = EnumMqttClientConfigurationParameters.TlsCertificateClientCertificatePath.ToString();

            m_clientCertificatePath = keyValuePairs.Find(kvp => kvp.Key.Name.Equals(qClientCertificatePath.Name))?.Value.Value as string;

            m_clientCertificatePassword = "";
            QualifiedName qClientCertificatePassword = EnumMqttClientConfigurationParameters.TlsCertificateClientCertificatePassword.ToString();

            m_clientCertificatePassword = keyValuePairs.Find(kvp => kvp.Key.Name.Equals(qClientCertificatePassword.Name))?.Value.Value as string;

            m_keyValuePairs = keyValuePairs;

            if (!string.IsNullOrEmpty(m_caCertificatePath))
            {
                m_caCertificate = X509Certificate.CreateFromCertFile(m_caCertificatePath);
            }
            if (!string.IsNullOrEmpty(clientCertificatePath))
            {
                m_clientCertificate = new X509Certificate2(clientCertificatePath, m_clientCertificatePassword);
            }
        }
        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);
        }
Example #4
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);
        }
Example #5
0
        public KeyValuePairCollection Reduce(KeyValuePairCollection inputKeyValuePairs)
        {
            var countKvps = inputKeyValuePairs
                            .GroupBy(x => ((CountKvp)x).Key)
                            .Select(x => (IKeyValuePair) new CountKvp(
                                        x.Key,
                                        x.Sum(y => ((CountKvp)y).Value)
                                        )
                                    );

            return(new KeyValuePairCollection(countKvps));
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="kvpMqttOptions">The key value pairs representing the values from which to construct MqttTlsOptions</param>
        public MqttTlsOptions(KeyValuePairCollection kvpMqttOptions)
        {
            m_certificates = new MqttTlsCertificates(kvpMqttOptions);

            QualifiedName qSslProtocolVersion = EnumMqttClientConfigurationParameters.TlsProtocolVersion.ToString();

            m_SslProtocolVersion = (SslProtocols)Convert.ToInt32(kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qSslProtocolVersion.Name))?.Value.Value);

            QualifiedName qAllowUntrustedCertificates = EnumMqttClientConfigurationParameters.TlsAllowUntrustedCertificates.ToString();

            m_allowUntrustedCertificates = Convert.ToBoolean(kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qAllowUntrustedCertificates.Name))?.Value.Value);

            QualifiedName qIgnoreCertificateChainErrors = EnumMqttClientConfigurationParameters.TlsIgnoreCertificateChainErrors.ToString();

            m_ignoreCertificateChainErrors = Convert.ToBoolean(kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qIgnoreCertificateChainErrors.Name))?.Value.Value);

            QualifiedName qIgnoreRevocationListErrors = EnumMqttClientConfigurationParameters.TlsIgnoreRevocationListErrors.ToString();

            m_ignoreRevocationListErrors = Convert.ToBoolean(kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qIgnoreRevocationListErrors.Name))?.Value.Value);

            QualifiedName qTrustedIssuerCertificatesStoreType = EnumMqttClientConfigurationParameters.TrustedIssuerCertificatesStoreType.ToString();
            string        issuerCertificatesStoreType         = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qTrustedIssuerCertificatesStoreType.Name))?.Value.Value as string;
            QualifiedName qTrustedIssuerCertificatesStorePath = EnumMqttClientConfigurationParameters.TrustedIssuerCertificatesStorePath.ToString();
            string        issuerCertificatesStorePath         = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qTrustedIssuerCertificatesStorePath.Name))?.Value.Value as string;

            m_trustedIssuerCertificates = new CertificateTrustList {
                StoreType = issuerCertificatesStoreType,
                StorePath = issuerCertificatesStorePath
            };

            QualifiedName qTrustedPeerCertificatesStoreType = EnumMqttClientConfigurationParameters.TrustedPeerCertificatesStoreType.ToString();
            string        peerCertificatesStoreType         = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qTrustedPeerCertificatesStoreType.Name))?.Value.Value as string;
            QualifiedName qTrustedPeerCertificatesStorePath = EnumMqttClientConfigurationParameters.TrustedPeerCertificatesStorePath.ToString();
            string        peerCertificatesStorePath         = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qTrustedPeerCertificatesStorePath.Name))?.Value.Value as string;

            m_trustedPeerCertificates = new CertificateTrustList {
                StoreType = peerCertificatesStoreType,
                StorePath = peerCertificatesStorePath
            };

            QualifiedName qRejectedCertificateStoreStoreType = EnumMqttClientConfigurationParameters.RejectedCertificateStoreStoreType.ToString();
            string        rejectedCertificateStoreStoreType  = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qRejectedCertificateStoreStoreType.Name))?.Value.Value as string;
            QualifiedName qRejectedCertificateStoreStorePath = EnumMqttClientConfigurationParameters.RejectedCertificateStoreStorePath.ToString();
            string        rejectedCertificateStoreStorePath  = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qRejectedCertificateStoreStorePath.Name))?.Value.Value as string;

            m_rejectedCertificateStore = new CertificateTrustList {
                StoreType = rejectedCertificateStoreStoreType,
                StorePath = rejectedCertificateStoreStorePath
            };

            m_keyValuePairs = kvpMqttOptions;
        }
        private string KeyValuePairCollectionHash(KeyValuePairCollection keyValuePairCollection)
        {
            var stringBuilder = new StringBuilder();

            foreach (var kvp in keyValuePairCollection)
            {
                stringBuilder.Append(JsonConvert.SerializeObject(kvp,
                                                                 new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                }));
            }

            return(HashHelper.GetHashSha256(stringBuilder.ToString()));
        }
Example #8
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();
        }
 /// <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));
         }
     }
 }
        public void Test()
        {
            // Arrange
            var makeAccidentCountReducer = new MakeAccidentCountReducer();
            var keyValuePairInputs       = new KeyValuePairCollection
            {
                new CountKvp("Ford", 1),
                new CountKvp("Vauxhall", 2),
                new CountKvp("Ford", 1),
                new CountKvp("Lotus", 3),
                new CountKvp("Lotus", 1),
            };

            // Act
            var keyValuePairOutputs = makeAccidentCountReducer.Reduce(keyValuePairInputs);

            // Assert
            keyValuePairOutputs.Count.ShouldBe(3);
            keyValuePairOutputs.ShouldContain(kvp => ((CountKvp)kvp).Key == "Ford" && ((CountKvp)kvp).Value == 2);
            keyValuePairOutputs.ShouldContain(kvp => ((CountKvp)kvp).Key == "Vauxhall" && ((CountKvp)kvp).Value == 2);
            keyValuePairOutputs.ShouldContain(kvp => ((CountKvp)kvp).Key == "Lotus" && ((CountKvp)kvp).Value == 4);
        }
        /// <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);
        }
        private KeyValuePairCollection<string, string> userRolesCollection; // Not an optimal collection to be used for this,

        #endregion Fields

        #region Constructors

        // but had problems in XML serialization with other objects
        public PermissionsParameters()
        {
            userList = new List<User>();
            roleList = new List<Role>();
            userRolesCollection = new KeyValuePairCollection<string, string>();
        }
        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);
        }
        string Process(
            KeyValuePairCollection kvpc,
            string nullValue,
            string emptyValue)
        {
            if (kvpc.Count == 0)
                return emptyValue;

            // find length of the longest key
            var maxKeyLen =
                (from kvp in kvpc
                 select kvp.Key.Length).Max();

            var sb = new StringBuilder();

            for (int i = 0; i < kvpc.Count; i++)
            {
                var kvp = kvpc[i];

                //# Key
                var keyLen = kvp.Key.Length;

                var numberOfTabsToFill =
                    (int)((maxKeyLen - Math.Floor(keyLen / 4.0) * 4) / TabSize) + 1;

                var alignmentStr = new string('\t', numberOfTabsToFill);

                var keyStr = "{0}{1}:".FormatWith(kvp.Key, alignmentStr);

                var keyStrLen = keyStr.GetLengthWithExpandedTabs(TabSize);

                //# Value

                var childKvpc = kvp.Value as KeyValuePairCollection;

                if (childKvpc != null)
                {
                    //# Value is KVPCollection

                    // start on a new line
                    // separator '--' from start of a ke to end of a key
                    // indent all lines by one '\t';

                    // e.g.
                    //  Message :   "msg"
                    //  Data    :
                    //  ----------
                    //      x   :   "v1"
                    //      y   :   "v2"

                    //# do not write key if it's empty
                    if (kvp.Key != "")
                    {
                        sb.Append(keyStr);
                        sb.AppendLine();
                        sb.Append(new string('-', keyStrLen));
                        sb.AppendLine();
                    }

                    var childAsString = Write(childKvpc, nullValue, emptyValue);

                    sb.Append(childAsString.PrefixEachLine("\t"));
                }
                else
                {
                    var valueStr = Write(kvp.Value, nullValue, emptyValue);

                    if (valueStr.IsMultiLine())
                    {
                        //# Multi-Line Values

                        // start on a new line
                        // separator '--' from start of a ke to end of a key
                        // indent all lines by one '\t';

                        // e.g.
                        //  Stack Trace  :
                        //  --------------
                        //      line_one_goes_here
                        //      line_two_goes_here

                        //# do not write key if it's empty
                        if (kvp.Key != "")
                        {
                            sb.Append(keyStr);
                            sb.AppendLine();
                            sb.Append(new string('-', keyStrLen));
                            sb.AppendLine();
                        }

                        var lines = valueStr.GetLines();

                        for (int lx = 0; lx < lines.Length; lx++)
                        {
                            // any other line indented by \t
                            sb.Append("\t" + lines[lx]);

                            if (lx < lines.Length - 1)
                                sb.AppendLine();
                        }
                    }
                    else
                    {
                        //# Single-Line Values

                        // write on a same line, prefix with '\t'

                        sb.Append("{0}\t{1}".FormatWith(keyStr, valueStr));
                    }
                }

                if(i < kvpc.Count - 1)
                    sb.AppendLine();

            }

            return sb.ToString();
        }
Example #16
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;
            }
        }
 /// <inheritdoc/>
 public virtual void Decode(IDecoder decoder)
 {
     Fields = (KeyValuePairCollection)decoder.ReadEncodeableArray(
         "EventFields", typeof(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);
        }
 /// <summary>
 /// Create
 /// </summary>
 public EncodeableDictionary()
 {
     Fields = new KeyValuePairCollection();
 }
Example #20
0
        private void ShowMatchFieldsDialog(string tableName)
        {
            Project project = page.GetProject();

            List <string> selectedFields = new List <string>();

            foreach (Field field in SelectedFields)
            {
                selectedFields.Add(field.Name);
            }

            Dictionary <string, string> fieldColumnNamePairs = new Dictionary <string, string>();

            foreach (KeyValuePair <string, int> kvp in ddlField.PairAssociated)
            {
                Field fieldById = page.view.GetFieldById(kvp.Value);
                fieldColumnNamePairs.Add(fieldById.Name, kvp.Key);
            }

            MatchFieldsDialog dialog = new MatchFieldsDialog
                                       (
                MainForm,
                project,
                tableName,
                selectedFields,
                ddlField.TextColumnName,
                fieldColumnNamePairs);

            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string valueTableName = tableName.ToString() + "value";

                fieldSetupTable = new DataTable(tableName);
                fieldSetupTable.Columns.Add(fieldName, dialog.PrimaryColumnData.GetType());
                fieldValueSetupTable = new DataTable(valueTableName);

                if (project.CollectedData.TableExists(tableName))
                {
                    fieldValueSetupTable = project.GetTableData(tableName, dialog.PrimaryColumnData.ToString());
                }

                newCodeTable = new DataTable();
                newCodeTable = fieldValueSetupTable.Clone();
                newCodeTable.Clear();

                if (newCodeTable.Columns.Count > 0)
                {
                    newCodeTable.Columns.RemoveAt(0);
                }

                newCodeTable.Columns.Add(fieldName, dialog.PrimaryColumnData.GetType());

                foreach (DataRow row in fieldValueSetupTable.Rows)
                {
                    DataRow rowToAdd = newCodeTable.NewRow();
                    rowToAdd[0] = row[0];
                    newCodeTable.Rows.Add(rowToAdd);
                }

                kvPairs = dialog.Codes;

                System.Collections.ArrayList codeColumns = new System.Collections.ArrayList();
                string columnNames = string.Empty;

                foreach (KeyValuePair kvPair in kvPairs)
                {
                    codeColumns.Add(kvPair.Value);
                    columnNames += kvPair.Value.ToString() + StringLiterals.COMMA;
                }

                if (columnNames.Length > 1)
                {
                    columnNames = columnNames.Substring(0, (columnNames.Length - 1));
                }

                sourceTableName = tableName;
                textColumnName  = dialog.PrimaryColumnData;

                if (Mode == CreationMode.CreateNewFromExisting)
                {
                    textColumnName = fieldName;

                    string[] comma  = { "," };
                    string   column = string.Empty;

                    foreach (KeyValuePair kvPair in kvPairs)
                    {
                        column += kvPair.Key.ToString() + StringLiterals.COMMA;
                    }

                    if (column.Length > 1)
                    {
                        column = column.Substring(0, (column.Length - 1));
                    }

                    string[] columns = column.Split(comma, StringSplitOptions.None);

                    for (int i = 0; i < columns.Length; i++)
                    {
                        newCodeTable.Columns.Add(columns[i]);
                    }

                    string columnNamesForValues = string.Empty;

                    foreach (KeyValuePair kvPair in kvPairs)
                    {
                        columnNamesForValues += kvPair.Value.ToString() + StringLiterals.COMMA;
                    }

                    if (columnNamesForValues.Length > 1)
                    {
                        columnNamesForValues = columnNamesForValues.Substring(0, (columnNamesForValues.Length - 1));
                    }

                    string newTableColumnName = string.Empty;
                    string existingColumnName = string.Empty;

                    foreach (DataColumn dataColumnOfNewTable in newCodeTable.Columns)
                    {
                        newTableColumnName = dataColumnOfNewTable.ColumnName;

                        foreach (KeyValuePair kvPair in kvPairs)
                        {
                            if (kvPair.Key == newTableColumnName)
                            {
                                existingColumnName = kvPair.Value;
                                break;
                            }
                        }

                        if (string.IsNullOrEmpty(existingColumnName) == false)
                        {
                            for (int i = 0; i < codeTable.Rows.Count; i++)
                            {
                                newCodeTable.Rows[i][newTableColumnName] = codeTable.Rows[i][existingColumnName];
                            }
                        }
                    }

                    sourceTableName        = GetNewCodeTableName(FieldName);
                    newCodeTable.TableName = sourceTableName;
                    codeTable = newCodeTable;
                }
                else
                {
                    relateCondition = string.Empty;

                    foreach (KeyValuePair kvPair in kvPairs)
                    {
                        relateCondition = relateCondition.Length > 0 ? relateCondition + "," : relateCondition;
                        int fieldId = this.page.Fields[kvPair.Key].Id;
                        relateCondition = string.Format("{0}{1}:{2}", relateCondition, kvPair.Value, fieldId);
                    }
                }

                dialog.Close();
                DisplayData();
            }
        }
Example #21
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));
                }
            }
        }
Example #22
0
 public MappingEditorViewModel(MappingEditorParameters <TSourceEnum, TTargetEnum> parameters, Config config)
 {
     Mapping       = new KeyValuePairCollection <TSourceEnum, TTargetEnum>(parameters.Mappings);
     ApplyToConfig = parameters.ApplyToConfig;
     Config        = config;
 }