Beispiel #1
0
        static int _m_ReadAsync(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.IO.MemoryStream gen_to_be_invoked = (System.IO.MemoryStream)translator.FastGetCSObj(L, 1);



                {
                    byte[] _buffer = LuaAPI.lua_tobytes(L, 2);
                    int    _offset = LuaAPI.xlua_tointeger(L, 3);
                    int    _count  = LuaAPI.xlua_tointeger(L, 4);
                    System.Threading.CancellationToken _cancellationToken; translator.Get(L, 5, out _cancellationToken);

                    System.Threading.Tasks.Task <int> gen_ret = gen_to_be_invoked.ReadAsync(_buffer, _offset, _count, _cancellationToken);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
        async Task SaveImage(BitmapSource bmp, string fileName)
        {
            //MessageBox.Show("OK");
            using (var stream = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
            {
                BmpBitmapEncoder       encoder      = new BmpBitmapEncoder();
                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
                BitmapImage            bImg         = new BitmapImage();

                encoder.Frames.Add(BitmapFrame.Create(bmp));
                encoder.Save(memoryStream);

                //memoryStream.Position = 0;
                //bImg.BeginInit();
                //bImg.StreamSource = memoryStream;
                //bImg.EndInit();

                //memoryStream.Close();
                //bImg.Freeze();
                //var s = bImg.StreamSource;
                var buf = new byte[1024];
                memoryStream.Position = 0;
                for (int nn; (nn = await memoryStream.ReadAsync(buf, 0, buf.Length)) != 0;)
                {
                    await stream.WriteAsync(buf, 0, nn);
                }
                stream.Close();
            }
        }
Beispiel #3
0
        static StackObject *ReadAsync_13(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 5);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Threading.CancellationToken @cancellationToken = (System.Threading.CancellationToken) typeof(System.Threading.CancellationToken).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Int32 @count = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Int32 @offset = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 4);
            System.Byte[] @buffer = (System.Byte[]) typeof(System.Byte[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 5);
            System.IO.MemoryStream instance_of_this_method = (System.IO.MemoryStream) typeof(System.IO.MemoryStream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.ReadAsync(@buffer, @offset, @count, @cancellationToken);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
        public async Task UserAvatar(IFormFile avatar)
        {
            var userId = userManager.GetUserId(User);
            var user   = await userManager.FindByIdAsync(userId);

            if (avatar == null)
            {
                throw new BadRequestException("文件格式不正确");
            }

            if (!avatar.ContentType.StartsWith("image/"))
            {
                throw new BadRequestException("文件格式不正确");
            }

            if (avatar.Length > 1048576)
            {
                throw new BadRequestException("文件大小不能超过 1 Mb");
            }

            await using var stream = new System.IO.MemoryStream();

            await avatar.CopyToAsync(stream);

            stream.Seek(0, System.IO.SeekOrigin.Begin);
            var buffer = new byte[stream.Length];
            await stream.ReadAsync(buffer);

            user.Avatar = buffer;
            await userManager.UpdateAsync(user);
        }
        public async Task RunAsync()
        {
            var apks = CommandRunner.Instance.GetInstalledPackagesApkInformation( );

            this.LogDebug("Initializing APK Cache");
            foreach (var item in apks)
            {
                var lvi = new ApkPackageListViewItem(item);

                // cant uninstall if we dont know the package
                if (string.IsNullOrEmpty(lvi.ApkInformation.Package))
                {
                    continue;
                }

                string keyName = lvi.ApkInformation.DevicePath;
                if (keyName.StartsWith("/"))
                {
                    keyName = keyName.Substring(1);
                }
                keyName = keyName.Replace("/", ".");

                if (!Program.SystemIcons.ContainsKey(keyName))
                {
                    // get apk and extract the app icon
                    var img = CommandRunner.Instance.GetLocalApkIconImage(item.LocalApk);

                    if (img == null)
                    {
                        img = DroidExplorer.Resources.Images.package32;
                    }
                    else
                    {
                        using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) {
                            string fileName = System.IO.Path.Combine(System.IO.Path.Combine(CommandRunner.Settings.UserDataDirectory, Cache.APK_IMAGE_CACHE), string.Format("{0}.png", keyName));
                            img.Save(stream, ImageFormat.Png);
                            stream.Position = 0;
                            using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) {
                                byte[] buffer    = new byte[2048];
                                int    readBytes = 0;
                                while ((readBytes = await stream.ReadAsync(buffer, 0, buffer.Length)) != 0)
                                {
                                    await fs.WriteAsync(buffer, 0, readBytes);
                                }
                            }
                        }
                    }
                    //SystemImageListHost.Instance.AddFileTypeImage ( keyName, img, img );
                }
            }
        }
Beispiel #6
0
        public async Task InvokeAsync(HttpContext context
                                      , ILogObj logObj
                                      )
        {
            var log = new LogModels.HttpRequest
            {
                RequestDate = DateTime.UtcNow,
                Url         = context.Request.Path,
                TraceId     = context.TraceIdentifier,
                RemoteIp    = context.Connection.RemoteIpAddress.ToString(),
            };

            logObj.AddChild(log);


            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            var responseBodyOrg = context.Response.Body;
            var responseBody    = new System.IO.MemoryStream();

            context.Response.Body = responseBody;

            ////////////////////////////
            //
            await _next(context);

            //
            ////////////////////////////

            var bytes = new byte[responseBody.Length];

            responseBody.Position = 0;
            await responseBody.ReadAsync(bytes, 0, (int)responseBody.Length);

            //var response = System.Text.Encoding.UTF8.GetString(bytes);
            var response = (1000000 < responseBody.Length)
                                ?"Interim measure for error."
                                :System.Text.Encoding.UTF8.GetString(bytes);

            responseBody.Position = 0;
            await responseBody.CopyToAsync(responseBodyOrg);

            sw.Stop();

            log.Response     = response;
            log.StatusCode   = context.Response.StatusCode;
            log.ElapsedTime  = sw.ElapsedMilliseconds;
            log.ResponseDate = DateTime.UtcNow;
        }
        public async Task <HttpResponseMessage> SendImg(string uuid)
        {
            try
            {
                DateTime now = DateTime.Now;
                if (cDict.ContainsKey(uuid))
                {
                    TimeSpan ts = now - cDict[uuid];
                    if (ts.TotalSeconds <= 1.5)
                    {
                        return(null);
                    }
                    cDict[uuid] = now;
                }
                else
                {
                    cDict.Add(uuid, now);
                }
            }
            catch
            {
            }

            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(null);
            }
            Util.ValidationCode vc = new Util.ValidationCode();
            Image img = vc.NextImage(4, System.Drawing.Drawing2D.HatchStyle.DiagonalCross, false, uuid);

            System.IO.MemoryStream Ms = new System.IO.MemoryStream();
            img.Save(Ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] imgByte = new byte[Ms.Length];
            Ms.Position = 0;
            await Ms.ReadAsync(imgByte, 0, Convert.ToInt32(Ms.Length));

            Ms.Close();

            var resp = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(imgByte)
            };

            resp.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpg");
            return(resp);
        }
		public async Task RunAsync() {
			var apks = CommandRunner.Instance.GetInstalledPackagesApkInformation ( );
			this.LogDebug("Initializing APK Cache");
			foreach(var item in apks) {
				var lvi = new ApkPackageListViewItem(item);

				// cant uninstall if we dont know the package
				if(string.IsNullOrEmpty(lvi.ApkInformation.Package)) {
					continue;
				}

				string keyName = lvi.ApkInformation.DevicePath;
				if(keyName.StartsWith("/")) {
					keyName = keyName.Substring(1);
				}
				keyName = keyName.Replace("/", ".");

				if(!Program.SystemIcons.ContainsKey(keyName)) {
					// get apk and extract the app icon
					var img = CommandRunner.Instance.GetLocalApkIconImage(item.LocalApk);

					if(img == null) {
						img = DroidExplorer.Resources.Images.package32;
					} else {
						using(System.IO.MemoryStream stream = new System.IO.MemoryStream()) {
							string fileName = System.IO.Path.Combine(System.IO.Path.Combine(CommandRunner.Settings.UserDataDirectory, Cache.APK_IMAGE_CACHE), string.Format("{0}.png", keyName));
							img.Save(stream, ImageFormat.Png);
							stream.Position = 0;
							using(System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) {
								byte[] buffer = new byte[2048];
								int readBytes = 0;
								while((readBytes = await stream.ReadAsync(buffer, 0, buffer.Length)) != 0) {
									await fs.WriteAsync(buffer, 0, readBytes);
								}
							}
						}

					}
					//SystemImageListHost.Instance.AddFileTypeImage ( keyName, img, img );

				}
			}
		}
Beispiel #9
0
        public async Task <string> SerializeAsync()
        {
            XmlSerializer     ser      = new XmlSerializer(GetType());
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent             = false;
            settings.Encoding           = Encoding.UTF8;
            settings.OmitXmlDeclaration = true;
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

            ns.Add("", "");
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            XmlWriter writer          = XmlWriter.Create(ms, settings);

            ser.Serialize(writer, this, ns);
            await writer.FlushAsync();

            byte[] data = new byte[ms.Length];
            ms.Position = 0;
            await ms.ReadAsync(data, 0, data.Length);

            return(Encoding.UTF8.GetString(data));
        }