Monday, April 23, 2012

from clipboard copy files specified path

? send files my to cliboard and ? want copy all wthin listbox files specified path a with click to button for example desktop,to folder such as my have single problem ? don t get selecteditems from listbox and ? don t copy now how ? can copy



CODE HERE



public partial class Form1 : Form
{
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetClipboardViewer(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
IntPtr SonrakiClipboardOgesi;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
SonrakiClipboardOgesi = SetClipboardViewer(this.Handle);
}
protected override void WndProc(ref Message m)
{
int WM_DRAWCLIPBOARD = 0x0308;
int WM_CHANGECBCHAIN = 0x030D;

if (m.Msg == WM_DRAWCLIPBOARD)
{
ClipboardOku();
SendMessage(SonrakiClipboardOgesi, m.Msg, m.WParam, m.LParam);
}
else if (m.Msg == WM_CHANGECBCHAIN)
{
if (m.WParam == SonrakiClipboardOgesi)
{
SonrakiClipboardOgesi = m.LParam;
}
else
{
SendMessage(SonrakiClipboardOgesi, m.Msg, m.WParam, m.LParam);
}
}

base.WndProc(ref m);
}

private void ClipboardRead()
{
StringCollection col = new StringCollection();
col = Clipboard.GetFileDropList();
for (int i = 0; i < col.Count; i++)
listBox1.Items.Add(col[i]);
listBox1.SelectionMode = SelectionMode.MultiSimple;
for (int i = 0; i < listBox1.Items.Count; i++)
listBox1.SetSelected(i, true);
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ChangeClipboardChain(this.Handle, SonrakiClipboardOgesi);
}

private void button1_Click(object sender, EventArgs e)
{
// ? make a with click copy within listbox files specified path
//What code I should write here
}
}
}




See if file is empty

How to a check if a file is empty in Java 7?

I tried it using the available() method from ObjectInputStream, but it returns always zero even if the the file contains data.





RavenDB disk storage

I have a requirement to keep the RavenDB database running when the disk for main database and index storage is full. I know I can configure provide a drive for storage with config option - Raven/IndexStoragePath



But I need to design for the corner case of when the this disk is full. What is the usual pattern used in this situation. One way is to halt all access while shutting the service down and updating the config file programatically and then start the service - but it is a bit risky.



I am aware of sharding and this question is not related to that , assume that sharding is enables and I have multiple shards and I want to increase storage for each shard by adding a new drive to each. Is there an elegant solution to this?





ASPX & SQL returning multiple recordsets - identify them

I am creating a simple report in aspx.



I have a stored procedure that I'm calling to get 5 recorsets.



First 4 have 7 columns and second has 6 columns.



This is my C# code:



protected void bindGridView()
{
string _connStr = ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString();
DataSet dSet = new DataSet();
try
{
using (SqlConnection conn = new SqlConnection(_connStr))
{
using (SqlCommand cmd = new SqlCommand("MyProcedure", conn))
{
cmd.CommandTimeout = 120;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@d", SqlDbType.VarChar).Value = dlDzial.SelectedValue;
cmd.Parameters.Add("@g", SqlDbType.Int).Value = dlGrupa.SelectedValue;
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
ad.Fill(dSet);
if (dSet.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = dSet.Tables[0];
GridView1.DataBind();
}
else
{
ShowNoResultFound(dSet.Tables[0], GridView1);
}
if (dSet.Tables[1].Rows.Count > 0)
{
GridView2.DataSource = dSet.Tables[1];
GridView2.DataBind();
}
else
{
ShowNoResultFound(dSet.Tables[1], GridView2);
}
if (dSet.Tables[2].Rows.Count > 0)
{
GridView3.DataSource = dSet.Tables[2];
GridView3.DataBind();
}
else
{
ShowNoResultFound(dSet.Tables[2], GridView3);
}
if (dSet.Tables[3].Rows.Count > 0)
{
GridView4.DataSource = dSet.Tables[3];
GridView4.DataBind();
}
else
{
ShowNoResultFound(dSet.Tables[3], GridView4);
}
lbl1.Visible = lbl2.Visible = lbl3.Visible = lbl4.Visible = true;
}
}
}
}
catch (Exception ex)
{
lblErrorMsg.Text = ex.Message;
}
}


But I have a problem. Depending on parameters sometimes recordset 2 & 3 are empty, thats why I get errors when trying to get some values from rows. recordset 4 is then Table[2] and is displayed in gridview 2 (it should be displayed in fourth gridview)



I would like to know how to identify recordsets that come from sql into C#.



I was searching a bit over the internet and I found that I can add extra column to every recordset and using this identify recordsets.



How to identify every recordset, so even if I change order of selects in sql I will be able to map then to correct GridView.





Add Value to RoutValues and keep Current Values in ASP.NET MVC 3

I have a view with two form one of them for declare rows per page. In post action I need my Url be the same and just add new parameter. at now I use like this:



[HttpPost]
public ActionResult Index(FormCollection collection) {

//Calculate Row Count

return RedirectToAction("Index", new { RC = RowCount });

}


with this implementation my all parameters lost and just RC = rowcountnumber replaced.
How can I keep parameters and just add new RC to it? what is fastest way to do it? is any performance issue here?





Global asax and application_endrequest asp.net

Hello i got some question why when i run my method in global.asax it don't run and when i use IHttp module it is workin any advice.
Maybe its caused of context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);



Is it posible to call it without Module?



Code Example:



Method that i run



        public static void EndSession()
{
HttpContext context = HttpContext.Current;
if (context.Session != null)
{
ISession session = context.Session["Session"] as ISession;
if (context.Session["Session"] != null)
{
if (!session.Transaction.IsActive)
OpenTransaction(session);
session.Flush();
CommitTransaction(session);
session.Close();
context.Session["Session"] = null;
}
}
}


Global



        private void Application_EndRequest(object sender, EventArgs e)
{
NhSessionHelper.EndSession();
}


IHTTPMODULE



  namespace MME.DAL.SesionManager
{
internal class SessionRequest : IHttpModule
{
#region Public Methods

public void Dispose()
{
}

public void Init(HttpApplication context)
{
context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);
}

Reading a file into a list?

I am trying to read a file into a list, and take every other line from this list, and try to add this to the hashset, and if the result of this operation is false, output the duplicate string. For some reason, it is not working, and i'm not sure what i've done wrong. Thanks .. here is my code:



public class Duplicates
{
public static void main(String[] args)
{

PrintWriter output = null;
BufferedReader input = null;

try
{

input = new BufferedReader(new FileReader(args[0]));
output = new PrintWriter(new FileWriter(args[1]));

List<String> list = new ArrayList<String>();
Set<String> usr = new HashSet<String>();

//Read the lines into lineList
String current;
boolean result;
while ((current = input.readLine()) != null)
list.add(current);


for (int index = 0; index < lineList.size() - 1; index =+2)
{
result = usr.add(list.get(index));
if (result = true)
System.out.println(list.get(index));
}
}//try
catch (Exception exception)
{
System.err.println(exception);
}//catch
finally
{
try {if (input != null) input.close(); }
catch (IOException exception)
{ System.err.println( exception) }
}
}
}




How to Find Duplicate Values in Arrays?

I am working on SQLlite and I have written a query which Returns me Two Array.<br/>
ItemsArray and CustomersIDArray as
<pre>
ItemsArray
Element at Index 0 = Off White,
Element at Index 1 = Fan,
Element at Index 2 = Off White,
Element at Index 3 = Delux,
Element at Index 4 = Fan
CustomerIDArray
Element at Index 0 = 1,
Element at Index 1 = 2,
Element at Index 2 = 2,
Element at Index 3 = 3,
Element at Index 4 = 4
</pre>
I want Result like that off White = 2 (count) , Fan = 2 (count) and Delux = 1;
and the Resultant Array,
<pre>
Result Array
Element at Index 0 = Off White,
Element at Index 1 = Fan,
Element at Index 3 = Delux <br/>
</pre>


Actually I want the count of repetition in first array but the value must not same for CustomerArray.
Please Help me through Logic or Code





How to import files while loading a groovy class?

I am loading a class and doing some sql select statements, it seems that import groovy.sql.Sql needs to be imported. How can I load some library while loading a class?



My code (works fine if I remove Sql operations)



def fClass = new GroovyClassLoader().parseClass( new File( 'plugin/Pi.groovy' ) )
result=fClass.newInstance().buildTags( params, i9piparams, "userRoleCount")


pi.groovy



public class Pi{
def result

private def getDbUrl(dbdriver,dbhost,dbport,dbname)
{
return "$dbdriver:@$dbhost:$dbport:$dbname"
}

public def buildTags(Map<String,String> params,Map<String,String> i9piparams,def i9piType)
{

println params
println i9piparams

/*some Sql operation*/
Driver="oracle.jdbc.driver.OracleDriver"
dbdriver="jdbc:oracle:thin"
def url=getDbUrl(dbdriver,params.tns,i9piparams.dbport,i9piparams.dbname)

def sql = Sql.newInstance(url,params.u,params.x,Driver)

sql.eachRow("select name, value from v\$parameter where name = 'open_cursors'"){ row ->
result.name=row.name
result.value=row.value
}

}
}


Output



[pd:admin, u:zx5531d, tns:foner, dh:abds, dn:D35531, dp:11531, un:admin, x:cx15531]
[:, dbname:orcl, dbport:1521, dbtype:oracle]
Exception in thread "main" groovy.lang.GroovyRuntimeException: Could not find matching constructor for: groovy.sql.Sql(org.codehaus.groovy.runtime.GStringImpl, groovy.util.slurpersupport.Attributes, java.lang.String, java.lang.String)
.
.
.




Retrieving HTML attribute values "the DOM 0 way"

jQuery has an attr() method which retrieves the value of a given HTML attribute. For instance:



var foo = document.getElementById("foo");
$(foo).attr("id");


But, performance-wise this is not optimal since an jQuery object has to be created just to call the attr() method. This performs better: foo.id.



So, ideally we would want to avoid using attr(). But, can we do that (for any attribute)? I believe foo.id and foo.value is "safe" (cross-browser), but I remember having issues with foo.href.



Here is a list of various attributes that I would like to be able to retrieve "directly":



For any element: foo.id, foo.name

For anchors: foo.href, foo.target, foo.rel

For images, objects, iframes: foo.src, foo.width, foo.height

For form elements: foo.checked, foo.selected, foo.disabled, foo.readonly, foo.type, foo.value, foo.action



So the question is: Are the above expressions cross-browser? Can I use them safely?



A link to an article which examines this issue would also be nice.



Edit (based on the answers): The expressions in bold are not safe to use!





Wordpress resets plugin settings when migrating

I am migrating a wordpress site from one domain to the other.Plugins lose my preferences in the process.I really don't understand why.I'm curious as to why this happens.



Here are the steps i went through:




1. uploaded wordpress files from localhost
through FTP on the new domain ( http://example-live.com )
2. uploaded database to the new domain
3. changed all links referring to http://localhost to http://example-live.com
4. treated text_widgets differently because they are serialized in the db.
5. edited .htaccess
6. updated wp_config.php


Pages display normally but I am missing plugin preferences...Any thoughts ?



Edit: Found this: http://codex.wordpress.org/Moving_WordPress





Reading 4 bits without losing information

I have come across with a problem I cannot seem to solve.
I have a type of file "ASDF", and in their header I can get the necessary information to read them. The problem is that one of the "fields" is only 4 bits long.
So, lets say it's like this:
From bit 0 to 8 it's the index of the current node (I've read this already)
From 8 to 16 it's the index for the next node (Read this as well)
From bit 16 to 20 Length of the content (string,etc..)



So my problem is that if I try to read the "length" with a bytereader I will be losing 4 bits of information, or would be "4 bits off". Is there anyway to read only 4 bits? Any ideas would be appreciated, thanks :)





Creating Partial view with Menu items populated from Model (Rails)

I am trying to use partial views to create Menu items which are driven from database.
I searched the web and found the below



 - Partial view files should have "_" at beginning of its name (_menu.html.erb)
- Partial views are called using <%= render "menu" %>


but in my application, i should load menu items which are taken from a db table and load it in a layout file (I could use models for interacting with db)
how do i achieve getting the model result in layout file? any reference would be helpful...!!



Thanks in advance.





two select query in one stored procedure

i want to select two queries from 1 stored procedure....my following query is correct? and how to call this in 2 gridview



create procedure tablename
@id varchar(50)
as
select a.id,
isnull(a.advance,0) as advance,
isnull(b.submitted_amt,0) as submitted
into #temp1
from
(select id,SUM(Amount)as advance
from table1 where type='Travel' group by id) a
full join
(select id,SUM(Amount)as submitted_amt
from table2 group by categeoryid) b
on a.id=b.id
select id,
advance,
submitted,
advance-submitted as balance_return
from #temp1
select categeoryid,advance,submitted,advance-submitted as balance_return from #temp1 id=@id




Camel send to multiple end points

How does these two differ



from(endpoint).to(endpoint:a, endpoint:b)

from(endpoint).multicast().to(endpoint:a, endpoint:b)


couldn't find any documentation for the first





PowerShell: Get-User –OrganizationalUnit One Level?

Hi I'm trying to get ONE LEVEL of the command Get-User –OrganizationalUnit.



Get-User –OrganizationalUnit "domain.local/ou/this-one"


This returns the this-one ou and everything under it, I want a one level return, what paramteres am I missing?





JBoss 7 Virtual Host getting page not found

I am trying to bind an alias to run my app instead of the ip address on the server. So I want to access my app on helloworld.businessname.com:8555/helloworld instead of 172.19.20.xxx:8555/helloworld I added a jboss-web.xml in my project under WEB-INF



<jboss-web>
<virtual-host>helloworld.businessname.com</virtual-host>
</jboss-web>


and i edited the virtual host tag in my standalone.xml



<subsystem xmlns="urn:jboss:domain:web:1.1" native="false" default-virtual-server="default-host">     
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<connector name="https" protocol="HTTP/1.1" scheme="https" socket- binding="https" enable-lookups="false" secure="true">
</connector>
<virtual-server name="default-host" enable-welcome-root="true">
<alias name="localhost"/>
<alias name="example.com"/>
</virtual-server>
<virtual-server name="helloworld.businessname.com" default-web-module="helloworld">
<alias name="helloworld.businessname.com"/>
</virtual-server>


When I go to helloworld.businessname.com:8555/ it says not found.



I appreciate it.





does PHP APC as local object store have any limits besides storage size?

I'm using PHP APC on production servers of a web service with 10M's hits/day successfuly for a long time.



I'm considering offloading much more data to the APC local cache.



Theoretically it looks to me that since APC call is mainly a local memory access. It should not become an issue to call it 10,000s of times/sec. As far as I can tell its limits can be in the memory size but as long as the server has free CPU it should not have performance or corruption issues at high rates.



Is there any limit I'm not aware of that might prevent me from using APC's local object cache in very high rate on app server (ubuntu).





How to implement proper HTTP error handling in .NET MVC 3?

I'm referring to Darin's answer in the following post.



I'm using MVC3 and I was wondering if this is still a way to handle errors?



In the rrror controller he has the following:



public ActionResult Http404()
{
Response.StatusCode = 404;

return Content("404", "text/plain");
}


Working from his code.. I want it to display the full URL, how would I do this? So it needs to be www.mywebsite.com/Error/Http404 and not just www.mywebsite.com. How would I do this? I thought that if I had the following code then it will display the full URL, but it still just displays www.mywebsite.com:



public ActionResult Http404()
{
Response.StatusCode = 404;

return View("Http404");
}


How would I get the value of ex that was set in the global.asax.cs to be displayed on this page?



I moved away from having my errors handled in the web.config because it kepted on have a aspxerrorpath in the querystring.





Checking internet connection

I check the connection with



ConnectivityManager connec = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);


i have wifi and i get wrong status on my cell phone what could i do ?





getAttribute() versus Element object properties?

Element.getAttribute("id") and Element.id returns same thing.



Which one should be used when we need attributes of an HTMLElement object?



Is there any cross browser issue with these methods like getAttribute() and setAttribute()?



Or Any input on performance difference b/w accessing directly properties vs using these methods?





flash need to have dynamic path for XML with Html Parameter

I have this flash mp3 player , and it read data from an XML file named "playlist.xml"
the code is :



if (xml == undefined && mp3 == undefined)
{
xml = "playlist.xml";


now I want this Path for my xml file to be dynamic and be in the HTML doc. so I can change it with php. can you please guide me how should I change my code to read the XML path from a parameter in HTML codes ?
p.s. My Flash file is in Actionscript 2.0





Jquery Mobile "pageinit" not firing

Im trying to use the Geolocation API with Jquery Mobile. Everything works fine if i browse directly to my page from the browser.



But, if i navigate to it from another page, it does not load.



Also, if i remove the line of code with the "pageinit" command, i get the same issue/error but if i refresh the page it will load.



I know it has something to do with the way the DOM is handled through AJAX but i cant seem to get it to work the way it should/i want it to.



<!DOCTYPE html>
<html>
<head>
<title>My Location</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>

</head>
<body>
<div data-role="page" id="geoPage">


<script type="text/javascript">

$("#geoPage").live("pageinit", function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('Geolocation not supported');
}
});

function success(position) {
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapcanvas = $('#mapcanvas');
var map = new google.maps.Map(mapcanvas[0], myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"I am here!"
});


//alert(latlng);


}


function error(msg) {
var errMsg = typeof msg == 'string' ? msg : "Geolocation failed";
$('#msg').html(errMsg);
}


$("#continue7").click(function(e){


$.mobile.changePage( "extension.htm", { transition: "slide"} );


});
</script>


<div data-role="header">
<h1>My Location</h1>
</div>
<div data-role="content">
<div id="msg"></div>
<div id="mapcanvas" style="height: 250px; width:250px;"></div>
<input id="continue7" type="button" value="Conintue" />



</div>
</div>
</body>
</html>




jquery mobile loads script twice

I'm trying to load some jquery javascript when my page is loaded, but it's always loaded twice. I'm using jquery 1.7.2 and jquery mobile 1.1.0. I tried this 3 different methods, but it's always loading the script twice.



$(document).bind("ready", function() { }
$(document).ready(function() { }
$(document).live('pageinit',function(event) { }




Can I add Microdata from HTML5 to a XHTML Strict site and still be compliant?

I've got a site coded in XHTML 1.0 Strict. I want to use the new Microdata to add breadcrumbs to my site (so Google will understand them).



My old non-microdata marked-up breadcrumbs look like this:



<ul>
<li><a href="...">Level 1</a></li>
<li><a href="...">Level 2</a></li>
<li><a href="...">Level 3</a></li>
</ul>


According to Google, to markup breadcrumbs using Microdata, you extend the above code like this:



<ul>
<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="..." itemprop="url">
<span itemprop="title">Level 1</span>
</a>
</li>
...
</ul>


But this is not valid XHTML 1.0 Strict.



What should I do?

Should I ignore the validation conflicts?

Should I write itemscope="itemscope" instead of just itemscope (this would be valid XML, but still not valid XHTML)?

Should I change the Doctype to be HTML5 instead of XHTML 1.0 Strict?



I want this to work all the way back to IE6!



Please advice :)





How to get sum of data in a list using multiple column values

I have a list using this Linq query



filterEntities = (from list in filterEntities where list.Id== 0 && list.Id== 1 && list.Id == 3 && list.Id== 6 select list).OrderBy(r => r.Id).ToList();


Now this linq returns a list like



ID  Age
0 18
0 19
1 21
3 24
6 32
6 08


I want to generate a list using sum of same Id's which returns like



ID  Age
0 37
1 21
3 24
6 40


Please suggest me possible query





Android App- Unofficial Android Market(Play Store) API

I want to display a List of some Apps using the unofficial Android Market(Play Store) API(http://code.google.com/p/android-market-api).



But I always get Errors. Does somebody have an idea why I get Errors?



Here is my Code:



 package iStore.App.Android;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import com.gc.android.market.api.MarketSession;
import com.gc.android.market.api.MarketSession.Callback;
import com.gc.android.market.api.model.Market.App;
import com.gc.android.market.api.model.Market.AppsRequest;
import com.gc.android.market.api.model.Market.AppsResponse;
import com.gc.android.market.api.model.Market.ResponseContext;

import android.provider.Settings.Secure;
import android.util.Log;
import android.widget.TextView;


public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView textview = (TextView) findViewById(R.id.TextView);

MarketSession session = new MarketSession();
session.login("my email adresse","my passsword");
String AndroidId = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
session.getContext().setAndroidId(AndroidId);

String query = "google";
AppsRequest appsRequest = AppsRequest.newBuilder()
.setQuery(query)
.setStartIndex(0).setEntriesCount(3)
.setWithExtendedInfo(false)
.build();

Callback<AppsResponse> callback = new Callback<AppsResponse> () {
public void onResult(ResponseContext context, AppsResponse response) {


textview.setText("It worked");

}
};
session.append(appsRequest, callback);
session.flush();
}
}


I tried this in a Java Project. There it worked, but instead of



    String AndroidId = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);


I used my actual Android ID. But why does it not work in an Android App?



Thanks.



EDIT:
My LogCat:



    04-23 15:18:16.379: E/dalvikvm(4111): Could not find class 'com.gc.android.market.api.MarketSession', referenced from method iStore.App.Android.MainActivity.onCreate
04-23 15:18:16.389: W/dalvikvm(4111): VFY: unable to resolve new-instance 11 (Lcom/gc/android/market/api/MarketSession;) in LiStore/App/Android/MainActivity;
04-23 15:18:16.429: W/dalvikvm(4111): threadid=1: thread exiting with uncaught exception (group=0x40018560)
04-23 15:18:16.429: E/AndroidRuntime(4111): FATAL EXCEPTION: main
04-23 15:18:16.429: E/AndroidRuntime(4111): java.lang.NoClassDefFoundError: com.gc.android.market.api.MarketSession
04-23 15:18:16.429: E/AndroidRuntime(4111): at iStore.App.Android.MainActivity.onCreate(MainActivity.java:27)
04-23 15:18:16.429: E/AndroidRuntime(4111): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-23 15:18:16.429: E/AndroidRuntime(4111): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-23 15:18:16.429: E/AndroidRuntime(4111): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
04-23 15:18:16.429: E/AndroidRuntime(4111): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-23 15:18:16.429: E/AndroidRuntime(4111): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-23 15:18:16.429: E/AndroidRuntime(4111): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 15:18:16.429: E/AndroidRuntime(4111): at android.os.Looper.loop(Looper.java:123)
04-23 15:18:16.429: E/AndroidRuntime(4111): at android.app.ActivityThread.main(ActivityThread.java:3729)
04-23 15:18:16.429: E/AndroidRuntime(4111): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 15:18:16.429: E/AndroidRuntime(4111): at java.lang.reflect.Method.invoke(Method.java:507)
04-23 15:18:16.429: E/AndroidRuntime(4111): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
04-23 15:18:16.429: E/AndroidRuntime(4111): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
04-23 15:18:16.429: E/AndroidRuntime(4111): at dalvik.system.NativeStart.main(Native Method)




ANDROID:How to open web page in class extends CCLayer

I am newbie in cocos2d game development and developed 50% game using of Cocos2d SDK Android.I am stuck when the user plays certain level of game more than 3 times then i have to redirect him to google play url to rate my app but not able to do this as i am not able to open the webpage as we did in a class extends activity.I searched every where but there is no such help found to help my cause.



Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("url"));
startActivity(in);


My class extends CCLayer is:



public class GameLayer extends CCLayer {
public int count=0;
public enum GAME_STATE {
GS_PLAY,
GS_PAUSE,
GS_GAMEOVER
};

public CCSprite background;
public CCSprite road;

public ArrayList<CCSprite> backArray;
public ArrayList<CCSprite> frontArray;

public ArrayList<CCSprite> sunArray;
public ArrayList<CCSprite> bloodArray;

public CCSprite die;
public CCSprite hit;
public CCSprite smoke;
public CCSprite blood;

public CCLabel lbScore;
public CCMenuItemToggle btPause;
public CCMenuItemImage btMainMenu;
public CCMenuItemImage btRetry;

public Player player;

public float score;
public CCSprite scores;
public CCLabel lbDistance;
// public CCLabel lbnotifi;
public CCLabel lbCurrentScore;
public CCLabel lbPersonalBest;
public CCLabel lbBestScore;

public GAME_STATE state;

public float POS_X_PREV_SOUND = (G.rwidth / 3);
public float POS_Y_PREV_SOUND = (G.rheight * 5 / 7);

public float POS_X_NEXT_SOUND = (G.rwidth / 3 * 2);
public float POS_Y_NEXT_SMOKE = (G.rheight * 4 / 7);

public CGPoint curDiePos;


public GameLayer()
{
backArray = new ArrayList<CCSprite>();
frontArray = new ArrayList<CCSprite>();
sunArray = new ArrayList<CCSprite>();
bloodArray = new ArrayList<CCSprite>();

this.setIsTouchEnabled(true);

background = CCSprite.sprite("background/back_ipad.png", CGRect.make(0, 0, 1024, 768));
background.setPosition(G.rwidth / 2, G.rheight / 2);
background.setScaleX(G.rX);
background.setScaleY(G.rY);
addChild(background);

CCSprite sp = CCSprite.sprite("background/back_ipad.png", CGRect.make(0, 846, 1024, 178));
sp.setPosition(G.rwidth / 2, sp.getContentSize().height / 2 * G.rY);
sp.setScaleX(G.rX);
sp.setScaleY(G.rY);
addChild(sp);
backArray.add(sp);

sp = CCSprite.sprite("background/back_ipad.png", CGRect.make(0, 846, 1024, 178));
sp.setPosition(G.rwidth * 3 / 2, sp.getContentSize().height / 2 * G.rY);
sp.setScaleX(G.rX);
sp.setScaleY(G.rY);
addChild(sp);
backArray.add(sp);

sp = CCSprite.sprite("background/front_mountion_ipad.png");
sp.setPosition(G.rwidth / 2, sp.getContentSize().height / 2 * G.rY);
sp.setScaleX(G.rX);
sp.setScaleY(G.rY);
addChild(sp);
frontArray.add(sp);

sp = CCSprite.sprite("background/front_mountion_ipad.png");
sp.setPosition(G.rwidth * 3 / 2, sp.getContentSize().height / 2 * G.rY);
sp.setScaleX(G.rX);
sp.setScaleY(G.rY);
addChild(sp);
frontArray.add(sp);

road = CCSprite.sprite("background/back_ipad.png", CGRect.make(0, 768, 1024, 24));
road.setAnchorPoint(0.5f, 1);
road.setPosition(G.rwidth / 2, G.LOAD_HEIGHT);
road.setScaleX(G.rX);
road.setScaleY(G.rY);
addChild(road);

lbScore = CCLabel.makeLabel("0", "arial", 30);
lbScore.setScale(G.rX);
lbScore.setPosition(G.rwidth - 70 * G.rX, G.rheight - 70 * G.rY);
lbScore.setColor(new ccColor3B(0, 0, 0));
addChild(lbScore);

btPause = CCMenuItemToggle.item(this, "selPause",
CCMenuItemImage.item("object/bt_pause.png", "object/bt_pause.png"),
CCMenuItemImage.item("object/bt_right01.png", "object/bt_right02.png"));
btPause.setScale(G.rX);
btPause.setPosition(70 * G.rX, G.rheight - 70 * G.rY);

btMainMenu = CCMenuItemImage.item("object/bt_main01.png", "object/bt_main02.png", this, "selMainMenu");
btMainMenu.setScale(G.rX);
btMainMenu.setPosition(G.rwidth / 4, G.rheight / 4);

btRetry = CCMenuItemImage.item("object/bt_retry01.png", "object/bt_retry02.png", this, "selRetry");
btRetry.setScale(G.rX);
btRetry.setPosition(G.rwidth * 3 / 4, G.rheight / 4);

CCMenu menu = CCMenu.menu(btPause, btMainMenu, btRetry);
menu.setPosition(0, 0);
addChild(menu, 5);

player = new Player();
player.setPosition(G.PLAYER_POS, G.LOAD_HEIGHT);
addChild(player, 5);

smoke = CCSprite.sprite("smoke/smoke_000.png");
smoke.setAnchorPoint(0.5f, 0);
smoke.setScale(G.rX);
smoke.setPosition(player.getPosition());
addChild(smoke);
CCTextureCache.sharedTextureCache().removeTexture(smoke.getTexture());

hit = CCSprite.sprite("object/c0001.png");
hit.setAnchorPoint(0.5f, 0.5f);
hit.setScale(G.rX);
hit.setPosition(CGPoint.ccpAdd(player.getPosition(),
CGPoint.ccp(player.spRun.getContentSize().width / 2 * G.rX,
player.spRun.getContentSize().height / 2 * G.rX)));
addChild(hit);
CCTextureCache.sharedTextureCache().removeTexture(hit.getTexture());

blood = CCSprite.sprite("object/blood_000.png");
blood.setScale(G.rX);
blood.setPosition(0, 0);
addChild(blood);
CCTextureCache.sharedTextureCache().removeTexture(blood.getTexture());

die = CCSprite.sprite("object/tombstone00.png");
die.setAnchorPoint(0.5f, 0);
die.setScale(G.rX);
die.setPosition(player.getPosition());
addChild(die);
CCTextureCache.sharedTextureCache().removeTexture(die.getTexture());

scores = CCSprite.sprite("object/t_score.png");
scores.setScale(G.rX);
scores.setPosition(G.rwidth / 2, 670 * G.rY);
addChild(scores);

lbDistance = CCLabel.makeLabel("Distance:", CGSize.make(G.rwidth, 150*G.rY), TextAlignment.LEFT, "arial", 35);
lbDistance.setAnchorPoint(0, 0.5f);
lbDistance.setScale(G.rX);
lbDistance.setPosition(POS_X_PREV_SOUND, POS_Y_PREV_SOUND);
ccColor3B col = new ccColor3B(0, 90, 0);
lbDistance.setColor(col);
addChild(lbDistance);

//
// lbnotifi = CCLabel.makeLabel("Distance:", CGSize.make(G.rwidth, 150*G.rY), TextAlignment.LEFT, "arial", 35);
// lbnotifi.setAnchorPoint(0, 0.5f);
// lbnotifi.setScale(G.rX);
// lbnotifi.setPosition(POS_X_PREV_SOUND, POS_Y_PREV_SOUND);
// ccColor3B col1 = new ccColor3B(0, 90, 0);
// lbDistance.setColor(col1);
// // addChild(lbDistance);


lbCurrentScore = CCLabel.makeLabel("0", CGSize.make(200*G.rX, 150*G.rY), TextAlignment.RIGHT, "arial", 35);
lbCurrentScore.setScale(G.rX);
lbCurrentScore.setPosition(POS_X_NEXT_SOUND, POS_Y_PREV_SOUND);
lbCurrentScore.setColor(col);
addChild(lbCurrentScore);

lbPersonalBest = CCLabel.makeLabel("Your Best Run:", CGSize.make(G.rwidth, 150*G.rY), TextAlignment.LEFT, "arial", 35);
lbPersonalBest.setAnchorPoint(0, 0.5f);
lbPersonalBest.setScale(G.rX);
lbPersonalBest.setPosition(POS_X_PREV_SOUND, POS_Y_NEXT_SMOKE);
lbPersonalBest.setColor(col);
addChild(lbPersonalBest);

lbBestScore = CCLabel.makeLabel("0", CGSize.make(200*G.rX, 150*G.rY), TextAlignment.RIGHT, "arial", 35);
lbBestScore.setScale(G.rX);
lbBestScore.setPosition(POS_X_NEXT_SOUND, POS_Y_NEXT_SMOKE);
lbBestScore.setColor(col);
addChild(lbBestScore);

startGame();
}

public CGRect sunRect(CCSprite sp)
{
CGRect rt;
CGSize sz = sp.getContentSize();
sz.width = sz.width * G.rX;
sz.height = sz.height * G.rY;

rt = CGRect.make(sp.getPosition().x, sp.getPosition().y, sz.width, sz.height);

return rt;
}

public void loadBloods()
{
if (bloodArray != null) {
int arrayCount = bloodArray.size();

if (arrayCount > 0) {
for (int i = 0; i < arrayCount; i++)
{
CCSprite spBlood = bloodArray.get(i);
removeSprite(spBlood);
}
}
bloodArray.clear();
}

CCSprite sp;

for (int i = 0; G.DATA_BLOOD[i][0] != 0; i ++) {
int imageNum = (int) G.DATA_BLOOD[i][1];
sp = CCSprite.sprite(G.IMG_BLOOD[ imageNum ]);
sp.setScale(G.rX);
sp.setAnchorPoint(0, 1);
sp.setPosition(G.DATA_BLOOD[i][0] * G.rX, G.LOAD_HEIGHT);
addChild(sp);
bloodArray.add(sp);
}
}

public void loadSuns()
{
if (sunArray != null) {
int arrayCount = sunArray.size();

if (arrayCount > 0) {
for (int i = 0; i < arrayCount; i++)
{
CCSprite sun = sunArray.get(i);
removeSprite(sun);
}
}
sunArray.clear();

}

CCSprite sp;


}

public void updateScore()
{
lbScore.setString(String.format("%d", (int)score));
}

public void initPlayer()
{
player.state = PLAYER_STATE.PS_RUN;
player.spRun.setVisible(true);
player.spJump.setVisible(false);
player.spDown.setVisible(false);
player.runBlood.setVisible(false);

player.timeStateUpdate(PLAYER_STATE.PS_RUN);
player.startRunAnimation();
player.setVisible(true);
}

public void startGame()
{
state = GAME_STATE.GS_PLAY;
score = 0;
updateScore();

btMainMenu.setVisible(false);
btRetry.setVisible(false);
scores.setVisible(false);
lbDistance.setVisible(false);
// lbnotifi.setVisible(false);
lbCurrentScore.setVisible(false);
lbPersonalBest.setVisible(false);
lbBestScore.setVisible(false);
lbScore.setVisible(true);
btPause.setVisible(true);
btPause.setSelectedIndex(0);

die.setVisible(false);

CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage("object/tombstone00.png");
if( texture != null)
{
die.setTexture(texture);
}
CCTextureCache.sharedTextureCache().removeTexture(die.getTexture());


hit.setVisible(false);
hit.setOpacity(255);
texture = CCTextureCache.sharedTextureCache().addImage("object/c0001.png");
if( texture != null )
{
hit.setTexture(texture);
}
CCTextureCache.sharedTextureCache().removeTexture(hit.getTexture());

blood.setVisible(false);
texture = CCTextureCache.sharedTextureCache().addImage("object/blood_000.png");
if( texture != null)
{
blood.setTexture(texture);
}
CCTextureCache.sharedTextureCache().removeTexture(blood.getTexture());

smoke.stopAllActions();
smoke.setVisible(false);
texture = CCTextureCache.sharedTextureCache().addImage("smoke/smoke_000.png");
if( texture != null)
{
smoke.setTexture(texture);
}
CCTextureCache.sharedTextureCache().removeTexture(smoke.getTexture());


loadSuns();
if (G.g_gameInfo.isSmokeOn == true)
{

loadBloods();
}
initPlayer();
this.schedule("onTime", 0.02f);

}

public void selMainMenu()
{
G.sd_button.start();
CCScene scene = CCScene.node();
scene.addChild(new FirstScene(), 1);
CCDirector.sharedDirector().replaceScene(CCFadeTransition.transition(1.0f, scene));
}

**public void selRetry()
{
count++;
G.sd_button.start();
if(count==3)
{

}
if(count<3){
startGame();
}
}**

public void processMovingObjects(float dt)
{
float backDelta = G.VEL_BACK_MOVE * dt;
float frontDelta = G.VEL_FRONT_MOVE * dt;
float sunDelta = G.VEL_RUN * dt;

score += backDelta / 2;
updateScore();

for (int i = 0; i < backArray.size(); i++)
{
CCSprite sp = backArray.get(i);
if ( (sp.getPosition().x + sp.getContentSize().width / 2 * G.rX) < 0)
{
sp.setPosition(CGPoint.ccpAdd(sp.getPosition(), CGPoint.ccp(G.rwidth * 2, 0)));
}

sp.setPosition(CGPoint.ccpSub(sp.getPosition(), CGPoint.ccp(backDelta, 0)));
}

for (int i = 0; i < frontArray.size(); i++)
{
CCSprite sp = frontArray.get(i);
if ( (sp.getPosition().x + sp.getContentSize().width / 2 * G.rX) < 0)
{
sp.setPosition(CGPoint.ccpAdd(sp.getPosition(), CGPoint.ccp(G.rwidth * 2, 0)));
}

sp.setPosition(CGPoint.ccpSub(sp.getPosition(), CGPoint.ccp(frontDelta, 0)));
}

for (int i = 0; i < sunArray.size(); i++)
{
CCSprite sp = sunArray.get(i);
sp.setPosition(CGPoint.ccpSub(sp.getPosition(), CGPoint.ccp(sunDelta, 0)));

if ( (sp.getPosition().x + sp.getContentSize().width / 2 * G.rX) < 0)
{
sp.setPosition(CGPoint.ccpAdd(sp.getPosition(), CGPoint.ccp(G.rwidth * 5, 0)));
}
}

if (G.g_gameInfo.isSmokeOn == true)
{

for (int i = 0; i < bloodArray.size(); i++)
{
CCSprite sp = bloodArray.get(i);
sp.setPosition(CGPoint.ccpSub(sp.getPosition(), CGPoint.ccp(sunDelta, 0)));

if ( (sp.getPosition().x + sp.getContentSize().width / 2 * G.rX) < 0)
{
sp.setPosition(CGPoint.ccpAdd(sp.getPosition(), CGPoint.ccp(G.rwidth * 5, 0)));
}
}

}
}

public void selShowGmaeOverMenu()
{
btMainMenu.setVisible(true);
btRetry.setVisible(true);
scores.setVisible(true);
lbDistance.setVisible(true);
lbCurrentScore.setVisible(true);
lbPersonalBest.setVisible(true);
lbBestScore.setVisible(true);

int bestScore = 0;
switch (G.g_gameInfo.trackNum)
{
case 0:
bestScore = G.g_gameInfo.scoreTrack1;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack1 = bestScore;
break;
case 1:
bestScore = G.g_gameInfo.scoreTrack2;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack2 = bestScore;

break;
case 2:
bestScore = G.g_gameInfo.scoreTrack3;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack3 = bestScore;

break;
case 3:
bestScore = G.g_gameInfo.scoreTrack4;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack4 = bestScore;

break;
case 4:
bestScore = G.g_gameInfo.scoreTrack5;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack5 = bestScore;

break;
case 5:
bestScore = G.g_gameInfo.scoreTrack6;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack6 = bestScore;

break;
case 6:
bestScore = G.g_gameInfo.scoreTrack7;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack7 = bestScore;

break;
case 7:
bestScore = G.g_gameInfo.scoreTrack8;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack8 = bestScore;
case 8:
bestScore = G.g_gameInfo.scoreTrack9;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack9 = bestScore;
case 9:
bestScore = G.g_gameInfo.scoreTrack10;
if (bestScore < (int)score) {
bestScore = (int)score;
}
G.g_gameInfo.scoreTrack10 = bestScore;

break;

default:
break;
}

G.saveHistory();

lbCurrentScore.setString(String.format("%d", (int)score));
lbBestScore.setString(String.format("%d", bestScore));
}

public void selShowDieAni()
{
G.sd_fire.start();

die.runAction(G.ani_die);
die.setVisible(true);
die.setPosition(curDiePos.x, G.LOAD_HEIGHT);

}

public void selHideBlood()
{
blood.setVisible(false);
}

public void selEndSmoke()
{
smoke.setVisible(false);
}

public void gameOver()
{
G.sd_delay.start();

state = GAME_STATE.GS_GAMEOVER;

btPause.setVisible(false);
lbScore.setVisible(false);

for (int i = 0; i < sunArray.size(); i++)
{
CCSprite sun = sunArray.get(i);
sun.stopAllActions();
}

this.unschedule("onTime");
player.stopRunAnimation();
player.setVisible(false);

// CCSequence seqSmoke = CCSequence.actions(G.ani_smoke copy] autorelease],
// [CCCallFunc actionWithTarget:self selector:@selector(selEndSmoke)], nil];
smoke.runAction(G.ani_smoke);
selEndSmoke();

smoke.setVisible(true);
smoke.setPosition(curDiePos);

if (G.g_gameInfo.isSmokeOn == true)
{
blood.setVisible(true);
blood.setPosition(curDiePos.x, G.LOAD_HEIGHT + 23 * G.rX);

// CCSequence *seqBlood = [CCSequence actions:[[ani_blood copy] autorelease],
// [CCCallFunc actionWithTarget:self selector:@selector(selHideBlood)], nil];

blood.runAction(G.ani_blood);
selHideBlood();

CCSequence seq = CCSequence.actions(CCCallFunc.action(this, "selShowDieAni"),
CCCallFunc.action(this, "selShowGmaeOverMenu"));

this.runAction(seq);
}
else {

CCSequence seq = CCSequence.actions(CCFadeOut.action(0.3f),
CCCallFunc.action(this, "selShowDieAni"),
CCCallFunc.action(this, "selShowGmaeOverMenu"));

hit.runAction(G.ani_hit);
hit.runAction(seq);
hit.setVisible(true);
hit.setPosition(curDiePos.x, G.LOAD_HEIGHT + 23 * G.rX);

}



}

public void scanCollision()
{
CGRect rcPlayer = player.playerRect();

for (int i = 0; i < sunArray.size(); i++)
{
CCSprite sun = sunArray.get(i);
CGRect rcSun = this.sunRect(sun);

if (CGRect.intersects(rcPlayer, rcSun))
{

curDiePos = CGPoint.ccpAdd(sun.getPosition(), CGPoint.ccp(sun.getContentSize().width / 2 * G.rX, 0));
sun.setVisible(false);

gameOver();
break;
}
}

if (G.g_gameInfo.isSmokeOn == true)
{

for (int i = 0; i < bloodArray.size(); i++)
{
CCSprite spBlood = bloodArray.get(i);
CGRect rcBlood = this.sunRect(spBlood);

if (player.getPosition().x > rcBlood.origin.x && player.getPosition().x < rcBlood.origin.x + rcBlood.size.width)
{
player.actionRunBlood();
}
}

}
}

public void onTime(float dt)
{
if(dt > 0.02f)
dt = 0.02f;

processMovingObjects(dt);
scanCollision();
}

public void selPause()
{
G.sd_button.start();

if (btPause.selectedIndex() == 0)
{
CCDirector.sharedDirector().resume();
state = GAME_STATE.GS_PLAY;
}
else
{

CCDirector.sharedDirector().pause();
state = GAME_STATE.GS_PAUSE;
}
}

public boolean ccTouchesBegan(MotionEvent event)
{
CGPoint touchPoint = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY()));

if (state == GAME_STATE.GS_PLAY)
{
if (touchPoint.x < G.rwidth / 2) {
player.timeStateUpdate(PLAYER_STATE.PS_DOWN);
}
else {
player.timeStateUpdate(PLAYER_STATE.PS_JUMP);

}

}

return true;
}

public boolean ccTouchesEnded(MotionEvent event)
{
CGPoint touchPoint = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY()));

if (state == GAME_STATE.GS_PLAY)
{
if (touchPoint.x < G.rwidth / 2) {
if (player.state == PLAYER_STATE.PS_DOWN)
{
player.timeStateUpdate(PLAYER_STATE.PS_RUN);
}
}
else {
if (player.state == PLAYER_STATE.PS_JUMP)
{
player.timeStateUpdate(PLAYER_STATE.PS_RUN);
}
}

}

return true;
}

public boolean ccTouchesCancelled(MotionEvent event)
{
CGPoint touchPoint = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(), event.getY()));

if (state == GAME_STATE.GS_PLAY)
{
if (touchPoint.x < G.rwidth / 2)
{
if (player.state == PLAYER_STATE.PS_DOWN)
{
player.timeStateUpdate(PLAYER_STATE.PS_RUN);
}
}
else {
if (player.state == PLAYER_STATE.PS_JUMP)
{
player.timeStateUpdate(PLAYER_STATE.PS_RUN);
}
}

}

return true;
}
public void onExit()
{
removeCache();
super.onExit();

}

}


Please assist me.Thanks in Advance





Check if a property value has changed on POCO

I have a POCO that is updated every N seconds. The problem I have is that not all properties may have changed since the last update.



I need to know which properties have changed since the last update so I can log the changes. I could do this by keeping a copy of the POCO from the previous update and performing a comparison each time and then maybe firing an event for each property change.



Does anyone have a better solution that I could use here?





Suitable use of Tuple<>, in a unit test?

Whilst writing a set of unit tests (for an existing legacy component), I wanted a way to associate a list of error codes (which will be returned by a service that I have mocked), and a list of corresponding error messages (which my component under test will return).



It seems that using a List<Tuple<string, string>> is a nice simple way to define this association.



var errorCodesAndMessages = new List<Tuple<string, string>>
{
Tuple.Create("CODE1", "Error message 1"),
Tuple.Create("CODE2", "Error message 2")
// etc...
};


In my unit test I can then loop through the errorCodesAndMessages, setting up my mocked service to return the nth error code, and asserting that the component under test returns the nth error message.



Is this a good use of — or an abuse of — Tuple<>?