コード例 #1
0
        public void CswRandomStringComplexAll_UnitTest()
        {
            bool AllPass = true;

            for (int i = 0; i < 100000; i += 1)
            {
                string RdmStr = CswRandom.RandomString();
                //All strings are 12 characters and has a letter, a number, and a special char
                AllPass = RdmStr.Length == 12 &&
                          AllPass &&
                          CswTools.HasAlpha(RdmStr) &&
                          CswTools.HasNumber(RdmStr) &&
                          CswTools.HasSpecialCharacter(RdmStr);
            }
            Assert.IsTrue(AllPass, "Not all strings met the complexity requirements.");
        }
コード例 #2
0
        public void CswRandomStringComplexAlpha_UnitTest()
        {
            bool AllPass = true;

            for (int i = 0; i < 100000; i += 1)
            {
                string RdmStr = CswRandom.RandomString(new CswRandom.Config {
                    IncludeLetters = true, IncludeNumbers = false, IncludeSymbols = false, Length = 9
                });
                //All strings are 9 characters, none has a special character or a number, and all have letters
                AllPass = AllPass &&
                          RdmStr.Length == 9 &&
                          false == CswTools.HasSpecialCharacter(RdmStr) &&
                          false == CswTools.HasNumber(RdmStr) &&
                          CswTools.HasAlpha(RdmStr);
            }
            Assert.IsTrue(AllPass, "Not all strings met the complexity requirements.");
        }
コード例 #3
0
        public void threadCallBack(ICswResources CswResources)
        {
            _LogicRunStatus = CswEnumScheduleLogicRunStatus.Running;

            CswNbtResources CswNbtResources = (CswNbtResources)CswResources;

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

            if (CswEnumScheduleLogicRunStatus.Stopping != _LogicRunStatus)
            {
                try
                {
                    CswNbtObjClassUser CswAdminAsUser = CswNbtResources.Nodes.makeUserNodeFromUsername(CswNbtObjClassUser.ChemSWAdminUsername);
                    if (null != CswAdminAsUser)
                    {
                        if (false == CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.NBTManager))
                        {
                            CswAdminAsUser.AccountLocked.Checked        = CswEnumTristate.True;
                            CswAdminAsUser.PasswordProperty.ChangedDate = DateTime.MinValue;
                        }
                        else
                        {
                            CswAdminAsUser.AccountLocked.Checked     = CswEnumTristate.False;
                            CswAdminAsUser.FailedLoginCount.Value    = 0;
                            CswAdminAsUser.PasswordProperty.Password = CswRandom.RandomString();
                            CswNbtResources.ConfigVbls.setConfigVariableValue(CswEnumNbtConfigurationVariables.password_length.ToString(), "16");
                            CswNbtResources.ConfigVbls.setConfigVariableValue(CswEnumNbtConfigurationVariables.passwordexpiry_days.ToString(), "30");
                        }
                        CswAdminAsUser.postChanges(ForceUpdate: true);
                    }
                    _CswScheduleLogicDetail.StatusMessage = "Completed without error";
                    _LogicRunStatus = CswEnumScheduleLogicRunStatus.Succeeded; //last line
                }//try

                catch (Exception Exception)
                {
                    _CswScheduleLogicDetail.StatusMessage = "CswScheduleLogicNbtDisableCswAdmin::GetUpdatedItems() exception: " + Exception.Message + "; " + Exception.StackTrace;
                    CswNbtResources.logError(new CswDniException(_CswScheduleLogicDetail.StatusMessage));
                    _LogicRunStatus = CswEnumScheduleLogicRunStatus.Failed;
                } //catch
            }     //if we're not shutting down
        }         //threadCallBack()
コード例 #4
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()