Post #1

Let’s start this brand new project with a nice post #1.! 🙂

Since my intent is to blog about creativity and the many ways you can express it, I would start with my favorite field, programming languages.

I’d like to share a C# project, a sort of  “userid-password manager”. I have been thinking about it many times, and now I got myself on it!

The following code exceprt is the main “Model” class:

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

namespace ProjectRepositoryService
{

class Service
{
private string _serviceName;
private string _serviceDescription;
private string _userID;
private string _userPwd;

public Service() { }

public Service(string nameService, string descrService = “service description”)
{
ServiceName = nameService;
}
public Service(string nameService, string userID, string userPwd)
: this(nameService)
{

UserID = userID;
UserPassword = userPwd;
}

public string ServiceName
{
get { return _serviceName; }
set
{

if (value == null)
{
throw new ArgumentNullException();
}
else
{

value = value.Trim();
if (value.Equals(“”))
{
throw new ArgumentException(“Service name cannot be blank”);

}
else
{
_serviceName = value;
}

}

}
}

public string ServiceDescription
{
get { return _serviceDescription; }

set { _serviceDescription = value; }

}

public string UserID
{
get { return _userID; }
set
{
if (value == null)
{
throw new ArgumentNullException();
}
else
{

value = value.Trim();
if (value.Equals(“”))
{
throw new ArgumentException(“User id cannot be blank”);

}
else
{
_userID = value;
}

}

}
}

public string UserPassword
{
get { return _userPwd; }

set
{
if (value == null)
{
throw new ArgumentNullException();
}
else
{

value = value.Trim();
if (value.Equals(“”))
{
throw new ArgumentException(“User id cannot be blank”);

}
else
{
_userPwd = value;
}

}

}
}
}

class DataStorage
{

private const string storeFileName=”c:\\service.dat”;

public static void Store(Service service)
{
//recupera i dati da un file

try
{

FileStream io = new FileStream(storeFileName,FileMode.Append);
StreamWriter writer = new StreamWriter(io);
writer.WriteLine(service.ServiceName);
writer.WriteLine(service.ServiceDescription);
writer.WriteLine(service.UserID);
writer.WriteLine(service.UserPassword);
writer.Close();

}
catch (System.NotSupportedException e)
{

throw;
}catch(Exception e){
throw;

} finally{

}

}

public static Service Load(string path)
{
Service service = new Service();

return service;
}

public static ListLoadLista(string path)
{
List lista = new List();

return lista;
}
}
}

As you can see it,I’m still working on it !) New methods soon to come and to implement!

Advertisements

Tags:

About ualentina

Shuffles bits back and forth, interested in fashion design and creativity

One response to “Post #1”

  1. Mr WordPress says :

    Hi, this is a comment.
    To delete a comment, just log in, and view the posts’ comments, there you will have the option to edit or delete them.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: