Archivio per la categoria 'programmazione'

16
Giu

Pattern & Practices Guidance Explorer

Come ben sa chi come me frequenta assiduamente i newsgroup Microsoft e i forum su Asp.Net non è raro incontrare richieste sul modo migliore di affrontare un determinato problema. Nel processo di analisi che precede lo sviluppo di una nuova applicazione poter contare su collaudate linee guida significa partire con il piede giusto ed esporci meno a problemi futuri durante lo sviluppo o peggio in fase di test.
L’area del sito di MSDN di Microsoft, Pattern & Practices viene in aiuto degli sviluppatori in questo senso con ampia documentazione sugli scenari più vari.
Per chi può considerare utile un tool per usufruire di questa documentazione anche quando non siamo connessi a Internet:

patterns & practices Guidance Explorer

Esiste anche una versione Online per chi non vuole o non può installare software:

Guidance Explorer Web

Il tool è ben realizzato, permette la sincronizzazione per l’aggiornamento dei contenuti e numerose funzionalità di subsetting, anche se lamenta qualche difetto di progettazione dei controlli; da provare…

27
Gen

Business Logical Layer LinqToSql per la classe Scheduler

LinqToSql rappresenta una delle grandi novità del .NET Framework 3.5, e permette di mappare le tabelle dei nostri database su classi ad hoc, che VisualStudio 2008 grazie ai file .dbml genera autonomamente, le classi possono essere completate con metodi mappati su stored procedure e user function. Questo si traduce con lo sviluppo estremamente rapido delle classi intermedie di accesso ai dati e la possibilità di effettuare query, insert e update verso il database con la stessa sintassi Linq utilizzata su xml e oggetti.

Schema DB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;[System.Data.Linq.Mapping.DatabaseAttribute(Name="SchedulerDB")]
public partial class DataClassesDataContext : System.Data.Linq.DataContext
{private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();#region Extensibility Method Definitions
partial void OnCreated();
partial void InsertSchedulazioni(Schedulazioni instance);
partial void UpdateSchedulazioni(Schedulazioni instance);
partial void DeleteSchedulazioni(Schedulazioni instance);
partial void InsertUser(User instance);
partial void UpdateUser(User instance);
partial void DeleteUser(User instance);
#endregionpublic DataClassesDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["SchedulerDBConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}public DataClassesDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}public DataClassesDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}public DataClassesDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}public DataClassesDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}public System.Data.Linq.Table Schedulazionis
{
get
{
return this.GetTable();
}
}public System.Data.Linq.Table Users
{
get
{
return this.GetTable();
}
}
}[Table(Name="dbo.Schedulazioni")]
public partial class Schedulazioni : INotifyPropertyChanging, INotifyPropertyChanged
{private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);private int _IdSchedulazione;private int _IdOwner;private string _NomeSchedulazione;private System.DateTime _StartDate;
private System.DateTime _EndDate;private System.DateTime _NextDate;private int _PatternGiorni;private int _PatternSettimane;private int _PatternMesi;private int _PatternFrequenza;private string _IntestazioneMessaggio;private string _CorpoMessaggio;private System.Xml.Linq.XElement _DestinatarioMessaggio;private System.Data.Linq.Binary _AllegatoMessaggio;private EntityRef _User;#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdSchedulazioneChanging(int value);
partial void OnIdSchedulazioneChanged();
partial void OnIdOwnerChanging(int value);
partial void OnIdOwnerChanged();
partial void OnNomeSchedulazioneChanging(string value);
partial void OnNomeSchedulazioneChanged();
partial void OnStartDateChanging(System.DateTime value);
partial void OnStartDateChanged();
partial void OnEndDateChanging(System.DateTime value);
partial void OnEndDateChanged();
partial void OnNextDateChanging(System.DateTime value);
partial void OnNextDateChanged();
partial void OnPatternGiorniChanging(int value);
partial void OnPatternGiorniChanged();
partial void OnPatternSettimaneChanging(int value);
partial void OnPatternSettimaneChanged();
partial void OnPatternMesiChanging(int value);
partial void OnPatternMesiChanged();
partial void OnPatternFrequenzaChanging(int value);
partial void OnPatternFrequenzaChanged();
partial void OnIntestazioneMessaggioChanging(string value);
partial void OnIntestazioneMessaggioChanged();
partial void OnCorpoMessaggioChanging(string value);
partial void OnCorpoMessaggioChanged();
partial void OnDestinatarioMessaggioChanging(System.Xml.Linq.XElement value);
partial void OnDestinatarioMessaggioChanged();
partial void OnAllegatoMessaggioChanging(System.Data.Linq.Binary value);
partial void OnAllegatoMessaggioChanged();
#endregionpublic Schedulazioni()
{
this._User = default(EntityRef);
OnCreated();
}

[Column(Storage="_IdSchedulazione", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public int IdSchedulazione
{
get
{
return this._IdSchedulazione;
}
set
{
if ((this._IdSchedulazione != value))
{
this.OnIdSchedulazioneChanging(value);
this.SendPropertyChanging();
this._IdSchedulazione = value;
this.SendPropertyChanged(”IdSchedulazione”);
this.OnIdSchedulazioneChanged();
}
}
}

[Column(Storage="_IdOwner", DbType="Int NOT NULL")]
public int IdOwner
{
get
{
return this._IdOwner;
}
set
{
if ((this._IdOwner != value))
{
if (this._User.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnIdOwnerChanging(value);
this.SendPropertyChanging();
this._IdOwner = value;
this.SendPropertyChanged(”IdOwner”);
this.OnIdOwnerChanged();
}
}
}

[Column(Storage="_NomeSchedulazione", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string NomeSchedulazione
{
get
{
return this._NomeSchedulazione;
}
set
{
if ((this._NomeSchedulazione != value))
{
this.OnNomeSchedulazioneChanging(value);
this.SendPropertyChanging();
this._NomeSchedulazione = value;
this.SendPropertyChanged(”NomeSchedulazione”);
this.OnNomeSchedulazioneChanged();
}
}
}

[Column(Storage="_StartDate", DbType="DateTime NOT NULL")]
public System.DateTime StartDate
{
get
{
return this._StartDate;
}
set
{
if ((this._StartDate != value))
{
this.OnStartDateChanging(value);
this.SendPropertyChanging();
this._StartDate = value;
this.SendPropertyChanged(”StartDate”);
this.OnStartDateChanged();
}
}
}

[Column(Storage="_EndDate", DbType="DateTime NOT NULL")]
public System.DateTime EndDate
{
get
{
return this._EndDate;
}
set
{
if ((this._EndDate != value))
{
this.OnEndDateChanging(value);
this.SendPropertyChanging();
this._EndDate = value;
this.SendPropertyChanged(”EndDate”);
this.OnEndDateChanged();
}
}
}

[Column(Storage="_NextDate", DbType="DateTime NOT NULL")]
public System.DateTime NextDate
{
get
{
return this._NextDate;
}
set
{
if ((this._NextDate != value))
{
this.OnNextDateChanging(value);
this.SendPropertyChanging();
this._NextDate = value;
this.SendPropertyChanged(”NextDate”);
this.OnNextDateChanged();
}
}
}

[Column(Storage="_PatternGiorni", DbType="Int NOT NULL")]
public int PatternGiorni
{
get
{
return this._PatternGiorni;
}
set
{
if ((this._PatternGiorni != value))
{
this.OnPatternGiorniChanging(value);
this.SendPropertyChanging();
this._PatternGiorni = value;
this.SendPropertyChanged(”PatternGiorni”);
this.OnPatternGiorniChanged();
}
}
}

[Column(Storage="_PatternSettimane", DbType="Int NOT NULL")]
public int PatternSettimane
{
get
{
return this._PatternSettimane;
}
set
{
if ((this._PatternSettimane != value))
{
this.OnPatternSettimaneChanging(value);
this.SendPropertyChanging();
this._PatternSettimane = value;
this.SendPropertyChanged(”PatternSettimane”);
this.OnPatternSettimaneChanged();
}
}
}

[Column(Storage="_PatternMesi", DbType="Int NOT NULL")]
public int PatternMesi
{
get
{
return this._PatternMesi;
}
set
{
if ((this._PatternMesi != value))
{
this.OnPatternMesiChanging(value);
this.SendPropertyChanging();
this._PatternMesi = value;
this.SendPropertyChanged(”PatternMesi”);
this.OnPatternMesiChanged();
}
}
}

[Column(Storage="_PatternFrequenza", DbType="Int NOT NULL")]
public int PatternFrequenza
{
get
{
return this._PatternFrequenza;
}
set
{
if ((this._PatternFrequenza != value))
{
this.OnPatternFrequenzaChanging(value);
this.SendPropertyChanging();
this._PatternFrequenza = value;
this.SendPropertyChanged(”PatternFrequenza”);
this.OnPatternFrequenzaChanged();
}
}
}

[Column(Storage="_IntestazioneMessaggio", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string IntestazioneMessaggio
{
get
{
return this._IntestazioneMessaggio;
}
set
{
if ((this._IntestazioneMessaggio != value))
{
this.OnIntestazioneMessaggioChanging(value);
this.SendPropertyChanging();
this._IntestazioneMessaggio = value;
this.SendPropertyChanged(”IntestazioneMessaggio”);
this.OnIntestazioneMessaggioChanged();
}
}
}

[Column(Storage="_CorpoMessaggio", DbType="NVarChar(MAX)")]
public string CorpoMessaggio
{
get
{
return this._CorpoMessaggio;
}
set
{
if ((this._CorpoMessaggio != value))
{
this.OnCorpoMessaggioChanging(value);
this.SendPropertyChanging();
this._CorpoMessaggio = value;
this.SendPropertyChanged(”CorpoMessaggio”);
this.OnCorpoMessaggioChanged();
}
}
}

[Column(Storage="_DestinatarioMessaggio", DbType="Xml NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
public System.Xml.Linq.XElement DestinatarioMessaggio
{
get
{
return this._DestinatarioMessaggio;
}
set
{
if ((this._DestinatarioMessaggio != value))
{
this.OnDestinatarioMessaggioChanging(value);
this.SendPropertyChanging();
this._DestinatarioMessaggio = value;
this.SendPropertyChanged(”DestinatarioMessaggio”);
this.OnDestinatarioMessaggioChanged();
}
}
}

[Column(Storage="_AllegatoMessaggio", DbType="VarBinary(MAX)", CanBeNull=true, UpdateCheck=UpdateCheck.Never)]
public System.Data.Linq.Binary AllegatoMessaggio
{
get
{
return this._AllegatoMessaggio;
}
set
{
if ((this._AllegatoMessaggio != value))
{
this.OnAllegatoMessaggioChanging(value);
this.SendPropertyChanging();
this._AllegatoMessaggio = value;
this.SendPropertyChanged(”AllegatoMessaggio”);
this.OnAllegatoMessaggioChanged();
}
}
}

[Association(Name="User_Schedulazioni", Storage="_User", ThisKey="IdOwner", IsForeignKey=true)]
public User User
{
get
{
return this._User.Entity;
}
set
{
User previousValue = this._User.Entity;
if (((previousValue != value)
|| (this._User.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._User.Entity = null;
previousValue.Schedulazionis.Remove(this);
}
this._User.Entity = value;
if ((value != null))
{
value.Schedulazionis.Add(this);
this._IdOwner = value.IdUser;
}
else
{
this._IdOwner = default(int);
}
this.SendPropertyChanged(”User”);
}
}
}

public event PropertyChangingEventHandler PropertyChanging;

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}

protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}

[Table(Name="dbo.Users")]
public partial class User : INotifyPropertyChanging, INotifyPropertyChanged
{

private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

private int _IdUser;

private string _UserName;

private string _UserPassword;

private EntitySet _Schedulazionis;

#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnIdUserChanging(int value);
partial void OnIdUserChanged();
partial void OnUserNameChanging(string value);
partial void OnUserNameChanged();
partial void OnUserPasswordChanging(string value);
partial void OnUserPasswordChanged();
#endregion

public User()
{
this._Schedulazionis = new EntitySet(new Action(this.attach_Schedulazionis), new Action(this.detach_Schedulazionis));
OnCreated();
}

[Column(Storage="_IdUser", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public int IdUser
{
get
{
return this._IdUser;
}
set
{
if ((this._IdUser != value))
{
this.OnIdUserChanging(value);
this.SendPropertyChanging();
this._IdUser = value;
this.SendPropertyChanged(”IdUser”);
this.OnIdUserChanged();
}
}
}

[Column(Storage="_UserName", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string UserName
{
get
{
return this._UserName;
}
set
{
if ((this._UserName != value))
{
this.OnUserNameChanging(value);
this.SendPropertyChanging();
this._UserName = value;
this.SendPropertyChanged(”UserName”);
this.OnUserNameChanged();
}
}
}

[Column(Storage="_UserPassword", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
public string UserPassword
{
get
{
return this._UserPassword;
}
set
{
if ((this._UserPassword != value))
{
this.OnUserPasswordChanging(value);
this.SendPropertyChanging();
this._UserPassword = value;
this.SendPropertyChanged(”UserPassword”);
this.OnUserPasswordChanged();
}
}
}

[Association(Name="User_Schedulazioni", Storage="_Schedulazionis", OtherKey="IdOwner")]
public EntitySet Schedulazionis
{
get
{
return this._Schedulazionis;
}
set
{
this._Schedulazionis.Assign(value);
}
}

public event PropertyChangingEventHandler PropertyChanging;

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}

protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}

private void attach_Schedulazionis(Schedulazioni entity)
{
this.SendPropertyChanging();
entity.User = this;
}

private void detach_Schedulazionis(Schedulazioni entity)
{
this.SendPropertyChanging();
entity.User = null;
}
}

27
Gen

Una classe per schedulare la posta

Differire l’invio della posta elettronica può tornare utile in molte occasioni, può ricordarci avvenimenti ricorrenti, o evitare il congestionamento della nostra connessione Internet. La semplice classe presentata può essere utilizzata per realizzare uno schedulatore di posta per il desktop o per integrare, con i dovuti accorgimenti, un servizio di newsletter in un’applicazione web… Continua a leggere ‘Una classe per schedulare la posta’