Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="manifest"></param>
        /// <exception cref="ArgumentNullException">The provided manifest was null.</exception>
        /// <exception cref="ArgumentException">The provided manifest failed validation.</exception>
        /// <exception cref="InvalidOperationException">A site wth the same domain name and path already exists.</exception>
        public void AddSite(SiteManifest manifest)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException(nameof(manifest));
            }

            if (!manifest.Validate().isValid)
            {
                throw new ArgumentException("Manifest is not valid for saving.");
            }

            //TODO: Check for duplicates.
            string potentialName = GenerateName(manifest);

            if (AvailableSites.Contains(potentialName))
            {
                throw new InvalidOperationException($"A site with the name: {potentialName} already exists.");
            }

            var folder = new ItemLocation(potentialName, "");

            this.fileViewer.CreateFolder(folder);
            new SiteManifestManager(this.fileViewer).CreateManifest(folder, manifest);
        }
Exemple #2
0
        /// <summary>
        /// Removes illegal characters from the manifest name.
        /// </summary>
        /// <param name="manifest"></param>
        /// <returns></returns>
        private string GenerateName(SiteManifest manifest)
        {
            //http://stackoverflow.com/a/7393722
            string invalidName = manifest.FTPServer + " " + manifest.FTPPath;

            return(Path.GetInvalidFileNameChars().Aggregate(invalidName, (current, c) => current.Replace(c.ToString(), " ")));
        }
Exemple #3
0
        public void ToStringReturnsDisplayNameIfAllSet()
        {
            var manifest = new SiteManifest()
            {
                DisplayName = "HelloWorld", FTPPath = "aa", FTPServer = "bb", UseSFTP = false, DefaultUserName = "******"
            };

            Assert.AreEqual("HelloWorld", manifest.ToString());
        }
Exemple #4
0
        public void ToStringReturnsServerAndNameIfDisplayNameEmpty()
        {
            var manifest = new SiteManifest()
            {
                DisplayName = "    ", FTPPath = "aa", FTPServer = "ftp.dur.ac.uk", UseSFTP = false, DefaultUserName = "******"
            };

            Assert.AreEqual("*****@*****.**", manifest.ToString());
        }
Exemple #5
0
        private void btn_OK_Click(object sender, EventArgs e)
        {
            SiteManifest selected = this.manifests[this.comboBox1.SelectedIndex];

            this.Result         = selected;
            this.DialogResult   = DialogResult.OK;
            this.PasswordResult = txt_Password.Text;
            this.Close();
        }
Exemple #6
0
        private SiteManifest LoadFile(ItemLocation potentialFile)
        {
            if (potentialFile == null)
            {
                throw new ArgumentNullException(nameof(potentialFile));
            }

            var manifest = fileSystemService.GetFile(potentialFile);

            return(SiteManifest.FromByteStream(manifest.GetContent()));
        }
Exemple #7
0
        private SiteManifest CreateManifestFromFields()
        {
            SiteManifest m = new SiteManifest();

            m.DisplayName     = this.txt_DisplayName.Text;
            m.DefaultUserName = this.UserName;
            m.FTPPath         = this.RootFolder;
            m.FTPServer       = FTPDomain;
            m.UseSFTP         = this.IsSFTP;
            return(m);
        }
Exemple #8
0
        private void selectManifest(int index)
        {
            this.comboBox1.SelectedIndex = index;
            SiteManifest selected = this.manifests[this.comboBox1.SelectedIndex];

            this.txt_DisplayName.Text = selected.DisplayName;
            this.txt_Domain.Text      = selected.FTPServer;
            this.txt_RootFolder.Text  = selected.FTPPath;
            this.cbx_secure.Checked   = selected.UseSFTP;
            this.txt_Username.Text    = selected.DefaultUserName;
        }
Exemple #9
0
        private IFTPClient getFTPClient(SiteManifest manifest, string password)
        {
            var    client = new FTPclient(manifest.FTPServer, manifest.DefaultUserName, password, true);
            string path   = manifest.FTPPath;

            if (!path.StartsWith("/"))
            {
                path = "/" + path;
            }
            client.CurrentDirectory = path;
            FTPClientValidationDecorator d = new FTPClientValidationDecorator(client);

            return(d);
        }
        public virtual void Setup()
        {
            MockSiteSettings  = new Mock <ISiteSettings>();
            MockSiteConnector = new Mock <ISiteConnector>();
            MockFormMapper    = new Mock <IFormMapper>();
            MockLogger        = new Mock <ILog>();

            _siteManifests = new ServiceConfiguration();


            HttpsTestsite = $"{SupportServiceIdentity.SupportEmployerAccount}|https://testsite/";

            TestSiteManifest = new EmployerAccountSiteManifest();

            _siteManifests.Add(TestSiteManifest);


            TestSites = HttpsTestsite;

            MockSiteSettings.SetupGet(x => x.BaseUrls)
            .Returns(TestSites);

            TestSiteUri = TestSites.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                          .Where(x => !string.IsNullOrWhiteSpace(x))
                          .Select(x => x.Split(new [] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                          .Select(x => new Uri(x[1])).First();

            TestSiteUri = new Uri($"{TestSiteUri}api/manifest");

            MockSiteConnector.Setup(x => x.Download <SiteManifest>(TestSiteUri)).ReturnsAsync(TestSiteManifest);

            Unit = new ApplicationServices.Services.ManifestRepository(
                MockSiteSettings.Object,
                MockSiteConnector.Object,
                MockFormMapper.Object,
                MockLogger.Object, _siteManifests);
        }
Exemple #11
0
        internal void CreateManifest(ItemLocation folder, SiteManifest manifest)
        {
            var file = new InMemoryFile(folder, new MemoryStream(manifest.ToByteArray()));

            fileSystemService.SaveFile(file);
        }