Exemplo n.º 1
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (ProductId != null)
         {
             hashCode = hashCode * 59 + ProductId.GetHashCode();
         }
         if (EffectiveFrom != null)
         {
             hashCode = hashCode * 59 + EffectiveFrom.GetHashCode();
         }
         if (EffectiveTo != null)
         {
             hashCode = hashCode * 59 + EffectiveTo.GetHashCode();
         }
         if (LastUpdated != null)
         {
             hashCode = hashCode * 59 + LastUpdated.GetHashCode();
         }
         if (ProductCategory != null)
         {
             hashCode = hashCode * 59 + ProductCategory.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Description != null)
         {
             hashCode = hashCode * 59 + Description.GetHashCode();
         }
         if (Brand != null)
         {
             hashCode = hashCode * 59 + Brand.GetHashCode();
         }
         if (BrandName != null)
         {
             hashCode = hashCode * 59 + BrandName.GetHashCode();
         }
         if (ApplicationUri != null)
         {
             hashCode = hashCode * 59 + ApplicationUri.GetHashCode();
         }
         if (IsTailored != null)
         {
             hashCode = hashCode * 59 + IsTailored.GetHashCode();
         }
         if (AdditionalInformation != null)
         {
             hashCode = hashCode * 59 + AdditionalInformation.GetHashCode();
         }
         return(hashCode);
     }
 }
Exemplo n.º 2
0
        private ClientConfigPaths(string exePath, bool includeUserConfig)
        {
            _includesUserConfig = includeUserConfig;

            Assembly exeAssembly  = null;
            bool     isSingleFile = false;

            if (exePath != null)
            {
                // Exe path was specified, use it
                ApplicationUri = Path.GetFullPath(exePath);
                if (!File.Exists(ApplicationUri))
                {
                    throw ExceptionUtil.ParameterInvalid(nameof(exePath));
                }
            }
            else
            {
                // Exe path wasn't specified, get it from the entry assembly
                exeAssembly = Assembly.GetEntryAssembly();

                // in case of SingleFile deployment, Assembly.Location is empty.
                if (exeAssembly?.Location.Length == 0)
                {
                    isSingleFile     = true;
                    HasEntryAssembly = true;
                }

                if (exeAssembly != null && !isSingleFile)
                {
                    HasEntryAssembly = true;

                    // The original .NET Framework code tried to get the local path without using Uri.
                    // If we ever find a need to do this again be careful with the logic. "file:///" is
                    // used for local paths and "file://" for UNCs. Simply removing the prefix will make
                    // local paths relative on Unix (e.g. "file:///home" will become "home" instead of
                    // "/home").
                    string configBasePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, exeAssembly.ManifestModule.Name);
                    Uri    uri            = new Uri(configBasePath);

                    Debug.Assert(uri.IsFile);
                    ApplicationUri = uri.LocalPath;
                }
                else
                {
                    try
                    {
                        // An EntryAssembly may not be found when running from a custom host.
                        // Try to find the native entry point.
                        using (Process currentProcess = Process.GetCurrentProcess())
                        {
                            ApplicationUri = currentProcess.MainModule?.FileName;
                        }
                    }
                    catch (PlatformNotSupportedException)
                    {
                        ApplicationUri = string.Empty;
                    }
                }
            }

            if (!string.IsNullOrEmpty(ApplicationUri))
            {
                string applicationPath = ApplicationUri;
                if (isSingleFile)
                {
                    // on Unix, we want to first append '.dll' extension and on Windows change '.exe' to '.dll'
                    // eventually, in ApplicationConfigUri we will get '{applicationName}.dll.config'
                    applicationPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
                                      Path.ChangeExtension(ApplicationUri, ".dll") : ApplicationUri + ".dll";
                }

                ApplicationConfigUri = applicationPath + ConfigExtension;
            }

            // In the case when exePath was explicitly supplied, we will not be able to
            // construct user.config paths, so quit here.
            if (exePath != null)
            {
                return;
            }

            // Skip expensive initialization of user config file information if requested.
            if (!_includesUserConfig)
            {
                return;
            }

            bool isHttp = StringUtil.StartsWithOrdinalIgnoreCase(ApplicationConfigUri, HttpUri);

            SetNamesAndVersion(exeAssembly, isHttp);
            if (isHttp)
            {
                return;
            }

            // Create a directory suffix for local and roaming config of three parts:

            // (1) Company name
            string part1 = Validate(_companyName, limitSize: true);

            // (2) Domain or product name & an application uri hash
            string namePrefix = Validate(AppDomain.CurrentDomain.FriendlyName, limitSize: true);

            if (string.IsNullOrEmpty(namePrefix))
            {
                namePrefix = Validate(ProductName, limitSize: true);
            }
            string applicationUriLower = !string.IsNullOrEmpty(ApplicationUri)
                ? ApplicationUri.ToLowerInvariant()
                : null;
            string hashSuffix = GetTypeAndHashSuffix(applicationUriLower, isSingleFile);
            string part2      = !string.IsNullOrEmpty(namePrefix) && !string.IsNullOrEmpty(hashSuffix)
                ? namePrefix + hashSuffix
                : null;

            // (3) The product version
            string part3 = Validate(ProductVersion, limitSize: false);

            string dirSuffix = CombineIfValid(CombineIfValid(part1, part2), part3);

            string roamingFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            if (Path.IsPathRooted(roamingFolderPath))
            {
                RoamingConfigDirectory = CombineIfValid(roamingFolderPath, dirSuffix);
                RoamingConfigFilename  = CombineIfValid(RoamingConfigDirectory, UserConfigFilename);
            }

            string localFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            if (Path.IsPathRooted(localFolderPath))
            {
                LocalConfigDirectory = CombineIfValid(localFolderPath, dirSuffix);
                LocalConfigFilename  = CombineIfValid(LocalConfigDirectory, UserConfigFilename);
            }
        }
Exemplo n.º 3
0
        private ClientConfigPaths(string exePath, bool includeUserConfig)
        {
            _includesUserConfig = includeUserConfig;

            Assembly exeAssembly         = null;
            string   applicationFilename = null;

            if (exePath != null)
            {
                // Exe path was specified, use it
                ApplicationUri = Path.GetFullPath(exePath);
                if (!File.Exists(ApplicationUri))
                {
                    throw ExceptionUtil.ParameterInvalid(nameof(exePath));
                }

                applicationFilename = ApplicationUri;
            }
            else
            {
                // Exe path wasn't specified, get it from the entry assembly
                exeAssembly = Assembly.GetEntryAssembly();

                if (exeAssembly == null)
                {
                    throw new PlatformNotSupportedException();
                }

                HasEntryAssembly = true;

                // The original .NET Framework code tried to get the local path without using Uri.
                // If we ever find a need to do this again be careful with the logic. "file:///" is
                // used for local paths and "file://" for UNCs. Simply removing the prefix will make
                // local paths relative on Unix (e.g. "file:///home" will become "home" instead of
                // "/home").
                string configBasePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, exeAssembly.ManifestModule.Name);
                Uri    uri            = new Uri(configBasePath);

                if (uri.IsFile)
                {
                    ApplicationUri      = uri.LocalPath;
                    applicationFilename = uri.LocalPath;
                }
                else
                {
                    ApplicationUri = Uri.EscapeDataString(configBasePath);
                }
            }

            ApplicationConfigUri = ApplicationUri + ConfigExtension;

            // In the case when exePath was explicitly supplied, we will not be able to
            // construct user.config paths, so quit here.
            if (exePath != null)
            {
                return;
            }

            // Skip expensive initialization of user config file information if requested.
            if (!_includesUserConfig)
            {
                return;
            }

            bool isHttp = StringUtil.StartsWithOrdinalIgnoreCase(ApplicationConfigUri, HttpUri);

            SetNamesAndVersion(applicationFilename, exeAssembly, isHttp);
            if (isHttp)
            {
                return;
            }

            // Create a directory suffix for local and roaming config of three parts:

            // (1) Company name
            string part1 = Validate(_companyName, limitSize: true);

            // (2) Domain or product name & an application urit hash
            string namePrefix = Validate(AppDomain.CurrentDomain.FriendlyName, limitSize: true);

            if (string.IsNullOrEmpty(namePrefix))
            {
                namePrefix = Validate(ProductName, limitSize: true);
            }
            string applicationUriLower = !string.IsNullOrEmpty(ApplicationUri)
                ? ApplicationUri.ToLowerInvariant()
                : null;
            string hashSuffix = GetTypeAndHashSuffix(applicationUriLower);
            string part2      = !string.IsNullOrEmpty(namePrefix) && !string.IsNullOrEmpty(hashSuffix)
                ? namePrefix + hashSuffix
                : null;

            // (3) The product version
            string part3 = Validate(ProductVersion, limitSize: false);

            string dirSuffix = CombineIfValid(CombineIfValid(part1, part2), part3);

            string roamingFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            if (Path.IsPathRooted(roamingFolderPath))
            {
                RoamingConfigDirectory = CombineIfValid(roamingFolderPath, dirSuffix);
                RoamingConfigFilename  = CombineIfValid(RoamingConfigDirectory, UserConfigFilename);
            }

            string localFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            if (Path.IsPathRooted(localFolderPath))
            {
                LocalConfigDirectory = CombineIfValid(localFolderPath, dirSuffix);
                LocalConfigFilename  = CombineIfValid(LocalConfigDirectory, UserConfigFilename);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns true if BankingProduct instances are equal
        /// </summary>
        /// <param name="other">Instance of BankingProduct to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(BankingProduct other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     ProductId == other.ProductId ||
                     ProductId != null &&
                     ProductId.Equals(other.ProductId)
                     ) &&
                 (
                     EffectiveFrom == other.EffectiveFrom ||
                     EffectiveFrom != null &&
                     EffectiveFrom.Equals(other.EffectiveFrom)
                 ) &&
                 (
                     EffectiveTo == other.EffectiveTo ||
                     EffectiveTo != null &&
                     EffectiveTo.Equals(other.EffectiveTo)
                 ) &&
                 (
                     LastUpdated == other.LastUpdated ||
                     LastUpdated != null &&
                     LastUpdated.Equals(other.LastUpdated)
                 ) &&
                 (
                     ProductCategory == other.ProductCategory ||
                     ProductCategory != null &&
                     ProductCategory.Equals(other.ProductCategory)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     Brand == other.Brand ||
                     Brand != null &&
                     Brand.Equals(other.Brand)
                 ) &&
                 (
                     BrandName == other.BrandName ||
                     BrandName != null &&
                     BrandName.Equals(other.BrandName)
                 ) &&
                 (
                     ApplicationUri == other.ApplicationUri ||
                     ApplicationUri != null &&
                     ApplicationUri.Equals(other.ApplicationUri)
                 ) &&
                 (
                     IsTailored == other.IsTailored ||
                     IsTailored != null &&
                     IsTailored.Equals(other.IsTailored)
                 ) &&
                 (
                     AdditionalInformation == other.AdditionalInformation ||
                     AdditionalInformation != null &&
                     AdditionalInformation.Equals(other.AdditionalInformation)
                 ));
        }
Exemplo n.º 5
0
        private ClientConfigPaths(string exePath, bool includeUserConfig)
        {
            _includesUserConfig = includeUserConfig;

            Assembly exeAssembly = null;
            string   applicationUri;
            string   applicationFilename = null;

            // get the assembly and applicationUri for the file
            if (exePath == null)
            {
                // Now figure out the application path.
                exeAssembly = Assembly.GetEntryAssembly();

                if (exeAssembly == null)
                {
                    throw new PlatformNotSupportedException();
                }

                HasEntryAssembly = true;
                applicationUri   = exeAssembly.CodeBase;

                bool isFile = false;

                if (StringUtil.StartsWithOrdinalIgnoreCase(applicationUri, FileUriLocal))
                {
                    // If it is a local file URI, convert it to its filename, without invoking Uri class.
                    // example: "file:///C:/WINNT/Microsoft.NET/Framework/v2.0.x86fre/csc.exe"
                    isFile         = true;
                    applicationUri = applicationUri.Substring(FileUriLocal.Length);
                }
                else
                {
                    // If it is a UNC file URI, convert it to its filename, without invoking Uri class.
                    // example: "file://server/share/csc.exe"
                    if (StringUtil.StartsWithOrdinalIgnoreCase(applicationUri, FileUriUnc))
                    {
                        isFile         = true;
                        applicationUri = applicationUri.Substring(FileUri.Length);
                    }
                }

                if (isFile)
                {
                    applicationUri      = applicationUri.Replace('/', '\\');
                    applicationFilename = applicationUri;
                }
                else
                {
                    applicationUri = exeAssembly.EscapedCodeBase;
                }
            }
            else
            {
                applicationUri = Path.GetFullPath(exePath);
                if (!File.Exists(applicationUri))
                {
                    throw ExceptionUtil.ParameterInvalid(nameof(exePath));
                }

                applicationFilename = applicationUri;
            }

            // Fallback if we haven't set the app config file path yet.
            if (ApplicationConfigUri == null)
            {
                ApplicationConfigUri = applicationUri + ConfigExtension;
            }

            // Set application path
            ApplicationUri = applicationUri;

            // In the case when exePath was explicitly supplied, we will not be able to
            // construct user.config paths, so quit here.
            if (exePath != null)
            {
                return;
            }

            // Skip expensive initialization of user config file information if requested.
            if (!_includesUserConfig)
            {
                return;
            }

            bool isHttp = StringUtil.StartsWithOrdinalIgnoreCase(ApplicationConfigUri, HttpUri);

            SetNamesAndVersion(applicationFilename, exeAssembly, isHttp);
            if (isHttp)
            {
                return;
            }

            string part1 = Validate(_companyName, limitSize: true);
            string validAppDomainName  = Validate(AppDomain.CurrentDomain.FriendlyName, limitSize: true);
            string applicationUriLower = !string.IsNullOrEmpty(ApplicationUri)
                ? ApplicationUri.ToLower(CultureInfo.InvariantCulture)
                : null;
            string namePrefix = !string.IsNullOrEmpty(validAppDomainName)
                ? validAppDomainName
                : Validate(ProductName, limitSize: true);
            string hashSuffix = GetTypeAndHashSuffix(applicationUriLower);

            string part2 = !string.IsNullOrEmpty(namePrefix) && !string.IsNullOrEmpty(hashSuffix)
                ? namePrefix + hashSuffix
                : null;

            string part3 = Validate(ProductVersion, limitSize: false);

            string dirSuffix = CombineIfValid(CombineIfValid(part1, part2), part3);

            string roamingFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            if (Path.IsPathRooted(roamingFolderPath))
            {
                RoamingConfigDirectory = CombineIfValid(roamingFolderPath, dirSuffix);
                RoamingConfigFilename  = CombineIfValid(RoamingConfigDirectory, UserConfigFilename);
            }

            string localFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            if (Path.IsPathRooted(localFolderPath))
            {
                LocalConfigDirectory = CombineIfValid(localFolderPath, dirSuffix);
                LocalConfigFilename  = CombineIfValid(LocalConfigDirectory, UserConfigFilename);
            }
        }