


<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OsMeusApontamentos &#187; programação</title>
	<atom:link href="http://blog.osmeusapontamentos.com/index.php/tag/programacao/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.osmeusapontamentos.com</link>
	<description></description>
	<lastBuildDate>Wed, 01 Feb 2012 14:20:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Cloud Computing</title>
		<link>http://blog.osmeusapontamentos.com/index.php/2009/05/31/cloud-computing/</link>
		<comments>http://blog.osmeusapontamentos.com/index.php/2009/05/31/cloud-computing/#comments</comments>
		<pubDate>Sun, 31 May 2009 10:00:21 +0000</pubDate>
		<dc:creator>vitorsilva</dc:creator>
				<category><![CDATA[ler/ ver/ ouvir/ passear]]></category>
		<category><![CDATA[cloud computing]]></category>
		<category><![CDATA[programação]]></category>

		<guid isPermaLink="false">http://blog.osmeusapontamentos.com/?p=1482</guid>
		<description><![CDATA[Algumas definições retiradas do artigo Above the Clouds: A Berkeley View of Cloud Computing &#8220;Cloud Computing refers to both the applications delivered as services over the Internet and the hardware and systems software in the datacenters that provide those services.&#8221; &#8220;The services themselves have long been referred to as Software as a Service (SaaS).&#8221; &#8220;The [...]]]></description>
			<content:encoded><![CDATA[<p>Algumas definições retiradas do artigo <a href="http://d1smfj0g31qzek.cloudfront.net/abovetheclouds.pdf">Above the Clouds: A Berkeley View of Cloud Computing</a></p>
<p>&#8220;<strong>Cloud Computing</strong> refers to both the applications delivered as services over the Internet and the hardware and systems software in the datacenters that provide those services.&#8221;</p>
<p>&#8220;The services themselves have long been referred to as <strong>Software as a Service (SaaS)</strong>.&#8221;</p>
<p>&#8220;The datacenter hardware and software is what we will call a <strong>Cloud</strong>.&#8221;</p>
<p>&#8220;When a Cloud is made available in a pay-as-you-go manner to the general public, we call it a <strong>Public Cloud</strong>; the service being sold is <strong>Utility Computing</strong>.&#8221;</p>
<p>&#8220;We use the term <strong>Private Cloud</strong> to refer to internal datacenters of a business or other organization, not made available to the general public.&#8221;</p>
<p>&#8220;Thus, Cloud Computing is the sum of SaaS and Utility Computing, but does not include Private Clouds. People can be users or providers of SaaS, or users or providers of Utility Computing.&#8221;</p>
<p>&#8220;<strong>When is Utility Computing preferable to running a Private Cloud</strong>? A first case is when demand for a service varies with time. (&#8230;)A second case is when demand is unknown in advance.&#8221;</p>
<p>&#8220;<strong>Amazon EC2</strong> is at one end of the spectrum. An EC2 instance looks much like physical hardware, and users can control nearly the entire software stack, from the kernel upwards. This low level makes it inherently difficult for Amazon to offer automatic scalability and failover&#8221;</p>
<p>&#8220;At the other extreme of the spectrum are application domainspecific platforms such as <strong>Google AppEngine</strong>. AppEngine is targeted exclusively at traditional web applications, enforcing an application structure of clean separation between a stateless computation tier and a stateful storage tier.&#8221;</p>
<p>&#8220;Applications for <strong>Microsoft’s Azure</strong> are written using the .NET libraries, and compiled to the Common Language Runtime, a language-independent managed environment. Thus, Azure is intermediate between application frameworks like AppEngine and hardware virtual machines like EC2.&#8221;</p>
<p>Oportunidades na utilização de uma infraestrutura de cloud computing</p>
<ul>
<li>Mobile interactive applications</li>
<li>Parallel batch processing.</li>
<li>The rise of analytics.</li>
<li>Extension of compute-intensive desktop applications.</li>
<li>“Earthbound” applications.</li>
</ul>
<p>Para além destas definições são apresentados também alguns indicadores para avaliar até que ponto pode ser interessante passar para uma infraestrutura de cloud computing, quais os custos operacionais e principais obstáculos previsiveis internos e externos como por exemplo a questão de &#8220;Data Lock-in&#8221;.</p>
<p>Um ponto que é importante considerar tem a ver com a transferência de grandes volumes de dados e os problemas / custos que podem aparecer quando começamos a pensar em muitos gigas ou terabytes de informação. &#8220;Jim Gray found that the cheapest<br />
way to send a lot of data is to physically send disks or even whole computers via overnight delivery services (A conversation with Jim Gray. ACM Queue 1, 4 (2003), 8–17.)&#8221;</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.osmeusapontamentos.com/index.php/2009/05/31/cloud-computing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Foreign Keys com SMO #2</title>
		<link>http://blog.osmeusapontamentos.com/index.php/2009/02/13/foreign-keys-com-smo-2/</link>
		<comments>http://blog.osmeusapontamentos.com/index.php/2009/02/13/foreign-keys-com-smo-2/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 19:32:52 +0000</pubDate>
		<dc:creator>vitorsilva</dc:creator>
				<category><![CDATA[ler/ ver/ ouvir/ passear]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[smo]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.osmeusapontamentos.com/?p=1260</guid>
		<description><![CDATA[Objectivo: Determinar o nome da tabela que está a ser referenciada a partir de uma chave externa Ferramentas: SQL Server Management Objects (SMO) Principais objectos e propriedades: Table, Table.ForeignKeys, Column, ForeignKey, ForeignKeyColumn Notas: chave primária e foreign key não composta &#160; Código private static string GetReferencedKeyColumnName(Database database, Table table, Column column) { Column c2 = [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Objectivo</strong>: Determinar o nome da tabela que está a ser referenciada a partir de uma chave externa<br />
<strong>Ferramentas</strong>: <a href="http://msdn.microsoft.com/en-us/library/ms162169.aspx">SQL Server Management Objects (SMO)</a><br />
<strong>Principais objectos e propriedades</strong>: <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.table_members.aspx">Table</a>, Table.ForeignKeys, <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.column_members.aspx">Column</a>, <a href="http://msdn.microsoft.com/pt-br/library/microsoft.sqlserver.management.smo.foreignkey_members.aspx">ForeignKey</a>, <a href="http://msdn.microsoft.com/pt-br/library/microsoft.sqlserver.management.smo.foreignkey.columns.aspx">ForeignKeyColumn</a><br />
<strong> Notas:</strong></p>
<ul>
<li> chave primária e foreign key não composta</li>
</ul>
<p>&nbsp;</p>
<p><strong>Código</strong></p>
<div style="overflow:scroll">
<pre lang="csharp">
private static string GetReferencedKeyColumnName(Database database, Table table, Column column)
{
    Column c2 = new Column();
    bool exists = false;
    string referencedKey = "";

    database.Refresh();
    foreach (ForeignKey ffk in table.ForeignKeys)
    {
        foreach (ForeignKeyColumn fc in ffk.Columns)
        {
            c2 = table.Columns[fc.Name];
            if (c2.Equals(column))
            {
                database.Tables[ffk.ReferencedTable].Refresh();
                database.Tables[ffk.ReferencedTable].Indexes.Refresh();

                Index idx =  database.Tables[ffk.ReferencedTable].Indexes[ffk.ReferencedKey];

                if (idx == null) idx =  database.Tables[ffk.ReferencedTable].Indexes["[" + ffk.ReferencedKey + "]"];

                if (idx != null)
                    referencedKey += idx.IndexedColumns[0].Name;

                exists = true;
                break;
            }
        }
        if (exists)
        {
            break; // not considering composite FK
        }
    }
    return referencedKey;
}
</pre>
</div>
<p>&nbsp;</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.osmeusapontamentos.com/index.php/2009/02/13/foreign-keys-com-smo-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebServices e Datasets</title>
		<link>http://blog.osmeusapontamentos.com/index.php/2009/02/13/webservices-e-datasets/</link>
		<comments>http://blog.osmeusapontamentos.com/index.php/2009/02/13/webservices-e-datasets/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 09:43:08 +0000</pubDate>
		<dc:creator>vitorsilva</dc:creator>
				<category><![CDATA[ler/ ver/ ouvir/ passear]]></category>
		<category><![CDATA[programação]]></category>

		<guid isPermaLink="false">http://blog.osmeusapontamentos.com/?p=1282</guid>
		<description><![CDATA[Se na vida não há verdades absolutas, no desenvolvimento de software muito menos. De qualquer forma as generalizações dão sempre jeito (quando contextualizadas) para não termos sempre que estar a pensar em todos os conceitos / problemas relacionados. Assim, para consumir com uma pitada de bom senso, aqui ficam alguns links sobre a opção de [...]]]></description>
			<content:encoded><![CDATA[<p>Se na vida não há verdades absolutas, no desenvolvimento de software muito menos. De qualquer forma as generalizações dão sempre jeito (quando contextualizadas) para não termos sempre que estar a pensar em todos os conceitos / problemas relacionados.</p>
<p>Assim, para consumir com uma pitada de bom senso, aqui ficam alguns links sobre a opção de passar datasets através de webservices</p>
<p>scott hanselman &#8211; <a href="http://www.hanselman.com/blog/ReturningDataSetsFromWebServicesIsTheSpawnOfSatanAndRepresentsAllThatIsTrulyEvilInTheWorld.aspx">Returning DataSets from WebServices is the Spawn of Satan and Represents All That Is Truly Evil in the World</a></p>
<p>rockford lohtka &#8211; <a href="http://www.lhotka.net/weblog/ThoughtsOnPassingDataSetObjectsViaWebServices.aspx">Thoughts on passing DataSet objects via web services</a></p>
<p>4guysfromrolla &#8211; <a href="http://aspnet.4guysfromrolla.com/articles/051805-1.aspx">More On Why I Don&#8217;t Use DataSets in My ASP.NET Applications </a></p>
<p><a href="http://weblogs.asp.net/aaguiar/archive/2004/06/03/147208.aspx">Web Services and DataSets</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.osmeusapontamentos.com/index.php/2009/02/13/webservices-e-datasets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Foreign Keys com SMO #1</title>
		<link>http://blog.osmeusapontamentos.com/index.php/2009/02/11/foreign-keys-com-smo-1/</link>
		<comments>http://blog.osmeusapontamentos.com/index.php/2009/02/11/foreign-keys-com-smo-1/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 19:28:00 +0000</pubDate>
		<dc:creator>vitorsilva</dc:creator>
				<category><![CDATA[ler/ ver/ ouvir/ passear]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[smo]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.osmeusapontamentos.com/?p=1257</guid>
		<description><![CDATA[Objectivo: Determinar o nome da tabela que está a ser referenciada a partir de uma chave externa Ferramentas: SQL Server Management Objects (SMO) Principais objectos e propriedades: Table, Table.ForeignKeys, Column, ForeignKey, ForeignKeyColumn Notas: chave primária e foreign key não composta &#160; Código private static string GetReferencedTableName(Table table, Column column) { Column c2 = new Column(); [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Objectivo</strong>: Determinar o nome da tabela que está a ser referenciada a partir de uma chave externa<br />
<strong>Ferramentas</strong>: <a href="http://msdn.microsoft.com/en-us/library/ms162169.aspx">SQL Server Management Objects (SMO)</a><br />
<strong>Principais objectos e propriedades</strong>: <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.table_members.aspx">Table</a>, Table.ForeignKeys, <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.column_members.aspx">Column</a>, <a href="http://msdn.microsoft.com/pt-br/library/microsoft.sqlserver.management.smo.foreignkey_members.aspx">ForeignKey</a>, <a href="http://msdn.microsoft.com/pt-br/library/microsoft.sqlserver.management.smo.foreignkey.columns.aspx">ForeignKeyColumn</a><br />
<strong> Notas:</strong></p>
<ul>
<li> chave primária e foreign key não composta</li>
</ul>
<p>&nbsp;</p>
<p><strong>Código</strong></p>
<div style="overflow:scroll">
<pre lang="csharp">
private static string GetReferencedTableName(Table table, Column column)
{
    Column c2 = new Column();
    bool exists = false;
    string referencedTable = "";
    foreach (ForeignKey ffk in table.ForeignKeys)
    {
        foreach (ForeignKeyColumn fc in ffk.Columns)
        {
            c2 = table.Columns[fc.Name];
            if (c2.ID == column.ID)
            {
                exists = true;
                break;
            }
        }
        if (exists)
        {
            referencedTable += ffk.ReferencedTable;
            break; // not considering composite FK
        }
    }
    return referencedTable;
}
</pre>
</div>
<p>&nbsp;</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.osmeusapontamentos.com/index.php/2009/02/11/foreign-keys-com-smo-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Criar Instrução SQL de Select usando SMO</title>
		<link>http://blog.osmeusapontamentos.com/index.php/2009/02/09/criar-instrucao-sql-de-select-usando-smo/</link>
		<comments>http://blog.osmeusapontamentos.com/index.php/2009/02/09/criar-instrucao-sql-de-select-usando-smo/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 19:16:12 +0000</pubDate>
		<dc:creator>vitorsilva</dc:creator>
				<category><![CDATA[ler/ ver/ ouvir/ passear]]></category>
		<category><![CDATA[programação]]></category>
		<category><![CDATA[smo]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.osmeusapontamentos.com/?p=1253</guid>
		<description><![CDATA[Objectivo: criar instrução SQL de Select que devolva todos os campos de uma tabela. Deve também &#8220;descodificar&#8221; as foreign keys de uma tabela enviando para isso um campo não chave da tabela referenciada. Ferramentas: SQL Server Management Objects (SMO) Principais objectos e propriedades: Table, Table.Columns, Column, Column.Identity, Column.InPrimaryKey Notas: chave primária não composta campos foreign [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Objectivo</strong>: criar instrução SQL de Select que devolva todos os campos de uma tabela. Deve também &#8220;descodificar&#8221; as foreign keys de uma tabela enviando para isso um campo não chave da tabela referenciada.<br />
<strong>Ferramentas</strong>: <a href="http://msdn.microsoft.com/en-us/library/ms162169.aspx">SQL Server Management Objects (SMO)</a><br />
<strong>Principais objectos e propriedades</strong>: <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.table_members.aspx">Table</a>, Table.Columns, <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.column_members.aspx">Column</a>, Column.Identity, Column.InPrimaryKey<br />
<strong> Notas:</strong></p>
<ul>
<li> chave primária não composta</li>
<li> campos foreign key podem ser nulos pelo que não podemos optar sempre pelo INNER JOIN</li>
<li> é assumida a existência de uma função chamada GetReferencedTableName() que devolve o nome da tabela que está a ser referencia por uma foreign key.</li>
<li> é assumida a existência de uma função chamada GetReferencedKeyColumnName() que devolve o primeiro campo nao chave de uma tabela referenciada. o nome desse campo aparecerá para fora com o nome da coluna inicial +  o sufixo &#8220;_description&#8221;</li>
<li> os nomes das tabelas referencias são convertidos para aliases do tipo t_(numero) em que numero é um simples contador que assume que a lista de foreign keys vem sempre pela mesma ordem</li>
<li> as colunas CreatedOn, CreatedBy, lastUpdatedOn, lastUpdatedBy existem sempre</li>
</ul>
<p><strong>Exemplo do resultado pretendido</strong></p>
<div style="overflow:scroll">
<pre lang="vbnet">
Dim sql As String = "SELECT {0}TM_Deslocacoes.IdDeslocacao, {0}TM_Deslocacoes.IdColaborador, convert(varchar(500), t_0.Nome) [IdColaborador_description], {0}TM_Deslocacoes.IdMeioDeslocacao, convert(varchar(500), t_1.Nome) [IdMeioDeslocacao_description], {0}TM_Deslocacoes.LocalDestino, convert(varchar(500), t_2.Designacao) [LocalDestino_description], {0}TM_Deslocacoes.DataPartida, {0}TM_Deslocacoes.LocalPartida, convert(varchar(500), t_3.Designacao) [LocalPartida_description], {0}TM_Deslocacoes.DataRegresso, {0}TM_Deslocacoes.Direccao, convert(varchar(500), t_4.Description) [Direccao_description], {0}TM_Deslocacoes.NumeroPessoas, {0}TM_Deslocacoes.Observacoes, {0}TM_Deslocacoes.CreatedOn, {0}TM_Deslocacoes.CreatedBy, {0}TM_Deslocacoes.LastUpdatedOn, {0}TM_Deslocacoes.LastUpdatedBy, {0}TM_Deslocacoes.LastUpdated FROM {0}TM_Deslocacoes INNER JOIN {0}TM_Colaboradores t_0 ON {0}TM_Deslocacoes.IdColaborador = t_0.IdColaborador INNER JOIN {0}TM_DefinicaoMeiosDeslocacaoDisponiveis t_1 ON {0}TM_Deslocacoes.IdMeioDeslocacao = t_1.IdMeioDeslocacaoDisponivel INNER JOIN {0}TM_DefinicaoLocalidades t_2 ON {0}TM_Deslocacoes.LocalDestino = t_2.IdLocalidade  LEFT OUTER JOIN {0}TM_DefinicaoLocalidades t_3 ON {0}TM_Deslocacoes.LocalPartida = t_3.IdLocalidade  INNER JOIN {0}TM_Parametros t_4 ON {0}TM_Deslocacoes.Direccao = t_4.Id       WHERE 	IdDeslocacao = @IdDeslocacao"
</pre>
</div>
<p>&nbsp;</p>
<p><strong>Código</strong></p>
<div style="overflow:scroll">
<pre lang="csharp">
private static string CreateMethodFindAll_SelectStatement(Table table, Database database)
{

    StringBuilder sb = new StringBuilder(200);
    database.Tables.Refresh();
    table.Refresh();

    sb.Append("SELECT ");
    bool primeiro = true;
    int fkCount = 0;

    foreach (Column c in table.Columns)
    {
        if (primeiro) primeiro = false; else sb.Append(", ");
        sb.AppendFormat("{{0}}{0}.{1}", table.Name, c.Name);
        if (c.IsForeignKey)
        {
            string fkt = GetReferencedTableName(table, c);
            if (fkt != "")
            {
                Table fkTable = database.Tables[fkt];
                if (fkTable != null)
                {
                    sb.AppendFormat(", convert(varchar(500), t_{0}.{1}) [{2}_description]", fkCount, GetFirstNonKeyColumnName(fkTable), c.Name);
                    fkCount++;
                }
            }
        }
    }

    return sb.ToString();
}

private static string CreateMethodFindAll_JoinStatement(Table table, Database database)
{
    StringBuilder sb = new StringBuilder(200);

    bool primeiro = true;
    int fkCount = 0;

    fkCount = 0;
    foreach (Column c in table.Columns)
    {
        if (primeiro) primeiro = false; else sb.Append(" ");
        if (c.IsForeignKey)
        {
            string fkt = GetReferencedTableName(table, c);
            if (fkt != "")
            {
                Table fkTable = database.Tables[fkt];
                if (fkTable != null)
                {
                    if (c.Nullable)
                        sb.AppendFormat("LEFT OUTER JOIN {{0}}{2} t_{7} ON {{0}}{4}.{5} = t_{7}.{6}", table.Parent.ToString(), fkTable.Schema, fkTable.Name, table.Schema, table.Name, c.Name, GetReferencedKeyColumnName(database, table, c), fkCount);
                    else
                        sb.AppendFormat("INNER JOIN {{0}}{2} t_{7} ON {{0}}{4}.{5} = t_{7}.{6}", table.Parent.ToString(), fkTable.Schema, fkTable.Name, table.Schema, table.Name, c.Name, GetReferencedKeyColumnName(database, table, c), fkCount);
                    fkCount++;
                }
            }
        }
    }

    return sb.ToString();
}

private static string CreateMethodFindAll_sql(Table table, Database database)
{
    StringBuilder sb = new StringBuilder(200);

    sb.Append(CreateMethodFindAll_SelectStatement(table, database));

    sb.AppendFormat(" FROM {{0}}{0}", table.Name);

    sb.Append(CreateMethodFindAll_JoinStatement(table, database));

    return sb.ToString();
}
</pre>
</div>
<p>&nbsp;</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Save</a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.osmeusapontamentos.com/index.php/2009/02/09/criar-instrucao-sql-de-select-usando-smo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

