Пример #1
0
 public void WarnWithMsgShouldNotCallUnderlyingWarnWhenWarnIsDisabled()
 {
     underlyingLoggerMock.Setup(l => l.IsWarnEnabled).Returns(false);
     isWarnEnabledResolverMock.Setup(r => r.Value).Returns(underlyingLoggerMock.Object.IsWarnEnabled);
     logger.Warn("msg");
     underlyingLoggerMock.Verify(l => l.Warn(It.IsAny <string>()), Times.Never());
 }
        public AuthState Authenticate()
        {
            if (string.IsNullOrEmpty(this.PasswordSource.Password) == true)
            {
                LoggerFacade.Warn("Cannot autheticate with empty password");
                this.SetState(AuthState.NoPassword);
                this.AuthStateChanged?.Invoke();
                return(AuthState.AccessDenied);
            }

            LoggerFacade.Info("Authenticating against local config with ID " + this.AuthID);
            AuthState newstate = AuthState.AccessDenied;

            foreach (Password pw in this._validpasswords)
            {
                if (pw.PasswordMatches(this.PasswordSource?.Password))
                {
                    newstate = AuthState.Authorised;
                    LoggerFacade.Info("Authorised.");
                    break;
                }
            }

            if (newstate != AuthState.Authorised)
            {
                LoggerFacade.Warn("Authentication failed");
            }


            this.SetState(newstate);
            this.AuthStateChanged?.Invoke();
            return(newstate);
        }
Пример #3
0
        void ShouldNotLogEverything()
        {
            // Arrange
            var logStrategy = new Mock <ILogStrategy>();

            logStrategy.Setup(x => x.WriteMessage(It.IsAny <string>())).Verifiable();
            var shouldLog = LogLevel.Fatal | LogLevel.Info | LogLevel.Warn;
            var logger    = new LoggerFacade <RawLogger>(new LoggerSettings
            {
                LogLevel           = shouldLog,
                DefaultLogStrategy = logStrategy.Object
            });

            // Act
            logger.Debug("debug");
            logger.Error("error");
            logger.Fatal("fatal");
            logger.Info("info;");
            logger.Warn("warm;");

            // Assert
            logStrategy.Verify(x => x.WriteMessage(It.IsAny <string>()), Times.Exactly(3));


            foreach (var logLevel in Enum.GetValues(typeof(LogLevel)))
            {
                var logLevelEnum = (LogLevel)logLevel;
                if ((logLevelEnum & shouldLog) != LogLevel.None)
                {
                    logStrategy.Verify(x => x.WriteMessage(It.Is <string>(s => s.Contains($"{logLevelEnum}"))), Times.Once);
                }
            }
        }
Пример #4
0
        public bool DoesMatch(string input)
        {
            double inputnum;
            double rulenum;

            if (!double.TryParse(input, out inputnum))
            {
                LoggerFacade.Warn("Failed to convert input to number: " + input);
                return(false);
            }
            if (!double.TryParse(this.Content, out rulenum))
            {
                LoggerFacade.Warn("Failed to convert rule content to number: " + this.Content);
                return(false);
            }

            bool result = this.Compare(inputnum, rulenum);

            if (this.Not)
            {
                return(!result);
            }
            else
            {
                return(result);
            }
        }
Пример #5
0
        public static bool IsUserMemberOfGroups(PrincipalContext context, string samaccountname, List <string> groups)
        {
            using (UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, samaccountname))
            {
                if (user != null)
                {
                    GroupPrincipal prigroup = GetPrimaryGroup(context, user);
                    PrincipalSearchResult <Principal> usergroups = user.GetAuthorizationGroups();

                    if (groups == null)
                    {
                        return(true);
                    }

                    foreach (string groupname in groups)
                    {
                        using (GroupPrincipal group = GroupPrincipal.FindByIdentity(context, groupname))
                        {
                            if (group == null)
                            {
                                LoggerFacade.Warn("Group not found: " + groupname);
                            }
                            else
                            {
                                //work around issue where IsMemherOf always returns false on users primary group
                                if (group.Equals(prigroup))
                                {
                                    return(true);
                                }

                                //now do normal processing
                                bool ismember = user.IsMemberOf(group);
                                if (ismember == false)
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    return(true);
                }

                else
                {
                    throw new NoMatchingPrincipalException("User not found: " + samaccountname);
                }
            }
        }
Пример #6
0
        public override ResultWrangler ProcessQuery()
        {
            if (this._authenticator?.State != AuthState.Authorised)
            {
                this._returnwrangler = null;
                return(null);
            }

            //Now go through the management objects return from WMI, and add the relevant values to the wrangler.
            //New sublists are created for each management object in the wrangler.
            try
            {
                if (this._processed == true)
                {
                    this._processingwrangler = this._processingwrangler.Clone();
                }

                using (PrincipalContext context = new PrincipalContext(ContextType.Domain, this._authenticator.Domain, this._baseou, this._authenticator.UsernameSource.Username, this._authenticator.PasswordSource.Password))
                {
                    GroupPrincipal groups = new GroupPrincipal(context, "*");
                    using (PrincipalSearcher ps = new PrincipalSearcher(groups))
                    {
                        PrincipalSearchResult <Principal> groupresults = ps.FindAll();
                        foreach (Principal group in groupresults)
                        {
                            this.AddPropertiesToWrangler(this._processingwrangler, group, this._propertyTemplates);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //throw new TsGuiKnownException("Active Directory OU query caused an error", e.Message);
                LoggerFacade.Warn("Active Directory OU groups query caused an error: " + e.Message);
            }

            this._processed = true;
            if (this.ShouldIgnore(this._processingwrangler.GetString()) == false)
            {
                this._returnwrangler = this._processingwrangler;
            }
            else
            {
                this._returnwrangler = null;
            }

            return(this._returnwrangler);
        }
Пример #7
0
        static int Main(string[] args)
        {
            ArgumentAdapter argumentAdapter = new ArgumentAdapter(args);
            ArgumentPayload ap = argumentAdapter.Parse();

            if (ap == null)
            {
                ApplicationUsage();
                return(1);
            }

            Command command;

            switch (ap.ProcessingCommand)
            {
            case Processing.Negative:
                command = new NegativeCommand(ap.BitmapPath, ap.OutcomeBitmapPath);
                break;

            case Processing.Grayscale:
                command = new GrayscaleCommand(ap.BitmapPath, ap.OutcomeBitmapPath);
                break;

            case Processing.Sepia:
                command = new SepiaCommand(ap.BitmapPath, ap.OutcomeBitmapPath);
                break;

            case Processing.Encode:
                command = new TextCodingCommand(ap.BitmapPath, ap.OutcomeBitmapPath, ap.TextToEncoding);
                break;

            case Processing.Decode:
                command = new TextDecodingCommand(ap.BitmapPath);
                break;

            case Processing.Bluish:
                command = new BluishCommand(ap.BitmapPath, ap.OutcomeBitmapPath);
                break;

            default:
                LoggerFacade.Warn("Niepoprawna akcja!");
                return(2);
            }
            command.Execute();
            LoggerFacade.Success("Gotowe!");
            return(0);
        }
Пример #8
0
        public override ResultWrangler ProcessQuery()
        {
            if (this._authenticator?.State != AuthState.Authorised)
            {
                this._returnwrangler = null;
                return(null);
            }

            try
            {
                if (this._processed == true)
                {
                    this._processingwrangler = this._processingwrangler.Clone();
                }
                using (GroupPrincipal group = GroupPrincipal.FindByIdentity(this._authenticator.Context, this._groupname))
                {
                    if (group == null)
                    {
                        LoggerFacade.Warn("Group not found: " + this._groupname);
                    }
                    else
                    {
                        this.AddPropertiesToWrangler(this._processingwrangler, group.Members, this._propertyTemplates);
                    }
                }
            }
            catch (Exception e)
            {
                throw new TsGuiKnownException("Active Directory group query caused an error:" + Environment.NewLine + this._groupname, e.Message);
            }

            this._processed = true;
            if (this.ShouldIgnore(this._processingwrangler.GetString()) == false)
            {
                this._returnwrangler = this._processingwrangler;
            }
            else
            {
                this._returnwrangler = null;
            }

            return(this._returnwrangler);
        }
Пример #9
0
        public AuthState Authenticate()
        {
            if (string.IsNullOrWhiteSpace(this.UsernameSource.Username) == true)
            {
                LoggerFacade.Warn("Cannot autheticate with empty username");
                this.SetState(AuthState.AccessDenied);
                return(AuthState.AccessDenied);
            }
            if (string.IsNullOrEmpty(this.PasswordSource.Password) == true)
            {
                LoggerFacade.Warn("Cannot autheticate with empty password");
                this.SetState(AuthState.AccessDenied);
                return(AuthState.AccessDenied);
            }

            LoggerFacade.Info("Authenticating user: "******" against domain " + this._domain);
            AuthState newstate;

            try
            {
                this.Context = new PrincipalContext(ContextType.Domain, this._domain, this.UsernameSource.Username, this.PasswordSource.Password);

                if (ActiveDirectoryMethods.IsUserMemberOfGroups(this.Context, this.UsernameSource.Username, this.RequiredGroups) == true)
                {
                    LoggerFacade.Info("Active Directory authorised");
                    newstate = AuthState.Authorised;
                }
                else
                {
                    LoggerFacade.Info("Active Directory not authorised");
                    newstate = AuthState.NotAuthorised;
                }
            }
            catch (Exception e)
            {
                LoggerFacade.Warn("Active Directory access denied");
                LoggerFacade.Trace(e.Message + Environment.NewLine + e.StackTrace);
                newstate = AuthState.AccessDenied;
            }

            this.SetState(newstate);
            return(newstate);
        }
Пример #10
0
        public override ResultWrangler ProcessQuery()
        {
            if (this._authenticator?.State != AuthState.Authorised)
            {
                this._returnwrangler = null;
                return(null);
            }

            //Now go through the management objects return from WMI, and add the relevant values to the wrangler.
            //New sublists are created for each management object in the wrangler.
            try
            {
                if (this._processed == true)
                {
                    this._processingwrangler = this._processingwrangler.Clone();
                }
                string fullbaseou = "LDAP://" + this._authenticator.Domain + "/" + this._baseou;
                using (DirectoryEntry de = new DirectoryEntry(fullbaseou, this._authenticator.UsernameSource.Username, this._authenticator.PasswordSource.Password))
                {
                    this._processingwrangler.AddResult(this.QueryDirectoryEntry(de));
                }
            }
            catch (Exception e)
            {
                //throw new TsGuiKnownException("Active Directory OU query caused an error", e.Message);
                LoggerFacade.Warn("Active Directory OU query caused an error: " + e.Message);
            }

            this._processed = true;
            if (this.ShouldIgnore(this._processingwrangler.GetString()) == false)
            {
                this._returnwrangler = this._processingwrangler;
            }
            else
            {
                this._returnwrangler = null;
            }

            return(this._returnwrangler);
        }
Пример #11
0
 public SccmConnector()
 {
     objTSEnv = Activator.CreateInstance(Type.GetTypeFromProgID("Microsoft.SMS.TSEnvironment"));
     try { objTSProgUI = Activator.CreateInstance(Type.GetTypeFromProgID("Microsoft.SMS.TsProgressUI")); }
     catch { LoggerFacade.Warn("Unable to attach to task sequence progress dialog"); }
 }
        public override void Execute()
        {
            LoggerFacade.Highlight($"Długość tekstu do zakodowania: {this.textToCoding.Length}");

            Bitmap bitmap = new Bitmap(Image.FromFile(bitmapPath));

            Color color;

            char[] chars     = this.textToCoding.ToCharArray();
            int    charIndex = 0;
            uint   charValue = (uint)chars.Length;
            uint   iCount    = (uint)(chars.Length * 4) + 4;

            int bitsPairNumber = 0;

            bool[] charBits = new bool[16];

            int x = 0;
            int y = 0;

            for (uint i = 0; i < iCount; i++)
            {
                bitsPairNumber = (int)(i % 4);

                if (bitsPairNumber == 0)
                {
                    if (i > 0)
                    {
                        charValue = chars[charIndex];
                        charIndex++;
                    }

                    for (int f = 0; f < 16; f++)
                    {
                        uint m = (uint)(1 << f);
                        bool j = (charValue & m) == m;
                        charBits[f] = j;
                    }
                }

                color = bitmap.GetPixel(x, y);
                int[] c = new int[] { color.A, color.R, color.G, color.B };

                for (int k = 0; k < 4; k++)
                {
                    int index = 4 * bitsPairNumber + k;
                    c[k] = charBits[index] ? c[k] |= 1 : c[k] &= ~1;
                }

                bitmap.SetPixel(x, y, Color.FromArgb(c[0], c[1], c[2], c[3]));

                if (x == bitmap.Width - 1)
                {
                    x = 0;
                    y++;
                }
                else
                {
                    x++;
                }

                if (y == bitmap.Height - 1)
                {
                    this.IsOutRange = true;
                    return;
                }
            }

            bitmap.Save(outcomeBitmapPath, ImageFormat.Png); // NOTE: jpg is also saved as bitmap
            if (this.IsOutRange)
            {
                LoggerFacade.Warn($"Ostrzeżenie: Zabrakło wolnych bitów do zakodowania!");
            }
        }