private void SetupColumnSelection(DataSourceInformation dataSourceInformation)
        {
            columnSelector.Controls.Clear();
            BackupCsvInstanceForCurrentColumns(dataSourceInformation);

            if (dataSourceInformation.DataSourceType != DataSourceType.CSV)
            {
                return;
            }

            CsvFile csvFile = ReadFiveLinesFromCsv(dataSourceInformation);
            IEnumerable <string> headers = csvFile.GetHeaders();

            var previousCoordinate = 0;

            for (int columnIndex = 0; columnIndex < csvFile.GetColumns(); columnIndex++)
            {
                Label label = CreateLabelForColumn();
                AddColumnIndexAndHeadersToLabel(dataSourceInformation, headers, columnIndex, label);
                AddContentToLabel(csvFile, columnIndex, label);

                label.Click        += ColumnSelector_ColumnClick;
                label.Left          = previousCoordinate + 2;
                previousCoordinate += label.Width;

                columnSelector.Controls.Add(label);
            }
        }
Example #2
0
        public void SerializeAndDeSerializeAsBaseClass()
        {
            string path = $"{Environment.CurrentDirectory}\\testfileinfofile.txt";

            try
            {
                DataFileInfo dfi = new DataFileInfo();
                dfi.Columns   = new string[] { "Col1" };
                dfi.Delimiter = "|";
                DataSourceInformation baseclass = dfi as DataSourceInformation;
                baseclass.SaveToFile(path);
                Assert.IsTrue(File.Exists(path));
                DataSourceInformation loadedFromFile = DataSourceInformation.LoadFromFile(path);
                DataFileInfo          dfi2           = loadedFromFile as DataFileInfo;
                Assert.AreEqual(expected: dfi.Delimiter, actual: dfi2.Delimiter);
                Assert.AreEqual(expected: dfi.Columns[0], actual: dfi2.Columns[0]);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }
Example #3
0
        private void modeApply(string[] obj)
        {
            //required options: name of source (filename or schema.table), the column to apply it on, and the type of mask to apply (must be defined in the maskingoptions enum in the enumerations file)
            //optional option: a method to use with the masking strategy, check the actual maskingstrategies to see how the method is used (for replace the 'method' is simply the string value to use in the replacement action
            if (!obj.Length.Between(3, 4))
            {
                Console.Error.WriteLine("Argument error, correct usage: rds mask -ADD {sourcename} {masktype} [method]");
            }
            string         filename = obj[0] + Settings.DataSourceFileExtension;
            string         colName  = obj[1];
            string         type     = obj[2];
            string         method   = obj.ElementAtOrDefault(3); //null values will be passed on, this is intended
            MaskingOptions typeEnum = (MaskingOptions)Enum.Parse(typeof(MaskingOptions), type, ignoreCase: true);
            Tuple <MaskingOptions, string> dictValue = new Tuple <MaskingOptions, string>(typeEnum, method);

            var dirinf    = new DirectoryInfo($"{Directory.GetCurrentDirectory()}\\{Settings.RdsDirectoryName}");
            var sourceInf = dirinf.EnumerateFiles().Where(
                file => file.Name == filename).FirstOrDefault();

            if (sourceInf == null)
            {
                Console.Error.Write($"File with name {filename} could not be found.");
                return;
            }
            DataSourceInformation dsi = DataSourceInformation.LoadFromFile(sourceInf.FullName);

            dsi.MaskingInformation.Add(colName, dictValue);
            dsi.SaveToFile(sourceInf.FullName);
        }
        private void ColumnSelector_ColumnClick(object sender, EventArgs e)
        {
            var clicked             = (Label)sender;
            var firstEnterCharIndex = clicked.Text.IndexOf('\n');

            if (firstEnterCharIndex < 0)
            {
                MessageBox.Show("Can't get this header.\nPlease check the content of this file.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var csvDataSource = (List <DataSourceInformation>)dataSourceInformationBindingSource.DataSource;
            DataSourceInformation currentCsvInfo = GetCsvInstanceForCurrentColumns();
            var csvInfoBounded = csvDataSource.FirstOrDefault(x => x == currentCsvInfo);

            if (chkHasHeaders.Checked)
            {
                var firstBracketIndex = clicked.Text.IndexOf('[');
                csvInfoBounded.ColumnIndex = int.Parse(clicked.Text.Substring(0, firstBracketIndex));
                csvInfoBounded.ColumnName  = $"{clicked.Text.Substring(firstBracketIndex + 1, firstEnterCharIndex - firstBracketIndex - 2)}";
            }
            else
            {
                csvInfoBounded.ColumnIndex = int.Parse(clicked.Text.Substring(0, firstEnterCharIndex));
                csvInfoBounded.ColumnName  = "";
            }
            gridCsvInformation.Refresh();
        }
        private CsvFile ReadFiveLinesFromCsv(DataSourceInformation dataSourceInformation)
        {
            var csvFile = new CsvFile();

            csvFile.ReadFile(dataSourceInformation.DataSourceName, ROWS_TO_SHOW_IN_COLUMN_SELECTOR);
            csvFile.HasHeaders = chkHasHeaders.Checked = dataSourceInformation.HasHeaders;
            return(csvFile);
        }
Example #6
0
        public void Constructor()
        {
            DataSourceInformation dataSource;

            dataSource = new DataSourceInformation(Settings.Default.UserServiceName,
                                                   Settings.Default.UserServiceMonesesFastAddress,
                                                   DataSourceType.WebService);
            Assert.IsNotNull(dataSource);
        }
        public DataContext GetDataContext(IUserContext testUserContext)
        {
            // Set data
            ILocale locale = new Locale(AnalysisPortalTestSettings.Default.SwedishLocaleId, AnalysisPortalTestSettings.Default.SwedishLocale, AnalysisPortalTestSettings.Default.SwedishNameString, AnalysisPortalTestSettings.Default.SvenskNameString, new DataContext(testUserContext));

            IDataSourceInformation dataSource  = new DataSourceInformation();
            DataContext            dataContext = new DataContext(dataSource, locale);

            return(dataContext);
        }
Example #8
0
 private DataSourceInformation GetDataSourceInformation(Boolean refresh)
 {
     if (_dataSourceInformation.IsNull() || refresh)
     {
         _dataSourceInformation = new DataSourceInformation(Settings.Default.UserServiceName,
                                                            Settings.Default.UserServiceMonesesFastAddress,
                                                            DataSourceType.WebService);
     }
     return(_dataSourceInformation);
 }
 private void AddColumnIndexAndHeadersToLabel(DataSourceInformation csvInformation, IEnumerable <string> headers, int columnIndex, Label label)
 {
     if (csvInformation.HasHeaders)
     {
         label.Text = $"{columnIndex} [{headers.ElementAt(columnIndex)}]";
     }
     else
     {
         label.Text = $"{columnIndex}";
     }
 }
Example #10
0
        private static List <DataSourceInformation> RetrieveDataSourceInformationList()
        {
            string        rdsDir  = Properties.Settings.RdsDirectoryName;
            DirectoryInfo rdsinfo = new DirectoryInfo($"{Environment.CurrentDirectory}\\{rdsDir}");
            string        ext     = Properties.Settings.DataSourceFileExtension;
            List <DataSourceInformation> DataSourceInformations = rdsinfo.EnumerateFiles().
                                                                  Where(x => x.Extension.Equals(ext)).
                                                                  Select(x => DataSourceInformation.LoadFromFile(x.FullName)).
                                                                  ToList();

            return(DataSourceInformations);
        }
Example #11
0
        private static DialogResult ConfirmToSelectANewFile(DataSourceInformation dataSourceInformation)
        {
            var userResponseToChangeFile = DialogResult.Yes;
            var fileName = dataSourceInformation.DataSourceName;

            if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
            {
                userResponseToChangeFile = MessageBox.Show("Change file?", "CONFIRM", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            }

            return(userResponseToChangeFile);
        }
Example #12
0
 private void _CreateSubset(DataTable dt, DataSourceInformation info)
 {
     if (info.GetType() == typeof(DataFileInfo))
     {
         DataFileInfo dfinfo = info as DataFileInfo;
         _CreateSubsetDataFileInfo(dt, dfinfo);
     }
     if (info.GetType() == typeof(SourceTableInfo))
     {
         SourceTableInfo stinfo = info as SourceTableInfo;
         _CreateSubsetSourceTableInfo(dt, stinfo);
     }
 }
Example #13
0
 private void _CreateSubset(IEnumerable <DataRow> dt, DataSourceInformation info, DataColumnCollection header)
 {
     if (info.GetType() == typeof(DataFileInfo))
     {
         DataFileInfo dfinfo = info as DataFileInfo;
         _CreateSubsetDataFileInfo(dt, dfinfo, header);
     }
     if (info.GetType() == typeof(SourceTableInfo))
     {
         SourceTableInfo stinfo = info as SourceTableInfo;
         _CreateSubsetSourceTableInfo(dt, stinfo, header);
     }
 }
Example #14
0
        private bool IsValidInputForSetbase(string file, string column)
        {
            string        ext          = Properties.Settings.DataSourceFileExtension;
            string        rdsDir       = Properties.Settings.RdsDirectoryName;
            DirectoryInfo rdsdir       = new DirectoryInfo($"{Environment.CurrentDirectory}\\{rdsDir}");
            var           datafileinfo = rdsdir.EnumerateFiles().                                     //all files
                                         Where(x => x.Extension.Equals(ext)).                         //with rds datafileinfo extension
                                         Select(x => DataSourceInformation.LoadFromFile(x.FullName)). //select the datafileinfo objects that are loaded from those files
                                         Where(x => x.SourceName.Equals(file)).                       //where the source name equals the supplied name
                                         FirstOrDefault();                                            //first one or null

            if (datafileinfo == null)
            {
                Console.Error.WriteLine($"{file} could not be found in the rds repository");
                return(false);
            }
            if (!datafileinfo.Columns.Contains(column))
            {
                Console.Error.WriteLine($"{column} could not be found in {file}");
                return(false);
            }
            return(true);
        }
Example #15
0
        private void modeRemove(string[] obj)
        {
            //required option: name of source and the column name
            if (!(obj.Length == 2))
            {
                Console.Error.WriteLine("Argument error, correct usage: rds mask -remove {sourcename} {columnname}");
                return;
            }
            string filename  = obj[0] + Settings.DataSourceFileExtension;
            string colName   = obj[1];
            var    dirinf    = new DirectoryInfo($"{Directory.GetCurrentDirectory()}\\{Settings.RdsDirectoryName}");
            var    sourceInf = dirinf.EnumerateFiles().Where(
                file => file.Name == filename).FirstOrDefault();

            if (sourceInf == null)
            {
                Console.Error.Write($"File with name {filename} could not be found.");
                return;
            }
            DataSourceInformation dsi = DataSourceInformation.LoadFromFile(sourceInf.FullName);

            dsi.MaskingInformation.Remove(colName);
            dsi.SaveToFile(sourceInf.FullName);
        }
Example #16
0
 private static void LoadFileToDataTable(DataTable table, DataSourceInformation dfInfo)
 {
     dfInfo.LoadToDataTable(table);
 }
Example #17
0
 public DataSourceInformationTest()
 {
     _dataSourceInformation = null;
 }
Example #18
0
        public void Run(string primaryFile, string primaryKey, string foreignFile, string foreignKey)
        {
            string        keyrelationFileName = Properties.Settings.KeyRelationshipFileName;
            string        strRdsDir           = Environment.CurrentDirectory + "\\.rds";
            DirectoryInfo rdsDirInfo          = new DirectoryInfo(strRdsDir);
            string        ext   = Properties.Settings.DataSourceFileExtension;
            var           files = rdsDirInfo.EnumerateFiles().Where(f => f.Extension.Contains(ext));
            List <DataSourceInformation> listOfInformation = new List <DataSourceInformation>();

            foreach (var file in files)
            {
                listOfInformation.Add(DataSourceInformation.LoadFromFile(file.FullName));
            }
            //check of both sources have their info defined in the rds directory and have the required column
            var primary = listOfInformation.FirstOrDefault(
                sauce => sauce.SourceName.Equals(primaryFile));
            var foreign = listOfInformation.FirstOrDefault(
                sauce => sauce.SourceName.Equals(foreignFile));
            bool IsInErrorState = false;

            if (primary == null)
            {
                IsInErrorState = true;
                Console.Error.WriteLine($"{primaryFile} could not be found in the rds directory, either the file is missing or is not initialized");
            }
            else if (!primary.Columns.Contains(primaryKey))
            {
                IsInErrorState = true;
                Console.Error.WriteLine($"{primaryFile} was found but does not contain column {primaryKey}.");
            }
            if (foreign == null)
            {
                IsInErrorState = true;
                Console.Error.WriteLine($"{foreignFile} could not be found in the rds directory, either the file is missing or is not initialized");
            }
            else if (!foreign.Columns.Contains(foreignKey))
            {
                IsInErrorState = true;
                Console.Error.WriteLine($"{foreignFile} was found but does not contain column {foreignKey}.");
            }

            if (IsInErrorState)
            {
                Console.Error.WriteLine("An error was encountered and the program could not continue");
                return;
            }
            //TODO: add validation (primary key specified is not a foreign key set in a different relationship or other nonsense)
            //TODO: add method to clean up keyrelationfile without resetting the whole repo
            Key                    prim             = new Key(primaryFile, primaryKey);
            Key                    fore             = new Key(foreignFile, foreignKey);
            KeyRelationship        rel              = new KeyRelationship(prim, fore);
            List <KeyRelationship> keyRelationships = new List <KeyRelationship>().LoadFromFile($"{strRdsDir}\\{keyrelationFileName}");

            if (keyRelationships.Contains(value: rel))
            {
                Console.Error.WriteLine("This relationship is already defined");
                return;
            }
            keyRelationships.Add(rel);
            keyRelationships.SaveToFile($"{strRdsDir}\\keyrelations.rdskrf");
            Console.Out.WriteLine($"Relationship set. Primary key: \"{primaryKey}\" in file \"{primaryFile}\". Foreign key: \"{foreignKey}\" in file \"{foreignFile}\"");
            return;
        }
        public RedirectResult SetUserInSession(string returnUrl)
        {
            IUserContext          userContext = new UserContext();
            DataSourceInformation dataSource;
            DataContext           dataContext;
            Locale locale;

            dataSource = new DataSourceInformation(
                "UserService",
                "https://moneses-dev.artdata.slu.se/UserService/UserService.svc/Fast",
                DataSourceType.WebService);

            locale = new Locale(
                175,
                "sv-SE",
                "Swedish (Sweden)",
                "svenska (Sverige)",
                new DataContext(dataSource, null));

            userContext.Locale = locale;

            dataContext      = new DataContext(dataSource, locale);
            userContext.User = new User(userContext);
            userContext.User.IsAccountActivated = true;
            userContext.User.Id       = 9710;
            userContext.User.PersonId = 12165;
            userContext.User.GUID     = "urn:lsid:artdata.slu.se:User:9710:2";
            userContext.User.UserName = "******";

            userContext.User.DataContext = dataContext;
            userContext.CurrentRoles     = new RoleList();

            Role role = new Role(userContext);

            role.GUID        = "urn:lsid:artdata.slu.se:User:9710:2";
            role.Id          = 2; //?
            role.Authorities = new AuthorityList();
            Authority authority = new Authority(userContext);

            authority.RoleId      = 2; //?
            authority.Id          = 3408;
            authority.Identifier  = "Sighting";
            authority.Description = "Ger rättigheter att se publika observationer arter i naturen.";
            authority.GUID        = "urn:lsid:artdata.slu.se:Authority:3408:3";
            authority.DataContext = dataContext;
            role.Authorities.Add(authority);
            role.DataContext = dataContext;
            userContext.CurrentRoles.Add(role);
            userContext.CurrentRole = userContext.CurrentRoles[0];

            userContext.Properties.Add("WebServiceClientToken:AnalysisService", "ABAAAAAANAIMJNNPABBFNBBBIMHKAAMAEPMCJHOLABAAAAAANMFHNLJMABLGPLEFIIGJEHCCCGDCCMDHAEAAAAAAACAAAAAAAAAAADGGAAAAKIAAAAAABAAAAAAAABLAJDMLMLANODBONBDJDIFGKPOGOCONAAAAAAAAAEIAAAAAKAAAAAAABAAAAAAADPNOALDAGGBLFAEMLKMGODLCCIGDONBMEAAAAAAANKMHBAGGLJDCMJGHBBADAENEABHJKEOEMNNDCELLNPGMJKLADIJEFIMNPCOBKLJDGPNEBFDPKBOJHILGECLEPAGOEKIGHAMMNMBHENBBPCIHKGNNBICGDOOCOEJDGDBCBEAAAAAALCFLNKBOHHIBMIJIBAGKFKEBPHOFPDIDECAEJIDA");
            userContext.Properties.Add("WebServiceClientToken:TaxonService", "ABAAAAAANAIMJNNPABBFNBBBIMHKAAMAEPMCJHOLABAAAAAANMFHNLJMABLGPLEFIIGJEHCCCGDCCMDHAEAAAAAAACAAAAAAAAAAADGGAAAAKIAAAAAABAAAAAAABNFMLFLLINODFMCBHLEJNNEHJJFEAEIIAAAAAAAAAEIAAAAAKAAAAAAABAAAAAAAPKAJNCCNBAFFGCCPPDOFJEEGJALBJOHBDIAAAAAAKLMNCLOLEDLEOOAOPMFOAIKMGBKDKDBFIPHAGGIEIJDNIKIDEJPIKDDJBGDDMHBGHANOBLFPLHGMLBAOLDLBDJNADNDFLLPDDKJFDLPOHJKHMEIPBEAAAAAAILLEPNJDDCNFHBHBKBJBFHGPBDHFKNBGFHNCLIAN");
            userContext.Properties.Add("WebServiceClientToken:SwedishSpeciesObservationSOAPService", "ABAAAAAANAIMJNNPABBFNBBBIMHKAAMAEPMCJHOLABAAAAAANMFHNLJMABLGPLEFIIGJEHCCCGDCCMDHAEAAAAAAACAAAAAAAAAAADGGAAAAKIAAAAAABAAAAAAAJIJEKMLGAMNFOFENAMIKFENEBAMJBFBJAAAAAAAAAEIAAAAAKAAAAAAABAAAAAAAMCLBCJMCIHOGECAINIIBAKHLNGFJBIDHFAAAAAAADHHJGOJECDGLFBAEFDDLFDKMNFEMJLPFHMGCEGNFMNJALGCLDPBKNKIHFBBKFOKPNFDAKMHPPEABNMMHHNLDBDLKCEPJGIBBAIJLJFCDKEKKHCINFMJHJDOIOOLPPJJNDPEFEHDFNGNGNIBHDJIGAGJLPLLACPEBBEAAAAAAEIJCHDEGJFIHCADCNBCDNCOOBLICMDOEOHLCJGMH");
            userContext.Properties.Add("WebServiceClientToken:UserService", "ABAAAAAANAIMJNNPABBFNBBBIMHKAAMAEPMCJHOLABAAAAAANMFHNLJMABLGPLEFIIGJEHCCCGDCCMDHAEAAAAAAACAAAAAAAAAAADGGAAAAKIAAAAAABAAAAAAAJNLBEPHKAEIABPELPMMKECDNMAHKOPPLAAAAAAAAAEIAAAAAKAAAAAAABAAAAAAAKCFCHEKOMBAGJHGOPLFLMLAKHFJFHCALDIAAAAAAHPILMCMMADNNPGEIFOPMAPNOBNANAJLEBBHJBCEPEOGPFJHCOKHNBNLHAEJIHOJHBIGBPICONOGNPGCHIBFLOFKMNOODOONPMIINBFDJJOOKFPLKBEAAAAAAOBHLFNOJNIPGNFDDCFDLLGBANHHGOIOAIABKOOJC");
            userContext.Properties.Add("WebServiceClientToken:GeoReferenceService", "ABAAAAAANAIMJNNPABBFNBBBIMHKAAMAEPMCJHOLABAAAAAANMFHNLJMABLGPLEFIIGJEHCCCGDCCMDHAEAAAAAAACAAAAAAAAAAADGGAAAAKIAAAAAABAAAAAAAMDCFKKNLGMECCCGFIGDGAMOOJOONJOLMAAAAAAAAAEIAAAAAKAAAAAAABAAAAAAABKFHLHNALJFKLJPLGOBLKMNEBNLEFEOAEAAAAAAAJNKNGGPDEDGMEJFGBGJPFPMGJLOEPKALNNILJEBKLDOGLKLDLJDFJFBBEHMLHEBNAKADEGEBHNMHMLHBONANMILANEJGDJDOAKCMLDEJANNMDBALBBOKPNGOBDAINIILBEAAAAAAMFONCMJDPOAPCKANOOJECFIFEOOLCFNHAIPFNOIL");

            SessionHandler.UserContext = userContext;

            if (String.IsNullOrEmpty(returnUrl))
            {
                return(Redirect(Url.Action("Index", "Home")));
            }

            return(Redirect(returnUrl));
        }
Example #20
0
 private void BackupCsvInstanceForCurrentColumns(DataSourceInformation csvInformation)
 {
     columnSelector.Tag = csvInformation;
 }