Beispiel #1
0
        /// <see>
        /// http://blogs.microsoft.co.il/yuvmaz/2013/05/10/longest-common-prefix-with-c-and-linq/
        /// </see>
        static string FindPrefix(string[] values)
        {
            if (values == null || values.Length == 0)
            {
                return(string.Empty);
            }

            const char SEPARATOR = '_';

            List <string> parts;

            parts = new List <string>(values[0].Split(SEPARATOR));

            for (int index = 1; index < values.Length; index++)
            {
                List <string> first     = parts;
                List <string> second    = new List <string>(values[index].Split(SEPARATOR));
                int           maxLength = Mathf.Min(first.Count, second.Count);
                List <string> tempParts = new List <string>(maxLength);
                for (int part = 0; part < maxLength; part++)
                {
                    if (first[part] == second[part])
                    {
                        tempParts.Add(first[part]);
                    }
                }
                parts = tempParts;
            }

            return(string.Join(SEPARATOR.ToString(), parts.ToArray()));
        }
Beispiel #2
0
        protected override string GetMessageToBeSent()
        {
            string proxySettings;

            switch (proxyStyle)
            {
            case HTTPHelper.ProxyStyle.SpecifiedProxy:
                proxySettings = String.Join(SEPARATOR.ToString(), new[] {
                    HealthCheckSettings.PROXY_SETTINGS,
                    ((Int32)HTTPHelper.ProxyStyle.SpecifiedProxy).ToString(),
                    proxyAddress,
                    proxyPort.ToString(),
                    timeOut.ToString(),
                    bypassProxyForServers.ToString(),
                    provideProxyCredentials.ToString(),
                    EncryptionUtils.ProtectForLocalMachine(proxyUsername),
                    EncryptionUtils.ProtectForLocalMachine(proxyPassword),
                    ((Int32)proxyAuthenticationMethod).ToString()
                });
                return(proxySettings);

            case HTTPHelper.ProxyStyle.SystemProxy:
                proxySettings = String.Join(SEPARATOR.ToString(), new[] {
                    HealthCheckSettings.PROXY_SETTINGS, ((Int32)HTTPHelper.ProxyStyle.SystemProxy).ToString()
                });
                return(proxySettings);

            default:
                proxySettings = String.Join(SEPARATOR.ToString(), new[] {
                    HealthCheckSettings.PROXY_SETTINGS, ((Int32)HTTPHelper.ProxyStyle.DirectConnection).ToString()
                });
                return(proxySettings);
            }
        }
Beispiel #3
0
        protected override string GetMessageToBeSent()
        {
            switch (proxyStyle)
            {
            case HTTPHelper.ProxyStyle.SpecifiedProxy:
                var proxyUsername = "";
                try
                {
                    if (!string.IsNullOrEmpty(protectedProxyUsername))
                    {
                        proxyUsername = EncryptionUtils.Unprotect(protectedProxyUsername);
                    }
                }
                catch (Exception e)
                {
                    log.Error("Could not unprotect internet proxy username.", e);
                    return(null);
                }

                var proxyPassword = "";
                try
                {
                    if (!string.IsNullOrEmpty(protectedProxyPassword))
                    {
                        proxyPassword = EncryptionUtils.Unprotect(protectedProxyPassword);
                    }
                }
                catch (Exception e)
                {
                    log.Error("Could not unprotect internet proxy password.", e);
                    return(null);
                }

                return(string.Join(SEPARATOR.ToString(),
                                   HealthCheckSettings.PROXY_SETTINGS,
                                   ((int)HTTPHelper.ProxyStyle.SpecifiedProxy).ToString(),
                                   proxyAddress, proxyPort.ToString(),
                                   timeOut.ToString(),
                                   bypassProxyForServers.ToString(),
                                   provideProxyCredentials.ToString(),
                                   EncryptionUtils.ProtectForLocalMachine(proxyUsername),
                                   EncryptionUtils.ProtectForLocalMachine(proxyPassword),
                                   ((int)proxyAuthenticationMethod).ToString()));

            case HTTPHelper.ProxyStyle.SystemProxy:
                return(string.Join(SEPARATOR.ToString(),
                                   HealthCheckSettings.PROXY_SETTINGS,
                                   ((int)HTTPHelper.ProxyStyle.SystemProxy).ToString()));

            default:
                return(string.Join(SEPARATOR.ToString(),
                                   HealthCheckSettings.PROXY_SETTINGS,
                                   ((int)HTTPHelper.ProxyStyle.DirectConnection).ToString()));
            }
        }
        /// <summary>
        /// Serializes the keys present in the in-memory representation of the index.
        /// </summary>
        /// <returns>The keys.</returns>
        protected string SerializeKeys()
        {
            string[] data  = new string[_INDEX.Count];
            int      index = 0;

            foreach (var kv in _INDEX)
            {
                data[index++] = string.Format("{0}:{1}", kv.Key, kv.Value);
            }
            return(string.Join(SEPARATOR.ToString(), data));
        }
        protected override string GetMessageToBeSent()
        {
            var host = Helpers.GetMaster(pool.Connection);

            if (host == null)
            {
                return(null);
            }

            if (healthCheckSettings.Status == HealthCheckStatus.Enabled && (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)))
            {
                return(null); // do not send empty/null username or password (when the Health Check is enabled), as they will be ignored
            }
            var credential = healthCheckSettings.Status == HealthCheckStatus.Enabled
                ? String.Join(SEPARATOR.ToString(), host.address, username, password)
                : String.Join(SEPARATOR.ToString(), host.address);

            return(EncryptionUtils.ProtectForLocalMachine(credential));
        }
Beispiel #6
0
        private string GetLongestCommonPrefix(IEnumerable <string> pathes)
        {
            if (pathes == null || pathes.Count() == 0)
            {
                return(String.Empty);
            }

            const char SEPARATOR = '/';

            string[] prefixParts =
                pathes.Select(dir => dir.Split(SEPARATOR))
                .Aggregate(
                    (first, second) => first.Zip(second, (a, b) =>
                                                 new { First = a, Second = b })
                    .TakeWhile(pair => pair.First.Equals(pair.Second))
                    .Select(pair => pair.First)
                    .ToArray()
                    );

            return(string.Join(SEPARATOR.ToString(), prefixParts));
        }
Beispiel #7
0
 public void Load()
 {
     Route = new Stack <Library.Point>();
     if (Handle.Exists)
     {
         var stream = Handle.Open(FileMode.Open, FileAccess.Read);
         var reader = new StreamReader(stream);
         for (string line = null; (line = reader.ReadLine()) != null;)
         {
             string[] temp = line.Trim().Split(SEPARATOR.ToCharArray());
             double   x, y, z;
             if (temp.Length == 3 &&
                 double.TryParse(temp[0].Trim(), out x) &&
                 double.TryParse(temp[1].Trim(), out y) &&
                 double.TryParse(temp[2].Trim(), out z))
             {
                 Route.Push(new Library.Point(x, y, z));
             }
         }
         stream.Close();
     }
 }
 /// <summary>
 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </returns>
 public override string ToString()
 {
     return(String.Join(SEPARATOR.ToString(), new string[] { base.ToString(), EmailMsgId.ToString(), EmailAttachmentIndex.ToString() }));
 }
Beispiel #9
0
 protected override string GetMessageToBeSent()
 {
     return(string.Join(SEPARATOR.ToString(), HealthCheckSettings.XENCENTER_METADATA,
                        EncryptionUtils.ProtectForLocalMachine(metadata)));
 }
Beispiel #10
0
 /// <summary>
 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </returns>
 public override string ToString()
 {
     return(String.Join(SEPARATOR.ToString(), new string[] { base.ToString(), UniqueId.ToString(), HistoryId.ToString() }));
 }
Beispiel #11
0
 /// <summary>
 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </returns>
 public override string ToString()
 {
     return(String.Join(SEPARATOR.ToString(), new string[] { base.ToString(), UniqueId.ToString(),
                                                             MetaObjectType, MetaObjectId.ToString(), MetaFieldName.ToString() }) + SEPARATOR);
 }
Beispiel #12
0
 /// <summary>
 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </returns>
 public override string ToString()
 {
     return(String.Join(SEPARATOR.ToString(), new string[] { base.ToString(), FileUID.ToString() }));
 }