Exemple #1
0
        public async Task AddDownload(string title, DownloadDelegate downloadMethod)
        {
            if (!this.Dispatcher.HasThreadAccess)
            {
                var completionSource = new TaskCompletionSource <object>();
                await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    try
                    {
                        await this.AddDownload(title, downloadMethod);
                        completionSource.SetResult(null);
                    }
                    catch (Exception e)
                    {
                        completionSource.SetException(e);
                    }
                });

                await completionSource.Task;
                return;
            }

            var item = new DownloadItem(title, downloadMethod, this.cancellation.Token);

            this.waitForDownloads.Enqueue(item);
            this.allQueued.Add(item);
            this.addSemaphore.Release();
            await item.Finished;
        }
Exemple #2
0
 public DownloadSetting(string relativeURL, string localStorePath, DateTime date, DownloadDelegate dlDelegate)
 {
     this.RelativeURL = relativeURL;
     LocalStorePath   = localStorePath;
     LastUpdateTime   = date;
     DownloadProc     = dlDelegate;
 }
Exemple #3
0
        public DownloadManager(string _type, Uri _dlink, string _filePath, string _directoryPath, string _refer, string _cookie, CancellationTokenSource _cts)
        {
            taskCts       = _cts;
            taskCt        = _cts.Token;
            downloadLink  = _dlink;
            referpath     = _refer;
            filePath      = _filePath;
            directoryPath = _directoryPath;
            webclient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363");
            if (_refer != "")
            {
                webclient.Headers.Add("Refer", _refer);
            }
            if (_cookie != "")
            {
                webclient.Headers.Add("Cookie", _cookie);
            }

            switch (_type)
            {
            case "photo":
                DownloadStart = Download_Photo;
                break;

            case "torrent":
                DownloadStart = Download_TorrentFile;
                break;
            }
        }
Exemple #4
0
        public MainForm()
        {
            InitializeComponent();

            ScanBtn.Enabled    = false;
            AntennaBtn.Enabled = false;
            RefreshBtn.Enabled = false;

            DelaySel.SelectedIndex  = 1;
            IntvalSel.SelectedIndex = 0;

            TxModSel.SelectedIndex = 0;
            GetSetupBtn.Enabled    = false;
            SetSetupBtn.Enabled    = false;

            CreateInvokers();

            hNur = new NurApi(this);

            hNur.ConnectedEvent    += new EventHandler <NurApi.NurEventArgs>(OnModuleConnect);
            hNur.DisconnectedEvent += new EventHandler <NurApi.NurEventArgs>(OnModuleDisconnect);

            _SetControlText(ConnLabel, "Not connected");
            _SetControlColor(ConnLabel, RED, BLACK);
            _SetControlText(TagLabel, "No tag");
            _SetControlColor(TagLabel, RED, BLACK);

            ConnGrp.Text = "Connection (" + NurApi.FileVersion + ", " + hNur.GetFileVersion() + ")";

            StatesNotAvailable(false);

            mDownload = new DownloadDelegate(DownloadAndShow);

            hNur.SetUsbAutoConnect(true);
        }
Exemple #5
0
 private DownloadItem(DownloadDelegate downloadFunction, CancellationToken cancel)
 {
     this.downloadFunction     = downloadFunction;
     this.globalCancle         = cancel;
     this.taskCompletionSource = new TaskCompletionSource <object>();
     this.CancelCommand        = new DelegateCommand(this.CancelDownload, () => !this.taskCompletionSource.Task.IsCompleted);
 }
        private void EndDownload(IAsyncResult ar)
        {
            DownloadDelegate del = (DownloadDelegate)ar.AsyncState;

            lock (this)
            {
                FireStatusChangedEvent(_downloadState);
            }
        }
Exemple #7
0
 private void btn_Download_Click(object sender, EventArgs e)
 {
     //check
     if (cmb_Database.SelectedIndex == -1 || cmb_Record.SelectedIndex == -1)
     {
         MessageBox.Show("Please select a record.");
         return;
     }
     DownloadDelegate downloadMission = new DownloadDelegate(DownloadMethod);
     this.Invoke(downloadMission);
 }
Exemple #8
0
        public static void CheckVersion(IntPtr[] Listeners)
        {
            if (Result != null)
            {
                if (!Result.AsyncWaitHandle.WaitOne(1, false))
                {
                    return;
                }
            }
            else
            {
                Download = new DownloadDelegate(DownloadWorker);
            }

            Result = Download.BeginInvoke(Listeners, null, null);
        }
        public void StartDownload()
        {
            lock (this)
            {
                if (_downloadState == DownloadStatus.NotDownloading)
                {
                    // Create a delegate to the calculation method.
                    DownloadDelegate download = new DownloadDelegate(Download);

                    // Start the calculation.
                    download.BeginInvoke(new AsyncCallback(EndDownload), download);

                    // Update the calculation status.
                    _downloadState = DownloadStatus.Downloading;

                    // Fire a status changed event.
                    FireStatusChangedEvent(_downloadState);
                }
            }
        }
Exemple #10
0
    /// <summary>
    /// Download the specified assets.
    /// </summary>
    /// <param name='dlObject'>
    /// The download object which affact the downloading task.
    /// The task can be canceled by destroying this download object.
    /// </param>
    /// <param name='prgDelegate'>
    /// Prgogress delegate to be callback after downloaded.
    /// </param>
    /// <param name='prgUserData'>
    /// Prgogress delegate user data.
    /// </param>
    /// <param name='assetFiles'>
    /// Asset files.
    /// </param>
    public static void Download(GameObject dlObject, DownloadDelegate prgDelegate, System.Object prgUserData, bool isReturnPerFrame, params string [] assetFiles)
    {
        if (assetFiles.Length == 0)
        {
            return;
        }

        if (_initialzed != EInializedState.Initialized)
        {
            DownloadTask dlTask = new DownloadTask();
            dlTask.DownloadObect    = dlObject;
            dlTask.ProgressFunction = prgDelegate;
            dlTask.ProgressUserData = prgUserData;

            foreach (string assetFile in assetFiles)
            {
                dlTask.AssetFiles.Add(assetFile);
            }

            _pendingTask.Add(dlTask);

            return;
        }

        if (dlObject == null)
        {
            dlObject = _downloadObject;
        }

        ResourceLoader resDl = dlObject.AddComponent <ResourceLoader> ();

        resDl.SetProgressDelegate(prgDelegate, prgUserData, isReturnPerFrame);

        foreach (string assetFile in assetFiles)
        {
            resDl.AddAssetLoader(AssetLoaderManager.CreateLoader(ToManifestPath(assetFile), _manifest));
        }
    }
Exemple #11
0
 /// <summary>
 /// Download the specified assets.
 /// </summary>
 /// <param name='prgDelegate'>
 /// Prgogress delegate to be callback after downloaded.
 /// </param>
 /// <param name='prgUserData'>
 /// Prgogress delegate user data.
 /// </param>
 /// <param name='assetFiles'>
 /// Asset files.
 /// </param>
 public static void Download(DownloadDelegate prgDelegate, System.Object prgUserData, bool isReturnPerFrame, params string [] assetFiles)
 {
     Download(null, prgDelegate, prgUserData, isReturnPerFrame, assetFiles);
 }
Exemple #12
0
 public Request(string url, DownloadDelegate del, object msg, byte[] bytes, Hashtable header) : this(url, del, msg, bytes)
 {
     this.header = header;
 }
Exemple #13
0
 public Request(string url, DownloadDelegate del, object msg, byte[] bytes) : this(url, del, msg)
 {
     this.bytes = bytes;
 }
Exemple #14
0
 public Request(string url, DownloadDelegate del, object msg, WWWForm form) : this(url, del, msg)
 {
     this.form = form;
 }
Exemple #15
0
 public Request(string url, DownloadDelegate del, object msg) : this(url, del)
 {
     this.message = msg;
 }
Exemple #16
0
 //-------------------------------------------------------------
 // Constractors
 //-------------------------------------------------------------
 public Request(string url, DownloadDelegate del)
 {
     this.url = url;
     this.del = del;
 }
Exemple #17
0
        public void StartDownload()
        {
            lock (this)
            {
                if (_downloadState == DownloadStatus.NotDownloading)
                {
                    // Create a delegate to the calculation method.
                    DownloadDelegate download = new DownloadDelegate(Download);

                    // Start the calculation.
                    download.BeginInvoke(new AsyncCallback(EndDownload), download);

                    // Update the calculation status.
                    _downloadState = DownloadStatus.Downloading;

                    // Fire a status changed event.
                    FireStatusChangedEvent(_downloadState);
                }
            }
        }
Exemple #18
0
 /// <summary>
 /// Download the specified assets.
 /// </summary>
 /// <param name='prgDelegate'>
 /// Prgogress delegate to be callback after downloaded.
 /// </param>
 /// <param name='assetFiles'>
 /// Asset files.
 /// </param>
 public static void Download(DownloadDelegate prgDelegate, bool isReturnPerFrame, params string [] assetFiles)
 {
     Download(null, prgDelegate, null, isReturnPerFrame, assetFiles);
 }
Exemple #19
0
 public DownloadItem(Song songToDownload, DownloadDelegate downloadFunction, CancellationToken cancel) : this(downloadFunction, cancel)
 {
     this.Song = songToDownload;
 }
Exemple #20
0
 /// <summary>
 /// Sets the progress delegate.
 /// </summary>
 /// <param name='prgDlgt'>
 /// Prg dlgt.
 /// </param>
 /// <param name='userData'>
 /// User data.
 /// </param>
 public void SetProgressDelegate(DownloadDelegate prgDlgt, System.Object userData, bool isReturnPerFrame)
 {
     _progressDelegate = prgDlgt;
     _prgDlgtUserData  = userData;
     _isReturnPerFrame = isReturnPerFrame;
 }
Exemple #21
0
 public DownloadItem(string title, DownloadDelegate downloadFunction, CancellationToken cancel) : this(downloadFunction, cancel)
 {
     this.Title = title;
 }
Exemple #22
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                Socket clientSocket = (Socket)ar.AsyncState;
                clientSocket.EndReceive(ar);

                //Transform the array of bytes received from the user into an
                //intelligent form of object Data
                Data msgReceived = new Data(byteData);

                //Csak a nekem szóló üzenet kell. Ez akkor szükésges, ha I SOCKETEN TÖBB KAPCSOLAT IS VAN - Ez az 1 port per IP miatt lehet probléma, 1 gépes bemutatás esetén.
                if (msgReceived.cmdCommand.Equals(Command.Logout) && msgReceived.strName.Equals(LoginName))
                {
                    //Lecsatlakozás
                    ClientSocket.Shutdown(SocketShutdown.Both);
                    ClientSocket.Close();

                    _safeClose = true;

                    FoFormDelegate foForm = new FoFormDelegate(FoForm);
                    this.Dispatcher.Invoke(DispatcherPriority.Normal, foForm);
                }
                else
                {
                    ClientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None,
                                              new AsyncCallback(OnReceive), ClientSocket);

                    if (msgReceived.cmdCommand.Equals(Command.List) && msgReceived.strName.Equals(LoginName))
                    {
                        //Új ablak nyitása a megfelelő adatok átadásával.
                        RecFormDelegate recForm = new RecFormDelegate(RecForm);
                        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, recForm,
                                                    msgReceived.strMessage);
                    }
                    else if (msgReceived.cmdCommand.Equals(Command.DownloadList) && msgReceived.strName.Equals(LoginName))
                    {
                        //Új ablak nyitása a megfelelő adatok átadásával.
                        DownloadDelegate downForm = new DownloadDelegate(DownForm);
                        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, downForm,
                                                    msgReceived.strMessage);
                    }
                    else
                    {
                        UpdateDelegate update = new UpdateDelegate(UpdateMessage);
                        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, update,
                                                    msgReceived.strMessage + "\r\n");

                        if (msgReceived.cmdCommand.Equals(Command.Close))
                        {
                            CloseDelegate closeRun = new CloseDelegate(CloseRun);
                            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, closeRun);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Client Receive");
            }
        }
Exemple #23
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                Socket clientSocket = (Socket)ar.AsyncState;
                clientSocket.EndReceive(ar);

                //Transform the array of bytes received from the user into an
                //intelligent form of object Data
                Data msgReceived = new Data(byteData);

                //We will send this object in response the users request
                Data msgToSend = new Data();

                byte[] message;

                //If the message is to login, logout, or simple text message
                //then when send to others the type of the message remains the same
                msgToSend.cmdCommand = msgReceived.cmdCommand;
                msgToSend.strName    = msgReceived.strName;
                msgToSend.strRec     = msgReceived.strRec;

                switch (msgReceived.cmdCommand)
                {
                case Command.Login:

                    //Check if the user is authorized for access
                    User connectedUser = new User(msgReceived.strName, msgReceived.strMessage);
                    if (connectedUser.SearchInList(_users) >= 0)
                    {
                        //When a user logs in to the server then we add her to our
                        //list of clients
                        msgToSend.cmdCommand = Command.Accept;
                        //message = msgToSend.ToByte();
                        //clientSocket.Send(message);

                        ClientInfo clientInfo = new ClientInfo();
                        clientInfo.socket  = clientSocket;
                        clientInfo.strName = msgReceived.strName;

                        clientList.Add(clientInfo);

                        //Set the text of the message that we will broadcast to all users
                        msgToSend.strMessage = "<<<" + msgReceived.strName + " csatlakozott a szobahoz>>>";
                    }
                    else
                    {
                        //Decline the user
                        msgToSend.cmdCommand = Command.Decline;
                        msgToSend.strName    = msgReceived.strName;
                        msgToSend.strMessage = null;
                        message = msgToSend.ToByte();

                        //Log it only on the server-side
                        UpdateDelegate update = new UpdateDelegate(UpdateMessage);
                        this.textBox1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, update,
                                                             "<<<" + msgReceived.strName + " megprobalt a szobahoz csatlakozni engedely nelkul>>>" + "\r\n");

                        //Send the message and close the connection
                        clientSocket.Send(message, 0, message.Length, SocketFlags.None);
                        clientSocket.Shutdown(SocketShutdown.Both);
                        clientSocket.Close();
                    }

                    break;

                case Command.Logout:

                    //When a user wants to log out of the server then we search for her
                    //in the list of clients and close the corresponding connection

                    int nIndex = 0;
                    foreach (ClientInfo client in clientList)
                    {
                        if (client.socket == clientSocket && client.strName.Equals(msgReceived.strName))
                        {
                            clientList.RemoveAt(nIndex);
                            break;
                        }
                        ++nIndex;
                    }

                    //Send ack data before closing - Only for the disconnectiong client
                    //msgToSend.cmdCommand = Command.Logout;
                    //msgToSend.strName = msgReceived.strName;
                    msgToSend.strMessage = null;        //A parancs és név marad, az üzenet törlődik.
                    message = msgToSend.ToByte();
                    clientSocket.Send(message, 0, message.Length, SocketFlags.None);

                    //Kapcsolat leállítása
                    clientSocket.Shutdown(SocketShutdown.Both);
                    clientSocket.Close();

                    msgToSend.strMessage = "<<<" + msgReceived.strName + " elhagyta a szobat>>>";
                    break;

                case Command.Message:

                    //Set the text of the message that we will broadcast to all  (if public)
                    msgToSend.strMessage = msgReceived.strName + " -> " +
                                           (msgReceived.strRec.Equals(Data.PUBLIC_ID) ? "Mindenki" : msgReceived.strRec) +
                                           " : " + msgReceived.strMessage;
                    break;

                case Command.Upload:
                    //Get the correct IP
                    IPEndPoint upEndPoint = clientSocket.RemoteEndPoint as IPEndPoint;

                    //Create a delegate for upload handling
                    string pathUp = Data.FILES_FOLDER + (msgReceived.strRec.Equals(Data.PUBLIC_ID) ? Data.PUBLIC_ID : (msgReceived.strName + "-" + msgReceived.strRec));
                    Directory.CreateDirectory(pathUp);
                    UploadDelegate upload = new UploadDelegate(BeginUpload);
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                upload, upEndPoint.Address, pathUp + "\\" + msgReceived.strMessage, msgReceived.strName, msgReceived.strRec);

                    msgToSend.strMessage = "<<<" + msgReceived.strName + " megkezdte a '" + System.IO.Path.GetFileName(msgReceived.strMessage) + "' nevu falj feltolteset>>>";

                    break;

                case Command.StartDownload:
                    //Get the correct IP
                    IPEndPoint downEndPoint = clientSocket.RemoteEndPoint as IPEndPoint;

                    //Delete message
                    msgToSend.strMessage = null;

                    //Create a delegate for upload handling
                    string pathDown = Data.FILES_FOLDER + (msgReceived.strName.Equals(Data.PUBLIC_ID) ? Data.PUBLIC_ID : (msgReceived.strName + "-" + msgReceived.strRec));
                    Directory.CreateDirectory(pathDown);
                    DownloadDelegate download = new DownloadDelegate(BeginDownload);
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                download, downEndPoint.Address, pathDown + "\\" + msgReceived.strMessage);

                    msgToSend.strMessage = "<<<" + msgReceived.strRec + " megkezdte a '" + System.IO.Path.GetFileName(msgReceived.strMessage) + "' nevu falj letolteset>>>";

                    break;

                case Command.DownloadAck:

                    //Set the text of the message that we will broadcast to all  (if public)
                    msgToSend.strMessage = "<<<" + msgReceived.strRec + " befejezte a '" + System.IO.Path.GetFileName(msgReceived.strMessage) + "' nevu falj letolteset>>>";
                    break;

                case Command.DownloadList:
                    //Delete message
                    msgToSend.strMessage = null;

                    //Create a delegate for upload handling
                    string pathDirectory = Data.FILES_FOLDER + (msgReceived.strRec.Equals(Data.PUBLIC_ID) ? Data.PUBLIC_ID : (msgReceived.strRec + "-" + msgReceived.strName));
                    Directory.CreateDirectory(pathDirectory);

                    //Collect all filenames
                    bool notFirstDownFiles = false;
                    foreach (string file in Directory.GetFiles(pathDirectory))
                    {
                        if (notFirstDownFiles)
                        {
                            msgToSend.strMessage += "*";
                        }
                        else
                        {
                            notFirstDownFiles = true;
                        }
                        msgToSend.strMessage += System.IO.Path.GetFileName(file);
                    }

                    message = msgToSend.ToByte();

                    //Send the filenames
                    clientSocket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                           new AsyncCallback(OnSend), clientSocket);

                    break;

                case Command.List:

                    //Send the names of all users in the chat room to the new user
                    msgToSend.cmdCommand = Command.List;
                    msgToSend.strName    = msgReceived.strName;
                    msgToSend.strMessage = null;

                    //Collect the names of the user in the chat
                    bool notFirstList = false;
                    foreach (ClientInfo client in clientList)
                    {
                        //To keep things simple we use asterisk as the marker to separate the user names
                        if (notFirstList)
                        {
                            msgToSend.strMessage += "*";
                        }
                        else
                        {
                            notFirstList = true;
                        }
                        msgToSend.strMessage += client.strName;
                    }

                    message = msgToSend.ToByte();

                    //Send the name of the users in the chat room
                    clientSocket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                           new AsyncCallback(OnSend), clientSocket);
                    break;
                }

                if (!(msgToSend.cmdCommand == Command.List || msgToSend.cmdCommand == Command.DownloadList || msgToSend.cmdCommand == Command.Decline))     //List and decline messages are not broadcasted
                {
                    message = msgToSend.ToByte();

                    foreach (ClientInfo clientInfo in clientList)
                    {
                        if (clientInfo.socket != clientSocket || msgToSend.cmdCommand != Command.Login)
                        {
                            //A publikus az broadcast, amúgy csak a 2 partnernek megy. -> Figyelni kell, hogy PUBLIC legyen alapból a cél, és feladó is legyen mindig.
                            if (msgToSend.strRec.Equals(Data.PUBLIC_ID) || clientInfo.strName.Equals(msgReceived.strRec) || clientInfo.strName.Equals(msgReceived.strName))
                            {
                                //Send the message to all users
                                clientInfo.socket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                                            new AsyncCallback(OnSend), clientInfo.socket);
                                //clientInfo.socket.Send(message, 0, message.Length, SocketFlags.None);
                            }
                        }
                    }

                    UpdateDelegate update = new UpdateDelegate(UpdateMessage);
                    this.textBox1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, update,
                                                         msgToSend.strMessage + "\r\n");
                }

                //If the user is logging out or declined, then we need not listen from her
                if (!(msgReceived.cmdCommand == Command.Logout || msgToSend.cmdCommand == Command.Decline))
                {
                    //Start listening to the message send by the user
                    clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), clientSocket);
                }

                //Check if it's the last logout
                if (msgReceived.cmdCommand == Command.Logout && clientList.Count <= 0)
                {
                    //Check if we started a close
                    CloseReadDelegate closeRead = new CloseReadDelegate(GetCloseStarted);
                    bool closeStarted           = (bool)this.Dispatcher.Invoke(DispatcherPriority.Normal, closeRead);

                    //Finish the close
                    if (closeStarted)
                    {
                        CloseDelegate closeRun = new CloseDelegate(CloseRun);
                        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, closeRun);
                    }
                }
            }
            catch (Exception ex)
            {
                new Thread(() =>
                {
                    MessageBox.Show(ex.Message, "Server Receive");
                }).Start();
            }
        }
Exemple #24
0
 public static void Download(DownloadDelegate prgDelegate, params string [] assetFiles)
 {
     Download(null, prgDelegate, null, true, assetFiles);
 }