Пример #1
0
        private static void HandleUploadControlUpload(HttpRequest Request, HttpResponse Response, Guid memberId)
        {
            Encoding e		= Encoding.Unicode;
            BinaryReader r	= new BinaryReader(Request.InputStream, e);
            int quota		= 0;
            int usedQuota	= 0;
            int resultCode	= -1;
            string message	= string.Empty;
            Database.UploadResultComplete res = new Database.UploadResultComplete();;
            try
            {
                if(memberId == Guid.Empty)
                {
                    resultCode = -2;
                    return;
                }

                uint version		= r.ReadUInt32();
                int clientVersion	= 1000+(int)version;

                int		len;
                byte[]	rawText;

                //read hash
                len					= r.ReadInt32();
                byte[] hash			= r.ReadBytes(len);

                //read targetcategory
                Guid targetCategory = new Guid(r.ReadBytes(16));

                //read hintable
                bool hintable		= r.ReadByte()!=0?true:false;

                //read uploadPath
                len					= r.ReadInt32();
                rawText				= r.ReadBytes(len);
                string uploadPath	= e.GetString(rawText, 0, rawText.Length-2);

                //read title
                len					= r.ReadInt32();
                rawText				= r.ReadBytes(len);
                string title		= e.GetString(rawText, 0, rawText.Length-2);

                //read text
                len					= r.ReadInt32();
                rawText				= r.ReadBytes(len);
                string text			= e.GetString(rawText, 0, rawText.Length-2);

                //read path
                len					= r.ReadInt32();
                rawText				= r.ReadBytes(len);
                string path			= e.GetString(rawText, 0, rawText.Length-2);

                len					= r.ReadInt32();

                quota				= Database.GetMemberQuota(memberId, out usedQuota);
                if(quota != -1 && len/1024+usedQuota>quota)
                {
                    resultCode = (int)UploadResult.StoreFull;
                    return;
                }

                byte[] imageData	= r.ReadBytes(len);
                if(true)
                {
                    if(uploadPath.Length > 0)
                        targetCategory = new Guid(uploadPath);

                    //TODO! validate title and text
                    res =
                        Database.UploadImage(
                            memberId, path, "image/jpeg",
                            imageData.Length, new MemoryStream(imageData, false),
                            targetCategory, title, clientVersion, hintable, text
                        );
                    if(res.ResultCode == UploadResult.Success)
                        usedQuota += len/1024;
                }
                else
                {
                    FileStream f	= new FileStream(Path.Combine(Configuration.Setting_DataPath,"uploaded"+title+".jpg"), FileMode.Create, FileAccess.ReadWrite);
                    f.Write(imageData,0,imageData.Length);
                    f.Flush();
                    f.Close();
                }
                resultCode = (int)res.ResultCode;

                Log.LogStatistics(1, "User uploaded image with client control.");
            }
            catch(Error_AccessDenied)
            {
                resultCode = 5;
                Log.LogStatistics(1, "User uploaded image with client control, access denied.");
            }
            catch
            {
                Log.LogStatistics(1, "User uploaded image with client control, unhandled exception.");
                resultCode = -1;
                throw;
            }
            finally
            {
                r.Close();
                BinaryWriter w = new BinaryWriter(Response.OutputStream, e);

                w.Write((System.UInt32)1);
                w.Write(resultCode);
                w.Write(res.photoId.ToByteArray());
                w.Write(quota);
                w.Write(usedQuota);

                w.Write((message.Length+1)*2);
                w.Write(e.GetBytes(message));
                w.Write(new byte[2] {0,0});

                w.Flush();
            }
        }
Пример #2
0
        private static void HandleUploadControlUpload(HttpRequest Request, HttpResponse Response, Guid memberId)
        {
            Encoding     e          = Encoding.Unicode;
            BinaryReader r          = new BinaryReader(Request.InputStream, e);
            int          quota      = 0;
            int          usedQuota  = 0;
            int          resultCode = -1;
            string       message    = string.Empty;

            Database.UploadResultComplete res = new Database.UploadResultComplete();;
            try
            {
                if (memberId == Guid.Empty)
                {
                    resultCode = -2;
                    return;
                }

                uint version       = r.ReadUInt32();
                int  clientVersion = 1000 + (int)version;


                int    len;
                byte[] rawText;

                //read hash
                len = r.ReadInt32();
                byte[] hash = r.ReadBytes(len);

                //read targetcategory
                Guid targetCategory = new Guid(r.ReadBytes(16));

                //read hintable
                bool hintable = r.ReadByte() != 0?true:false;

                //read uploadPath
                len     = r.ReadInt32();
                rawText = r.ReadBytes(len);
                string uploadPath = e.GetString(rawText, 0, rawText.Length - 2);

                //read title
                len     = r.ReadInt32();
                rawText = r.ReadBytes(len);
                string title = e.GetString(rawText, 0, rawText.Length - 2);

                //read text
                len     = r.ReadInt32();
                rawText = r.ReadBytes(len);
                string text = e.GetString(rawText, 0, rawText.Length - 2);

                //read path
                len     = r.ReadInt32();
                rawText = r.ReadBytes(len);
                string path = e.GetString(rawText, 0, rawText.Length - 2);

                len = r.ReadInt32();

                quota = Database.GetMemberQuota(memberId, out usedQuota);
                if (quota != -1 && len / 1024 + usedQuota > quota)
                {
                    resultCode = (int)UploadResult.StoreFull;
                    return;
                }

                byte[] imageData = r.ReadBytes(len);
                if (true)
                {
                    if (uploadPath.Length > 0)
                    {
                        targetCategory = new Guid(uploadPath);
                    }

                    //TODO! validate title and text
                    res =
                        Database.UploadImage(
                            memberId, path, "image/jpeg",
                            imageData.Length, new MemoryStream(imageData, false),
                            targetCategory, title, clientVersion, hintable, text
                            );
                    if (res.ResultCode == UploadResult.Success)
                    {
                        usedQuota += len / 1024;
                    }
                }
                else
                {
                    FileStream f = new FileStream(Path.Combine(Configuration.Setting_DataPath, "uploaded" + title + ".jpg"), FileMode.Create, FileAccess.ReadWrite);
                    f.Write(imageData, 0, imageData.Length);
                    f.Flush();
                    f.Close();
                }
                resultCode = (int)res.ResultCode;

                Log.LogStatistics(1, "User uploaded image with client control.");
            }
            catch (Error_AccessDenied)
            {
                resultCode = 5;
                Log.LogStatistics(1, "User uploaded image with client control, access denied.");
            }
            catch
            {
                Log.LogStatistics(1, "User uploaded image with client control, unhandled exception.");
                resultCode = -1;
                throw;
            }
            finally
            {
                r.Close();
                BinaryWriter w = new BinaryWriter(Response.OutputStream, e);

                w.Write((System.UInt32) 1);
                w.Write(resultCode);
                w.Write(res.photoId.ToByteArray());
                w.Write(quota);
                w.Write(usedQuota);

                w.Write((message.Length + 1) * 2);
                w.Write(e.GetBytes(message));
                w.Write(new byte[2] {
                    0, 0
                });

                w.Flush();
            }
        }