Пример #1
0
        /// <summary>
        /// Creates a hash string based on the beacon ID1s in the given layout.
        /// </summary>
        /// <param name="layout">The layout containing the beacon ID1s.</param>
        /// <returns>A hash string of the beacon ID1s or null in case of an error.</returns>
        public static string CreateHashOfBeaconId1SInLayout(Layout layout)
        {

            if (layout != null)
            {
                IList<string> beaconId1S = layout.AccountBeaconId1S;

                if (beaconId1S.Count > 0)
                {
                    StringBuilder hash = new StringBuilder(beaconId1S[0]);

                    for (int i = 1; i < beaconId1S.Count; ++i)
                    {
                        var currentUuid = beaconId1S[i];

                        for (int j = 0; j < currentUuid.Length; ++j)
                        {
                            if (hash.Length < j + 1)
                            {
                                hash.Append(currentUuid[j]);
                            }
                            else
                            {
                                char combinationChar = (char) ((hash[j] + currentUuid[j])/2 + 1);

                                string hashToString = hash.ToString();
                                if (j == 0)
                                {
                                    hash = new StringBuilder(combinationChar);
                                    hash.Append(hashToString.Substring(j + 1));
                                }
                                else
                                {
                                    hash = new StringBuilder(hashToString.Substring(0, j));
                                    hash.Append(combinationChar);
                                    if (hash.Length > j + 1)
                                    {
                                        hash.Append(hashToString.Substring(j + 1));
                                    }
                                }
                            }
                        }
                    }
                    return hash.ToString();
                }
            }

            return null;
        }
 public void SetLayout(Layout layout)
 {
     Layout = layout;
 }