Line prefixer suffixer in C#

I extracted a lot of Ids from a database table and needed to pass such Ids as a parameter to a webservice method. The webservice method was expecting a parameter of type List<long>. I didn’t find a way of passing such a list to the webservice using the built in webservice form constructed by Visual Studio. The cause is that a List<long> isn’t a primitive type.

Talking with my peers I learned of a tool called soapUI. It’s a tool used to test webservices. Using it I could pass the list of Ids.

I created a new project in soapUI passing to it the webservice WSDL URL and I was ready to go.

 soapUI New Project

New soapUI Project

This is the value I’ve put in Initial WSDL/WADL:

http://localhost:7777/WebServices/MyWebserviceName.asmx?WSDL

After clicking OK, soapUI will then load the webservice definition.

Clicking in Request 1 as shown in the following picture, the XML of a SOAP envelope appears so that we can test the webservice method.

soapUI Request 1

The problem now was that I had a file called “input.txt” with only the Ids – each one in its proper line. The XML of the SOAP envelope expect that each id be passed in the format:

<ns:long>?</ns:long>

For example,

<ns:long>7</ns:long>

As we can observe, my input data don’t fit the pattern required by the XML.

To put my data in conformity with the XML I created a small but useful application called LinePrefixerSuffixer that receives the name of an input file containing the the initial data, the text to be “prefixed” in the start of each line, the text to be “suffixed” in the end of each line of the file and the name of the output file.

So for example, to comply with the above pattern, I’d call the console application with:

LinePrefixerSuffixer input.txt “<ns:long>” “</ns:long>” output.txt

Let’s say I have a file called input.txt with 1000 numbers in the same directory of the LinePrefixerSuffixer.exe executable.

Each line of the input.txt file has a number as:

1
2
3
4
5
6
7
.
.
.

Running the above command line in the command prompt I’d get a file called output.txt with each line now in the format I want, that is:

<ns:long>1</ns:long>
<ns:long>2</ns:long>
<ns:long>3</ns:long>
<ns:long>4</ns:long>
<ns:long>5</ns:long>
<ns:long>6</ns:long>
<ns:long>7</ns:long>
. 
. 
.

Line Prefixer Suffixer

The C# code of the app is as follow:

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace LinePrefixerSuffixer
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Read in all lines of the file using query expression (LINQ).
                // I "prefix" the start of each line with the content of args[1] and
                // "suffix" the end of each line with the content of args[2].
                IEnumerable<string> fileLines = from line in File.ReadAllLines(args[0])
                                                select args[1] + line + args[2];

                // Writing the prefixed and suffixed file lines to a file named with the content of args[3].
                File.WriteAllLines(args[3], fileLines.ToArray());

                Console.WriteLine("Operation done.");
            }
            catch(Exception e)
            {
                Console.WriteLine("Use: LinePrefixerSuffixer <input.txt> prefix suffix <output.txt>");
            }
        }
    }
}

Now I can pass the content of the output.txt file to soapUI without worrying about having to manually prefix/suffix each line of my input.txt file:

soapUI Request 1

Summary
In this post we saw how to build a simple but powerful application that prefixes and suffixes each line of a file.

We’ve used concepts related to file handling and LINQ and with only 4 lines of code we could manage to accomplish the task.

I think this shows how powerful modern programming languages as C# enables a clean and beautiful coding experience.

Hope this helps.

Visual Studio C# Console Application
You can get the Microsoft Visual Studio Project and the app executable at:

http://leniel.googlepages.com/LinePrefixerSuffixer.zip

Note: As this program uses LINQ, you must have Microsoft .NET Framework 3.5 runtime libraries installed on you computer. You can get it at:

http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&DisplayLang=en

References
[1] soapUI - the Web Services Testing tool. Available at <http://www.soapui.org>. Accessed on January 20, 2009.

[2] Sam Allen. File Handling - C#. Available at <http://dotnetperls.com/Content/File-Handling.aspx>. Accessed on January 20, 2009.

[3] LINQ. The LINQ Project. Available at <http://msdn.microsoft.com/en-us/netframework/aa904594.aspx>. Accessed on January 20, 2008.

[4] LINQ. Language Integrated Query. Available at <http://www.leniel.net/2008/01/linq-language-integrated-query.html>. Accessed on January 20, 2008.

Chemtech compliments newly graduated engineers

Last Friday, January 16th, I was complimented by Chemtech. The company gave compliments to all employees that finished their college course in 2007/2008.

Chemtech compliments engineers 
The computer engineers including me beside Rubião from right to left.

We got together at the 23rd floor of Rio de Janeiro’s office where Luiz Eduardo Ganem Rubião (CEO and founder of Chemtech) talked a little bit about the company’s perspectives giving us some insight related to life, economy, the job market and ongoing and future projects.

The way Rubião thinks about life subjects, mainly being an optimist is how I face the day to day. There’s no time to be wasted with illusions and we should always think positive. Doing so we’ll for sure harvest good fruits.

The following is the transcription of the letter I received with a present (a book of my area of specialization - computer engineering) …

Rio de Janeiro, January 16th, 2009

Dear Leniel Braz de Oliveira Macaferi,

Young people like you represent the future of technology. With your know how you can contribute to Brazil’s development so that it stands out in the worldwide technology. It is in the knowledge, in technology that a differential arises.

Chemtech is proud to have been with you in your first steps to engineering and for us still being together. It’s with satisfaction that today we call you an engineer! A Chemtecheano engineer, a Brazilian engineer.

We’re together in this journey that starts with your graduation. Success!

A strong hug from the Chemtech family.

NHibernate Query Analyzer + ActiveRecord

It's been a long time since I last posted something.

My work at Chemtech is really motivating and is keeping me busy. Well, I think this is good because I really like to work and while I help my team building new projects, we as a group contribute in some way to the world.

Each day I learn new things and the tip I want to pass ahead is related to a new tool I knew a few days ago. It's called NHibernate Query Analyzer. NHQA helps a lot while working in a project with a relational database that makes use of NHibernate as the persistence manager.

I was having a problem getting NHQA to work with a business data layer constructed with the help of ActiveRecord - I searched the Internet for a path that would led me in the right direction and after solving small errors I got NHQA working with a proper configuration file. Below I post the content of the file so that you can get a sense of what must be done with the initial configuration of NHQA:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <configSections>
    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" ></section>
  </configSections>

  <activerecord>
    <config>
      <add key="hibernate.show_sql" value="true" />

      <add key="hibernate.connection.driver_class" value="NHibernate.Driver.OracleClientDriver" />

      <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />

      <add key="hibernate.dialect" value="NHibernate.Dialect.OracleDialect" />

      <add key="hibernate.connection.connection_string" value="Data Source=YOUR DATA SOURCE;User ID=YOUR USER ID;Password=YOUR PASSWORD;" />
    </config>
  </activerecord>

</configuration>

See a screenshot of NHQA with a business data layer DLL plus the app.config file:

NHQAMainForm

To get it going, just hit the Build Project button and once it’s built, just open a new Query (ctrl + Q) and start visualizing the SQL generated from the Hibernate Query Language (HQL) you type. Besides this great feature you can also view the results from an HQL query in both tabular and object graph formats.

Get a copy of the app.config file here.

Hope this helps.

Arriving at Chemtech

chemtechlogoIt's with great pleasure that I'm writing this post. I finally got a job after 5 months of eager expectation. I'm going to work at Chemtech.

I've been sending lots of resumes to almost all IT related companies from Brazil and to some international companies since I got out of ITA-Petrobras.

Fortunately, on July 10 I received an e-mail from Chemtech asking for my grade transcripts related to the computer engineering course. I then sent the transcripts to them on July 30. On August 28 I was invited to participate in a in house interview that would take place the next day. On August 29 I went to Rio de Janeiro. During the interview conducted by two managers and one software developer, a job proposal for a Junior Analyst position was made and I accepted. The area of specialty is computer engineering.

I dreamed about getting a job in a top technology company. From the moment I began the Computer Engineering course in 2003 my constant thought has been to get a position in a company that is attractive.

Today what was a dream is now pure reality.

I'm extremely motivated to be a part of the Chemtech team!

I thank Jesus Christ for helping me to achieve this goal. After all, it's for Him that I live! :)

Systems Analyst job interview at Oi

On Tuesday, July 8, I went to Praia de Botafogo in Rio de Janeiro to take part in a job interview scheduled for 2:00 P.M. I arrived there 1:45 P.M. During the trip (2 hours) the bus got backed up because there were some construction being carried out at Via Dutra highway. I thought I wouldn't get there on time, but fortunately everything went OK.

As I mentioned in the post Network Analyst job interview at Oi, I participated in the first interview for a Network Analyst position.

On Monday, June 30, I got a phone call from Oi's HR department offering me an interview for a Systems Analyst position. I told the girl called Sofia that I had already participated in an interview there and that I'd like to know the feedback first so that I could decide if I wanted to go for a second interview this time regarding a different position. She then told me that the systems analyst position would better fit my skills and that I would work directly in the IT department. The department is responsible for the development and improvement of the tools. She asked me a few questions (technical skills) and said I wouldn't need to go for the first interview again with the HR department. The most intriguing question she asked was: How much do you wanna earn? I answered that this question is a filter and that if I said a high value they wouldn't let me go ahead in the recruiting process. She then took the time to say to me how much Oi could pay me (she said she was opening an exception for telling me the value they could pay). I then agreed with the value since the wage plus the benefits would sum a great amount for someone who is just beginning his professional life. Sofia said that she would forward my name for the second round of interviews (the whole process is comprised of 3 interviews). This second interview is the one that would assess my technical skills. I asked when would this interview take place. She answered that there was no scheduled time.

On Monday, July 7, I got a phone call from the manager of the area I would work for. He is called Juscelino. I was being called for an interview on the next day.

I was interviewed by three guys. The other two are professionals already working on the IT department. Juscelino conducted the interview. I was asked about how I started my career in the IT area. I told the complete story starting in August 1997 when I first got a computer then passing to the computer technician course from 1999 to 2002 and then the computer engineering course from 2003 to 2007. He asked some questions about my experience on the previous jobs I had and other questions related to technical skills such as object oriented programming, databases, UML, etc. The focus on this job will be PHP + MySQL. One thing that I emphasized is that if you know well one programming language and a database technology it gets easy to learn a new one, that is, you already know the basic concepts and that the rest of the work is to manage to learn the intrinsic syntax of the different programming language or database technology. At the end Juscelino asked me if I had any doubts regarding the technical details of the job. I said no. Then they asked me non technical questions as: What's your hobby?, Where do you see yourself in the future? Things like that. Juscelino ended the interview and said or no (I don't remember exactly) that I would be contacted for the last interview. While I was heading to the exit door he said: we'll talk more latter. I think this is a good signal. The interview lasted only 15-20 minutes.

Let's see what happens next. If it happens I'll post here some notes about the third part of the interview process.

Nanotechnology and the future of technology

Nanotech Nanotechnology refers to a field of applied science and technology whose theme is the control of matter on the atomic and molecular scale, generally 100 nanometers (billionths of meters) or smaller, and the fabrication of devices or materials that lie within that size range. Is any technology that is based on the placement or manipulation of single atoms.

Many innovations will come to light, which will make extensive use of nanotechnology. We know little about the natural phenomena that are surrounding us. In truth everything is already made and is near us, but we just can’t see because we need in the course of time develop our science and create new tools that will make us capable of discovering new chemical elements.

There is a famous maxim from French chemist Lavoisier that is:
In nature nothing is lost, nothing is created, everything is transformed.


We are in a constant process of evolution and development.

With the discovering of new chemical elements and inherent natural phenomena, we’ll be capable of creating new types of materials what on the other hand will bring over more and more discoveries. Discoveries lead to innovations.

If we think that we are working with minuscule particles and that the smaller particle hasn’t been discovered yet, we can assert that we have a lot to learn. In truth it wasn’t long since that the first chemical elements were discovered.

Now it’s interesting to catch sight of how many nice opportunities there are to use nanotechnology. As an example: the manufacturing process of computer processors. I just can’t wait to have a super fast computer. To that end it’s necessary that nanotechnology evolves. For a faster processor it is necessary that billions of small electrical components called transistors be placed in a microchip. The smaller the transistors the greater amount of them can be put in a single chip. There’s a law specific to this subject called Moore's law.

New techniques can also be applied in the medicine field with the development of robots invisible to the human eyes that can flow within the human body fighting against all sorts of diseases.

At last, nanotechnology is a really important and promising technology and I expect that it evolves rapidly for the sake of men’s well being of course because other forms of use also exists. I won’t comment about them here. I think that the reader caught what I want to express with this. If not, try to remember about war technologies.

I can foresee that in a time period of 40 years (approximately 2050) we’ll be in a new baseline and nanotechnology will be a completely forgotten technology. As a matter of fact, it always happens with technologies.

As of the date of this post we already have 11 nanometers technology. For comparison, the processor Intel Core Duo that is the one I use today is manufactured with a 65 nanometers technology.

Petrobras 2008 public contest - Junior System Analyst

On June 7 I went to Rio de Janeiro to take a test on the next day regarding a public contest where I was disputing one of 36 vacancies for a Junior Systems Analyst - Infrastructure position at Petrobras.

The test started at 9:00 A.M. and ended at 1:00 P.M and took place at Estácio de Sá university - Campus Uruguaiana at Presidente Vargas Avenue that is located downtown. I stayed at a hotel called Planalto. It is located near the place where I did the test.

Petrobras is one of the major companies of the world. As of May 19, Petrobras became the world's sixth-largest company by market value. Its market value was $295.6 billion. Microsoft for example has a market value of $274.0 billion. You can see more details reading this new at Bloomberg site: Petrobras Tops Microsoft, Is Sixth-Biggest Company.

Petrobras's field of operation has a high demand because its principal product is petroleum. Yesterday the oil barrel achieved the highest price in history as can be read in Oil sets record above $140 a barrel on supply concerns.

Getting back to the public contest. Petrobras's test is in my humble opinion one of the hardest ones in Brazil in my area of specialization. Maybe it is the hardest one. :-) This was the second time that I participated in such public contests.

An organizing institution is responsible for the test creation and collection of the registration tax. The organizing institution responsible for the first test I did in 2007 was CESPE and this time the organizing institution was CESGRANRIO. I had to pay R$ 40,00 Brazilian Reais that is approximately $ 25,00 for the registration tax. I'm considering $1 dollar = R$ 1.60 as of the date of this post.

The test was comprised of 70 questions in the multiple choice form. From these 20 questions were about basic knowledge (BK) (10 Portuguese questions and 10 English questions). The other 50 questions were about specific knowledge (SK) related to system analysis - infrastructure.

The content that should be studied is described in the following table:

Computer Network and Distributed Systems Computer Network Architectures
Topologies
Connection and Transmission devices
QOS
ISO OSI model
TCP/IP Architecture and Protocols
TCP/IP Application layer: DNS, FTP, NFS, TELNET, SMTP, HTTP, LDAP, DHCP, IPSEC, SSH, SNMP and NAT
Basic notions about IPv6
Storage concepts (NAS and SAN)
UNIX Environment Installation and support to TCP/IP, DHCP, DNS, NIS, CIFS, NFS, network printing services
Installation and configuration of Apache server
Integration with Windows environment
Script languages
Microsoft Windows 2000/2003 environment Installation and support to TCP/IP, DHCP, DNS
Active Directory, IIS, Terminal Service
File services and network printing
Integration with Unix environment
Script languages
Information Security Physical and logical security
Firewall and proxies
Cryptography
VPN
Malicious software (Virus, Spywares, Rootkit, etc)
Intrusion detection systems
Computer Architecture and High Performance Computing HPC RISC and CISC architectures
Processor organization
Memory organization
Concurrency concepts, parallelism and distributed computing
Flynn taxonomy
Distributed systems architecture: SMP and MPP
Basic concepts about agglomerate computing (Cluster) and grid computing (Grids)
Load balancing
Performance profiling
Project Management Basic concepts
Resources allocation
Chronogram;
Analytical structure
Operating Systems OS structure
Processor management
Memory management
File systems
Input and Output
Basic concepts about compilers
RAID
Databases Data independency
Relational approach
entity-relationship approach
Triggers and Stored Procedures
SQL language
High availability concepts
Transactions management
Locks management
Performance management
Programming Algorithms and data structures
Java code debugging
Notions about Software Engineering
Markup languages: HTML and XML
Notions about Java programming (JEE, Servelets, JSP and EJB)
IT Service Management Concepts about the ITIL® library: Support and service delivery
COBIT processes domain
Logical Reasoning Sentential and first order logic
Enumeration by resources
Counting: Additive and multiplicative principles
Information Security Management General concepts
Information security policies
Information classification
Norm ISO 27001:2005

The questions were graded according to the following table:

Portuguese language English language Specific knowledge
Question Points Question Points Question Points
1 to 10 1.0 11 to 20 1.0 21 to 30 1.0
        31 to 40 1.3
        41 to 50 1.6
        51 to 60 1.9
        61 to 70 2.2

Despite the difficulty I think I performed well if I take into account that this was my second try.

Today I got the final result and my final grades were:

Basic Knowledge = 15 points = 75% of BK test.

I needed 12 points = 60% of BK test.

Specific Knowledge = 41.3 points = 51.63% of SK test.

I needed 48 points = 60% of SK test.

Result = BK + SK = 15 + 41.3 = 56.3 points

48 - 41.3 = 6.7 points to pass in the specific knowledge test.

Bellow I show the grades obtained by the candidates that passed the public contest:

Specific Knowledge test grade Classification
61.5 1
61.4 2
61.2 3
59.6 4
56.4 5
55.8 6
55.6 7
54.8 8
54.5 9
54.2 10
54.1 11
54.0 12
53.8 13
52.6 14
52.1 15
51.8 16
51.4 17
51.2 18
50.9 19
50.7 20
50.7 21
50.7 22
50.7 23
50.6 24
50.5 25
50.1 26
50.1 27
50.0 28
50.0 29
49.9 30
49.9 31
49.6 32
49.6 33
49.5 34
49.5 35
49.4 36
49.3 37
49.2 38
49.2 39
49.2 40
49.1 41
49.1 42
48.8 43
48.7 44
48.7 45
48.7 46
48.7 47
48.7 48
48.5 49
48.4 50
48.4 51
48.3 52
48.1 53
48.1 54
48.0 55
48.0 56

I almost got there. For a difference of 6.7 points I didn't pass the specific knowledge test, but I'm happy with my accomplishment. I'm a young guy and for sure if it is God's will I'll get there in the future. I'll keep studying. That's really necessary!

There are lots of public contests happening every year and not only related to Petrobras.

Some interesting facts about this public contest:

There were 5866 candidates disputing 36 vacancies for this specific role within Petrobras.

Candidate/vacancy relation = 163

Only 56 candidates were approved = 0.96% of candidates. Practically 1%.

Total collected with the registration tax money = R$ 40,00 * 5866 = R$ 234.540,00 =
$ 146.587,00.

Just to close this post - you may ask: Why someone would dispute a so wanted vacancy? The answer is easy: Petrobras pays a worthy salary, for example for this specific position (Junior System Analyst) the salary value is R$4.798,64 = $ 2998.75. Here in Brazil this is a good value for someone who is beginning his career. Besides that the company has many advantages (salary bonus, paid courses, health plan, etc) if compared with others. Generally who gets a job through a public contest will end their career in the company they took a test for. It is a permanent job.

As you see only the ones that study hard get a job at such companies and such companies have the best committed employees.