예제 #1
0
        /// <summary>
        /// The Init function
        /// </summary>
        /// <param name="core">A reference to Core</param>
        public void Init(Core core)
        {
            ServerClients  = core.GameServerClients;
            DownloadModule = core.GetModule <DownloadModule>();

            if (core.IsServer)
            {
                Listener = new TcpListener(IPAddress.Any, PlexerConfig.Port);
            }
        }
 protected override void Awake()
 {
     base.Awake();
     Module = new DownloadModule();
     Module.TempFileExtension            = m_TempFileExtension;
     Module.ChunkSizeToSave              = m_ChunkSizeToSave;
     Module.ConcurrentDownloadCountLimit = m_ConcurrentDownloadCountLimit;
     Module.Timeout = m_Timeout;
     Module.DownloadTaskImplFactory         = new DownloadTaskImplFactory();
     Module.DownloadTaskPool                = new DownloadTaskPool();
     Module.DownloadTaskPool.DownloadModule = Module;
 }
예제 #3
0
        public static List <Packet> UnvalidateDL(Core core, Client client, Packet packet)
        {
            PacketArg args = packet.GetArguments(new[]
            {
                typeof(int)
            });

            int            id = args.Get <int>(0);
            DownloadModule a  = core.GetModule <DownloadModule>();
            DownloadTask   t  = a.Tasks.FirstOrDefault(i => i.Token == id);

            t.ToRemove = true;
            t.Fail?.Invoke();
            return(null);
        }
예제 #4
0
        public ActionResult DownloadSave(DownloadDataModel model)
        {
            int id = 0;

            using (DownloadModule module = new DownloadModule())
            {
                if (model.OldFilesId.Count == 0 && model.Files.Count == 0)
                {
                    TempData["UndefinedFile"] = "請上傳檔案";
                    return(RedirectToAction("DownloadEdit", new { ID = (int?)null }));
                }
                id = module.DoSaveData(model);
            }
            var redirectUrl = new UrlHelper(Request.RequestContext).Action("DownloadEdit", "_SysAdm", new { ID = id });

            return(Json(new { Url = redirectUrl }));
        }
예제 #5
0
        public ActionResult DownloadEdit(int?ID)
        {
            if (!ID.HasValue)
            {
                return(RedirectToAction("DownloadList"));
            }
            DownloadDetailsModel model = new DownloadDetailsModel();

            using (DownloadModule module = new DownloadModule())
            {
                model = module.DoGetDetailsByID((int)ID);
            }
            FileModule fileModule = new FileModule();

            model.Files = fileModule.GetFiles((int)model.ID, "Download", "F");
            return(View(model));
        }
예제 #6
0
        // 檔案下載
        public ActionResult DownloadList(int?page, string qry, string sort, string disable, string pDate)
        {
            DownLoadListViewModel model = new DownLoadListViewModel();

            model.Filter.CurrentPage = page ?? 1;
            model.Filter.QueryString = qry ?? string.Empty;
            model.Filter.SortColumn  = sort ?? string.Empty;
            model.Filter.Disable     = disable ?? string.Empty;
            model.Filter.PublishDate = pDate;

            using (DownloadModule module = new DownloadModule())
            {
                model.Result = module.DoGetList(model.Filter);
            }

            return(View(model));
        }
예제 #7
0
        public static List <Packet> DownloadAccept(Core core, Client client, Packet packet)
        {
            PacketArg args = packet.GetArguments(new[]
            {
                typeof(int),
                typeof(string)
            });

            DownloadModule module = core.GetModule <DownloadModule>();
            Plexer         p      = core.GetModule <Plexer>();
            IPEndPoint     end    = (IPEndPoint)client.GetSocket().RemoteEndPoint;
            Client         c      = p.ConnectToServer(end.Address.ToString(), end.Port, true, args.Get <int>(0));

            int    token = args.Get <int>(0);
            string hash  = args.Get <string>(1);

            module.BindTask(c, (i => i.Hash == hash), token, true);

            return(null);
        }
예제 #8
0
        public static List <Packet> AskDownload(Core core, Client client, Packet packet)
        {
            PacketArg args = packet.GetArguments(new[]
            {
                typeof(int),
                typeof(string),
                typeof(string)
            });

            DownloadModule module = core.GetModule <DownloadModule>();
            DownloadTask   t      = module.CreateDownload(args.Get <string>(1));

            /*if (core.GetModule<Plexer>().PacketMayBeTreated(args.Get<string>(2)) == false)
             *  throw new Exception("Impossible to treat the packet " + args.Get<string>(2));*/

            t.Size       = args.Get <int>(0);
            t.Callback   = new Packet(packet.ExtractAfter(' ', 2));
            t.MainClient = client;
            return(DownloadPacketCreator.DownloadAccept(t.Token, args.Get <string>(1)).ToList());
        }
예제 #9
0
        /// <summary>
        /// The class constructor
        /// </summary>
        /// <param name="socket">A socket from this client</param>
        public Client(Socket socket, bool serverSide, DownloadModule dl = null)
        {
            Socket              = socket;
            PacketBuilder       = new PacketBuilder();
            ReceivedPackets     = new List <Packet>();
            SendingPackets      = new List <Packet>();
            DisconnectCallbacks = new List <ClientDisconnectDelegate>();

            if (serverSide)
            {
                byte[] a = new byte[4];
                int    i = Socket.Receive(a, 4, SocketFlags.None);
                DLToken = BitConverter.ToInt32(a, 0);

                if (DLToken != 0)
                {
                    IsFileSocket = true;
                    dl.BindTask(this, (elem => elem.Token == DLToken), null, false);
                }
            }
        }
예제 #10
0
        public JsonResult DownloadDelete(int?ID)
        {
            bool   success  = true;
            string messages = string.Empty;

            try
            {
                using (DownloadModule module = new DownloadModule())
                {
                    module.DoDeleteByID((int)ID);
                }
                messages = "刪除成功";
            }
            catch (Exception ex)
            {
                success  = false;
                messages = ex.Message;
            }
            var resultJson = Json(new { success = success, messages = messages });

            return(resultJson);
        }