コード例 #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()
コード例 #2
0
        /// <summary>
        /// This method determines whether the C3SyncDate is older than either
        /// the LastExtChemDataImportDate or the LastRegulationDataImportDate. If it is
        /// out of date, we return true so that a sync is then performed.
        /// </summary>
        /// <param name="CswNbtResources"></param>
        /// <returns></returns>
        private bool outOfDate(CswNbtResources CswNbtResources)
        {
            bool OutOfDate = false;

            CswC3SearchParams     CswC3SearchParams     = new CswC3SearchParams();
            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(CswNbtResources, CswC3SearchParams);
            SearchClient          SearchClient          = CswNbtC3ClientManager.initializeC3Client();

            if (null != SearchClient)
            {
                string LastExtChemDataImportDate = CswNbtC3ClientManager.getLastExtChemDataImportDate(SearchClient);
                string LastRegDataImportDate     = CswNbtC3ClientManager.getLastRegulationDataImportDate(SearchClient);

                // Compare the dates and return true if a sync should be performed
                DateTime NbtC3SyncDate = CswConvert.ToDateTime(CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumConfigurationVariableNames.C3SyncDate));

                if (NbtC3SyncDate == DateTime.MinValue ||
                    (NbtC3SyncDate < CswConvert.ToDateTime(LastExtChemDataImportDate) || (false == string.IsNullOrEmpty(LastRegDataImportDate) && NbtC3SyncDate < CswConvert.ToDateTime(LastRegDataImportDate))))
                {
                    OutOfDate = true;
                }
            }
            else
            {
                // TODO: What should we do with the error in the case of the schedule service?
            }

            return(OutOfDate);
        }
コード例 #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);
            }
        }
コード例 #4
0
        }//getImportBtnItems()

        /// <summary>
        /// Returns either C3 or ACD depending on which module is enabled.
        /// </summary>
        /// <param name="CswResources"></param>
        /// <param name="Return"></param>
        /// <param name="EmptyObject"></param>
        public static void GetC3DataService(ICswResources CswResources, CswNbtC3SearchReturn Return, object EmptyObject)
        {
            CswNbtResources       _CswNbtResources      = (CswNbtResources)CswResources;
            CswC3SearchParams     CswC3SearchParams     = new CswC3SearchParams();
            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3SearchParams);

            Return.Data.DataService = CswNbtC3ClientManager.DataService;
        }//getC3DataService()
コード例 #5
0
        }//GetSearchProperties()

        public static void RunC3FilteredSearch(ICswResources CswResources, CswNbtC3SearchReturn Return, CswC3SearchParams CswC3SearchParams)
        {
            JObject         Ret = new JObject();
            CswNbtResources _CswNbtResources = (CswNbtResources)CswResources;

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

            if (null != C3SearchClient)
            {
                CswRetObjSearchResults SearchResults;
                try
                {
                    SearchResults = C3SearchClient.searchFiltered(CswC3SearchParams);
                }
                catch (Exception exception)
                {
                    throw (new CswDniException(CswEnumErrorType.Error, "There was an error searching ChemCatCentral", exception.Message, exception));
                }

                ExternalImageRet ImageRet = new ExternalImageRet();

                /*
                 * We have to create our own Acd Search params and set Product Id to Int32.MinVal because C3 is serializing ProductId to "0" instead of MinVal.
                 */
                ACDSearchParams acdSearchParams = new ACDSearchParams();
                acdSearchParams.ProductId = Int32.MinValue;
                acdSearchParams.Cdbregno  = CswC3SearchParams.ACDSearchParams.Cdbregno;
                getExternalImage(CswResources, ImageRet, acdSearchParams);
                string imageStrBase64 = "data:image/png;base64," + Convert.ToBase64String(ImageRet.Data);

                CswNbtWebServiceTable wsTable = new CswNbtWebServiceTable(_CswNbtResources, null, Int32.MinValue);
                Ret["table"]                = wsTable.getTable(SearchResults, CswC3SearchParams.Field, CswNbtC3ClientManager.DataService, true);
                Ret["filters"]              = "";
                Ret["searchterm"]           = CswC3SearchParams.Query;
                Ret["field"]                = CswC3SearchParams.Field;
                Ret["filtersapplied"]       = "";
                Ret["sessiondataid"]        = "";
                Ret["searchtarget"]         = "chemcatcentral";
                Ret["c3dataservice"]        = CswNbtC3ClientManager.DataService;
                Ret["filtered"]             = true;
                Ret["staticbase64imagestr"] = imageStrBase64;
                if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.C3ACD))
                {
                    Ret["prefsuppliers"] = CswC3SearchParams.ACDSearchParams.CompanyIds;
                }

                Return.Data.SearchResults = Ret.ToString();
            }
        }//RunC3FilteredSearch()
コード例 #6
0
        public void threadCallBack(ICswResources CswResources)
        {
            _LogicRunStatus = CswEnumScheduleLogicRunStatus.Running;

            CswNbtResources CswNbtResources = (CswNbtResources)CswResources;

            CswNbtResources.AuditContext = "Scheduler Task: " + RuleName;

            if (CswEnumScheduleLogicRunStatus.Stopping != _LogicRunStatus)
            {
                try
                {
                    if (_SyncModules.Any(SyncModule => CswNbtResources.Modules.IsModuleEnabled(SyncModule)))
                    {
                        // Check C3 Status
                        CswC3Params           CswC3Params           = new CswC3Params();
                        CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(CswNbtResources, CswC3Params);
                        SearchClient          SearchClient          = CswNbtC3ClientManager.initializeC3Client();
                        if (null != SearchClient)
                        {
                            int MaterialsProcessedPerIteration = CswConvert.ToInt32(CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumConfigurationVariableNames.NodesProcessedPerCycle));
                            int TotalProcessedThisIteration    = 0;
                            while (TotalProcessedThisIteration < MaterialsProcessedPerIteration && _MaterialPks.Count > 0 && (CswEnumScheduleLogicRunStatus.Stopping != _LogicRunStatus))
                            {
                                CswNbtObjClassChemical MaterialNode = CswNbtResources.Nodes[_MaterialPks[0]];
                                if (null != MaterialNode)
                                {
                                    _setPendingUpdate(CswNbtResources, CswConvert.ToString(MaterialNode.NodeId.PrimaryKey));
                                    _MaterialPks.RemoveAt(0);
                                    TotalProcessedThisIteration++;
                                } //if (null != MaterialNode)
                            }
                        }
                        else
                        {
                            // TODO: What should we do with the error in the case of the schedule service?
                        }
                    }

                    _CswScheduleLogicDetail.StatusMessage = "Completed without error";
                    _LogicRunStatus = CswEnumScheduleLogicRunStatus.Succeeded; //last line
                }//try
                catch (Exception Exception)
                {
                    _CswScheduleLogicDetail.StatusMessage = "CswScheduleLogicNbtExtChemDataSync exception: " + Exception.Message + "; " + Exception.StackTrace;
                    CswNbtResources.logError(new CswDniException(_CswScheduleLogicDetail.StatusMessage));
                    _LogicRunStatus = CswEnumScheduleLogicRunStatus.Failed;
                }
            }
        }
コード例 #7
0
        }//getC3DataService()

        public static void GetVendorOptions(ICswResources CswResources, CswNbtC3SearchReturn Return, CswC3Params CswC3Params)
        {
            CswNbtResources _CswNbtResources = (CswNbtResources)CswResources;

            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3Params);

            if (CswNbtC3ClientManager.DataService == "C3")
            {
                Return.Data.VendorListOptions = _getAvailableDataSources(CswNbtC3ClientManager, CswC3Params);
            }
            else if (CswNbtC3ClientManager.DataService == "ACD")
            {
                Return.Data.VendorListOptions = _getPreferredSuppliers(_CswNbtResources);
            }
        }
コード例 #8
0
        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;
                    }
                }
            }
        }
コード例 #9
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;
                }
            }
        }
コード例 #10
0
        public static void RunChemCatCentralSearch(ICswResources CswResources, CswNbtC3SearchReturn Return, CswC3SearchParams CswC3SearchParams)
        {
            JObject         Ret = new JObject();
            CswNbtResources _CswNbtResources = (CswNbtResources)CswResources;

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

            if (null != C3SearchClient)
            {
                CswRetObjSearchResults SearchResults;

                try
                {
                    SearchResults = C3SearchClient.search(CswC3SearchParams);
                }
                catch (TimeoutException TimeoutException)
                {
                    const string WarningMessage = "The search has timed out. Please use more specific search terms.";
                    throw (new CswDniException(CswEnumErrorType.Warning, WarningMessage, WarningMessage, TimeoutException));
                }

                CswNbtWebServiceTable wsTable = new CswNbtWebServiceTable(_CswNbtResources, null, Int32.MinValue);
                Ret["table"]          = wsTable.getTable(SearchResults, CswC3SearchParams.Field, CswNbtC3ClientManager.DataService);
                Ret["filters"]        = "";
                Ret["searchterm"]     = CswC3SearchParams.Query;
                Ret["field"]          = CswC3SearchParams.Field;
                Ret["filtersapplied"] = "";
                Ret["sessiondataid"]  = "";
                Ret["searchtarget"]   = "chemcatcentral";
                Ret["c3dataservice"]  = CswNbtC3ClientManager.DataService;
                Ret["filtered"]       = "C3" == CswNbtC3ClientManager.DataService;
                if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.C3ACD))
                {
                    Ret["prefsuppliers"] = CswC3SearchParams.ACDSearchParams.CompanyIds;
                }

                Return.Data.SearchResults = Ret.ToString();
            }
        }
コード例 #11
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()
コード例 #12
0
ファイル: CswNbtSdC3.cs プロジェクト: crfroehlich/legacy
        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()
コード例 #13
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()
コード例 #14
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()