示例#1
0
        public static void LoadChildren(SequenceNode root, YamlSequenceNode sequence)
        {
            foreach (var child in sequence.Children)
            {
                if (child is YamlSequenceNode)
                {
                    var node = root.AddChild(new SequenceNode(root.Value, child, ImageLoad.GetImageIndex(child), id, root));
                    id++;
                    LoadChildren(node as SequenceNode, child as YamlSequenceNode);
                }
                else if (child is YamlMappingNode)
                {
                    var teste = child as YamlMappingNode;
                    var node  = root.AddChild(new MappingNode(root.Value, child, ImageLoad.GetImageIndex(child), id, root));
                    id++;

                    LoadChildren(node as MappingNode, child as YamlMappingNode);
                }
                else if (child is YamlScalarNode)
                {
                    var scalar = child as YamlScalarNode;
                    var node   = root.AddChild(new ScalarNode(scalar.Value, child, scalar.Tag, ImageLoad.GetImageIndex(child), id, root));
                    id++;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Propagate the image load event from root container.
 /// </summary>
 protected virtual void OnImageLoad(HtmlImageLoadEventArgs e)
 {
     ImageLoad?.Invoke(this, e);
     if (!e.Handled)
     {
         YamuiThemeManager.GetHtmlImages(e);
     }
 }
示例#3
0
        public static void LoadChildren(MappingNode root, YamlMappingNode mapping)
        {
            var children = mapping?.Children;

            if (children == null)
            {
                return;
            }

            foreach (var child in children)
            {
                var key = child.Key as YamlScalarNode;
                System.Diagnostics.Trace.Assert(key != null);

                if (child.Value is YamlScalarNode)
                {
                    var scalar = child.Value as YamlScalarNode;

                    if (scalar.Tag == "!include")
                    {
                        MappingNode scalarToMapping = (MappingNode)root.AddChild(new MappingNode(scalar.Value, scalar.Tag, ImageLoad.GetImageIndex(scalar), id, root));
                        id++;

                        var yaml = FileHandler.LoadFile(scalarToMapping as MappingNode, scalar.Value);
                        if (yaml.Documents.Count == 0)
                        {
                            continue;
                        }

                        //scalarToMapping.AddChild(newRoot);
                        LoadChildren(scalarToMapping, yaml.Documents[0].RootNode as YamlMappingNode);
                        continue;
                    }

                    ScalarNode scalarToSave = new ScalarNode(scalar.Value, child, scalar.Tag, ImageLoad.GetImageIndex(scalar), id, root, key.Value);
                    id++;
                    if (scalar.Tag == "!secret")
                    {
                        scalarToSave.Property   = scalar.Tag;
                        scalarToSave.ImageIndex = 2;
                    }
                    var node = root.AddChild(scalarToSave);
                }
                else if (child.Value is YamlSequenceNode)
                {
                    var node = root.AddChild(new SequenceNode(key.Value, child.Value, ImageLoad.GetImageIndex(child.Value), id, root));
                    id++;

                    LoadChildren(node as SequenceNode, child.Value as YamlSequenceNode);
                }
                else if (child.Value is YamlMappingNode)
                {
                    var node = root.AddChild(new MappingNode(key.Value, child.Value, ImageLoad.GetImageIndex(child.Value), id, root));
                    id++;
                    LoadChildren(node as MappingNode, child.Value as YamlMappingNode);
                }
            }
        }
示例#4
0
 public Download(Image image)
 {
     Status     = "Download Completed";
     this.Link  = "Raw Image";
     this.image = image;
     Thumbnail  = ImageLoad.GetThumbnailImage(image, 100);
     Vault.Controller.AddImageToDownloadFolder(this.image);
     this.image = null;
     SD.Garbage.ClearRAM.Clear();
     DownloadCompleted?.Invoke(null, EventArgs.Empty);
 }
示例#5
0
        public static IAsyncResult Begin(ImageLoad load, IntPtr p, Session session, ImageSize size,
                                         AsyncCallback userCallback, object state)
        {
            AsyncLoadImageResult result = new AsyncLoadImageResult(userCallback, state);
            Image image = new Image(LibSpotify.sp_image_create_r(session.Handle, load(p, size)));

            result.Closure = image;
            image.Loaded  += result.HandleImageLoaded;

            // It's possible the image loaded before we registered the result.HandleImageLoaded
            if (image.IsLoaded)
            {
                result.CompletedSynchronously = true;
                result.SetCompleted(image.Error);
            }

            return(result);
        }
示例#6
0
        private void FetchImage()
        {
            try
            {
                HttpWebRequest  httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(Link);
                HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
                Stream          stream         = httpWebReponse.GetResponseStream();
                this.image = Image.FromStream(stream);
                Thumbnail  = ImageLoad.GetThumbnailImage(image, 100);
                Controller.AddImageToDownloadFolder(this.image);
                this.image = null;
                SD.Garbage.ClearRAM.Clear();
                Status = "Download Completed";
            }
            catch (Exception ee)
            {
                image     = null;
                Thumbnail = new Bitmap(1, 1);

                Status = "Download Failed" + " " + ee.Message;
            }
        }
        //[EnableCors("CorsPolicy")]
        public IActionResult ImageLoad([FromForm] ImageLoad model)
        {
            FindFromToTagFilterQuery query     = new FindFromToTagFilterQuery();
            List <ImageJson>         imageList = new List <ImageJson>();

            try
            {
                query.BeginIndex = model.BeginIndex;
                query.EndIndex   = model.EndIndex;
                query.TagFilters = new List <Guid>();
                if (!string.IsNullOrWhiteSpace(model.Search))
                {
                    query.Search = model.Search.ToLower();
                }

                if (model.TagFilters != null)
                {
                    foreach (string str in model.TagFilters)
                    {
                        query.TagFilters.Add(Guid.Parse(str));
                    }
                }
                this.service.FindFromToTagFilter(query);

                foreach (AlbumImage image in query.AlbumImages)
                {
                    imageList.Add(new ImageJson {
                        ImageAlt = image.ImageAlt.Trim(), ImageName = image.ImageName, ImageUrl = image.ImageUrl, ImageId = image.ImageId
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(JsonConvert.SerializeObject(imageList)));
        }
示例#8
0
        public static CurrentClipboard GetImage()
        {
            try
            {
                if (Clipboard.ContainsText())
                {
                    if (Clipboard.GetText() != clipboard.text)
                    {
                        clipboard.text      = Clipboard.GetText();
                        clipboard.PlainText = clipboard.text;
                    }
                }
                if (Clipboard.ContainsImage())
                {
                    if (Clipboard.GetImage() != clipboard.image)
                    {
                        clipboard.image = Clipboard.GetImage();
                    }
                }
                if (Clipboard.ContainsFileDropList())
                {
                    foreach (string s in Clipboard.GetFileDropList())
                    {
                        if (s.ToLower().Contains(".jpg") || s.ToLower().Contains(".bmp") || s.ToLower().Contains(".png"))
                        {
                            clipboard.image = ImageLoad.LoadBitmapImage(s);
                        }
                    }
                }

                return(clipboard);
            }
            catch (Exception ee)
            {
                return(new CurrentClipboard());
            }
        }
示例#9
0
        public void Process()
        {
            string line;

            uint methodToken = 0x06000001;

            string filename = Path.Combine(Path.GetDirectoryName(_outputFile), Path.GetFileNameWithoutExtension(_outputFile));

            Guid   pdbSig;
            uint   pdbAge;
            string dllPath = CreatePdbFile(out pdbSig, out pdbAge);

            _allMethods.Clear();

            int tickCount = 0;

            using (var reader = new StreamReader(_filename)) {
                var logCreationTime      = DateTime.Now;
                var logCreationTimeStamp = Stopwatch.GetTimestamp();

                var log = TraceLog.Start(filename + ".etl", null);

                try {
                    EVENT_TRACE_HEADER header;

                    //////////////////////////////////////
                    header = NewHeader();
                    //header.TimeStamp = currentTimeStamp++;
                    header.Guid    = TraceLog.ProcessEventGuid;
                    header.Version = 3;
                    header.Type    = 3;

                    var processInfo = new ProcessInfo();
                    processInfo.UniqueProcessKey = 100;
                    processInfo.ProcessId        = ProcessId;
                    processInfo.ParentId         = 100;

                    log.Trace(header, processInfo, Encoding.ASCII.GetBytes("node.exe"), String.Empty);

                    //////////////////////////////////////
                    header         = NewHeader();
                    header.Guid    = TraceLog.ThreadEventGuid;
                    header.Version = 3;
                    header.Type    = 3;

                    var threadInfo = new ThreadInfo();
                    threadInfo.ProcessId      = ProcessId; // setup the thread as if it was a reasonable real thread
                    threadInfo.TThreadId      = ThreadId;
                    threadInfo.Affinity       = 0xFF;
                    threadInfo.Win32StartAddr = 0x8888;
                    threadInfo.UserStackBase  = 0xF0000;
                    threadInfo.UserStackLimit = 0xF00200;
                    threadInfo.IoPriority     = 2;
                    log.Trace(header, threadInfo);

                    //////////////////////////////////////
                    header = NewHeader();
                    //header.TimeStamp = currentTimeStamp++;
                    header.Guid    = TraceLog.ImageEventGuid;
                    header.Version = 2;
                    header.Type    = 3;

                    var imgLoad = new ImageLoad();
                    imgLoad.ImageBase = 0x10000;
                    imgLoad.ImageSize = 10000;
                    imgLoad.ProcessId = ProcessId;
                    log.Trace(header, imgLoad, dllPath);

                    //////////////////////////////////////
                    header         = NewHeader();
                    header.Guid    = TraceLog.LoaderEventGuid;
                    header.Version = 2;
                    header.Type    = 33;

                    var moduleLoad = new ManagedModuleLoadUnload();
                    moduleLoad.AssemblyID = 1;
                    moduleLoad.ModuleID   = JitModuleId;

                    log.Trace(header, moduleLoad, dllPath, dllPath,
                              (ushort)1,                                         // clr instance ID
                              pdbSig,                                            // pdb sig
                              pdbAge,                                            // pdb age
                              dllPath.Substring(0, dllPath.Length - 4) + ".pdb", // path to PDB,
                              Guid.Empty,
                              0,
                              String.Empty
                              );

                    while ((line = reader.ReadLine()) != null)
                    {
                        var records = SplitRecord(line);
                        if (records.Length == 0)
                        {
                            continue;
                        }

                        switch (records[0])
                        {
                        case "shared-library":
                            if (records.Length < 4)
                            {
                                continue;     // missing info?
                            }
                            break;

                        case "profiler":
                            break;

                        case "code-creation":
                            int shift = (_nodeVersion >= v012 ? 1 : 0);
                            if (records.Length < shift + 5)
                            {
                                continue;     // missing info?
                            }
                            var startAddr = ParseAddress(records[shift + 2]);

                            header = NewMethodEventHeader();

                            var methodLoad = new MethodLoadUnload();
                            methodLoad.MethodID           = methodToken;
                            methodLoad.ModuleID           = JitModuleId;
                            methodLoad.MethodStartAddress = startAddr;
                            methodLoad.MethodSize         = (uint)ParseAddress(records[shift + 3]);
                            methodLoad.MethodToken        = methodToken;
                            methodLoad.MethodFlags        = 8;

                            var    funcInfo     = ExtractNamespaceAndMethodName(records[shift + 4], records[1]);
                            string functionName = funcInfo.Function;
                            if (funcInfo.IsRecompilation)
                            {
                                functionName += " (recompiled)";
                            }

                            _codeAddresses[new AddressRange(startAddr, methodLoad.MethodSize)] = IsMyCode(funcInfo);
                            log.Trace(header, methodLoad, funcInfo.Namespace, functionName, String.Empty /* signature*/);

                            methodToken++;
                            break;

                        case "tick":
                            if (records.Length < 5)
                            {
                                continue;
                            }
                            var addr = ParseAddress(records[1]);

                            header = NewTickRecord();

                            var profileInfo = new SampledProfile();
                            profileInfo.InstructionPointer = (uint)addr;
                            profileInfo.ThreadId           = ThreadId;
                            profileInfo.Count = 1;

                            log.Trace(header, profileInfo);

                            if (records.Length > 2)
                            {
                                header = NewStackWalkRecord();

                                var sw = new StackWalk();
                                // this timestamp is independent from the timestamp in our header,
                                // and this one is not filled in for us by ETW.  So we need to fill
                                // it in here.
                                sw.TimeStamp = (ulong)Stopwatch.GetTimestamp();
                                sw.Process   = ProcessId;
                                sw.Thread    = ThreadId;

                                // tick, ip, esp, ? [always zero], ?, always zero[?], stack IPs...
                                const int nonStackFrames = 6;       // count of records, including IP, which aren't stack addresses.

                                List <object> args = new List <object>();
                                args.Add(sw);
                                var ipAddr = ParseAddress(records[1]);
                                if (ipAddr != 0 && ShouldIncludeCode(ipAddr))
                                {
                                    args.Add(ipAddr);
                                }
                                for (int i = nonStackFrames; i < records.Length; i++)
                                {
                                    var callerAddr = ParseAddress(records[i]);
                                    if (callerAddr != 0 && ShouldIncludeCode(callerAddr))
                                    {
                                        args.Add(callerAddr);
                                    }
                                }

                                if ((records.Length - nonStackFrames) == 0)
                                {
                                    // idle CPU time
                                    sw.Process = 0;
                                }
                                tickCount++;
                                log.Trace(header, args.ToArray());
                            }
                            break;

                        default:
                            Console.WriteLine("Unknown record type: {0}", line);
                            break;
                        }
                    }

                    header         = NewHeader();
                    header.Guid    = TraceLog.ProcessEventGuid;
                    header.Version = 3;
                    header.Type    = 4; // DCEnd

                    processInfo = new ProcessInfo();
                    processInfo.UniqueProcessKey = 100;
                    processInfo.ProcessId        = ProcessId;
                    processInfo.ParentId         = 100;

                    log.Trace(header, processInfo, Encoding.ASCII.GetBytes("node.exe"), String.Empty);
                } finally {
                    log.Stop();
                }

                RelogTrace(_executionTime.Value, tickCount, filename + ".etl");
            }

            // save the VSPX file
            using (var stream = new FileStream(filename + ".vspx", FileMode.Create, FileAccess.ReadWrite, FileShare.None)) {
                using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, false)) {
                    var entry = archive.CreateEntry("VSProfilingData\\" + Path.GetFileName(filename) + ".etl");

                    using (FileStream etlStream = new FileStream(filename + ".etl", FileMode.Open, FileAccess.Read)) {
                        using (var entryStream = entry.Open()) {
                            etlStream.CopyTo(entryStream);
                        }
                    }
                }
            }
        }
示例#10
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageLoad obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
示例#11
0
        public void ImageLoad_ReturnsCorrectJSONdata_WhenPassedAllParameters()
        {
            //Mock<ImageRepository> mockImageRepository = new Mock<ImageRepository>();
            Mock <IImageService> mockService = new Mock <IImageService>();
            Guid imageGuid = Guid.NewGuid();
            Guid tagGuid   = Guid.NewGuid();

            //setup model for passing into the controller
            ImageLoad model = new ImageLoad();

            model.BeginIndex = 0;
            model.EndIndex   = 4;
            model.Search     = "test";
            model.TagFilters = new string[] { imageGuid.ToString(), tagGuid.ToString() };

            //setup reference object to be returned when calling the image service
            List <AlbumImage>    images = new List <AlbumImage>();
            List <AlbumImageTag> tags   = new List <AlbumImageTag>();

            tags.Add(new AlbumImageTag {
                ImageId = imageGuid, ImageTagId = tagGuid, Name = "tag", TagId = tagGuid
            });
            images.Add(new AlbumImage {
                Image = new byte[0], ImageId = imageGuid, ImageAlt = "testalt", ImageName = "testname", ImageUrl = "testurl", ImageTags = tags
            });
            FindFromToTagFilterQuery query = new FindFromToTagFilterQuery();

            query.BeginIndex  = model.BeginIndex;
            query.EndIndex    = model.EndIndex;
            query.AlbumImages = images;
            query.Response    = EventMessage.SUCCESS;
            query.Search      = model.Search;
            query.TagFilters  = new List <Guid>();
            query.TagFilters.Add(imageGuid);
            query.TagFilters.Add(tagGuid);

            //because the method FindFromToTagFirlter returns void and insteads gets data by passing
            //FindFromToTagFilterQuery object by reference...
            //set up the MOQ to return the reference object inside the controller
            mockService.Setup(x => x.FindFromToTagFilter(It.IsAny <FindFromToTagFilterQuery>()))
            .Callback((FindFromToTagFilterQuery c) =>
            {
                c.AlbumImages = query.AlbumImages;
                c.BeginIndex  = query.BeginIndex;
                c.EndIndex    = query.EndIndex;
                c.Response    = query.Response;
                c.Search      = query.Search;
                c.TagFilters  = query.TagFilters;
            });


            ImageController controller = new ImageController(mockService.Object);

            JsonResult result = controller.ImageLoad(model) as JsonResult;

            Assert.That(result.Value, Is.Not.Null);
            List <ImageJson> imageList = JsonConvert.DeserializeObject <List <ImageJson> >(result.Value.ToString());

            Assert.That(imageList.Count, Is.EqualTo(1));
            Assert.That(imageList[0].ImageAlt, Is.EqualTo(query.AlbumImages[0].ImageAlt));
            Assert.That(imageList[0].ImageId, Is.EqualTo(query.AlbumImages[0].ImageId));
            Assert.That(imageList[0].ImageName, Is.EqualTo(query.AlbumImages[0].ImageName));
            Assert.That(imageList[0].ImageUrl, Is.EqualTo(query.AlbumImages[0].ImageUrl));
        }