Exemple #1
2
 public TCPConnection(Socket socket, bool verbose, ProcessLine processLine, Disconected onDisconnect)
 {
     Socket = socket;
     Verbose = verbose;
     OnProcessLine = processLine;
     OnDisconnect = onDisconnect;
     NotifyOnDisconnect = true;
     BeginReceive();
 }
        public void Handle(ProcessLine message)
        {
            IncrementMessagesReceived();
            var wordsInLine = message.LineToProcess.Split(' ').Length;

            Sender.Tell(new WordCount(wordsInLine));
        }
        public void Run(ProcessLine processLine)
        {
            while (!Terminate)
            {
                if (!Connected)
                {
                    Connect();
                }

                if (Connected)
                {
                    Process(processLine);
                }
                else
                if (--ConnectionAttemptsLeft <= 0)
                {
                    Terminate = true;
                }

                if (!Terminate)
                {
                    if (Verbose)
                    {
                        Console.Error.WriteLine("STATUS: Will attempt to reconnect in " + ReconnectInterval.ToString() + " seconds.");
                    }

                    Thread.Sleep(new TimeSpan(0, 0, ReconnectInterval));
                }
            }

            Disconnect();
        }
 public TCPConnection(Socket socket, bool verbose, ProcessLine processLine, Disconected onDisconnect)
 {
     Socket             = socket;
     Verbose            = verbose;
     OnProcessLine      = processLine;
     OnDisconnect       = onDisconnect;
     NotifyOnDisconnect = true;
     BeginReceive();
 }
Exemple #5
0
        /****************************************************************************/
        public void Process(ProcessLine fncProcess)
        {
            foreach (string strLine in this)
            {
                fncProcess(strLine);
            }

            return;
        }
Exemple #6
0
        /// <summary>
        /// Goes through the input file line-by-line and puts the results of the given function to the output file.
        /// </summary>
        /// <param name="processLine">A function that runs on a string and returns its results as a string</param>
        public void ProcessFile(ProcessLine processLine)
        {
            using (StreamWriter writer = new StreamWriter(_outputFile))
            {
                foreach (string line in File.ReadLines(_inputFile))
                {
                    string missingNumber = processLine(line);

                    if (!String.IsNullOrEmpty(missingNumber))
                    {
                        writer.WriteLine(missingNumber);
                    }
                }
            }
        }
        protected void Process(ProcessLine processLine)
        {
            while (Connected)
            {
                lock (this)
                {
                    processLine(GetLine());

                    if (Terminate)
                    {
                        Disconnect();
                    }

                    Monitor.Wait(this, TimeSpan.FromMilliseconds(500));
                }
            }
        }
Exemple #8
0
        private bool Iterate_File_And_Make_Changes(string path, string file, ProcessLine pl)
        {
            bool bAChangeIsMade = false;

            using (TextWriter writer = File.CreateText((path + '\\' + file + ".new")))
            {
                using (TextReader reader = File.OpenText(path + '\\' + file))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        // Make a line Change (passed by ref)
                        LineChanges change = pl(ref line);

                        if (change == LineChanges.skip)
                        {
                            bAChangeIsMade = true;
                            continue; // ignore this line
                        }
                        else if (change == LineChanges.modified)
                        {
                            bAChangeIsMade = true;
                            writer.WriteLine(line); // write the modified line to file
                        }
                        else
                        {
                            // No Change is made so just write the original line
                            writer.WriteLine(line);
                        }
                    }
                    reader.Close();
                }
                writer.Close();
            }

            if (!bAChangeIsMade)
            {
                // If there was no change made no need to keep the .new file
                File.Delete((path + '\\' + file + ".new"));
                return(false);
            }
            else
            {
                return(true); // A change was made (.new file created)
            }
        }
Exemple #9
0
 public ActionResult GetLocationHierData(string level, string id)
 {
     if (level == "BU")
     {
         BusinessUnit BU = new BusinessUnit();
         BU.BuList = new SelectList(svcDao.GetBusinessUnits(), "strBUID", "strBUID");
         return(Json(BU.BuList, JsonRequestBehavior.AllowGet));
     }
     else if (level == "Seg")
     {
         BUSegment Segment = new BUSegment
         {
             SegmentSelectList = new SelectList(svcDao.GetSegments(id), "strSegmentID", "strSegmentID")
         };
         return(Json(Segment.SegmentSelectList, JsonRequestBehavior.AllowGet));
     }
     else if (level == "Plant")
     {
         Plant Plant = new Plant();
         Plant.PlantList = new SelectList(svcDao.GetPlants(id), "intPlantID", "strPlantName");
         return(Json(Plant.PlantList, JsonRequestBehavior.AllowGet));
     }
     else if (level == "Proc")
     {
         ProcessPlant Process = new ProcessPlant();
         Process.ProcessPlantList = new SelectList(svcDao.GetProcessPlants(Convert.ToInt32(id)), "intProductID", "strProcessID");
         return(Json(Process.ProcessPlantList, JsonRequestBehavior.AllowGet));
     }
     else if (level == "Line")
     {
         ProcessLine Line = new ProcessLine();
         Line.ProcessLineList = new SelectList(svcDao.GetProcessLines(Convert.ToInt32(id)), "ProductProcessID", "strLineID");
         return(Json(Line.ProcessLineList, JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(View("PageNotFound"));
     }
 }
Exemple #10
0
        protected void Process(ProcessLine processLine)
        {
            while (Connected)
            {
                lock (this)
                {
                    processLine(GetLine());

                    if (Terminate)
                        Disconnect();

                    Monitor.Wait(this, TimeSpan.FromMilliseconds(500));
                }
            }
        }
Exemple #11
0
        public void Run(ProcessLine processLine)
        {
            while (!Terminate)
            {
                if (!Connected)
                    Connect();

                if (Connected)
                    Process(processLine);
                else
                    if (--ConnectionAttemptsLeft <= 0)
                        Terminate = true;

                if (!Terminate)
                {
                    if (Verbose)
                        Console.Error.WriteLine("STATUS: Will attempt to reconnect in " + ReconnectInterval.ToString() + " seconds.");

                    Thread.Sleep(new TimeSpan(0, 0, ReconnectInterval));
                }
            }

            Disconnect();
        }