Ejemplo n.º 1
0
        }//_getPreferredSuppliers()

        private static Collection <VendorOption> _getAvailableDataSources(CswNbtC3ClientManager CswNbtC3ClientManager, CswC3Params CswC3Params)
        {
            Collection <VendorOption> AvailableDataSources = new Collection <VendorOption>();

            SearchClient C3SearchClient = CswNbtC3ClientManager.initializeC3Client();

            if (null != C3SearchClient)
            {
                CswRetObjSearchResults SourcesList = C3SearchClient.getDataSources(CswC3Params);
                if (null != SourcesList)
                {
                    //Create the "All Sources" option
                    CswCommaDelimitedString AllSources = new CswCommaDelimitedString();
                    AllSources.FromArray(SourcesList.AvailableDataSources);

                    VendorOption allSourcesDs = new VendorOption();
                    allSourcesDs.value   = AllSources.ToString();
                    allSourcesDs.display = "All Sources";
                    AvailableDataSources.Add(allSourcesDs);

                    //Add available data source options
                    foreach (string DataSource in SourcesList.AvailableDataSources)
                    {
                        VendorOption dS = new VendorOption();
                        dS.value   = DataSource;
                        dS.display = DataSource;
                        AvailableDataSources.Add(dS);
                    }
                } //if( null != SourcesList )
            }     //if( null != C3SearchClient )

            return(AvailableDataSources);
        }//_getAvailableDataSources()
Ejemplo n.º 2
0
        } // getTable()

        /// <summary>
        /// Get table from a CswRetObjSearchResult (the return object from C3 searches).
        /// </summary>
        /// <param name="C3SearchResultsObj"></param>
        /// <returns></returns>
        public JObject getTable( CswRetObjSearchResults C3SearchResultsObj, string SearchField, string DataService, bool filtered = false )
        {

            JObject ret = new JObject();

            Collection<string> PropsToHide = new Collection<string>();
            foreach( string Property in C3SearchResultsObj.AllC3ProductProperties )
            {
                PropsToHide.Add( Property );
            }

            PropsToHide.Remove( SearchField );
            if( "ACD" == DataService )
            {
                if( filtered )
                {
                    PropsToHide.Add( "CatalogNo" ); //Filtered ACD searches should NEVER show "CatalogNo"

                    PropsToHide.Remove( "CatalogName" );
                    PropsToHide.Remove( "CatalogNumbers" );
                    PropsToHide.Remove( "SupplierName" );
                }
                PropsToHide.Remove( "Formula" );
            }
            else
            {
                PropsToHide.Remove( "SourceName" );
                PropsToHide.Remove( "SupplierName" );
                PropsToHide.Remove( "CatalogNo" );
            }

            ret = makeTableFromWebServiceObj( C3SearchResultsObj, PropsToHide, DataService );

            return ret;
        }
Ejemplo n.º 3
0
        public static void getExternalImage(ICswResources CswResources, ExternalImageRet Return, ACDSearchParams ACDSearchParams)
        {
            CswNbtResources   _CswNbtResources  = (CswNbtResources)CswResources;
            CswC3SearchParams CswC3SearchParams = new CswC3SearchParams();

            CswC3SearchParams.ACDSearchParams = ACDSearchParams;
            CswC3Product C3ProductDetails = new CswC3Product();

            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3SearchParams);
            SearchClient          C3SearchClient        = CswNbtC3ClientManager.initializeC3Client();

            if (null != C3SearchClient)
            {
                CswRetObjSearchResults SearchResults = C3SearchClient.getACDMolImage(CswC3SearchParams);
                if (null != SearchResults.CswC3SearchResults && SearchResults.CswC3SearchResults.Length > 0)
                {
                    C3ProductDetails = SearchResults.CswC3SearchResults[0];
                }
            }

            if (String.IsNullOrEmpty(C3ProductDetails.MolImage))
            {
                CswNbtMetaDataObjectClass ChemicalOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.ChemicalClass);
                Return.Data = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + CswNbtMetaDataObjectClass.IconPrefix100 + ChemicalOC.IconFileName);
            }
            else
            {
                Return.Data = Convert.FromBase64String(C3ProductDetails.MolImage);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get the most recent ExtChemData import date.
        /// </summary>
        /// <param name="SearchClient"></param>
        /// <returns></returns>
        public string getLastExtChemDataImportDate(SearchClient SearchClient)
        {
            string Ret = string.Empty;

            CswRetObjSearchResults ReturnObject = SearchClient.getLastExtChemDataImportDate(_CswC3SearchParams);

            Ret = ReturnObject.LastExtChemDataImportDate;

            return(Ret);
        }//getLastExtChemDataImportDate()
Ejemplo n.º 5
0
        }//getLastExtChemDataImportDate()

        /// <summary>
        /// Get the most recent Regulation database data import date.
        /// </summary>
        /// <param name="SearchClient"></param>
        /// <returns></returns>
        public string getLastRegulationDataImportDate(SearchClient SearchClient)
        {
            string Ret = string.Empty;

            if (false == string.IsNullOrEmpty(_RegulationDatabase))
            {
                // We set the Regulation Database so that C3 knows which date to retrieve
                _CswC3SearchParams.RegulationDatabase = _RegulationDatabase;
                CswRetObjSearchResults ReturnObject = SearchClient.getLastestRegDbDate(_CswC3SearchParams);
                Ret = ReturnObject.LastestRegulationDbDate;
            }

            return(Ret);
        }//getLastRegulationDataImportDate()
        private void _searchRegulationDb(string SearchTerm, Int32 SearchThreshold)
        {
            CswC3SearchParams     CswC3SearchParams     = new CswC3SearchParams();
            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3SearchParams);
            SearchClient          C3SearchClient        = CswNbtC3ClientManager.initializeC3Client();

            if (null != C3SearchClient)
            {
                CswNbtObjClassRegulatoryList RegListNode = _CswNbtResources.Nodes.GetNode(RegulatoryList.RelatedNodeId);
                if (null != RegListNode)
                {
                    CswC3SearchParams.RegulationDatabase = CswNbtC3ClientManager.RegulationDatabase;

                    string Regions = "";
                    if (string.IsNullOrEmpty(CswConvert.ToString(RegListNode.Regions.Value)))
                    {
                        if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.ArielSync))
                        {
                            Regions = _CswNbtResources.ConfigVbls.getConfigVariableValue(CswConvert.ToString(CswEnumNbtConfigurationVariables.arielmodules));
                        }
                    }
                    else
                    {
                        Regions = CswConvert.ToString(RegListNode.Regions.Value);
                    }
                    CswC3SearchParams.Regions = Regions;
                }
                CswC3SearchParams.Query = SearchTerm;

                // Perform the search
                CswRetObjSearchResults SearchResults = C3SearchClient.getListCodesByName(CswC3SearchParams);
                if (null != SearchResults.RegulationDbDataResults)
                {
                    if (SearchResults.RegulationDbDataResults.Length > 0 && SearchResults.RegulationDbDataResults.Length < SearchThreshold)
                    {
                        Collection <CswNbtNodeTypePropListOption> MatchingRegLists = new Collection <CswNbtNodeTypePropListOption>();

                        foreach (CswC3RegulationDbData RegDbRecord in SearchResults.RegulationDbDataResults)
                        {
                            MatchingRegLists.Add(new CswNbtNodeTypePropListOption(RegDbRecord.ListName, CswConvert.ToString(RegDbRecord.ListId)));
                        }

                        // Set the list options
                        ListName.Options.Options = MatchingRegLists;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Make a table from a C3 search result object.
        /// </summary>
        /// <param name="C3SearchResultsObj"></param>
        /// <param name="PropsToHide"></param>
        /// <returns></returns>
        public JObject makeTableFromWebServiceObj( CswRetObjSearchResults C3SearchResultsObj, Collection<string> PropsToHide, string DataService )
        {
            JObject ret = new JObject();

            if( C3SearchResultsObj != null )
            {
                Int32 results = _populateDictionary( C3SearchResultsObj, PropsToHide, DataService );

                ret["results"] = results;
                ret["nodetypecount"] = _TableDict.Keys.Count;
                ret["truncated"] = null;
                ret["pagesize"] = _CswNbtResources.CurrentNbtUser.PageSize;
                ret["nodetypes"] = _dictionaryToJson();
                ret["importmenu"] = CswNbtWebServiceC3Search.getImportBtnItems( _CswNbtResources );
                ret["searchtarget"] = "chemcatcentral";
            }
            return ret;
        }
Ejemplo n.º 8
0
        }//RunC3FilteredSearch()

        public static void GetC3ProductDetails(ICswResources CswResources, CswNbtC3SearchReturn Return, CswC3SearchParams CswC3SearchParams)
        {
            CswNbtResources _CswNbtResources = (CswNbtResources)CswResources;

            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3SearchParams);
            SearchClient          C3SearchClient        = CswNbtC3ClientManager.initializeC3Client();

            if (null != C3SearchClient)
            {
                // For now, the only option here is C3
                CswC3SearchParams.DataService = CswNbtC3ClientManager.DataService;

                CswRetObjSearchResults SearchResults = C3SearchClient.getProductDetails(CswC3SearchParams);
                if (SearchResults.CswC3SearchResults.Length > 0)
                {
                    CswC3Product C3ProductDetails = SearchResults.CswC3SearchResults[0];
                    Return.Data.ProductDetails = C3ProductDetails;
                }
            }
        }
Ejemplo n.º 9
0
        }//getCurrentC3Version()

        public CswC3ServiceLogicGetDataSourcesDataSource[] getDataSourceDates()
        {
            CswC3ServiceLogicGetDataSourcesDataSource[] DataSourceDates = null;
            bool Status = false;

            SearchClient C3Service = initializeC3Client();

            if (null != C3Service)
            {
                Status = _checkConnection(C3Service);
                if (Status)
                {
                    CswRetObjSearchResults DataSources = C3Service.getDataSourceDates(_CswC3Params);
                    if (null != DataSources.DataSourceDates)
                    {
                        DataSourceDates = DataSources.DataSourceDates.Data;
                    }
                }
            }

            return(DataSourceDates);
        }
Ejemplo n.º 10
0
        public static void GetACDSuppliers(ICswResources CswResources, CswNbtC3SearchReturn Return, CswC3Params CswC3Params)
        {
            CswNbtResources _CswNbtResources = (CswNbtResources)CswResources;

            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3Params);
            SearchClient          C3SearchClient        = CswNbtC3ClientManager.initializeC3Client();

            if (null != C3SearchClient)
            {
                CswRetObjSearchResults Results = C3SearchClient.getACDSuppliers(CswC3Params);

                // Get the already set perferred suppliers so we can select them
                List <string>      PreferredSuppliers = new List <string>();
                CswNbtObjClassUser CurrentUser        = _CswNbtResources.Nodes.GetNode(_CswNbtResources.CurrentNbtUser.UserId);
                if (null != CurrentUser)
                {
                    PreferredSuppliers = CurrentUser.C3ACDPreferredSuppliers.Text.Split(',').ToList();
                }

                Collection <ACDSupplier>  ACDSuppliers    = new Collection <ACDSupplier>();
                IEnumerable <ACDSupplier> SortedSuppliers = new Collection <ACDSupplier>();
                if (null != Results)
                {
                    foreach (CswC3ACDResponseACDSupplier ACDSupplier in Results.ACDSuppliers)
                    {
                        ACDSupplier NewSupplier = new ACDSupplier();
                        NewSupplier.Name     = ACDSupplier.Name + ": " + ACDSupplier.Country;
                        NewSupplier.Id       = CswConvert.ToString(ACDSupplier.Id);
                        NewSupplier.Selected = PreferredSuppliers.Contains(ACDSupplier.Id.ToString());
                        ACDSuppliers.Add(NewSupplier);
                    }

                    SortedSuppliers = ACDSuppliers.OrderBy(si => si.Name);
                }

                Return.Data.ACDSuppliers = SortedSuppliers;
            }
        }//GetACDSuppliers()
Ejemplo n.º 11
0
        public static C3CreateMaterialResponse importC3Product(ICswResources CswResources, CswNbtC3Import.Request Request)
        {
            C3CreateMaterialResponse ret = new C3CreateMaterialResponse();

            CswNbtResources _CswNbtResources = (CswNbtResources)CswResources;

            CswC3SearchParams CswC3SearchParams = new CswC3SearchParams();
            CswC3Product      C3ProductDetails  = new CswC3Product();

            if (Int32.MinValue != Request.Cdbregno && Int32.MinValue != Request.C3ProductId)
            {
                CswC3SearchParams.ACDSearchParams           = new ACDSearchParams();
                CswC3SearchParams.ACDSearchParams.ProductId = Request.C3ProductId;
                CswC3SearchParams.ACDSearchParams.Cdbregno  = Request.Cdbregno;
            }
            else if (Int32.MinValue != Request.C3ProductId)
            {
                CswC3SearchParams.C3SearchParams           = new C3SearchParams();
                CswC3SearchParams.C3SearchParams.ProductId = Request.C3ProductId;
            }
            else
            {
                throw new CswDniException(CswEnumErrorType.Error, "Cannot run import, missing parameters.", "Cannot import C3 or ACD data without a Product Id or CdbRegNo.");
            }

            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3SearchParams);
            SearchClient          C3SearchClient        = CswNbtC3ClientManager.initializeC3Client();

            if (null != C3SearchClient)
            {
                // Perform C3 search to get the product details
                CswRetObjSearchResults SearchResults = C3SearchClient.getProductDetails(CswC3SearchParams);
                if (SearchResults.CswC3SearchResults.Length > 0)
                {
                    C3ProductDetails = SearchResults.CswC3SearchResults[0];

                    string NodeTypeName = Request.NodeTypeName;
                    if (false == string.IsNullOrEmpty(NodeTypeName))
                    {
                        CswNbtMetaDataNodeType NodeTypeToBeImported = _CswNbtResources.MetaData.getNodeType(NodeTypeName);
                        if (null != NodeTypeToBeImported)
                        {
                            // Instance the ImportManger
                            ImportManager C3Import = new ImportManager(_CswNbtResources, C3ProductDetails);

                            // Create the temporary material node
                            CswNbtPropertySetMaterial C3ProductTempNode = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(NodeTypeToBeImported.NodeTypeId, IsTemp : true, OnAfterMakeNode : delegate(CswNbtNode NewNode)
                            {
                                //Set the c3productid property
                                ((CswNbtPropertySetMaterial)NewNode).C3ProductId.Text = C3ProductDetails.ProductId.ToString();
                                // Add props to the tempnode
                                C3Import.addNodeTypeProps(NewNode);

                                // Sync Hazard Classes and PCID data if C3ProductTempNode is of type Chemical
                                if (NewNode.getObjectClass().ObjectClass == CswEnumNbtObjectClass.ChemicalClass)
                                {
                                    CswNbtObjClassChemical ChemicalNode = NewNode;
                                    ChemicalNode.syncFireDbData();
                                    ChemicalNode.syncPCIDData();
                                }
                                //C3ProductTempNode.postChanges( false );
                            });

                            // Get or create a vendor node
                            C3CreateMaterialResponse.State.Supplier Supplier = C3Import.constructVendorObject(C3ProductDetails.SupplierName);

                            // Create size node(s)
                            Collection <C3CreateMaterialResponse.State.SizeRecord> ProductSizes = C3Import.constructSizeObjects();

                            // Create synonyms node(s)
                            C3Import.createMaterialSynonyms(C3ProductTempNode);

                            // Create a document node if C3ProductTempNode is of type Chemical
                            CswPrimaryKey SDSDocumentNodeId = new CswPrimaryKey();
                            if (C3ProductTempNode.ObjectClass.ObjectClass == CswEnumNbtObjectClass.ChemicalClass)
                            {
                                SDSDocumentNodeId = C3Import.createMaterialDocument(C3ProductTempNode);
                            }

                            #region Return Object

                            ret.success    = true;
                            ret.actionname = "create material";

                            C3CreateMaterialResponse.State.MaterialType MaterialType = new C3CreateMaterialResponse.State.MaterialType();
                            MaterialType.name = Request.NodeTypeName;
                            MaterialType.val  = Request.NodeTypeId;

                            C3CreateMaterialResponse.State State = new C3CreateMaterialResponse.State();
                            State.materialId = C3ProductTempNode.NodeId.ToString();
                            State.tradeName  = C3ProductTempNode.TradeName.Text;
                            State.partNo     = C3ProductTempNode.PartNumber.Text;
                            ret.state        = State;

                            //State.useExistingTempNode = true;
                            State.supplier = Supplier;
                            if (string.IsNullOrEmpty(State.supplier.val))
                            {
                                State.addNewC3Supplier = true;
                            }
                            State.materialType = MaterialType;
                            State.sizes        = ProductSizes;
                            if (null != SDSDocumentNodeId)
                            {
                                State.sds.sdsDocId = SDSDocumentNodeId.ToString();
                            }

                            #endregion Return Object
                        } //if (null != NodeTypeToBeImported)
                    }     //if( false == string.IsNullOrEmpty( NodeTypeName ) )
                }         //if( SearchResults.CswC3SearchResults.Length > 0 )
            }             //if( null != C3SearchClient )

            return(ret);
        }//importC3Product()
Ejemplo n.º 12
0
        public JObject makeVersionJson(CswSessionResourcesNbt _CswSessionResources)
        {
            JObject ret = new JObject();

            string AssemblyFilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "/_Assembly.txt";

            if (File.Exists(AssemblyFilePath))
            {
                TextReader AssemblyFileReader = new StreamReader(AssemblyFilePath);
                ret.Add(new JProperty("assembly", AssemblyFileReader.ReadLine()));
                AssemblyFileReader.Close();
            }

            JObject   ComponentObj   = new JObject();
            JProperty ComponentsProp = new JProperty("components", ComponentObj);

            ret.Add(ComponentsProp);
            string ThisYear = DateTime.Now.Year.ToString();

            ArrayList CswAssemblies = new ArrayList();

            CswAssemblies.Add("NbtWebApp");
            CswAssemblies.Add("CswCommon");
            CswAssemblies.Add("CswWebControls");
            CswAssemblies.Add("NbtLogic");
            CswAssemblies.Add("NbtWebControls");

            foreach (string AssemblyName in CswAssemblies)
            {
                string name = AssemblyName.Contains(",") ? AssemblyName.Substring(0, AssemblyName.IndexOf(',')) : AssemblyName;

                JObject AssemObj = new JObject();
                ComponentObj.Add(new JProperty(name, AssemObj));

                Assembly AssemblyInfo = Assembly.Load(AssemblyName);
                string   Version      = AssemblyInfo.GetName().Version.ToString();
                AssemObj.Add(new JProperty("name", name));
                AssemObj.Add(new JProperty("version", Version));
                AssemObj.Add(new JProperty("copyright", "Copyright &copy; ChemSW, Inc. 2005-" + ThisYear));
            }

            ArrayList ThirdAssemblies = new ArrayList();

            ThirdAssemblies.Add("CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304");
            ThirdAssemblies.Add("Telerik.Web.UI");

            foreach (string AssemblyName in ThirdAssemblies)
            {
                string name = AssemblyName.Contains(",") ? AssemblyName.Substring(0, AssemblyName.IndexOf(',')) : AssemblyName;

                JObject AssemObj = new JObject();
                ComponentObj.Add(new JProperty(name, AssemObj));

                Assembly AssemblyInfo       = Assembly.Load(AssemblyName);
                object[] AssemblyAttributes = (object[])AssemblyInfo.GetCustomAttributes(true);

                string Version   = AssemblyInfo.GetName().Version.ToString();
                string Copyright = string.Empty;
                foreach (AssemblyCopyrightAttribute AssemblyAttribute in AssemblyAttributes.OfType <AssemblyCopyrightAttribute>())
                {
                    Copyright = (AssemblyAttribute).Copyright;
                }
                AssemObj.Add(new JProperty("name", name));
                AssemObj.Add(new JProperty("version", Version));
                AssemObj.Add(new JProperty("copyright", Copyright));
            }

            ComponentObj.Add(new JProperty("Schema",
                                           new JObject(
                                               new JProperty("name", "Schema"),
                                               new JProperty("version", _CswNbtResources.ConfigVbls.getConfigVariableValue("schemaversion")),
                                               new JProperty("copyright", "Copyright &copy; ChemSW, Inc. 2005-" + ThisYear)
                                               )

                                           ));

            #region ChemCatCentral Products Versions
            // Add ChemCatCentral version to the About dialog: Case 29380
            if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.C3Products))
            {
                CswC3Params           CswC3Params     = new CswC3Params();
                CswNbtC3ClientManager C3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3Params);
                SearchClient          C3SearchClient  = C3ClientManager.initializeC3Client();
                if (null != C3SearchClient)
                {
                    string C3Version = C3ClientManager.getCurrentC3Version();
                    ComponentObj.Add(new JProperty("ChemCatCentral", new JObject(
                                                       new JProperty("name", "ChemCatCentral"),
                                                       new JProperty("version", Regex.Replace(C3Version, "_", " ")),
                                                       new JProperty("copyright", "Copyright &copy; ChemSW, Inc. 2005-" + ThisYear))));

                    // Add the datasource import dates (if they are available to the user and/or the module is enabled
                    CswC3ServiceLogicGetDataSourcesDataSource[] DataSourceDates = C3ClientManager.getDataSourceDates();
                    if (null != DataSourceDates)
                    {
                        JObject DSDatesObj = new JObject();
                        foreach (CswC3ServiceLogicGetDataSourcesDataSource ds in DataSourceDates)
                        {
                            if (ds.DataType == "Extra Chemical")
                            {
                                switch (ds.DataSourceName)
                                {
                                case "FireDb":
                                    if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.FireDbSync))
                                    {
                                        DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate));
                                    }
                                    break;

                                case "PCID":
                                    if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.PCIDSync))
                                    {
                                        DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate));
                                    }
                                    break;
                                } //switch
                            }
                            else
                            {
                                DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate));
                            }
                        }
                        ret.Add(new JProperty("dsDates", DSDatesObj));
                    }
                }//if( C3ClientManager.checkC3ServiceReferenceStatus() )
            }
            #endregion ChemCatCentral Products Versions

            #region ACD Version
            if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.C3ACD))
            {
                CswC3Params           CswC3Params     = new CswC3Params();
                CswNbtC3ClientManager C3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3Params);
                SearchClient          C3SearchClient  = C3ClientManager.initializeC3Client();
                if (null != C3SearchClient)
                {
                    CswRetObjSearchResults Results = C3SearchClient.getACDVersion(CswC3Params);
                    if (null != Results)
                    {
                        ComponentObj.Add(new JProperty("ACD", new JObject(
                                                           new JProperty("name", "Available Chemicals Directory (ACD)"),
                                                           new JProperty("version", Regex.Replace(Results.ACDVersion, "_", " ")),
                                                           new JProperty("copyright", "Copyright &copy; Accelrys, Inc. 1983-" + ThisYear))));
                    }
                }
            }
            #endregion ACD Version


            SortedList <string, CswSessionsListEntry> sessions = _CswSessionResources.CswSessionManager.SessionsList.AllSessions;
            CswDateTime loginDate = new CswDateTime(_CswNbtResources);
            foreach (var entry in sessions)
            {
                CswSessionsListEntry sessionEntry = entry.Value;
                if (sessionEntry.UserName.Equals(_CswNbtResources.CurrentUser.Username))
                {
                    loginDate.FromClientDateString(sessionEntry.LoginDate.ToString());
                }
            }

            JObject UserObj = new JObject();
            UserObj["customerid"]   = new JObject(new JProperty("componentName", "Customer ID:"), new JProperty("value", _CswNbtResources.AccessId));
            UserObj["loggedinas"]   = new JObject(new JProperty("componentName", "Logged in as:"), new JProperty("value", _CswNbtResources.CurrentUser.Username));
            UserObj["sessionsince"] = new JObject(new JProperty("componentName", "Session since:"), new JProperty("value", loginDate.ToDateTime().ToString()));

            ret.Add(new JProperty("userProps", UserObj));

            return(ret);
        } // makeVersionJson()
Ejemplo n.º 13
0
        } // getCASNumbers()


        /// <summary>
        /// Returns a collection of matching Regulatory List primary keys, based on the provided cas numbers
        /// </summary>
        public static Collection<CswPrimaryKey> findMatches( CswNbtResources CswNbtResources, Collection<string> CasNos )
        {
            Collection<CswPrimaryKey> ret = new Collection<CswPrimaryKey>();
            if( CswNbtResources.Modules.IsModuleEnabled( CswEnumNbtModuleName.RegulatoryLists ) )
            {
                CswNbtMetaDataObjectClass RegulatoryListOC = CswNbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.RegulatoryListClass );
                CswNbtMetaDataObjectClass RegListCasNoOC = CswNbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.RegulatoryListCasNoClass );
                if( null != RegulatoryListOC && null != RegListCasNoOC )
                {
                    CswNbtMetaDataObjectClassProp RegListExclusiveOCP = RegulatoryListOC.getObjectClassProp( CswNbtObjClassRegulatoryList.PropertyName.Exclusive );
                    CswNbtMetaDataObjectClassProp RegListCasNoCasNoOCP = RegListCasNoOC.getObjectClassProp( CswNbtObjClassRegulatoryListCasNo.PropertyName.CASNo );
                    Collection<CswPrimaryKey> ExclusiveMatches = new Collection<CswPrimaryKey>();

                    // find matches
                    if( CasNos.Count > 0 )
                    {
                        #region Manually Managed Reg Lists

                        CswNbtView View = new CswNbtView( CswNbtResources );
                        View.ViewName = "Reglist_findMatches";
                        CswNbtViewRelationship casnoRel = View.AddViewRelationship( RegListCasNoOC, false );
                        CswNbtViewProperty casnoVP = View.AddViewProperty( casnoRel, RegListCasNoCasNoOCP );
                        foreach( string cas in CasNos )
                        {
                            View.AddViewPropertyFilter( casnoVP, Conjunction: CswEnumNbtFilterConjunction.Or, FilterMode: CswEnumNbtFilterMode.Equals, Value: cas );
                        }
                        CswNbtViewRelationship regListRel = View.AddViewRelationship( casnoRel, CswEnumNbtViewPropOwnerType.First, RegListCasNoOC.getObjectClassProp( CswNbtObjClassRegulatoryListCasNo.PropertyName.RegulatoryList ), false );
                        View.AddViewProperty( regListRel, RegListExclusiveOCP );

                        ICswNbtTree Tree = CswNbtResources.Trees.getTreeFromView( View, RequireViewPermissions: false, IncludeSystemNodes: true, IncludeHiddenNodes: true );
                        for( Int32 i = 0; i < Tree.getChildNodeCount(); i++ ) // RegListCasNo
                        {
                            Tree.goToNthChild( i );
                            for( Int32 j = 0; j < Tree.getChildNodeCount(); j++ ) // RegList
                            {
                                Tree.goToNthChild( j );

                                CswPrimaryKey thisRegListId = Tree.getNodeIdForCurrentPosition();

                                CswNbtTreeNodeProp exclusiveTreeProp = Tree.getChildNodePropsOfNode().FirstOrDefault( p => p.ObjectClassPropName == RegListExclusiveOCP.PropName );
                                if( null != exclusiveTreeProp )
                                {
                                    CswEnumTristate thisExclusive = CswConvert.ToTristate( exclusiveTreeProp[( (CswNbtFieldTypeRuleLogical) RegListExclusiveOCP.getFieldTypeRule() ).CheckedSubField.Column] );
                                    if( CswEnumTristate.True == thisExclusive )
                                    {
                                        ExclusiveMatches.Add( thisRegListId );
                                    }
                                    else
                                    {
                                        ret.Add( thisRegListId );
                                    }
                                }
                                Tree.goToParentNode();
                            } // for( Int32 j = 0; j < Tree.getChildNodeCount(); j++ ) // RegList
                            Tree.goToParentNode();
                        } // for( Int32 i = 0; i < Tree.getChildNodeCount(); i++ ) // RegListCasNo

                        #endregion Manually Managed Reg Lists

                        #region Regulation Database Managed Reg Lists

                        string SyncModule = string.Empty;
                        if( CswNbtResources.Modules.IsModuleEnabled( CswEnumNbtModuleName.LOLISync ) )
                        {
                            SyncModule = CswEnumRegulatoryListListModes.LOLIManaged;
                        }
                        else if( CswNbtResources.Modules.IsModuleEnabled( CswEnumNbtModuleName.ArielSync ) )
                        {
                            SyncModule = CswEnumRegulatoryListListModes.ArielManaged;
                        }
                        if( false == string.IsNullOrEmpty( SyncModule ) ) //at least one of LOLISync or ArielSync is enabled
                        {
                            CswNbtMetaDataObjectClass RegListListCodeOC = CswNbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.RegulatoryListListCodeClass );
                            if( null != RegListListCodeOC )
                            {
                                CswNbtMetaDataObjectClassProp RegListListCodeListCodeOCP = RegListListCodeOC.getObjectClassProp( CswNbtObjClassRegulatoryListListCode.PropertyName.ListCode );
                                CswNbtMetaDataObjectClassProp RegListListCodeRegulatoryListOCP = RegListListCodeOC.getObjectClassProp( CswNbtObjClassRegulatoryListListCode.PropertyName.RegulatoryList );
                                CswNbtMetaDataObjectClassProp RegListListModeOCP = RegulatoryListOC.getObjectClassProp( PropertyName.ListMode );

                                // Get all regulation db managed regulatory lists
                                CswNbtView View1 = new CswNbtView( CswNbtResources );
                                View1.ViewName = "RegLists_RegDbManaged";
                                CswNbtViewRelationship ParentRelationship = View1.AddViewRelationship( RegulatoryListOC, false );
                                View1.AddViewPropertyAndFilter( ParentViewRelationship: ParentRelationship,
                                                                MetaDataProp: RegListListModeOCP,
                                                                Value: SyncModule, //sync module that is enabled
                                                                SubFieldName: CswNbtFieldTypeRuleList.SubFieldName.Value,
                                                                FilterMode: CswEnumNbtFilterMode.Equals );
                                CswNbtViewRelationship SecondaryRelationship = View1.AddViewRelationship( ParentRelationship, CswEnumNbtViewPropOwnerType.Second, RegListListCodeRegulatoryListOCP, false );
                                View1.AddViewProperty( SecondaryRelationship, RegListListCodeListCodeOCP );

                                // Dictionary that stores the Regions and List Codes for each Regulatory List
                                Dictionary<CswPrimaryKey, Tuple<string, List<string>>> RegListListCodes = new Dictionary<CswPrimaryKey, Tuple<string, List<string>>>();

                                // Get and iterate the Tree
                                ICswNbtTree Tree1 = CswNbtResources.Trees.getTreeFromView( View1, false, true, true );
                                for( Int32 i = 0; i < Tree1.getChildNodeCount(); i++ ) // Regulatory List Nodes
                                {
                                    Tree1.goToNthChild( i );

                                    List<string> CurrentListCodes = new List<string>();
                                    CswNbtObjClassRegulatoryList CurrentRegListNode = Tree1.getCurrentNode();
                                    CswPrimaryKey CurrentRegListPk = CurrentRegListNode.NodeId;
                                    string CurrentRegListRegions = "";
                                    if( string.IsNullOrEmpty( CswConvert.ToString( CurrentRegListNode.Regions.Value ) ) )
                                    {
                                        if( SyncModule.Equals( CswEnumRegulatoryListListModes.ArielManaged ) )
                                        {
                                            CurrentRegListRegions = CswNbtResources.ConfigVbls.getConfigVariableValue( CswConvert.ToString( CswEnumNbtConfigurationVariables.arielmodules ) );
                                        }
                                    }
                                    else
                                    {
                                        CurrentRegListRegions = CswConvert.ToString( CurrentRegListNode.Regions.Value );
                                    }

                                    for( int j = 0; j < Tree1.getChildNodeCount(); j++ ) // Regulatory List List Code Nodes
                                    {
                                        Tree1.goToNthChild( j );
                                        CswNbtTreeNodeProp ListCodeTreeProp = null;
                                        foreach( CswNbtTreeNodeProp currentTnp in Tree1.getChildNodePropsOfNode() )
                                        {
                                            if( currentTnp.ObjectClassPropName == RegListListCodeListCodeOCP.PropName )
                                            {
                                                ListCodeTreeProp = currentTnp;
                                                break;
                                            }
                                        }
                                        if( null != ListCodeTreeProp )
                                        {
                                            CurrentListCodes.Add( CswConvert.ToString( ListCodeTreeProp.Field1 ) );
                                        }
                                        Tree1.goToParentNode();
                                    }

                                    // Add to the dictionary
                                    RegListListCodes.Add( CurrentRegListPk, new Tuple<string, List<string>>( CurrentRegListRegions, CurrentListCodes ) );

                                    Tree1.goToParentNode();
                                }

                                // Search the regulation database
                                foreach( string CurrentCasNo in CasNos )
                                {
                                    foreach( KeyValuePair<CswPrimaryKey, Tuple<string, List<string>>> Pair in RegListListCodes )
                                    {
                                        CswC3SearchParams CswC3SearchParams = new CswC3SearchParams();
                                        CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager( CswNbtResources, CswC3SearchParams );
                                        SearchClient C3SearchClient = CswNbtC3ClientManager.initializeC3Client();
                                        if( null != C3SearchClient )
                                        {
                                            string ListCodes = string.Join( ",", Pair.Value.Item2.ToArray() );
                                            string Regions = Pair.Value.Item1;

                                            CswC3SearchParams.Query = CurrentCasNo; // Query takes the Cas Number
                                            CswC3SearchParams.ListCodes = ListCodes; // ListCodes should be a comma delimited string of all list codes
                                            CswC3SearchParams.Regions = Regions; // String list of all regions (for Ariel)
                                            CswC3SearchParams.RegulationDatabase = CswNbtC3ClientManager.RegulationDatabase; // Which Regulation Database to search

                                            CswRetObjSearchResults SearchResults = C3SearchClient.getListCodesByCasNo( CswC3SearchParams );
                                            if( null != SearchResults.RegulationDbDataResults )
                                            {
                                                if( SearchResults.RegulationDbDataResults.Length > 0 )
                                                {
                                                    // If at least one list code was returned, add this regulatory list id to the list of matching reg lists
                                                    ret.Add( Pair.Key );
                                                }
                                            }
                                        }

                                    } //foreach( KeyValuePair<CswPrimaryKey, List<string>> Pair in RegListListCodes )

                                } //foreach( string CurrentCasNo in CasNos )

                            }//if (null != RegListListCodeOC)

                        }//if (CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.LOLISync))

                        #endregion Regulation Database Managed Reg Lists

                    } // if( CasNos.Count > 0 )

                    // find exclusive lists that didn't match
                    {
                        CswNbtView exclusiveView = new CswNbtView( CswNbtResources );
                        CswNbtViewRelationship regListRel = exclusiveView.AddViewRelationship( RegulatoryListOC, false );
                        regListRel.NodeIdsToFilterOut = ExclusiveMatches;
                        exclusiveView.AddViewPropertyAndFilter( regListRel, RegListExclusiveOCP, Value: CswEnumTristate.True.ToString() );

                        ICswNbtTree Tree = CswNbtResources.Trees.getTreeFromView( exclusiveView, RequireViewPermissions: false, IncludeSystemNodes: true, IncludeHiddenNodes: true );
                        for( Int32 i = 0; i < Tree.getChildNodeCount(); i++ )
                        {
                            Tree.goToNthChild( i );
                            ret.Add( Tree.getNodeIdForCurrentPosition() );
                            Tree.goToParentNode();
                        }
                    } // exclusive

                } // if( null != RegulatoryListOC && null != RegListCasNoOC )
            } // if( CswNbtResources.Modules.IsModuleEnabled( CswEnumNbtModuleName.RegulatoryLists ) )
            return ret;
        } // findMatches()
Ejemplo n.º 14
0
        } // _populateDictionary()

        /// <summary>
        /// FOR DISPLAYING CHEMCAT RESULTS
        /// </summary>
        /// <param name="C3SearchResultsObj"></param>
        /// <param name="PropsToHide"></param>
        /// <returns></returns>
        private Int32 _populateDictionary( CswRetObjSearchResults C3SearchResultsObj, Collection<string> PropsToHide, string DataService )
        {
            Int32 results = 0;

            for( int i = 0; i < C3SearchResultsObj.CswC3SearchResults.Count(); i++ )//todo: if results are null
            {
                TableNode thisNode = new TableNode();

                //Note: For now, we are hardcoding the nodetype as "Chemical" for each results from ChemCatCentral.
                thisNode.NodeType = _CswNbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.ChemicalClass ).FirstNodeType;
                if( null != thisNode.NodeType )
                {
                    // default image, overridden below
                    if( thisNode.NodeType.IconFileName != string.Empty )
                    {
                        thisNode.ThumbnailUrl = CswNbtMetaDataObjectClass.IconPrefix100 + thisNode.NodeType.IconFileName;
                    }
                    else
                    {
                        thisNode.ThumbnailUrl = "Images/icons/300/_placeholder.gif";
                    }

                    thisNode.AllowView = _CswNbtResources.Permit.canAnyTab( Security.CswEnumNbtNodeTypePermission.View, thisNode.NodeType );
                    thisNode.AllowEdit = _CswNbtResources.Permit.canAnyTab( Security.CswEnumNbtNodeTypePermission.Edit, thisNode.NodeType );

                    //C3 results are not nodes and hence they can't be deleted.
                    thisNode.AllowDelete = false;
                    //C3 results CAN however be imported into Nbt IF the user has Create Material Permissions
                    thisNode.AllowImport = _CswNbtResources.Permit.can( CswEnumNbtActionName.Create_Material, _CswNbtResources.CurrentNbtUser );
                    thisNode.AllowRequest = _CswNbtResources.Permit.can( CswEnumNbtActionName.Submit_Request, _CswNbtResources.CurrentNbtUser );

                    // Properties
                    int propIndex = 0;
                    CswC3Product[] products = C3SearchResultsObj.CswC3SearchResults;

                    CswC3Product product = products[i];
                    JObject productObject = JObject.FromObject( product );
                    IEnumerable properties = productObject.Properties();
                    foreach( JProperty prop in properties )
                    {
                        string name = prop.Name;
                        string value = prop.Value.ToString();

                        if( prop.Name == "TradeName" )
                        {
                            thisNode.NodeName = prop.Value.ToString();
                        }

                        if( prop.Name == "ProductId" )
                        {
                            thisNode.C3ProductId = CswConvert.ToInt32( prop.Value );
                        }

                        if( prop.Name == "Cdbregno" )
                        {
                            thisNode.ACDCdbregno = CswConvert.ToInt32( prop.Value );
                        }

                        TableProp thisProp = new TableProp();
                        if( PropsToHide == null || false == PropsToHide.Contains( name ) )
                        {
                            thisProp.PropName = name;
                            thisProp.Gestalt = value;
                            thisNode.Props.Add( propIndex, thisProp );
                        }

                        propIndex++;

                    }

                    // Thumbnail image -- set to molimage if we have one
                    if( DataService.Equals( "C3" ) && false == String.IsNullOrEmpty( product.MolImage ) )
                    {
                        thisNode.ThumbnailBase64Str = "data:image/jpeg;base64," + product.MolImage;
                    }
                    else if( DataService.Equals( "ACD" ) )
                    {
                        thisNode.ThumbnailUrl = "Services/BlobData/getExternalImage?cdbregno=" + thisNode.ACDCdbregno + "&productid=" + product.ProductId + "&uid=" + CswRandom.RandomString();
                    }

                    if( false == _TableDict.ContainsKey( thisNode.NodeType ) )
                    {
                        _TableDict.Add( thisNode.NodeType, new Collection<TableNode>() );
                    }
                    _TableDict[thisNode.NodeType].Add( thisNode );

                    results++;

                }//if (null != thisNode.NodeType)

            }//for( int i = 0; i < C3SearchResultsObj.CswC3SearchResults.Count(); i++ )

            return results;
        } // _populateDictionary()