Exemple #1
0
        private static readonly CookieManagerBehavior _cookieBehavior = new CookieManagerBehavior(); //All ChemWatch service clients must share this

        public static CswNbtChemWatchRequest Initialize(ICswResources CswResources, CswNbtChemWatchRequest Request)
        {
            CswNbtChemWatchRequest Return       = new CswNbtChemWatchRequest();
            CswNbtResources        NbtResources = (CswNbtResources)CswResources;

            CswNbtObjClassChemical ChemicalNode = NbtResources.Nodes[Request.NbtMaterialId];

            Return.Supplier      = ChemicalNode.Supplier.CachedNodeName;
            Return.PartNo        = ChemicalNode.PartNumber.Text;
            Return.MaterialName  = ChemicalNode.TradeName.Text;
            Return.NbtMaterialId = ChemicalNode.NodeId;

            string errorMsg;

            if (_authenticate(NbtResources, out errorMsg))
            {
                CommonServiceClient cwCommonClient = new CommonServiceClient();
                cwCommonClient.Endpoint.Behaviors.Add(_cookieBehavior);

                // Populate Language list
                List <ChemWatchMultiSlctListItem> Languages = new List <ChemWatchMultiSlctListItem>();
                Languages cwLanguages = cwCommonClient.GetLanguages();
                foreach (Language cwLanguage in cwLanguages)
                {
                    if (cwLanguage.UILanguage)
                    {
                        Languages.Add(new ChemWatchMultiSlctListItem()
                        {
                            Name = cwLanguage.Name,
                            Id   = CswConvert.ToString(cwLanguage.Id)
                        });
                    }
                }
                IEnumerable <ChemWatchMultiSlctListItem> SortedLanguages = Languages.OrderBy(si => si.Name);
                Return.Languages.options = SortedLanguages.ToList();

                // Populate Country list
                List <ChemWatchMultiSlctListItem> Countries = new List <ChemWatchMultiSlctListItem>();
                Countries cwCountries = cwCommonClient.GetCountries();
                foreach (Country cwCountry in cwCountries)
                {
                    Countries.Add(new ChemWatchMultiSlctListItem()
                    {
                        Name = cwCountry.Name,
                        Id   = CswConvert.ToString(cwCountry.Id)
                    });
                }
                IEnumerable <ChemWatchMultiSlctListItem> SortedCountries = Countries.OrderBy(si => si.Name);
                Return.Countries.options = SortedCountries.ToList();

                // Attempt to populate the Suppliers list
                _getMatchingSuppliers(Return.Supplier, Return);
            }
            else
            {
                throw new CswDniException(CswEnumErrorType.Error, "There was a problem authenticating with ChemWatch", errorMsg);
            }

            return(Return);
        }