Ejemplo n.º 1
0
        public void EmptyHosts()
        {
            var pm = new PartitionMap {
                PartitionCount = 3, Hosts = Array.Empty <PartitionHostMap>()
            };

            var(ok, err) = pm.Validate();
            Assert.False(ok);
        }
Ejemplo n.º 2
0
        public ConfigFixture()
        {
            var cfg = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory);

            cfg.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);
            cfg.AddJsonFile("appsettings.dev.json", optional: true, reloadOnChange: false);
            Config = cfg.Build();

            ConnectionString = Config.GetValue("eventr:postgresql:connectionString", Util.LocalConnectionString);
            PartitionMap     = PartitionMap.FromConfig(Config, "eventr:postgresql:partitionMap");
            PartitionMap.ValidateOrThrow();
        }
Ejemplo n.º 3
0
        public void DuplicatePartitions()
        {
            var pm = new PartitionMap
            {
                PartitionCount = 3,
                Hosts          = new[]
                {
                    new PartitionHostMap {
                        Host = "localhost", Port = 5432, Partitions = new[] { 1, 2, 2 }
                    }
                }
            };

            var(ok, err) = pm.Validate();
            Assert.False(ok);
        }
Ejemplo n.º 4
0
        public void Correct()
        {
            var pm = new PartitionMap
            {
                PartitionCount = 3,
                Hosts          = new[]
                {
                    new PartitionHostMap {
                        Host = "localhost", Port = 5432, Partitions = new[] { 1, 2 }
                    },
                    new PartitionHostMap {
                        Host = "localhost", Port = 5433, Partitions = new[] { 3 }
                    }
                }
            };

            var(ok, err) = pm.Validate();
            Assert.True(ok);
        }
        /// <summary>
        /// Reads a logical volume descriptor from the buffer.
        /// </summary>
        /// <param name="buffer">The buffer to read the data from.</param>
        /// <returns>Returns true if the descriptor is valid.</returns>
        private bool ReadLogicalDescriptor(byte[] buffer)
        {
            LogicalVolume volume = new LogicalVolume();
            volume.Id.Parse(84, buffer);
            volume.BlockSize = UdfHelper.Get32(212, buffer);
            if (volume.BlockSize < VirtualSectorSize || volume.BlockSize > MaxExtents)
            {
                return false;
            }

            volume.FileSetLocation.Parse(248, buffer);

            int numPartitionMaps = UdfHelper.Get32(268, buffer);
            if (numPartitionMaps > MaxPartitions)
            {
                return false;
            }

            int position = 440;
            for (int index = 0; index < numPartitionMaps; index++)
            {
                if (position + 2 > SectorSize)
                {
                    return false;
                }

                PartitionMap pm = new PartitionMap();
                pm.Type = buffer[position];
                byte length = buffer[position + 1];
                if (position + length > SectorSize)
                {
                    return false;
                }

                if (pm.Type == 1)
                {
                    if (position + 6 > SectorSize)
                    {
                        return false;
                    }

                    pm.PartitionNumber = UdfHelper.Get16(position + 4, buffer);
                }
                else
                {
                    return false;
                }

                position += length;
                pm.PartitionIndex = volume.PartitionMaps.Count;
                volume.PartitionMaps.Add(pm);
            }

            this.LogicalVolumes.Add(volume);
            return true;
        }
Ejemplo n.º 6
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="source">Source string</param>
            public Line(string source, Line parent)
            {
                Source = source;
                int layoutFirstIndex  = 4;                                                                   // Layout starting symbol index in the source line
                int layoutSecondIndex = source[5] != ' ' ? 5 : 12;                                           // Layout ending symbol index in the source line

                Layout = (source[layoutFirstIndex].ToString() + source[layoutSecondIndex]).Replace(" ", ""); // Getting the layout



                if (PartitionMap.ContainsKey(Layout)) // Checking if such layout exists in the partition map
                {
                    try
                    {
                        Program.mainForm.Status = "Loading data from file...";


                        int continuationIndexLocation     = Program.mainForm.GetInfoLocationInMapperList(PartitionMap[Layout], "cnum");
                        int continuationIndexTypeLocation = Program.mainForm.GetInfoLocationInMapperList(PartitionMap[Layout], "cnum_type");



                        char continuationType;

                        if (continuationIndexTypeLocation != -1)
                        {
                            MyRecordType     = GetRecordType(source[continuationIndexLocation]);
                            continuationType = source[continuationIndexLocation + 1];
                        }
                        else
                        if (continuationIndexLocation != -1)
                        {
                            MyRecordType     = GetRecordType(source[continuationIndexLocation]);
                            continuationType = 'A';
                        }
                        else
                        {
                            MyRecordType     = RecordType.PrimaryWithoutContinuationFollowing;
                            continuationType = '\0';
                        }

                        if (MyRecordType == RecordType.Continuation)
                        {
                            if (parent != null)
                            {
                                parent.Children.Add(this);
                            }

                            if (PartitionMap.ContainsKey(Layout + "_" + continuationType))
                            {
                                Layout += "_" + continuationType;
                            }
                            else
                            {
                                Console.WriteLine(Layout += "_" + continuationType);
                            }
                        }

                        List <TableMapper> partition = PartitionMap[Layout];;

                        if (partition.Count > 0)
                        {
                            for (int i = 0; i < partition.Count - 1; i++)
                            {
                                Contents.Add(source.Substring(partition[i].Index, partition[i + 1].Index - partition[i].Index)); // Getting the content according to the partition map
                                ColumnNames.Add(partition[i].Name);                                                              // Setting the column names for the line
                            }

                            Contents.Add(source.Substring(partition[partition.Count - 1].Index)); // Adding the last content element
                            ColumnNames.Add(partition[partition.Count - 1].Name);                 // Adding the last column name element
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message + " (" + Layout + ")"); // Also adding the layout name to the exception message
                    }
                }
                else
                {
                    Program.mainForm.Status = "No layout partition template found for: " + Layout;
                }
            }