Beispiel #1
0
        public void testUpload()
        {
            WebDAVClient wdc = getClient();

            wdc.UploadComplete += new UploadCompleteDel(wdc_UploadComplete);
            wdc.ListComplete   += new ListCompleteDel(wdc_ListComplete);
            wdc.DeleteComplete += new DeleteCompleteDel(wdc_DeleteComplete);

            createTestFile();
            try
            {
                wdc.Upload(TESTFILE, TESTFILE);
                autoReset.WaitOne(TIMEOUT);
                Assert.AreNotEqual(status, -1, "wrong status - upload");

                autoReset.Reset();
                wdc.List();
                autoReset.WaitOne(TIMEOUT);
                Assert.AreNotEqual(status, -1, "wrong status - list");
                List <String> listing = (List <string>)result;
                Assert.IsTrue(listing.Contains(TESTFILE));

                // now delete again
                autoReset.Reset();
                wdc.Delete(TESTFILE);
                autoReset.WaitOne(TIMEOUT);
                Assert.AreNotEqual(status, -1, "wrong status - delete");
            }
            finally
            {
                deleteTestFile();
            }
        }
Beispiel #2
0
        public void testCreateDir()
        {
            String       dir = "testcreatedir";
            WebDAVClient wdc = getClient();

            wdc.CreateDirComplete += new CreateDirCompleteDel(wdc_CreateDirComplete);
            wdc.ListComplete      += new ListCompleteDel(wdc_ListComplete);
            wdc.DeleteComplete    += new DeleteCompleteDel(wdc_DeleteComplete);
            wdc.CreateDir(dir);
            autoReset.WaitOne(TIMEOUT);
            Assert.AreNotEqual(status, -1, "wrong status - create");

            autoReset.Reset();
            wdc.List();
            autoReset.WaitOne(TIMEOUT);
            Assert.AreNotEqual(status, -1, "wrong status - list");
            List <String> listing = (List <string>)result;

            Assert.IsTrue(listing.Contains(dir + "/"));             // directories have the / appended to the name

            // now delete again
            autoReset.Reset();
            wdc.Delete(dir + "/");
            autoReset.WaitOne(TIMEOUT);
            Assert.AreNotEqual(status, -1, "wrong status - delete");
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Debug.Listeners.Add(new ConsoleTraceListener());
            Boolean      result;
            WebDAVClient c;

            // A private mod_dav WebDAV server running on Apache (All tests pass)
            // Basic authentication required
            c          = new WebDAVClient();
            c.User     = "******";
            c.Pass     = "******";
            c.Server   = "http://192.168.1.55:8080";
            c.BasePath = "/jnstorage/webdav/repo1/javanes/iamedu/";
            result     = RunWebDAVTests(c);

            if (!result)
            {
                Debug.WriteLine("Tests didn't pass");
            }
            else
            {
                Debug.WriteLine("All passed");
            }
            Console.ReadLine();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Debug.Listeners.Add(new ConsoleTraceListener());
            Boolean result;

            // A private mod_dav WebDAV server running on Apache (All tests pass)
            // No authentication required
            WebDAVClient c = new WebDAVClient();

            c.Server   = "http://dev.kvdb.net";
            c.BasePath = "/openshare";
            result     = RunWebDAVTests(c);

            // A private mod_dav WebDAV server running on Apache (All tests pass)
            // Basic authentication required
            c          = new WebDAVClient();
            c.User     = "******";
            c.Pass     = "******";
            c.Server   = "http://dev.kvdb.net";
            c.BasePath = "/basicshare";
            result     = result && RunWebDAVTests(c);

            // A private mod_dav WebDAV server running on Apache (All tests pass)
            // Digest authentication required
            c          = new WebDAVClient();
            c.User     = "******";
            c.Pass     = "******";
            c.Domain   = "webdav";
            c.Server   = "http://dev.kvdb.net";
            c.BasePath = "/digestshare";
            result     = result && RunWebDAVTests(c);

            // A public WebDAV server for testing purposes. (All tests pass)
            // http://www.maxum.com/Rumpus/TestRumpus.html
            c        = new WebDAVClient();
            c.Server = "http://www.testrumpus.com/";
            c.User   = "******";
            c.Pass   = "******";
            result   = result && RunWebDAVTests(c);

            /*
             * // A public WebDAV server for testing purposes. (Doesn't work with this client yet)
             * // Running lighttpd 1.4.22
             * c = new WebDAVClient();
             * c.Server = "http://webdav.schlitt.info/";
             * result = result && RunWebDAVTests(c);
             */

            if (!result)
            {
                Debug.WriteLine("Tests didn't pass");
            }
            else
            {
                Debug.WriteLine("All passed");
            }
            Console.ReadLine();
        }
Beispiel #5
0
        public void listTest()
        {
            WebDAVClient wdc = getClient();

            wdc.ListComplete += new ListCompleteDel(wdc_ListComplete);
            wdc.List();
            autoReset.WaitOne(TIMEOUT);
            Assert.AreNotEqual(status, -1, "wrong status");
            Assert.IsNotNull(result, "result object was null");
        }
Beispiel #6
0
        private WebDAVClient getClient()
        {
            WebDAVClient wdc = new WebDAVClient();

            wdc.Server   = TESTSERVER;
            wdc.User     = TESTUSER;
            wdc.Pass     = TESTPASSWORD;
            wdc.BasePath = TESTPATH;
            return(wdc);
        }
Beispiel #7
0
        public Player(WebDAVClient client)
        {
            _client = client;

            _resourceItemQueue = new FixedSizedQueue <ResourceItem>(3, (resourceItem, size) =>
            {
                Log(string.Format("Disposing : '{0}'", resourceItem.DisplayName));
                if (resourceItem.Stream != null)
                {
                    resourceItem.Stream.Dispose();
                    resourceItem.Stream = null;
                }
            });

            _waveOutDevice = new WaveOut();
        }
Beispiel #8
0
        public IActionResult CreateInvoice([FromBody] InvoiceAjaxModel model)
        {
            try {
                if (ModelState.IsValid)
                {
                    var userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
                    using (DBEntities dbe = new DBEntities())
                    {
                        User    loggedUser = dbe.Users.SingleOrDefault(u => u.Id == userId);
                        Invoice invoice    = new Invoice()
                        {
                            CreatedBy           = dbe.Users.SingleOrDefault(u => u.Id == userId),
                            DateCreated         = DateTime.UtcNow,
                            InvoiceGuid         = Guid.NewGuid(),
                            State               = (int)InvoiceState.NOT_PAID,
                            Name                = model.Name,
                            Description         = model.Description,
                            Recipient           = model.Recipient,
                            FiatCurrencyCode    = model.FiatCurrencyCode,
                            ExchangeRateMode    = model.ExchangeRateMode,
                            ExchangeRateSetTime = null,
                            FiatAmount          = model.FiatAmount,
                            FileName            = model.FileName,
                            File                = model.File
                        };

                        // Proccess uploaded file
                        if (!string.IsNullOrEmpty(invoice.File))
                        {
                            string[] fileInfo    = invoice.File.Split(';');
                            string   mimeType    = fileInfo[0].Split(':')[1];
                            string   fileContent = fileInfo[1].Split(',')[1];

                            FileData fileData = new FileData()
                            {
                                FileName    = invoice.InvoiceGuid.ToString() + Path.GetExtension(invoice.FileName),
                                FileContent = Convert.FromBase64String(fileContent),
                            };

                            WebDAVClient client = new WebDAVClient(env, configuration);
                            invoice.File     = client.UploadFile(fileData);
                            invoice.FileMime = mimeType;
                        }

                        foreach (string cc in model.Accept)
                        {
                            string CC = cc.ToUpper();

                            // Check if exchange rate should be calculated now, or when the recipent opens payment page
                            double?exchangeRate = invoice.ExchangeRateMode == "invoice" ?
                                                  currencyConfiguration.Adapters[CC].GetExchangeRate(invoice.FiatCurrencyCode) : (double?)null;

                            invoice.PaymentsAvailable.Add(new InvoicePayment()
                            {
                                CurrencyCode = CC,
                                VarSymbol    = currencyConfiguration.Adapters[CC].GetVarSymbol(),
                                ExchangeRate = exchangeRate
                            });
                        }

                        dbe.Invoices.Add(invoice);
                        dbe.SaveChanges();

                        foreach (string cc in model.Accept)
                        {
                            currencyConfiguration.Adapters[cc.ToUpper()].GetAddress(invoice.Id, loggedUser);
                        }

                        // send info e-mail
                        string invoiceUrl = string.Format("{0}/invoice/{1}",
                                                          env.IsDevelopment() ? configuration["FrontEndHostName:Development"] : configuration["FrontEndHostName:Production"],
                                                          invoice.InvoiceGuid);

                        string subject    = $"New invoice from {loggedUser.UserName}";
                        string attachment = !string.IsNullOrEmpty(invoice.File) ? $"{invoice.File}|{invoice.FileName}|{invoice.FileMime}" : "";
                        string body       = System.IO.File.ReadAllText("wwwroot/web-api-static/templates/email/invoice.html");
                        body = body.Replace("{User.Name}", loggedUser.UserName)
                               .Replace("{Invoice.Name}", invoice.Name)
                               .Replace("{Invoice.Description}", invoice.Description)
                               .Replace("{URL}", invoiceUrl);

                        EmailSender sender = new EmailSender(configuration);
                        Email       email  = sender.CreateEmailEntity("*****@*****.**", invoice.Recipient, body, subject, attachment);

                        sender.AddEmailToQueue(email);

                        //Front end needs this new id to call GetInvoice
                        return(Created("/api/invoices/" + invoice.InvoiceGuid, invoice.InvoiceGuid));
                    }
                }
                else
                {
                    var query = from state in ModelState.Values
                                from error in state.Errors
                                select error.ErrorMessage;
                    var    errors    = query.ToList();
                    string allErrors = "";
                    foreach (string error in errors)
                    {
                        allErrors += error + "\n";
                    }
                    return(BadRequest(allErrors));
                }
            }
            catch (Exception ex) {
                return(BadRequest(ex));
            }
        }
Beispiel #9
0
        static Boolean RunWebDAVTests(WebDAVClient c)
        {
            autoResetEvent = new AutoResetEvent(false);

            // Generate unique string to test with.
            string basepath           = Path.GetRandomFileName() + '/';
            string tempFilePath       = Path.GetTempFileName();
            string uploadTestFilePath = @"c:\windows\notepad.exe";
            //string uploadTestFilePath = @"c:\windows\explorer.exe";
            // string uploadTestFilePath = @"c:\windows\setuplog.txt";
            string uploadTestFileName = Path.GetFileName(uploadTestFilePath);

            c.CreateDirComplete += new CreateDirCompleteDel(c_CreateDirComplete);
            c.CreateDir(basepath);
            autoResetEvent.WaitOne();
            Debug.WriteLine("CreateDir passed");

            c.ListComplete += new ListCompleteDel(c_ListComplete);
            c.List(basepath);
            autoResetEvent.WaitOne();
            if (_files.Count != 0)
            {
                return(false);
            }
            Debug.WriteLine("List passed");

            c.UploadComplete += new UploadCompleteDel(c_UploadComplete);
            c.Upload(uploadTestFilePath, basepath + uploadTestFileName);
            autoResetEvent.WaitOne();
            Debug.WriteLine("Upload 1/2 passed");
            c.List(basepath);
            autoResetEvent.WaitOne();
            if (_files.Count != 1)
            {
                return(false);
            }
            Debug.WriteLine("Upload 2/2 passed");

            autoResetEvent      = new AutoResetEvent(false);
            c.DownloadComplete += new DownloadCompleteDel(c_DownloadComplete);
            c.Download(basepath + uploadTestFileName, tempFilePath);
            autoResetEvent.WaitOne();
            Debug.WriteLine("Download 1/2 passed");
            HashAlgorithm h = HashAlgorithm.Create("SHA1");

            byte[] localhash;
            byte[] remotehash;
            using (FileStream fs = new FileStream(uploadTestFilePath, FileMode.Open))
            {
                localhash = h.ComputeHash(fs);
            }
            using (FileStream fs = new FileStream(tempFilePath, FileMode.Open))
            {
                remotehash = h.ComputeHash(fs);
            }
            for (int i = 0; i < localhash.Length; i++)
            {
                if (localhash[i] != remotehash[i])
                {
                    return(false);
                }
            }
            Debug.WriteLine("Download 2/2 passed");

            c.DeleteComplete += new DeleteCompleteDel(c_DeleteComplete);
            c.Delete(basepath + uploadTestFileName);
            autoResetEvent.WaitOne();
            Debug.WriteLine("Delete 1/2 passed");

            c.List(basepath);
            autoResetEvent.WaitOne();
            if (_files.Count != 0)
            {
                return(false);
            }
            Debug.WriteLine("Delete 2/2 passed");

            return(true);
        }