Ejemplo n.º 1
0
        public void CreateDXFFromMasterAlignment(string fileName, string compareFileName)
        {
            var f      = NFFFile.CreateFromFile(Path.Combine("TestData", "Common", fileName));
            var master = f.GuidanceAlignments?.Where(x => x.IsMasterAlignment()).FirstOrDefault();

            master.Should().NotBeNull();

            var export = new ExportToDXF
            {
                AlignmentLabelingInterval = 10,
                Units = DistanceUnitsType.Meters
            };

            export.ConstructSVLCenterlineDXFAlignment(master, out var calcResult, out var MS).Should().BeTrue();
            calcResult.Should().Be(DesignProfilerRequestResult.OK);
            MS.Should().NotBeNull();

            // File.WriteAllBytes(Path.GetTempFileName() + fileName + ".MasterAlignment.DXF", MS.ToArray());

            // The Writer writes lines with environment line endings. Done this way we read the file with environment line endings and have
            // more accurate equality checking vs ReadAllBytes.
            var input = File.ReadAllLines(Path.Combine("TestData", "Common", compareFileName));
            var sb    = new StringBuilder();

            foreach (var s in input)
            {
                sb.Append(s + Environment.NewLine);
            }

            // Compare with known good file
            var goodFile = Encoding.UTF8.GetBytes(sb.ToString());

            MS.ToArray().Should().BeEquivalentTo(goodFile);
        }
Ejemplo n.º 2
0
 public void ReadServertData(IAsyncResult ar)
 {
     try
     {
         if (!ClientSocket.IsConnected || !IsConnected)
         {
             IsConnected = false;
             Dispose();
             return;
         }
         int recevied = SslClient.EndRead(ar);
         if (recevied > 0)
         {
             MS.Write(Buffer, 0, recevied);
             if (MS.Length == 4)
             {
                 Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                 Debug.WriteLine("/// Client Buffersize " + Buffersize.ToString() + " Bytes  ///");
                 MS.Dispose();
                 MS = new MemoryStream();
                 if (Buffersize > 0)
                 {
                     Buffer = new byte[Buffersize];
                     while (MS.Length != Buffersize)
                     {
                         int rc = SslClient.Read(Buffer, 0, Buffer.Length);
                         if (rc == 0)
                         {
                             IsConnected = false;
                             Dispose();
                             return;
                         }
                         MS.Write(Buffer, 0, rc);
                         Buffer = new byte[Buffersize - MS.Length];
                     }
                     if (MS.Length == Buffersize)
                     {
                         ThreadPool.QueueUserWorkItem(Packet.Read, MS.ToArray());
                         Buffer = new byte[4];
                         MS.Dispose();
                         MS = new MemoryStream();
                     }
                 }
             }
             SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null);
         }
         else
         {
             IsConnected = false;
             Dispose();
             return;
         }
     }
     catch
     {
         IsConnected = false;
         Dispose();
         return;
     }
 }
Ejemplo n.º 3
0
        public void ExtractEventData()
        {
            foreach (var machine in _siteModel.Machines)
            {
                var basePath = Path.Combine(_projectOutputPath, "Events", machine.ID.ToString());
                Directory.CreateDirectory(basePath);

                foreach (var evtList in ProductionEventLists.ProductionEventTypeValues)
                {
                    var eventsFileName = ProductionEvents.EventChangeListPersistantFileName(machine.InternalSiteModelMachineIndex, evtList);
                    var readResult     = _siteModel.PrimaryStorageProxy.ReadStreamFromPersistentStore(_siteModel.ID, eventsFileName, FileSystemStreamType.Events, out MemoryStream MS);

                    if (readResult != FileSystemErrorStatus.OK || MS == null)
                    {
                        Log.LogError($"Failed to read directory stream for {eventsFileName} with error {readResult}, or read stream is null");
                        Console.WriteLine($"Failed to read directory stream for {eventsFileName} with error {readResult}, or read stream is null");
                        continue;
                    }

                    using (MS)
                    {
                        File.WriteAllBytes(Path.Combine(basePath, eventsFileName), MS.ToArray());
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void label2_Click(object sender, EventArgs e)
        {
            MemoryStream MS;

            if (pictureBox1.Image != null)
            {
                MS = new MemoryStream();
                pictureBox1.Image.Save(MS, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            else
            {
                MessageBox.Show("Please Select an Image !");
                return;
            }

            UpdateUser(new UserData()
            {
                FirstName = TxtFirstName.Text,
                LastName  = TxtLastName.Text,
                Email     = TxtEmail.Text,
                Picture   = MS.ToArray(),
                Username  = TxtUsername.Text,
                Password  = TxtPassword.Text
            });
        }
Ejemplo n.º 5
0
 public static void ReadServertData(IAsyncResult ar)
 {
     try
     {
         if (!TcpClient.Connected || !IsConnected)
         {
             IsConnected = false;
             return;
         }
         int recevied = SslClient.EndRead(ar);
         if (recevied > 0)
         {
             MS.Write(Buffer, 0, recevied);
             if (MS.Length == 4)
             {
                 Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                 Debug.WriteLine("/// Plugin Buffersize " + Buffersize.ToString() + " Bytes  ///");
                 MS.Dispose();
                 MS = new MemoryStream();
                 if (Buffersize > 0)
                 {
                     Buffer = new byte[Buffersize];
                     while (MS.Length != Buffersize)
                     {
                         int rc = SslClient.Read(Buffer, 0, Buffer.Length);
                         if (rc == 0)
                         {
                             IsConnected = false;
                             return;
                         }
                         MS.Write(Buffer, 0, rc);
                         Buffer = new byte[Buffersize - MS.Length];
                     }
                     if (MS.Length == Buffersize)
                     {
                         Thread thread = new Thread(new ParameterizedThreadStart(Packet.Read));
                         thread.Start(MS.ToArray());
                         Buffer = new byte[4];
                         MS.Dispose();
                         MS = new MemoryStream();
                     }
                 }
             }
             SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null);
         }
         else
         {
             IsConnected = false;
             return;
         }
     }
     catch
     {
         IsConnected = false;
         return;
     }
 }
Ejemplo n.º 6
0
        public static void ReadServertData(IAsyncResult Iar)
        {
            try
            {
                if (!Client.Connected)
                {
                    Connected = false;
                    return;
                }

                int Recevied = Client.EndReceive(Iar);
                if (Recevied > 0)
                {
                    if (BufferRecevied == false)
                    {
                        MS.Write(Buffer, 0, Recevied);
                        Buffersize = BitConverter.ToInt32(MS.ToArray(), 0);
                        Debug.WriteLine("/// Client Buffersize " + Buffersize.ToString() + " Bytes  ///");
                        MS.Dispose();
                        MS = new MemoryStream();
                        if (Buffersize > 0)
                        {
                            Buffer         = new byte[Buffersize];
                            BufferRecevied = true;
                        }
                    }
                    else
                    {
                        MS.Write(Buffer, 0, Recevied);
                        if (MS.Length == Buffersize)
                        {
                            ThreadPool.QueueUserWorkItem(HandlePacket.Read, Settings.aes256.Decrypt(MS.ToArray()));
                            Buffer = new byte[4];
                            MS.Dispose();
                            MS             = new MemoryStream();
                            BufferRecevied = false;
                        }
                        else
                        {
                            Buffer = new byte[Buffersize - MS.Length];
                        }
                    }
                    Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null);
                }
                else
                {
                    Connected = false;
                    return;
                }
            }
            catch
            {
                Connected = false;
                return;
            }
        }
Ejemplo n.º 7
0
        public void ExtractSiteModelFile(string fileName, FileSystemStreamType streamType)
        {
            var readResult = _siteModel.PrimaryStorageProxy.ReadStreamFromPersistentStore(_siteModel.ID, fileName, streamType, out var MS);

            if (readResult != FileSystemErrorStatus.OK || MS == null)
            {
                Log.LogInformation($"Failed to read file {fileName} of type {streamType}, (readResult = {readResult}), or stream is null");
                Console.WriteLine($"Failed to read file {fileName} of type {streamType}, (readResult = {readResult}), or stream is null");
                Console.WriteLine($"Failed to read existence map (readResult = {readResult}), or stream is null");
            }
            else
            {
                using (MS)
                {
                    var basePath = Path.Combine(_projectOutputPath);
                    Directory.CreateDirectory(basePath);

                    File.WriteAllBytes(Path.Combine(basePath, fileName), MS.ToArray());
                }
            }
        }
Ejemplo n.º 8
0
        public async void ReadClientData(IAsyncResult ar)
        {
            try
            {
                if (!Client.Connected)
                {
                    Disconnected();
                }
                else
                {
                    int Recevied = Client.EndReceive(ar);
                    if (Recevied > 0)
                    {
                        if (BufferRecevied == false)
                        {
                            if (Buffer[0] == 0)
                            {
                                Buffersize = Convert.ToInt64(Encoding.UTF8.GetString(MS.ToArray()));
                                MS.Dispose();
                                MS = new MemoryStream();
                                if (Buffersize > 0)
                                {
                                    Buffer         = new byte[Buffersize - 1];
                                    BufferRecevied = true;
                                }
                            }
                            else
                            {
                                await MS.WriteAsync(Buffer, 0, Buffer.Length);
                            }
                        }
                        else
                        {
                            await MS.WriteAsync(Buffer, 0, Recevied);

                            if (MS.Length == Buffersize)
                            {
                                // Read.BeginInvoke(this, MS.ToArray(), null, null);
                                await Task.Run(() =>
                                {
                                    HandlePacket.Read(this, MS.ToArray());
                                    Settings.Received += MS.ToArray().Length;
                                    Buffer             = new byte[1];
                                    Buffersize         = 0;
                                    MS.Dispose();
                                    MS             = new MemoryStream();
                                    BufferRecevied = false;
                                });
                            }
                            else
                            {
                                Buffer = new byte[Buffersize - MS.Length];
                            }
                        }
                        Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadClientData, null);
                    }
                    else
                    {
                        Disconnected();
                    }
                }
            }
            catch
            {
                Disconnected();
            }
        }
Ejemplo n.º 9
0
        /// get the length of the buffer by reading byte by byte [1]
        /// until we get the full size.
        public static void ReadServertData(IAsyncResult ar)
        {
            try
            {
                if (Client.Connected == false)
                {
                    Reconnect();
                    return;
                }

                int Recevied = Client.EndReceive(ar);

                if (Recevied > 0)
                {
                    if (BufferRecevied == false)
                    {
                        if (Buffer[0] == 0)
                        {
                            Buffersize = Convert.ToInt64(Encoding.UTF8.GetString(MS.ToArray()));
                            Debug.WriteLine("///  Buffersize: " + Buffersize.ToString() + "Bytes  ///");
                            MS.Dispose();
                            MS = new MemoryStream();
                            if (Buffersize > 0)
                            {
                                Buffer         = new byte[Buffersize - 1];
                                BufferRecevied = true;
                            }
                        }
                        else
                        {
                            MS.Write(Buffer, 0, Buffer.Length);
                        }
                    }
                    else
                    {
                        MS.Write(Buffer, 0, Recevied);
                        if (MS.Length == Buffersize)
                        {
                            ThreadPool.QueueUserWorkItem(HandlePacket.Read, MS.ToArray());
                            MS.Dispose();
                            MS             = new MemoryStream();
                            Buffer         = new byte[1];
                            Buffersize     = 0;
                            BufferRecevied = false;
                        }
                        else
                        {
                            Buffer = new byte[Buffersize - MS.Length];
                        }
                    }
                    Client.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, ReadServertData, null);
                }
                else
                {
                    Reconnect();
                }
            }
            catch
            {
                Reconnect();
            }
        }
Ejemplo n.º 10
0
        public void ExtractSpatialData()
        {
            //  overallMap.ScanAllSetBitsAsSubGridAddresses(address => subGridGrouper.IntegrateSubGridGroup(result.ConstructPathToCell(address.X, address.Y, SubGridPathConstructionType.CreateLeaf) as IServerLeafSubGrid));

            // First write out the subGrid directory stream

            var basePath = Path.Combine(_projectOutputPath, "Spatial");

            Directory.CreateDirectory(basePath);

            _siteModel.ExistenceMap.ScanAllSetBitsAsSubGridAddresses(address =>
            {
                var fileName = ServerSubGridTree.GetLeafSubGridFullFileName(address);
                var FSError  = _siteModel.PrimaryStorageProxy.ReadSpatialStreamFromPersistentStore(_siteModel.ID, fileName, address.X, address.Y, -1, -1, 1,
                                                                                                   FileSystemStreamType.SubGridDirectory, out var MS);

                if (FSError != FileSystemErrorStatus.OK || MS == null)
                {
                    Log.LogError($"Failed to read directory stream for {fileName} with error {FSError}, or read stream is null");
                    Console.WriteLine($"Failed to read directory stream for {fileName} with error {FSError}, or read stream is null");
                    return;
                }

                using (MS)
                {
                    File.WriteAllBytes(Path.Combine(basePath, fileName), MS.ToArray());

                    // Write out all segment streams for the subGrid

                    using (var subGrid = new ServerSubGridTreeLeaf())
                    {
                        subGrid.SetIsMutable(true);

                        MS.Position = 0;
                        if (subGrid.LoadDirectoryFromStream(MS))
                        {
                            subGrid.Directory.SegmentDirectory.ForEach(segment =>
                            {
                                var segmentFileName = segment.FileName(address.X, address.Y);
                                var FSErrorSegment  = _siteModel.PrimaryStorageProxy.ReadSpatialStreamFromPersistentStore
                                                          (_siteModel.ID, segmentFileName, address.X, address.Y, segment.StartTime.Ticks, segment.EndTime.Ticks, segment.Version,
                                                          FileSystemStreamType.SubGridDirectory, out var MSSegment);

                                if (FSErrorSegment != FileSystemErrorStatus.OK)
                                {
                                    Log.LogError($"Failed to read segment stream for {segmentFileName} with error {FSErrorSegment}");
                                    Console.WriteLine($"Failed to read segment stream for {segmentFileName} with error {FSErrorSegment}");
                                    return;
                                }

                                using (MSSegment)
                                {
                                    File.WriteAllBytes(Path.Combine(basePath, segmentFileName), MSSegment.ToArray());
                                }
                            });
                        }
                        else
                        {
                            Log.LogError($"Failed to read directory stream for {fileName}");
                        }
                    }
                }
            });
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
#if DEBUG
            args = new string[]
            {
                @"C:\Users\AyrA\Desktop\rnd\rnd_*.bin",
                @"C:\Users\AyrA\Desktop\rnd\_test.rnd"
            };
            long start = DateTime.Now.Ticks;
#endif
            if (args.Length > 1)
            {
                List <string> Source = new List <string>();
                string        Dest   = args[args.Length - 1];
                for (int i = 0; i < args.Length - 1; i++)
                {
                    if (args[i].Contains("?") || args[i].Contains("*"))
                    {
                        int len = Source.Count;
                        Source.AddRange(MaskMatch.Match(args[i], MatchType.File));
                        if (len == Source.Count)
                        {
                            Console.Error.WriteLine("Mask yielded 0 rresults: {0}", args[i]);
                            return;
                        }
                    }
                    else
                    {
                        if (File.Exists(args[i]))
                        {
                            Source.Add(args[i]);
                        }
                        else
                        {
                            Console.Error.WriteLine("Input file not found: {0}", args[i]);
                            return;
                        }
                    }
                }
                if (File.Exists(Dest))
                {
                    File.Delete(Dest);
                }
                foreach (string F in Source)
                {
                    if (!File.Exists(F))
                    {
                        Console.Error.WriteLine("Input file not found: {0}", F);
                    }
                }
                using (FileStream FS = File.Create(Dest))
                {
                    MemoryStream MS = new MemoryStream();
                    foreach (string F in Source)
                    {
                        Console.Error.WriteLine("{0} [READ]", F);
                        byte[] B = File.ReadAllBytes(F);

                        //if Position==0, do not copy but wait one more turn
                        if (MS.Position + B.Length > MAXLEN && MS.Position > 0)
                        {
                            Console.Error.WriteLine("Flushing buffer [WRITE]");
                            FS.Write(MS.ToArray(), 0, (int)MS.Position);
                            MS.Dispose();
                            MS = new MemoryStream();
                        }
                        MS.Write(B, 0, B.Length);
                    }
                    Console.Error.WriteLine("Flushing buffer [WRITE]");
                    FS.Write(MS.ToArray(), 0, (int)MS.Position);
                    MS.Dispose();
                    Console.Error.WriteLine("[DONE]");
                }
            }
#if DEBUG
            long end = DateTime.Now.Ticks;
            Console.Error.WriteLine("Execution time: {0:0.00} Seconds", new TimeSpan(end - start).TotalSeconds);
            Console.Error.WriteLine("#END");
            Console.ReadKey(true);
#endif
        }