コード例 #1
0
        /// <summary>
        ///     Convert picture to byte array of pixels.
        /// </summary>
        /// <param name="picture">The picture.</param>
        /// <returns>
        ///     Byte array of pixels.
        /// </returns>
        public static byte[] PictureToByteArray(Picture picture)
        {
            var amountOfPixels = picture.Width * picture.Height * 3;
            var pixelArray     = new byte[amountOfPixels];
            var arrayIndex     = 0;

            for (var i = 0; i < picture.Height; i++)
            {
                for (var j = 0; j < picture.Width; j++)
                {
                    j = HeaderManager.SkipHeaderLocation(i, j);

                    var sourcePixelColor = PixelUtilities.GetPixelBgra8(picture.Pixels, i, j,
                                                                        picture.Width, picture.Height);

                    var colorChannels = new List <byte> {
                        sourcePixelColor.R,
                        sourcePixelColor.G,
                        sourcePixelColor.B
                    };

                    foreach (var currentByte in colorChannels)
                    {
                        pixelArray[arrayIndex] = currentByte;
                        arrayIndex++;
                    }
                }
            }

            return(pixelArray);
        }
コード例 #2
0
        public JsonResult GetAllTemplateInformation()
        {
            var username       = "******";
            var headers        = new HeaderManager(Request);
            var clientTemplate = new ClientTemplateService();
            var isValidToken   = TokenManager.IsValidSession(headers.AuthToken);

            return(Json(clientTemplate.GetAllTemplateInformation(username)));
        }
コード例 #3
0
        public void Update_HeadersNull_Throws()
        {
            // arrange
            var manager = new HeaderManager();

            // act
            // assert
            Assert.Throws <ArgumentNullException>(() => manager.Update(null));
        }
コード例 #4
0
        public MainWindow()
        {
            InitializeComponent();

            ExportPathAddress = Properties.Settings.Default.ExportPath;

            DataContext = this;

            Import.Visibility   = Visibility.Collapsed;
            Export.Visibility   = Visibility.Collapsed;
            Settings.Visibility = Visibility.Collapsed;

            header = new HeaderManager(MainControl);

            header.AddButton(ImportB, Import);
            header.AddButton(ExportB, Export);
            header.AddButton(SettingsB, Settings);

            exportImageGrid = new ImageGrid(ExportGrid);
            exportImageGrid.SetGroupView();

            GetAllGroups();

            exportImageGrid.ViewModeChanged += (mode) => {
                switch (mode)
                {
                case ImageGrid.ViewMode.Group:
                    ExportAllView();
                    break;

                case ImageGrid.ViewMode.ImageGroup:
                    ExportImageGroupView();
                    break;

                case ImageGrid.ViewMode.All:
                    ExportAllView();
                    break;
                }
            };
            exportImageGrid.ViewModeChanged  += CacheExportScrollPosition;
            exportImageGrid.SelectionChanged += ExportSelectionChanged;

            CanExport    = false;
            IsNotLoading = true;
            ReturnToGroupBut.Visibility = Visibility.Collapsed;

            LoadingIcon.Visibility = Visibility.Hidden;


            ImageGrid.ImageView.removeAlpha   = TransparencyCheck.IsChecked == false;
            ImageGrid.ImageView.removeShadows = ShadowCheck.IsChecked == false;

            //ExportGroupIDs.SelectedIndex = 0;
            //ExportGrid.Children.Add(new ExportedBitmap());
        }
コード例 #5
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="SteganographyPageViewModel" /> class.
 /// </summary>
 public SteganographyPageViewModel()
 {
     this.SourcePicture       = new Picture();
     this.HiddenPicture       = new Picture();
     this.EmbeddedPicture     = new Picture();
     this.ExtractedPicture    = new Picture();
     this.embeddingManager    = new EmbeddingManager(this.HiddenPicture, this.EmbeddedPicture);
     this.extractionManager   = new ExtractionManager(this.ExtractedPicture);
     this.headerManager       = new HeaderManager(this.SourcePicture);
     this.BitsPerColorChannel = 1;
 }
コード例 #6
0
        public void Get_CacheNull_ReturnsDefault()
        {
            // arrange
            var manager = new HeaderManager();

            // act
            var result = manager.Get <string>(ResponseHeader.PageSize);

            // assert
            Assert.Null(result);
        }
コード例 #7
0
        public void StrippingEmptyDataListShouldThrowException()
        {
            List <byte> emptyHeader = new List <byte>();

            // empty header doesn't have enough bytes, strip should fail

            try {
                HeaderManager.StripHeader(emptyHeader);
                Assert.Fail();
            }
            catch (MessageHeaderException e) {
                Assert.Pass(e.Message);
            }
        }
コード例 #8
0
        public void StrippingShortDataListShouldThrowException()
        {
            List <byte> shortHeader = new List <byte>();

            shortHeader.Add((byte)1);

            // short header doesn't have enough bytes, strip should fail

            try {
                HeaderManager.StripHeader(shortHeader);
                Assert.Fail();
            }
            catch (MessageHeaderException e) {
                Assert.Pass(e.Message);
            }
        }
コード例 #9
0
        public void Update_CacheUpdated_Success()
        {
            // arrange
            var items = new List <(string, string)>
            {
                (ResponseHeader.PageSize.Name, "50"),
                (ResponseHeader.Count.Name, "100"),
            };

            var manager = new HeaderManager();

            // act
            manager.Update(items);

            // assert
            Assert.NotEmpty(manager.Get <string>(ResponseHeader.PageSize));
        }
コード例 #10
0
        public void Get_FailsConvertion_ReturnsDefault()
        {
            // arrange
            var items = new List <(string, string)>
            {
                (ResponseHeader.PageSize.Name, "Not an integer"),
                (ResponseHeader.Count.Name, "100"),
            };

            var manager = new HeaderManager();

            manager.Update(items);

            // act
            var result = manager.Get <int>(ResponseHeader.PageSize);

            // assert
            Assert.Equal(0, result);
        }
コード例 #11
0
        public void Get_KeyDoesNotExist_ReturnsDefault()
        {
            // arrange
            var items = new List <(string, string)>
            {
                ("key1", "value1"),
                ("key2", "value2"),
            };

            var manager = new HeaderManager();

            manager.Update(items);

            // act
            var result = manager.Get <string>(ResponseHeader.PageSize);

            // assert
            Assert.Null(result);
        }
コード例 #12
0
        public void StripHeaderShouldRemoveTwoBytes()
        {
            // create a data list with enough bytes

            List <byte> data = new List <byte> ();

            data.Insert(0, (byte)0);             // this byte should end up being the protocol
            data.Insert(1, (byte)1);             // this byte should end up being the type
            data.Insert(2, (byte)2);             // this byte should not end up in the header


            // strip the header into a struct

            HeaderManager.StripHeader(data);

            // data list should now now contain those bytes

            Assert.AreEqual(1, data.Count);
        }
コード例 #13
0
    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
      Data = new DataManager(filterContext.HttpContext);
      Mailer = new SiteMailer();
      Mailer.EmailLogoPath = filterContext.HttpContext.Server.MapPath("~/email-logo.png");
      Cookies = new CookieManager(this);
      Users = new UserManager(Data);

      base.OnActionExecuting(filterContext);

      if(filterContext.HttpContext.Request.HttpMethod.Equals("GET", StringComparison.InvariantCultureIgnoreCase)
        && !filterContext.HttpContext.Request.IsSecureConnection && Cookies.UseHttps())
      {
        string url = Environment.GetAbsoluteDomain(true) + filterContext.HttpContext.Request.RawUrl;
        filterContext.Result = new RedirectResult(url);
      }
      else
      {
        UserToken token = Cookies.GetUserToken();
        User user = Users.GetUser(token);
        ViewBag.CurrentUser = CurrentUser = user;

        /* Set user context for API calls */
        if(CurrentUser == null)
        {
          var apiToken = new HeaderManager().GetApiToken(Request.Headers);
          ViewBag.CurrentUser = CurrentUser = Users.GetApiUser(apiToken);
        }

        ViewBag.Message = Cookies.GetMessage();
        Cookies.ClearMessage();

        if(CurrentUser == null || !CurrentUser.EnableProfiler)
        {
          MiniProfiler.Stop(true);
        }
        else
        {
          ViewBag.IncludeProfiler = true;
        }
      }
    }
コード例 #14
0
        public void Get_KeyExists_Success()
        {
            // arrange
            const int PAGE_SIZE = 50;
            var       items     = new List <(string, string)>
            {
                (ResponseHeader.PageSize.Name, PAGE_SIZE.ToString()),
                (ResponseHeader.Count.Name, "100"),
            };

            var manager = new HeaderManager();

            manager.Update(items);

            // act
            var result = manager.Get <int>(ResponseHeader.PageSize);

            // assert
            Assert.Equal(PAGE_SIZE, result);
        }
コード例 #15
0
        public void StripHeaderShouldReturnCorrectHeaderStruct()
        {
            // create a data list with enough bytes

            List <byte> data = new List <byte> ();

            data.Insert(0, UpdateManager.PROTOCOL_VERSION);   //insert the valid protocol type
            data.Insert(1, UpdateManager.PLAYER);             // insert any update identifier


            // strip the header into a struct

            HeaderManager.Header result = HeaderManager.StripHeader(data);


            // shold return the right header struct for these bytes
            HeaderManager.Header expected =
                new HeaderManager.Header(UpdateManager.PROTOCOL_VERSION, UpdateManager.PLAYER);

            Assert.AreEqual(expected, result);
        }
コード例 #16
0
        public void StripHeaderShouldLookAtFirstTwoBytes()
        {
            // create a data list with enough bytes

            List <byte> data = new List <byte> ();

            data.Insert(0, (byte)0);             // this byte should end up being the protocol
            data.Insert(1, (byte)1);             // this byte should end up being the type
            data.Insert(2, (byte)2);             // this byte should not end up in the header


            // strip the header into a struct

            HeaderManager.Header result = HeaderManager.StripHeader(data);


            // shold return the right header struct for these bytes

            HeaderManager.Header expected = new HeaderManager.Header(0, 1);

            Assert.AreEqual(expected, result);
        }
コード例 #17
0
 void Awake()
 {
     instance = this;
 }