public override void Download()
        {
            try
            {
                Client.Connect();
            }
            catch (Exception e)
            {
                DataSvc.ChannelLog("Connection Failure", $"Failed to connect to the server.\n{e.Message}");
                return;
            }

            Directory.CreateDirectory(LocalPath);

            SftpFile fileDemo = GetFile(FtpPath, DemoName);

            DownloadFile(fileDemo, $"{LocalPath}\\{fileDemo.Name}");

            SftpFile fileBsp = GetFile($"{FtpPath}/maps/workshop/{WorkshopId}", ".bsp");

            DownloadFile(fileBsp, $"{LocalPath}\\{fileBsp.Name}");

            Client.Disconnect();
            DataSvc.ChannelLog("Listing of Download Directory", $"{string.Join("\n", Directory.GetFiles(LocalPath))}");
        }
Esempio n. 2
0
        public override void Download()
        {
            try
            {
                Client.Connect();
            }
            catch (Exception e)
            {
                DataSvc.ChannelLog("Connection Failure",
                                   "Failed to connect to the server.\n" +
                                   $"{e.Message}");
                return;
            }

            // Downloads the demo file.
            DownloadFile(GetFile(FtpPath, DemoName),
                         $"{LocalPath}\\{DemoName}_{gamemode}.dem");

            // Downloads the BSP file.
            string sourceBsp =
                GetFile($"{FtpPath}/maps/workshop/{WorkshopId}", ".bsp");

            DownloadFile(sourceBsp,
                         $"{LocalPath}\\{Path.GetFileName(sourceBsp)}");

            Client.Disconnect();
            DataSvc.ChannelLog("Listing of Download Directory",
                               $"{string.Join("\n", Directory.GetFiles(LocalPath))}");
        }
Esempio n. 3
0
        private void DownloadFile(string sourcePath, string destPath)
        {
            if (sourcePath == null)
            {
                DataSvc.ChannelLog("File Not Found",
                                   "Failed to find the file on the server.");
                return;
            }

            DataSvc.ChannelLog("Downloading File From Playtest",
                               $"{sourcePath}\n{destPath}");

            try {
                if (!Client.DownloadFile(destPath, sourcePath))
                {
                    DataSvc.ChannelLog("Download Failed",
                                       "Failed to download the file.");
                }
            } catch (Exception e)
            {
                DataSvc.ChannelLog("Download Failed",
                                   "Failed to download the file.\n" +
                                   $"{e.Message}");
            }

            DataSvc.ChannelLog("Download Completed",
                               "Successfully downloaded the demo file.");
        }
        private void DownloadFile(SftpFile file, string destPath)
        {
            if (file == null)
            {
                DataSvc.ChannelLog("File Not Found", "Failed to find the file on the server.");
                return;
            }

            DataSvc.ChannelLog("Downloading File From Playtest", $"{file.FullName}\n{destPath}");

            try
            {
                using (Stream stream = File.OpenWrite(destPath))
                    Client.DownloadFile(file.FullName, stream);

                DataSvc.ChannelLog("Download Completed", "Successfully downloaded the demo file.");
            }
            catch (Exception e)
            {
                DataSvc.ChannelLog("Download Failed", $"Failed to download the file.\n{e.Message}");
            }
        }
        static void Main(string[] args)
        {
            try
            {
                DebugToFile("Programmstart");
                String Prefix = "http://*:8080/";
                DebugToFile("Starte Listener");

                #region "Starte HTTP"
                HttpListener listener = new HttpListener();
                listener.Prefixes.Add(Prefix);
                listener.Start();
                DebugToFile("HTTP Einsatzbereit...");
                #endregion

                #region "Starte CAP"
                DataSvc m_DataSvcReadWrite = null;
                m_DataSvcReadWrite = new DataSvc();
                DebugToFile("CAP Einsatzbereit...");
                #endregion



                #region "Listenerschleife für Anfragen"
                while (true)
                {
                    // Wartet auf die Anfrage durch mich im Browser
                    // http://localhost:8080/?request=hallo)
                    // http://localhost:8080/?write=R-Parameter1&wert=150

                    //Meldung an Console in Gelb.
                    DebugToFile("Warte auf Anfrage...");

                    HttpListenerContext context = listener.GetContext();
                    HttpListenerRequest request = context.Request; //Hier steht der Request drinnen
                    String Antwort = "";
                    DebugToFile("Abfrage");

                    try //Try für die CAP-Anfrage.
                    {
                        // In dem Objekt request wird auf die Anfrage url eingegangen
                        String Gets = request.Url.Query.Remove(0, 1);
                        // Konvertiert eine Zeichenfolge in eine Darstellung ohne Escapezeichen damit bestimmte Zeichen vernünftig dargestellt werden!
                        Gets = Uri.UnescapeDataString(Gets);

                        DebugToFile("Anfrage");

                        //Schreiben?
                        if (Gets.Split('=')[0] == "write")
                        {
                            //Korrekt aufteilen.
                            string[] Befehlsteile    = Gets.Split('&');
                            string[] Variablenbefehl = Befehlsteile[0].Split('=');
                            string[] Wertbefehl      = Befehlsteile[1].Split('=');
                            DebugToFile(" Schreibe");

                            //Schreibe über CAP
                            Item itemWrite = new Item();
                            itemWrite.Path  = Variablenbefehl[1];
                            itemWrite.Value = Wertbefehl[1];
                            m_DataSvcReadWrite.Write(itemWrite);

                            //Antwort via http
                            Antwort = "true";
                        }
                        else if (Gets.Split('=')[0] == "request")
                        {
                            string[] Befehlsteile = Gets.Split('&'); //Wenn mehrere Variablen abgefragt werden.
                            foreach (String EinBefehlsteil in Befehlsteile)
                            {
                                string[] Lesebefehl = EinBefehlsteil.Split('=');
                                DebugToFile("Lese");

                                Item itemRead = new Item();
                                itemRead.Path = Lesebefehl[1];
                                m_DataSvcReadWrite.Read(itemRead);
                                Antwort = Antwort + itemRead.Value.ToString() + ";";
                            }
                        }
                    }

                    catch (DataSvcException ex)
                    {
                        // set status to statusbar
                        Antwort = ("DataSvcException: ErrorNr: " + ex.ErrorNumber.ToString() + " ; Message: " + ex.Message);
                        DebugToFile(Antwort);
                    }
                    catch (Exception e) //Bei einem Fehler wird diese auch über HTTP gepostet
                    {
                        DebugToFile(e.Message);
                        Antwort = e.Message;
                        DebugToFile(Antwort);
                    }


                    HttpListenerResponse response = context.Response;
                    response.AddHeader("Content-type", "text/html");
                    // In UTF8 decodieren der Antowrt und Bytes zerlegen. Die Zahl 29 ist 50 (=>2) und 57 (=>9)
                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(Antwort);

                    // Get a response stream and write the response to it.
                    response.ContentLength64 = buffer.Length;
                    System.IO.Stream output = response.OutputStream;
                    output.Write(buffer, 0, buffer.Length);
                    output.Close();
                }
                #endregion
            }
            catch (Exception e)
            {
                DebugToFile(e.Message);
            }
        }