private List <ProviderFactoryInfo> InitializeProviderFactories(ProviderKey key, IEnumerable <ITypeProvider> providerCollection, ProviderFactoryInfo loadedFactory)
        {
            var loadedFactoryPassedIn = false;

            if (loadedFactory != null && !string.IsNullOrEmpty(loadedFactory.Name))
            {
                loadedFactoryPassedIn = true;
            }

            var factories = new List <ProviderFactoryInfo>();

            if (providerCollection == null || !providerCollection.Any())
            {
                return(factories);
            }

            foreach (var provider in providerCollection)
            {
                if (loadedFactoryPassedIn)
                {
                    if (loadedFactory.Name.Equals(provider.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        factories.Add(loadedFactory);
                        continue;
                    }
                }

                factories.Add(new ProviderFactoryInfo(key, provider.Name, ValidateProviderType(provider.Type)));
            }

            return(factories);
        }
Example #2
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((LoginProvider != null ? ProviderKey.GetHashCode() : 0) * 397) ^ (LoginProvider != null ? ProviderKey.GetHashCode() : 0));
     }
 }
        private static IAuthenticationProvider DiscoverProvider(IEnumerable <Type> discoveredProviders,
                                                                ProviderKey providerKey)
        {
            if (discoveredProviders == null)
            {
                throw new ArgumentNullException("discoveredProviders");
            }

            if (providerKey == null)
            {
                throw new ArgumentNullException("providerKey");
            }

            var name = providerKey.Name.ToLowerInvariant();

            var provider = discoveredProviders.SingleOrDefault(x => x.Name.ToLowerInvariant().StartsWith(name));

            if (provider == null)
            {
                var errorMessage =
                    string.Format(
                        "Unable to find the provider [{0}]. Is there a provider dll available? Is there a typo in the provider name? Solution suggestions: Check to make sure the correct dll's are in the 'bin' directory and/or check the name to make sure there's no typo's in there. Example: If you're trying include the GitHub provider, make sure the name is 'github' (any case) and that the ExtraProviders dll exists in the 'bin' directory or make sure you've downloaded the package via NuGet -> install-package SimpleAuthentication.ExtraProviders.",
                        name);
                //TraceSource.TraceError(errorMessage);
                throw new ApplicationException(errorMessage);
            }

            IAuthenticationProvider authenticationProvider = null;

            // Make sure we have a provider with the correct constructor parameters.
            // How? If a person creates their own provider and doesn't offer a constructor
            // that has a sigle ProviderParams, then we're stuffed. So we need to help them.
            if (provider.GetConstructor(new[] { typeof(ProviderParams) }) != null)
            {
                var parameters = new ProviderParams
                {
                    PublicApiKey = providerKey.Key,
                    SecretApiKey = providerKey.Secret,
                    Scopes       = string.IsNullOrEmpty(providerKey.Scope)
                                                  ? null
                                                  : providerKey.Scope.Split(new[] { ',' },
                                                                            StringSplitOptions.RemoveEmptyEntries)
                };
                authenticationProvider = Activator.CreateInstance(provider, parameters) as IAuthenticationProvider;
            }

            if (authenticationProvider == null)
            {
                // We didn't find a proper constructor for the provider class we wish to instantiate.
                var errorMessage =
                    string.Format(
                        "The type {0} doesn't have the proper constructor. It requires a constructor that only accepts 1 argument of type ProviderParams. Eg. public MyProvider(ProviderParams providerParams){{ .. }}.",
                        provider.FullName);
                //TraceSource.TraceError(errorMessage);
                throw new ApplicationException(errorMessage);
            }

            return(authenticationProvider);
        }
        public virtual int _GetUniqueIdentifier()
        {
            var hashCode = 399326290;

            hashCode = hashCode * -1521134295 + (Id?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (LoginProvider?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (ProviderKey?.GetHashCode() ?? 0);
            return(hashCode);
        }
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = LoginProvider.GetHashCode();
         hashCode = (hashCode * 397) ^ ProviderKey.GetHashCode();
         return(hashCode);
     }
 }
Example #6
0
 public override int GetHashCode()
 {
     unchecked {
         const int randomPrime = 397;
         int       hashCode    = Id.GetHashCode();
         hashCode = (hashCode * randomPrime) ^ (LoginProvider != null ? LoginProvider.GetHashCode() : 0);
         hashCode = (hashCode * randomPrime) ^ (ProviderKey != null ? ProviderKey.GetHashCode() : 0);
         hashCode = (hashCode * randomPrime) ^ UserId.GetHashCode();
         return(hashCode);
     }
 }
Example #7
0
 public Node(ProviderKey provider, TreeNode root, Node parentNode, NodeData value, ENodeType nodeType, INodePipeline pipeline = null)
 {
     Provider        = provider;
     this.root       = root;
     this.parentNode = parentNode;
     this.value      = value;
     this.nodeType   = nodeType;
     this.pipeline   = pipeline;
     Key             = this.GetTreeKey();
     Topic           = this.GetTopic(parentNode);
 }
Example #8
0
 public override int GetHashCode()
 {
     unchecked {
         int result = (ProviderKey != null ? ProviderKey.GetHashCode() : 0);
         result = (result * 397) ^ IsDeleted.GetHashCode();
         result = (result * 397) ^ Id.GetHashCode();
         result = (result * 397) ^ (Fields != null ? Fields.GetHashCode() : 0);
         result = (result * 397) ^ (Tags != null ? Tags.GetHashCode() : 0);
         result = (result * 397) ^ (Notes != null ? Notes.GetHashCode() : 0);
         return(result);
     }
 }
        /// <summary>
        /// Method used when using custom config section
        /// </summary>
        private static IAuthenticationProvider DiscoverProvider(IList <Type> discoveredProviders,
                                                                ProviderKey providerKey)
        {
            providerKey.ThrowIfNull("providerKey");

            var name = providerKey.Name.ToLowerInvariant();

            return(DiscoverProvider(discoveredProviders, name, () => new ProviderParams
            {
                PublicApiKey = providerKey.Key,
                SecretApiKey = providerKey.Secret,
                Scopes = providerKey.Scope.ScopesToCollection()
            }));
        }
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is ApplicationUserLogin))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(LoginProvider) ||
                string.IsNullOrEmpty(this.ProviderKey))
            {
                return(false);
            }

            return(LoginProvider.Equals((obj as ApplicationUserLogin).LoginProvider) &&
                   ProviderKey.Equals((obj as ApplicationUserLogin).ProviderKey));
        }
Example #11
0
 public override int GetHashCode()
 {
     return(Id.GetHashCode() ^
            PersonId.GetHashCode() ^
            ConceptId.GetHashCode() ^
            TypeConceptId.GetHashCode() ^
            (SourceValue != null ? SourceValue.GetHashCode() : 0) ^
            SourceConceptId.GetHashCode() ^
            (CareSiteId.GetHashCode()) ^
            (StartDate.GetHashCode()) ^
            (EndDate.GetHashCode()) ^
            AdmittingSourceConceptId.GetHashCode() ^
            (AdmittingSourceValue != null ? AdmittingSourceValue.GetHashCode() : 0) ^
            (ProviderKey != null ? ProviderKey.GetHashCode() : 0) ^
            (ProviderId.GetHashCode()) ^
            DischargeToConceptId.GetHashCode() ^
            (DischargeToSourceValue != null ? DischargeToSourceValue.GetHashCode() : 0) ^
            PrecedingVisitDetailId.GetHashCode() ^
            VisitDetailParentId.GetHashCode());
 }
Example #12
0
 public DictionaryNode(ProviderKey provider, TreeNode root, Node parentNode, NodeData value, ENodeType nodeType, string childArrayName, INodePipeline pipeline = null)
     : base(provider, root, parentNode, value, nodeType, pipeline)
 {
     this.childArrayName = childArrayName;
 }
        private IEnumerable <TProvider> GetProviderInstances <TProvider>(ProviderFactoryInfo[] factories, ProviderKey key, Func <Type, object> creator)
            where TProvider : class
        {
            IEnumerable <TProvider> providers;

            TryGetProviderInstances <TProvider>(factories, key, creator, (p, f) => true, out providers);
            return(providers);
        }
 private IEnumerable <TProvider> GetProviderInstances <TProvider>(ProviderFactoryInfo[] factories, ProviderKey key)
     where TProvider : class
 {
     return(GetProviderInstances <TProvider>(factories, key, null));
 }
Example #15
0
        private static IAuthenticationProvider DiscoverProvider(IEnumerable <Type> discoveredProviders, ProviderKey providerKey)
        {
            var name = providerKey.Name.ToLowerInvariant();

            var provider = discoveredProviders.SingleOrDefault(x => x.Name.ToLowerInvariant().StartsWith(name));

            if (provider == null)
            {
                throw new ApplicationException(
                          string.Format("Unable to find the provider [{0}]. Is there a provider dll available? Is there a typo in the provider name? Solution suggestions: Check to make sure the correct dll's are in the 'bin' directory and/or check the name to make sure there's no typo's in there. Example: If you're trying include the GitHub provider, make sure the name is 'github' (any case) and that the ExtraProviders dll exists in the 'bin' directory.",
                                        name));
            }

            var parameters = new ProviderParams
            {
                Key    = providerKey.Key,
                Secret = providerKey.Secret
            };

            return(Activator.CreateInstance(provider, parameters) as IAuthenticationProvider);
        }
        private void Validate(string datafile, string schema)
        {
            CurrentStep = this["SchemaValidation"];
            CurrentStep.Start();

            //Ensure all required parameters are available
            if (_schema == string.Empty || UniqueFileName == string.Empty || _connectionString == string.Empty ||
                _mappingSchema == string.Empty || _schema == null || UniqueFileName == null ||
                _connectionString == null ||
                _mappingSchema == null)
            {
                //PublishError("Bulk Upload", 3, "Missing Schema, Mapping Schema, Data File or Connection String.", _inputFileHistoryCode, null, null);
                _errorCode     = 1;
                _isSchemaValid = false;
                throw new ApplicationException("Missing Schema, Mapping Schema, Data File or Connection String.");
            }
            else
            {
                //Consider making the XmlReaderSettings instance static if it uses the same settings
                //for all xml validation
                XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
                xmlReaderSettings.CheckCharacters = true;
                xmlReaderSettings.CloseInput      = true;
                //if you have a finite number of schemas, consider caching each schema in
                //a static XmlSchemaSet instance
                xmlReaderSettings.Schemas.Add(null, schema);
                xmlReaderSettings.ValidationType   = ValidationType.Schema;
                xmlReaderSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
                //...add any other ValidationFlags necessary here...

                xmlReaderSettings.ValidationEventHandler += new ValidationEventHandler(ShowCompileErrors);
                try
                {
                    //Wrap the creation of the XmlReader in a 'using' block since
                    //it implements IDisposable

                    string     SchemaVersion = "";
                    int        MaxChunksToReadForSchemaVersionCountdown = 10; // Max number of xml chunks to read to try and get schema version
                    int        PercentThroughOld = 0;
                    int        PercentThroughInt = 0;
                    FileStream DataFileStream    = new FileStream(datafile, FileMode.Open, FileAccess.Read);
                    using (XmlReader xmlReader = XmlReader.Create(DataFileStream, xmlReaderSettings))
                    {
                        if (xmlReader != null)
                        {
                            // Definitions for reading extra info surrounding DOB
                            string LastRegion    = string.Empty;
                            string LastAgreement = string.Empty;
                            string LastParticipantReferenceID = string.Empty;
                            string LastStartDate = string.Empty;

                            while (xmlReader.Read())
                            {
                                if (xmlReader.LocalName == "ParticipantInformation" && xmlReader.IsStartElement())
                                {
                                    SchemaVersion = xmlReader.GetAttribute("SchemaVersion");
                                }

                                if (MaxChunksToReadForSchemaVersionCountdown < 1 && SchemaVersion != "1.0")
                                {
                                    // Set the error and exit immediately as this must be an invalid xml file, e.g.,
                                    // saved from excel!!
                                    _errorCode     = 5;
                                    _isSchemaValid = false;
                                    spRunner2.PublishError("Schema Validation", 3, "This xml file is in an unrecognisable format.",
                                                           _inputFileHistoryCode, null, null);
                                    break;
                                }

                                // decrement countdown used for trying to get the schema version
                                if (MaxChunksToReadForSchemaVersionCountdown >= 1)
                                {
                                    MaxChunksToReadForSchemaVersionCountdown--;
                                }

                                //Ensure the providing organisation is the one selected on the ui
                                if (xmlReader.LocalName == "ProvidingOrganisation" && xmlReader.IsStartElement())
                                {
                                    string ProvidingOrganisationString = xmlReader.ReadString();
                                    if (ProvidingOrganisationString != ProviderKey.Substring(0, ProviderKey.Length - 2))
                                    {
                                        _errorCode = 5;
                                        //InputFileErrors.PublishError("The file providing organisation: " + ProvidingOrganisationString +
                                        //    " does not match the selected value of " +
                                        //    ProviderKey.Substring(0, ProviderKey.Length - 2), 3, "Schema Validation", _inputFileHistoryCode);

                                        // set the error and exit immediatley as the file is not fit for purpose

                                        _isSchemaValid = false;
                                        spRunner2.PublishError("Schema Validation", 3, "The xml file Providing Organisation does not match selection", _inputFileHistoryCode
                                                               , null, null);
                                        break;
                                    }
                                }
                                //Ensure the providing organisation is the one selected on the ui

                                if (xmlReader.LocalName == "FileRunDate" && xmlReader.IsStartElement())
                                {
                                    string FileRunDate = xmlReader.ReadString();
                                    _inputFileHistoryRow.TransferDate = DateTime.Parse(FileRunDate);
                                    inputFileHistoryRepository.Update(_inputFileHistoryRow);
                                    inputFileHistoryRepository.SaveChanges();
                                }

                                //Ensure the region is the one selected on the ui

                                if (ProviderKey.Substring(ProviderKey.Length - 2, 2) != "XX")
                                {
                                    if (xmlReader.LocalName == "RegionCode" && xmlReader.IsStartElement())
                                    {
                                        string RegionCodeString = xmlReader.ReadString();

                                        // Used to store for reporting schema errors, e.g., DOB errors
                                        LastRegion = RegionCodeString;

                                        if (RegionCodeString != ProviderKey.Substring(ProviderKey.Length - 2, 2))
                                        {
                                            _errorCode = 5;

                                            //InputFileErrors.PublishError("The file RegionCode: " + RegionCodeString +
                                            //    " does not match the selected value of " +
                                            //    ProviderKey.Substring(ProviderKey.Length - 2, 2), 3, "Schema Validation", _inputFileHistoryCode);

                                            // set the error and exit immediatley as the file is not fit for purpose
                                            _isSchemaValid = false;
                                            spRunner2.PublishError("Schema Validation", 3, "The xml file Region does not match selection", _inputFileHistoryCode,
                                                                   null, null);
                                            break;
                                        }
                                    }
                                }


                                if (this._fileType == "Participant")
                                {
                                    #region Store info for reporting schema errors, e.g., DOB errors

                                    if (ProviderKey.Substring(ProviderKey.Length - 2, 2) == "XX")
                                    {
                                        if (xmlReader.LocalName == "RegionCode" && xmlReader.IsStartElement())
                                        {
                                            // Set last region if All region, i.e., XX otherwise Last region is already set elsewhere in
                                            // this code
                                            LastRegion = xmlReader.ReadString();
                                        }
                                    }

                                    // Set AgreementID
                                    if (xmlReader.LocalName == "AgreementID" && xmlReader.IsStartElement())
                                    {
                                        LastAgreement = xmlReader.ReadString();
                                    }

                                    // Set Participant Ref ID
                                    if (xmlReader.LocalName == "ParticipantReferenceID" && xmlReader.IsStartElement())
                                    {
                                        LastParticipantReferenceID = xmlReader.ReadString();
                                    }

                                    // Set Start Date
                                    if (xmlReader.LocalName == "StartDate" && xmlReader.IsStartElement())
                                    {
                                        LastStartDate = xmlReader.ReadString();
                                    }

                                    #endregion

                                    #region DOB Error Check

                                    if (xmlReader.LocalName == "DOB" && xmlReader.IsStartElement())
                                    {
                                        try
                                        {
                                            string   DOBDateTimeString = xmlReader.ReadString();
                                            DateTime SqlMinDateTime    = new DateTime(1753, 1, 1);
                                            DateTime DOBDateTime       = Convert.ToDateTime(DOBDateTimeString);


                                            if (DOBDateTime < SqlMinDateTime)
                                            {
                                                _errorCode = 5;

                                                // Don't process the file
                                                _isSchemaValid = false;
                                                throw new ApplicationException("The DOB is prior to 1 Jan 1753 on record: "
                                                                               + "KeyValue: " + ProviderKey
                                                                               + " Region: " + LastRegion + " Agreement: " + LastAgreement +
                                                                               " Participant Ref ID: " + LastParticipantReferenceID
                                                                               + " Start Date: " + LastStartDate + " DOB: " + DOBDateTime.ToString("dd/MM/yyyy")
                                                                               );
                                            }
                                        }
                                        catch (FormatException ex)
                                        {
                                            _errorCode = 5;

                                            // Don't process the file
                                            _isSchemaValid = false;
                                            throw new ApplicationException("The DOB is incorrect on record: " + "KeyValue: " + ProviderKey
                                                                           + " Region: " + LastRegion + " Agreement: " + LastAgreement +
                                                                           " Participant Ref ID: " + LastParticipantReferenceID
                                                                           + " Start Date: " + LastStartDate + " DOB: Invalid Date or Non Date Format"
                                                                           , ex);
                                        }
                                    }

                                    #endregion
                                }

                                long    CurrentPosition = DataFileStream.Position;
                                decimal PercentThrough  = Convert.ToDecimal(CurrentPosition) / Convert.ToDecimal(_fileLength) * 100;
                                PercentThroughInt = Convert.ToInt32(decimal.Truncate(PercentThrough));
                                if (PercentThroughInt > PercentThroughOld)
                                {
                                    CurrentStep.UpdateProgress(PercentThroughInt);
                                    //OnProgressEvent(new ProgressEventArgs("Schema", PercentThroughInt, PercentThroughInt - PercentThroughOld, "Validating file content"));
                                    PercentThroughOld = PercentThroughInt;
                                }
                                if (this._fileType == "Participant")
                                {
                                    if (xmlReader.LocalName == "Participant" && xmlReader.IsStartElement())
                                    {
                                        _recordCount++;
                                        _flatRecordCount++;
                                    }
                                    if (xmlReader.LocalName == "ESFP1P4Qualification" && xmlReader.IsStartElement())
                                    {
                                        _flatRecordCount++;
                                    }
                                    if (xmlReader.LocalName == "ESFP2P5Qualification" && xmlReader.IsStartElement())
                                    {
                                        _flatRecordCount++;
                                    }
                                }
                            }
                            //explicitly call Close on the XmlReader to reduce strain on the GC
                            xmlReader.Close();
                        }
                    }

                    //Update status to 'Schema Validated'
                    UpdateHistoryStatus("Schema Validated");
                }

                catch (Exception ex)//..various types of Exceptions can be thrown by the XmlReader.Create() method)
                {
                    _errorCode = 5;
                    throw new ApplicationException(ex.Message, ex);
                }
            }
            if (!_isSchemaValid)
            {
                throw new ApplicationException("Schema Invalid");
            }
            CurrentStep.Finish(true);
        }
Example #17
0
 public override int GetHashCode()
 {
     return((LoginProvider.ToString() + "|" + ProviderKey.ToString() + "|" + UserId.ToString()).GetHashCode());
 }
Example #18
0
 public override int GetHashCode()
 {
     return(ProviderKey.ToStringOrDefault().GetHashCode() ^ UserKey.ToStringOrDefault().GetHashCode());
 }
Example #19
0
        private IEnumerable <TProvider> GetProviderInstances <TProvider>(ProviderFactoryInfo[] factories, ProviderKey key)
            where TProvider : class
        {
            IEnumerable <ProviderFactoryInfo> selectedFactories = factories.Where(p => p.Key.Name == key.Name);

            if (!selectedFactories.Any())
            {
                return(null);
            }

            return(selectedFactories.Select(f => f.ExportFactory.CreateExport <TProvider>()));
        }
 private List <ProviderFactoryInfo> InitializeProviderFactories(ProviderKey key, IEnumerable <ITypeProvider> providerCollection)
 {
     return(InitializeProviderFactories(key, providerCollection, null));
 }
 public override int GetHashCode()
 {
     return(LoginProvider.GetHashCode() * 17 + ProviderKey.GetHashCode());
 }
        private TProvider GetSingleProviderInstance <TProvider>(ProviderFactoryInfo[] factories, ProviderKey key)
        {
            var factory = factories.FirstOrDefault(p => p.Key.Name == key.Name);

            if (factory == null)
            {
                return(default(TProvider));
            }

            return(factory.ExportFactory.CreateExport <TProvider>());
        }
        private bool TryGetProviderInstances <TProvider>(ProviderFactoryInfo[] factories, ProviderKey key, Func <Type, object> creator, Func <TProvider, ProviderFactoryInfo, bool> initializer, out IEnumerable <TProvider> providers)
            where TProvider : class
        {
            IEnumerable <ProviderFactoryInfo> selectedFactories = factories.Where(p => p.Key.Name == key.Name);

            if (!selectedFactories.Any())
            {
                providers = null;
                return(true);
            }

            providers = new List <TProvider>();

            var list = (List <TProvider>)providers;

            foreach (var f in selectedFactories)
            {
                var provider = creator == null?f.ExportFactory.CreateExport <TProvider>() : f.ExportFactory.CreateExport <TProvider>(creator);

                if (!initializer(provider, f))
                {
                    return(false);
                }

                list.Add(provider);
            }

            return(true);
        }
Example #24
0
 protected bool Equals(ProviderKey other)
 {
     return(string.Equals(ProviderName, other.ProviderName) && string.Equals(ConnectionString, other.ConnectionString));
 }