route line does not appear using MkMap in xamarin ios - c#

i want to draw route line using mkMap in xamarin ios. my code is working correctly but it does not show route line between points. my code is given below
my first picture shows the starting annotation point and second picture shows ending annotation point
MapView Code:
private MKMapView _map;
private MapDelegate _mapDelegate;
public QiblaCompassVC (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
_map = new MKMapView(mapsView.Bounds)
{
MapType = MKMapType.Standard,
ShowsUserLocation = true,
ZoomEnabled = true,
ScrollEnabled = true
};
//_map = new MKMapView(mapsView.Bounds);
// _map.ShowsUserLocation = true;
_mapDelegate = new MapDelegate();
_map.Delegate = _mapDelegate;
//mapsView.Add(_map);
View = _map;
var target = new CLLocationCoordinate2D(30.3753, 69.3451);
var viewPoint = new CLLocationCoordinate2D(21.3891, 39.8579);
var annotation = new mapAnnotation(new CLLocationCoordinate2D(30.3753, 69.3451), "Pakistan", "Countery of love");
_map.AddAnnotation(annotation);
var annotation1 = new mapAnnotation(new CLLocationCoordinate2D(21.3891, 39.8579), "Makka", "Allah home");
_map.AddAnnotation(annotation1);
var camera = MKMapCamera.CameraLookingAtCenterCoordinate(target, viewPoint, 500);
_map.Camera = camera;
createRoute();
//CLLocationCoordinate2D coords = new CLLocationCoordinate2D(30.3753, 69.3451);
//MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude));
//_map.Region = new MKCoordinateRegion(coords, span);
}
public void createRoute()
{
var dict = new NSDictionary();
var orignPlaceMark = new MKPlacemark(new CLLocationCoordinate2D(30.3753, 69.3451), dict);
var sourceItem = new MKMapItem(orignPlaceMark);
//End at Xamarin Cambridge Office
var destPlaceMark = new MKPlacemark(new CLLocationCoordinate2D(21.3891, 39.8579), dict);
var destItem = new MKMapItem(destPlaceMark);
var request = new MKDirectionsRequest
{
Source = sourceItem,
Destination = destItem,
RequestsAlternateRoutes = true,
};
var directions = new MKDirections(request);
directions.CalculateDirections((response, error) =>
{
if (error != null)
{
Console.WriteLine(error.LocalizedDescription);
}
else
{
//Add each Polyline from route to map as overlay
foreach (var route in response.Routes)
{
_map.AddOverlay(route.Polyline);
}
}
});
}
MapDelegate Code:
class MapDelegate : MKMapViewDelegate
{
public override MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay)
{
if (overlay is MKPolyline)
{
var route = (MKPolyline)overlay;
var renderer = new MKPolylineRenderer(route) { StrokeColor = UIColor.Blue };
return renderer;
}
return null;
}
public override MKOverlayView GetViewForOverlay(MKMapView mapView, IMKOverlay overlay)
{
if (overlay is MKPolyline)
{
// return a view for the polygon
MKPolyline l_polyline = overlay as MKPolyline;
MKPolylineView l_polylineView = new MKPolylineView(l_polyline);
MKPolylineRenderer l_polylineRenderer = new MKPolylineRenderer(l_polyline);
l_polylineView.FillColor = UIColor.Blue;
l_polylineView.StrokeColor = UIColor.Red;
return l_polylineView;
}
return null;
}
}

The problem is in the GetViewForOverlay method,
The overlay parameter is not not of type MKPolyline, it is a wrapper containing the MKPolyline, this is how to get it :
MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlayWrapper)
{
var overlay = Runtime.GetNSObject(overlayWrapper.Handle) as IMKOverlay;
...
}
Source from xamarin forum

Related

Android.Util.AndroidRuntimeException: <Timeout exceeded getting exception details> occurred

I am android c# developer beginner and need to work in back ground showing my listview but my code have a load action such as fetching database and convert from byte array to image so I used async task but it hangs and give me this error Unhandled Exception:
Android.Util.AndroidRuntimeException: occurred
//this my async class :
public class UpdatePB : AsyncTask<string, string, string>
{
private Activity context;
private ProgressDialog progressDialog;
public List<Advertise_TableItem> GroupLst;
Dictionary<Advertise_TableItem, List<Replies_TableItem>> ChildLst;
// Advertise_HomeScreenAdapter adb;
public ExpandableListViewAdapter Adapter;
AbdoService.abdo_service AbdoService;
//string user_id;
Context myContext;
ExpandableListView listview;
DataTable table;
public UpdatePB(Activity context, ExpandableListView listview, Context myContext)
{
this.context = context;
this.listview = listview;
this.myContext = myContext;
}
protected override string RunInBackground(string[] #params)
{
//System.Threading.Thread.Sleep(3000);
//adb = new Advertise_HomeScreenAdapter(this, tableItems);
//listview.Adapter = adb;
//progressDialog = new ProgressDialog(context);
//progressDialog.Show();
AbdoService = new AbdoService.abdo_service();
GroupLst = new List<Advertise_TableItem>();
ChildLst = new Dictionary<Advertise_TableItem, List<Replies_TableItem>>();
if (CrossConnectivity.Current.IsConnected)
{
table = AbdoService.selectAllAdvertises().table;
int I = 0;
foreach (DataRow item in table.Rows)
{
// bitmap = BitmapFactory.DecodeByteArray(AbdoService.GetByteImage(item[1].ToString()).ByteImage, 0, AbdoService.GetByteImage(item[1].ToString()).ByteImage.Length);
GroupLst.Add(new Advertise_TableItem(item[1].ToString(), item[2].ToString(), item[3].ToString(), item[0].ToString()));
List<Replies_TableItem> child = new List<Replies_TableItem>();
//child.Add(new Replies_TableItem("mohammed", "comment 1 "));
//child.Add(new Replies_TableItem("ahmed", "comment 2 "));
var childTable = AbdoService.selectReply(item[0].ToString());
foreach (DataRow childItem in childTable.table.Rows)
{
child.Add(new Replies_TableItem(childItem[1].ToString(), childItem[2].ToString()));
}
ChildLst.Add(GroupLst[I], child);
I++;
}
}
else
{
if_connected();
}
Adapter = new ExpandableListViewAdapter(myContext, GroupLst, ChildLst);
////System.Threading.Thread.Sleep(3000);
listview.SetAdapter(Adapter);
for (int i = 0; i < Adapter.GroupCount; i++)
{
listview.ExpandGroup(i);
}
//listview.GroupClick += Listview_GroupClick;
//startServices();
////RunOnUiThread(() => progressBar.Visibility = ViewStates.Invisible);
return context.Title;
}
public void if_connected()
{
var callDialog = new Android.App.AlertDialog.Builder(context);
callDialog.SetTitle("Notify");
callDialog.SetMessage("connect internet");
callDialog.SetNeutralButton("ok", delegate
{
context.Finish();
context.StartActivity(typeof(AllAdvertises));
});
callDialog.Show();
}
protected override void OnPreExecute()
{
progressDialog = new ProgressDialog(context);
progressDialog.Show();
}
//protected override void OnProgressUpdate(params string[] values)
//{
// //mtv.Text = Convert.ToString(values[0]);
// //Android.Util.Log.Error("lv==", values[0] + "");
// listview.SetAdapter(Adapter);
// for (int i = 0; i < Adapter.GroupCount; i++)
// {
// listview.ExpandGroup(i);
// }
//}
protected override void OnPostExecute(string result)
{
result = context.Title;
progressDialog.Dismiss();
}
}
//this is my Activity function oncreate()
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetTheme(Resource.Style.AppTheme);
SetContentView(Resource.Layout.AllAdvertises);
//progressDialog = new ProgressDialog(this);
//progressDialog.SetMessage("hiiiiiiiiiiiii");
//progressDialog.Show();
// System.Threading.Thread.Sleep(1000);
//ProgressBar progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar);
//RunOnUiThread(() => progressBar.Visibility=ViewStates.Visible);
//DoSomeWork1(arguments);
prefs = PreferenceManager.GetDefaultSharedPreferences(this);
TextView UserName = FindViewById<TextView>(Resource.Id.txtUserName);
string user_id = prefs.GetString("UserId", "0");
if (user_id != "0")
{
UserName.Text = " Hello " + prefs.GetString("UserName", "0");
}
//AbdoService = new AbdoService.abdo_service();
////table= b.GetResult();
//// //AbdoService.selectAllAdvertisesCompleted += AbdoService_selectAllAdvertisesCompleted;
//// //AbdoService.selectAllAdvertisesAsync();
listview = FindViewById<ExpandableListView>(Resource.Id.EdListView);
//GroupLst = new List<Advertise_TableItem>();
//ChildLst = new Dictionary<Advertise_TableItem, List<Replies_TableItem>>();
//if (CrossConnectivity.Current.IsConnected)
//{
// //table = AbdoService.selectAllAdvertises().table;
// int I = 0;
// foreach (DataRow item in table.Rows)
// {
// // bitmap = BitmapFactory.DecodeByteArray(AbdoService.GetByteImage(item[1].ToString()).ByteImage, 0, AbdoService.GetByteImage(item[1].ToString()).ByteImage.Length);
// GroupLst.Add(new Advertise_TableItem(item[1].ToString(), item[2].ToString(), item[3].ToString(), item[0].ToString()));
// List<Replies_TableItem> child = new List<Replies_TableItem>();
// //child.Add(new Replies_TableItem("mohammed", "comment 1 "));
// //child.Add(new Replies_TableItem("ahmed", "comment 2 "));
// var childTable = AbdoService.selectReply(item[0].ToString());
// foreach (DataRow childItem in childTable.table.Rows)
// {
// child.Add(new Replies_TableItem(childItem[1].ToString(), childItem[2].ToString()));
// }
// ChildLst.Add(GroupLst[I], child);
// I++;
// }
//}
//else
//{
// if_connected();
//}
////adb = new Advertise_HomeScreenAdapter(this, tableItems);
////listview.Adapter = adb;
//Adapter = new ExpandableListViewAdapter(this, GroupLst, ChildLst);
UpdatePB uptask = new UpdatePB(this, listview, this);
uptask.Execute("paramter");
//uptask.GetResult();
//listview.SetAdapter(Adapter);
//for (int i = 0; i < Adapter.GroupCount; i++)
//{
// listview.ExpandGroup(i);
//}
listview.GroupClick += Listview_GroupClick;
startServices();
//////RunOnUiThread(() => progressBar.Visibility = ViewStates.Invisible);
}
you can not touch the UI from a background thread so you need to move this line:
listview.SetAdapter(Adapter);
for (int i = 0; i < Adapter.GroupCount; i++)
{
listview.ExpandGroup(i);
}
from RunInBackground(string[] #params) to OnPostExecute(string result)
also move if_connected(); from RunInBackground(string[] #params) to OnPostExecute(string result) because if_connected(); shows a dialog it can not be run in background
And add your complete Stack Trace of error to your question because there may be some other errors there in addition to mentioned ones.

System.OutOfMemoryExeption C#

When I'm running my application and load a file(25MB) through it, everything runs just fine.
But when I try loading a file(160MB) I get a System.OutOfMemoryExeption.
Although I have been able to load the larger file at some point in time.
Is there anyway to fix this? If so, any help would be much appreciated!
My Code that loads the files:
private void openFile (string fileName)
{
List<Structs.strValidData> _header1 = new List<Structs.strValidData>();
List<Structs.strValidData> _header2 = new List<Structs.strValidData>();
List<Structs.strValidData> _header3 = new List<Structs.strValidData>();
List<Structs.strValidData> _header4 = new List<Structs.strValidData>();
var textBoxArray = new[]
{
textBoxResStart_Status1,
textBoxResStart_Status2,
textBoxResStart_Status3,
textBoxResStart_Status4,
textBoxResStart_Status5,
textBoxResStart_Status6,
textBoxResStart_Status7,
textBoxResStart_Status8,
};
var radioButtonArray = new[]
{
radioButtonResStart_SelectStr1,
radioButtonResStart_SelectStr2,
radioButtonResStart_SelectStr3,
radioButtonResStart_SelectStr4,
radioButtonResStart_SelectStr5,
radioButtonResStart_SelectStr6,
radioButtonResStart_SelectStr7,
radioButtonResStart_SelectStr8,
};
readCSV read;
read = new readCSV();
strInfo = default(Structs.strInfo);
strData = default(Structs.strData);
strSetup = default(Structs.strSetup);
strValidData = new List<Structs.strValidData>();
readID = default(Structs.ReadID);
try
{
strInfo = read.loadInfo(fileName);
strData = read.loadData(fileName);
strSetup = read.loadSetup(fileName);
readID = read.loadID(fileName);
strValidData = read.loadValidData(fileName);
var Str1 = read.loadStr1(fileName);
var Str235678 = read.loadStr235678(fileName);
var Str4 = read.loadStr4(fileName);
foreach (Structs.strValidData items in strValidData)
{
if (items.Str1_ValidData == true)
{
Str1_headers.Add(items);
}
if (items.Str2_ValidData == true ||
items.Str3_ValidData == true ||
items.Str5_ValidData == true ||
items.Str6_ValidData == true ||
items.Str7_ValidData == true ||
items.Str8_ValidData == true)
{
Str235678_headers.Add(items);
}
if (items.Str4_ValidData == true)
{
Str4_headers.Add(items);
}
}
Str1_data = combineData(Str1, Str1_headers);
Str4_data = combineData(Str4, Str4_headers);
var Str235678_CombinedData = combineData(Str235678, Str235678_headers);
foreach (Structs.strValidData items in Str235678_CombinedData)
{
if (items.Str2_ValidData == true)
{
Str2_data.Add(items);
}
if (items.Str3_ValidData == true)
{
Str3_data.Add(items);
}
if (items.Str5_ValidData == true)
{
Str5_data.Add(items);
}
if (items.Str6_ValidData == true)
{
Str6_data.Add(items);
}
if (items.Str7_ValidData == true)
{
Str7_data.Add(items);
}
if (items.Str8_ValidData == true)
{
Str8_data.Add(items);
}
}
strInfo = read.loadInfo(openDialog.FileName);
strData = read.loadData(openDialog.FileName);
strSetup = read.loadSetup(openDialog.FileName);
readID = read.loadID(openDialog.FileName);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
error.logSystemError(err);
}
}
Here are the ReadCSV() code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FileHelpers;
using FileHelpers.Events;
namespace Reading_Files
{
public class readCSV
{
public int strCnt = 0;
private readCSVprogressForm _waitForm;
public List<Structs.strDataImport> copyList(List<strData> copyFrom)
{
List<Structs.strDataImport> list = new List<Structs.strDataImport>();
list.AddRange(copyFrom.Select(s => copyListContents(s)));
return list;
}
public Structs.strDataImport copyListContents(strData copyFrom)
{
Structs.strDataImport data = new Structs.strDataImport();
data.sCD_TimeCP2711 = copyFrom.sCD_TimeCP2711;
data.sCD_TimeCX9020_1 = copyFrom.sCD_TimeCX9020_1;
data.sCD_TimeCX9020_2 = copyFrom.sCD_TimeCX9020_2;
data.rCD_CX9020_1_TimeDiff_DataLow = (Int32)(copyFrom.rCD_CX9020_1_TimeDiff_DataLow);
data.rCD_CX9020_2_TimeDiff_DataLow = (Int32)(copyFrom.rCD_CX9020_2_TimeDiff_DataLow);
data.iCD_NumUpper = copyFrom.iCD_NumUpper;
data.iCD_NumUpper = copyFrom.iCD_NumUpper;
data.iCD_NumLower = copyFrom.iCD_NumLower;
data.iCD_NumLower = copyFrom.iCD_NumLower;
data.bCD_1_Status = copyFrom.bCD_1_Status;
data.bCD_1_Overrange = copyFrom.bCD_1_Overrange;
data.iCD_1_Str_ID = copyFrom.iCD_1_Str_ID;
data.rCD_1_Value = copyFrom.rCD_1_Value;
data.bCD_2_Status = copyFrom.bCD_2_Status;
data.bCD_2_Overrange = copyFrom.bCD_2_Overrange;
data.iCD_2_Str_ID = copyFrom.iCD_2_Str_ID;
data.rCD_2_Value = copyFrom.rCD_2_Value;
data.bCD_3_Status = copyFrom.bCD_3_Status;
data.bCD_3_Overrange = copyFrom.bCD_3_Overrange;
data.iCD_3_Str_ID = copyFrom.iCD_3_Str_ID;
data.iCD_3_RawData = copyFrom.iCD_3_RawData;
data.rCD_3_Value = copyFrom.rCD_3_Value;
data.bCD_4_Status = copyFrom.bCD_4_Status;
data.bCD_4_Overrange = copyFrom.bCD_4_Overrange;
data.iCD_4_Str_ID = copyFrom.iCD_4_Str_ID;
data.iCD_4_RawData = copyFrom.iCD_4_RawData;
data.rCD_4_Value = copyFrom.rCD_4_Value;
data.bCD_5_Status = copyFrom.bCD_5_Status;
data.bCD_5_Overrange = copyFrom.bCD_5_Overrange;
data.iCD_5_Str_ID = copyFrom.iCD_5_Str_ID;
data.iCD_5_RawData = copyFrom.iCD_5_RawData;
data.rCD_5_Value = copyFrom.rCD_5_Value;
data.bCD_6_Status = copyFrom.bCD_6_Status;
data.bCD_6_Overrange = copyFrom.bCD_6_Overrange;
data.iCD_6_Str_ID = copyFrom.iCD_6_Str_ID;
data.iCD_6_RawData = copyFrom.iCD_6_RawData;
data.rCD_6_Value = copyFrom.rCD_6_Value;
data.bCD_7_Status = copyFrom.bCD_7_Status;
data.bCD_7_Overrange = copyFrom.bCD_7_Overrange;
data.iCD_7_Str_ID = copyFrom.iCD_7_Str_ID;
data.iCD_7_RawData = copyFrom.iCD_7_RawData;
data.rCD_7_Value = copyFrom.rCD_7_Value;
data.bCD_8_Status = copyFrom.bCD_8_Status;
data.bCD_8_Overrange = copyFrom.bCD_8_Overrange;
data.iCD_8_Str_ID = copyFrom.iCD_8_Str_ID;
data.iCD_8_RawData = copyFrom.iCD_8_RawData;
data.rCD_8_Value = copyFrom.rCD_8_Value;
data.bCD_9_Status = copyFrom.bCD_9_Status;
data.bCD_9_Overrange = copyFrom.bCD_9_Overrange;
data.iCD_9_Str_ID = copyFrom.iCD_9_Str_ID;
data.iCD_9_RawData = copyFrom.iCD_9_RawData;
data.rCD_9_Value = copyFrom.rCD_9_Value;
data.bCD_10_Status = copyFrom.bCD_10_Status;
data.bCD_10_Overrange = copyFrom.bCD_10_Overrange;
data.iCD_10_Str_ID = copyFrom.iCD_10_Str_ID;
data.iCD_10_RawData = copyFrom.iCD_10_RawData;
data.rCD_10_Value = copyFrom.rCD_10_Value;
data.bCD_11_Status = copyFrom.bCD_11_Status;
data.bCD_11_Overrange = copyFrom.bCD_11_Overrange;
data.iCD_11_Str_ID = copyFrom.iCD_11_Str_ID;
data.iCD_11_RawData = copyFrom.iCD_11_RawData;
data.rCD_11_Value = copyFrom.rCD_11_Value;
data.bCD_12_Status = copyFrom.bCD_12_Status;
data.bCD_12_Overrange = copyFrom.bCD_12_Overrange;
data.iCD_12_Str_ID = copyFrom.iCD_12_Str_ID;
data.iCD_12_RawData = copyFrom.iCD_12_RawData;
data.rCD_12_Value = copyFrom.rCD_12_Value;
data.bCD_13_Status = copyFrom.bCD_13_Status;
data.bCD_13_Overrange = copyFrom.bCD_13_Overrange;
data.iCD_13_Str_ID = copyFrom.iCD_13_Str_ID;
data.iCD_13_RawData = copyFrom.iCD_13_RawData;
data.rCD_13_Value = copyFrom.rCD_13_Value;
data.bCD_14_Status = copyFrom.bCD_14_Status;
data.bCD_14_Overrange = copyFrom.bCD_14_Overrange;
data.iCD_14_Str_ID = copyFrom.iCD_14_Str_ID;
data.iCD_14_RawData = copyFrom.iCD_14_RawData;
data.rCD_14_Value = copyFrom.rCD_14_Value;
data.bCD_15_Status = copyFrom.bCD_15_Status;
data.bCD_15_Overrange = copyFrom.bCD_15_Overrange;
data.iCD_15_Str_ID = copyFrom.iCD_15_Str_ID;
data.iCD_15_RawData = copyFrom.iCD_15_RawData;
data.rCD_15_Value = copyFrom.rCD_15_Value;
data.bCD_16_Status = copyFrom.bCD_16_Status;
data.bCD_16_Overrange = copyFrom.bCD_16_Overrange;
data.iCD_16_Str_ID = copyFrom.iCD_16_Str_ID;
data.iCD_16_RawData = copyFrom.iCD_16_RawData;
data.rCD_16_Value = copyFrom.rCD_16_Value;
data.bCD_17_Status = copyFrom.bCD_17_Status;
data.bCD_17_Overrange = copyFrom.bCD_17_Overrange;
data.iCD_17_Str_ID = copyFrom.iCD_17_Str_ID;
data.iCD_17_RawData = copyFrom.iCD_17_RawData;
data.rCD_17_Value = copyFrom.rCD_17_Value;
data.bCD_18_Status = copyFrom.bCD_18_Status;
data.bCD_18_Overrange = copyFrom.bCD_18_Overrange;
data.iCD_18_Str_ID = copyFrom.iCD_18_Str_ID;
data.iCD_18_RawData = copyFrom.iCD_18_RawData;
data.rCD_18_Value = copyFrom.rCD_18_Value;
data.bCD_19_Status = copyFrom.bCD_19_Status;
data.bCD_19_Overrange = copyFrom.bCD_19_Overrange;
data.iCD_19_Str_ID = copyFrom.iCD_19_Str_ID;
data.rCD_19_Value = copyFrom.rCD_19_Value;
data.bCD_20_Status = copyFrom.bCD_20_Status;
data.bCD_20_Overrange = copyFrom.bCD_20_Overrange;
data.iCD_20_Str_ID = copyFrom.iCD_20_Str_ID;
data.rCD_20_Value = copyFrom.rCD_20_Value;
return data;
}
public Structs.ReaStrID load_ID(string FileName)
{
var engine = new MultiRecordEngine(typeof(strInfo),
typeof(strData),
typeof(strSetup),
typeof(strID),
typeof(strData));
engine.RecordSelector = new RecordTypeSelector(strIDSelector);
var data = engine.ReadFile(FileName);
Structs.ReaStrID structure = new Structs.ReaStrID();
foreach (strID filteredData in data)
{
structure.steID[0] = filteredData._1_Ste_ID;
structure.Status[0] = filteredData._1_Status;
structure.steID[1] = filteredData._2_Ste_ID;
structure.Status[1] = filteredData._2_Status;
structure.steID[2] = filteredData._3_Ste_ID;
structure.Status[2] = filteredData._3_Status;
structure.steID[3] = filteredData._4_Ste_ID;
structure.Status[3] = filteredData._4_Status;
structure.steID[4] = filteredData._5_Ste_ID;
structure.Status[4] = filteredData._5_Status;
}
return structure;
}
public Structs.strInfo loadInfo(string FileName)
{
var engine = new MultiRecordEngine(typeof(strInfo),
typeof(strData),
typeof(strSetup),
typeof(strID),
typeof(strData));
engine.RecordSelector = new RecordTypeSelector(strInfoSelector);
var data = engine.ReadFile(FileName);
Structs.strInfo structure = new Structs.strInfo();
foreach (strInfo filteredData in data)
{
structure.Date = filteredData.Date;
structure.Description1 = filteredData.Description1;
structure.Description2 = filteredData.Description2;
structure.Description3 = filteredData.Description3;
}
return structure;
}
public Structs.strData loadData(string FileName)
{
var engine = new MultiRecordEngine(typeof(strInfo),
typeof(strData),
typeof(strSetup),
typeof(strID),
typeof(strData));
engine.RecordSelector = new RecordTypeSelector(strDataSelector);
var data = engine.ReadFile(FileName);
Structs.strData structure = new Structs.strData();
foreach (strData filteredData in data)
{
structure.iMDstr_var1_TypeID = filteredData.iMDstr_var1_TypeID;
structure.rMDstr_var1_Lenght = filteredData.rMDstr_var1_Lenght;
structure.iMDstr_var2_TypeID = filteredData.iMDstr_var2_TypeID;
structure.rMDstr_var2_Lenght = filteredData.rMDstr_var2_Lenght;
structure.iMDstr_var3_TypeID = filteredData.iMDstr_var3_TypeID;
structure.rMDstr_var3_Lenght = filteredData.rMDstr_var3_Lenght;
structure.iMDstr_var4_TypeID = filteredData.iMDstr_var4_TypeID;
structure.rMDstr_var4_Lenght = filteredData.rMDstr_var4_Lenght;
}
return structure;
}
public Structs.strSetup loadSetup(string FileName)
{
var engine = new MultiRecordEngine(typeof(strInfo),
typeof(strID),
typeof(strData),
typeof(strSetup),
typeof(strData));
engine.RecordSelector = new RecordTypeSelector(strSetupSelector);
var data = engine.ReadFile(FileName);
Structs.strSetup structure = new Structs.strSetup();
foreach (strSetup filteredData in data)
{
structure.sSSstr_Sens = filteredData.sSSstr_Sens;
structure.bSSstr_S1_A = filteredData.bSSstr_S1_A;
structure.iSSstr_S1_B = filteredData.iSSstr_S1_B;
structure.sSSstr_S1_C = filteredData.sSSstr_S1_C;
structure.rSSstr_S1_D = filteredData.rSSstr_S1_D;
structure.bSSstr_S2_A = filteredData.bSSstr_S2_A;
structure.iSSstr_S2_B = filteredData.iSSstr_S2_B;
structure.sSSstr_S2_C = filteredData.sSSstr_S2_C;
structure.rSSstr_S2_D = filteredData.rSSstr_S2_D;
structure.bSSstr_S3_A = filteredData.bSSstr_S3_A;
structure.iSSstr_S3_B = filteredData.iSSstr_S3_B;
structure.sSSstr_S3_C = filteredData.sSSstr_S3_C;
structure.iSSstr_S3_D = filteredData.iSSstr_S3_D;
}
return structure;
}
public List<Structs.str1> load1(string FileName)
{
var engine = new MultiRecordEngine(typeof(strInfo),
typeof(strData),
typeof(strSetup),
typeof(strData),
typeof(strID),
typeof(strValidData),
typeof(strStartNum),
typeof(str1),
typeof(str4));
engine.RecordSelector = new RecordTypeSelector(str1Selector);
var data = engine.ReadFile(FileName);
List<Structs.str1> list = new List<Structs.str1>();
int i = 0;
foreach (str1 data1 in data)
{
Structs.str1 structure = new Structs.str1();
structure.rGL_1_L_Positive = data1.rGL_1_L_Positive;
structure.rGL_1_L_Negative = data1.rGL_1_L_Negative;
structure.rGL_1_R_Positive = data1.rGL_1_R_Positive;
structure.rGL_1_R_Negative = data1.rGL_1_R_Negative;
list.Add(structure);
i++;
}
return list;
}
public List<Structs.str4> load4(string FileName)
{
var engine = new MultiRecordEngine(typeof(strInfo),
typeof(strData),
typeof(strSetup),
typeof(strData),
typeof(strValidData),
typeof(strStartNum),
typeof(str1),
typeof(str4));
engine.RecordSelector = new RecordTypeSelector(str4Selector);
var data = engine.ReadFile(FileName);
List<Structs.str4> list = new List<Structs.str4>();
int i = 0;
foreach (str4 data4 in data)
{
Structs.str4 structure = new Structs.str4();
structure.rGL_4_1 = data4.rGL_4_1;
structure.rGL_4_2 = data4.rGL_4_2;
structure.rGL_4_3 = data4.rGL_4_3;
structure.rGL_4_4 = data4.rGL_4_4;
structure.rGL_4_5 = data4.rGL_4_5;
structure.rGL_4_6 = data4.rGL_4_6;
structure.rGL_4_7 = data4.rGL_4_7;
structure.rGL_4_8 = data4.rGL_4_8;
list.Add(structure);
i++;
}
return list;
}
public List<Structs.strValidData> loadValidData(string FileName)
{
var engine = new MultiRecordEngine(typeof(strInfo),
typeof(strData),
typeof(strSetup),
typeof(strID),
typeof(strData),
typeof(strValidData));
engine.RecordSelector = new RecordTypeSelector(strValidDataSelector);
var data = engine.ReadFile(FileName);
List<Structs.strValidData> list = new List<Structs.strValidData>();
int i = 0;
foreach (strValidData strValidData in data)
{
Structs.strValidData structure = new Structs.strValidData();
structure._name = String.Format("strItem {0}", i + 1);
structure._index = i;
structure.str1_ValidData = strValidData.str1_ValidData;
structure.str2_ValidData = strValidData.str2_ValidData;
structure.str3_ValidData = strValidData.str3_ValidData;
structure.str4_ValidData = strValidData.str4_ValidData;
structure.str5_ValidData = strValidData.str5_ValidData;
structure.str6_ValidData = strValidData.str6_ValidData;
structure.str7_ValidData = strValidData.str7_ValidData;
structure.str8_ValidData = strValidData.str8_ValidData;
structure.str9_ValidData = strValidData.str9_ValidData;
list.Add(structure);
i++;
}
return list;
}
public List<List<Structs.strDataImport>> loadstrDataAsync(string FileName)
{
var engine_Data = new FileHelperAsyncEngine<strData>();
engine_Data.BeforeReadRecord += BeforeEventAsync;
engine_Data.AfterReadRecord += AfterEventAsync;
engine_Data.Progress += ReadProgress;
List<strData> list = new List<strData>();
List<List<Structs.strDataImport>> list2D = new List<List<Structs.strDataImport>>();
using (engine_Data.BeginReadFile(FileName))
{
var prevRowNo = 0;
var j = 0;
strCnt = 0;
foreach (strData filteredData in engine_Data)
{
if (prevRowNo > filteredData.RowNo)
{
list2D.Add(copyList(list));
list.Clear();
}
prevRowNo = filteredData.RowNo;
list.Add(filteredData);
}
list2D.Add(copyList(list));
}
return list2D;
}
private Type strIDSelector(MultiRecordEngine engine, string recordLine)
{
if (recordLine.Length == 0)
return null;
if (recordLine.Contains("** #_DATA .STATUS .STRID **"))
return typeof(strID);
else
{
return null;
}
}
private Type InfoSelector(MultiRecordEngine engine, string recordLine)
{
if (recordLine.Length == 0)
return null;
if (recordLine.Contains("** #_FILE **"))
return typeof(strInfo);
else
{
return null;
}
}
private Type strDataSelector(MultiRecordEngine engine, string recordLine)
{
if (recordLine.Length == 0)
return null;
if (recordLine.Contains("** #_DATA **"))
return typeof(strData);
else
{
return null;
}
}
private Type strSetupSelector(MultiRecordEngine engine, string recordLine)
{
if (recordLine.Length == 0)
return null;
if (recordLine.Contains("** #_SETUP **"))
return typeof(strSetup);
else
{
return null;
}
}
private Type strValidDataSelector(MultiRecordEngine engine, string recordLine)
{
if (recordLine.Length == 0)
return null;
if (recordLine.Contains("** #_VALID_DATA **"))
return typeof(strValidData);
else
{
return null;
}
}
private Type StartNumSelector(MultiRecordEngine engine, string recordLine)
{
if (recordLine.Length == 0)
return null;
if (recordLine.Contains("** #_START_NUMBER **"))
return typeof(strStartNum);
else
{
return null;
}
}
private Type str1Selector(MultiRecordEngine engine, string recordLine)
{
if (recordLine.Length == 0)
return null;
if (recordLine.Contains("** #_1 **"))
return typeof(str1);
else
{
return null;
}
}
private Type str4Selector(MultiRecordEngine engine, string recordLine)
{
if (recordLine.Length == 0)
return null;
if (recordLine.Contains("** #_4 **"))
return typeof(str4);
else
{
return null;
}
}
private void BeforeEventAsync(EngineBase engine, BeforeReadEventArgs<strData> e)
{
if (e.RecordLine != "")
{
if (Char.IsDigit(e.RecordLine, 0))
{
}
else
{
e.SkipThisRecord = true;
}
}
if (e.RecordLine.Contains("** #_VALID_DATA **;"))
{
e.SkipThisRecord = true;
}
}
private void AfterEventAsync(EngineBase engine, AfterReadEventArgs<strData> e)
{
if (e.RecordLine.Contains("** #_VALID_DATA **;"))
{
e.SkipThisRecord = true;
}
}
private void ReadProgress(object sender, ProgressEventArgs e)
{
ShowWaitForm("Opening file." + "\n" + "\n" + "Please wait...", "Open File");
_waitForm.progressBar1.Value = Convert.ToInt16(e.Percent);
}
public void ShowWaitForm(string message, string caption)
{
if (_waitForm != null && !_waitForm.IsDisposed)
{
return;
}
_waitForm = new readCSVprogressForm();
_waitForm.ShowMessage(message);
_waitForm.Text = caption;
_waitForm.TopMost = true;
_waitForm.Show();
_waitForm.Refresh();
System.Threading.Thread.Sleep(700);
Application.Idle += OnLoaded;
}
private void OnLoaded(object sender, EventArgs e)
{
Application.Idle -= OnLoaded;
_waitForm.Close();
}
}
}
Given the comments, it sounds like the problem is really that you're using structs extensively. These should almost certainly be classes for idiomatic C#. See the design guidelines for more details of how to pick between these.
At the moment, you're loading all the values in a big List<T>. Internally, that has an array - so it's going to be an array of your struct type. That means all the values are required to be in a single contiguous chunk of memory - and it sounds like that chunk can't be allocated.
If you change your data types to classes, then a contiguous chunk of memory will still be required - but only enough to store references to the objects you create. You'll end up using slightly more data overall (due to per-object overhead and the references to those objects) but you won't have nearly as strict a requirement on allocating a single big chunk of memory.
That's only one reason to use classes here - the reason of "this just isn't a normal use of structs" is a far bigger one, IMO.
As an aside, I'd also very strongly recommend that you start following .NET naming conventions, particularly around the use of capitalization and avoiding underscores to separate words in names. (There are other suggestions for improving the code in the question too, and I'd advise reading them all carefully.)

asynchronous operation with recyclerview and asynctask in xamarin android

i just started to work on performance in mobile app development and i am using asynctask. but i encounter a few challenges, whenever i instantiate my recyclerview in the oncreate method of my activity and retrieve data through async task, i then try to update the recyclerview adapter but it doesn't work. Here's my code below. Here's my activity below
public class awarenessActivity : Activity
{
public RecyclerView mRecyclerView;
public RecyclerView.LayoutManager mLayoutManager;
public RecyclerAdapter mAdapter;
public List<AwarePosts> awrPosts;
ScrollView tabsitem;
ImageButton aware;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//preparing the datasource
awrPosts = new List<AwarePosts>();//empty for now, its the data that i'm trying to retrieve with asynctask
//setting view from Layout resource
SetContentView(Resource.Layout.Main);
//get the linearlayout from the layout resource
tabsitem = (ScrollView)FindViewById(Resource.Id.scrollView1);
tabsitem.RemoveAllViews();
LayoutInflater.Inflate(Resource.Layout.awareness, tabsitem);
//this adds this layout to the main page
mRecyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);
//Create our layoutManager
mLayoutManager = new StaggeredGridLayoutManager(2, 1);
mRecyclerView.SetLayoutManager(mLayoutManager);
mRecyclerView.NestedScrollingEnabled = false;
//instantiate the adapter and pass in it the datasource
mAdapter = new RecyclerAdapter(awrPosts);
mAdapter.ItemClick += OnItemClick;
//plug the adapter into the recycler view
mRecyclerView.SetAdapter(mAdapter);
new retrievePosts(this).Execute();//executing the asynctask
ActionBar.SetHomeButtonEnabled(true);
ActionBar.SetDisplayHomeAsUpEnabled(true);// these are for the back arrow item
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
int id = item.ItemId;
if (id == global::Android.Resource.Id.Home)
{
StartActivity(typeof(menuActivity));
return true;
}
return base.OnOptionsItemSelected(item);
}
public void OnItemClick(object sender, int position)
{
string img, author, caption, info, postid, link, videolink;
try
{
img = awrPosts[position].image;
author = awrPosts[position].author;
caption = awrPosts[position].title;
info = awrPosts[position].externaL_LINK;
postid = awrPosts[position].awarenesS_EVENT_ID.ToString();
link = awrPosts[position].externaL_LINK;
videolink = awrPosts[position].videO_LINK;
string[] arr = new string[] { img.ToString(), author, caption, info, postid, link, videolink };
Bundle b = new Bundle();
Intent awareDetailInt = new Intent(this, typeof(awareDetailActivity));
b.PutStringArray("array", arr);
awareDetailInt.PutExtras(b);
StartActivity(awareDetailInt);
}
catch (Exception ex)
{
Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
}
}
public override void OnBackPressed()
{
Finish();
}
internal List<AwarePosts> getPosts(List<string> imag)
{
List<AwarePosts> ap = new List<AwarePosts>();
try
{
ap.Add(new AwarePosts()
{
awarenesS_EVENT_ID = 1,
gendeR_TARGET = 2,
image = imag.ElementAt(0),
title = "Are you Happy?",
author = "casual optimist",
videO_LINK = "",
externaL_LINK = "",
agE_TARGET_MIN = 5,
agE_TARGET_MAX = 9,
creatioN_DATE = "",
creatioN_USER = ""
});
ap.Add(new AwarePosts()
{
awarenesS_EVENT_ID = 2,
gendeR_TARGET = 2,
image = imag.ElementAt(1),
title = "Positive Vibes",
author = "etsy",
videO_LINK = "",
externaL_LINK = "",
agE_TARGET_MIN = 5,
agE_TARGET_MAX = 9,
creatioN_DATE = "",
creatioN_USER = ""
});
ap.Add(new AwarePosts()
{
awarenesS_EVENT_ID = 3,
gendeR_TARGET = 2,
image = imag.ElementAt(2),
title = "30+ funny comics",
author = "jimmy benton",
videO_LINK = "",
externaL_LINK = "",
agE_TARGET_MIN = 5,
agE_TARGET_MAX = 9,
creatioN_DATE = "",
creatioN_USER = ""
});
ap.Add(new AwarePosts()
{
awarenesS_EVENT_ID = 4,
gendeR_TARGET = 2,
image = imag.ElementAt(3),
title = "Smiling Doodle",
author = "instagram",
videO_LINK = "",
externaL_LINK = "",
agE_TARGET_MIN = 5,
agE_TARGET_MAX = 9,
creatioN_DATE = "",
creatioN_USER = ""
});
ap.Add(new AwarePosts()
{
awarenesS_EVENT_ID = 5,
gendeR_TARGET = 2,
image = imag.ElementAt(4),
title = "Have a good day",
author = "society6",
videO_LINK = "",
externaL_LINK = "",
agE_TARGET_MIN = 5,
agE_TARGET_MAX = 9,
creatioN_DATE = "",
creatioN_USER = ""
});
return ap;
}
catch (WebException web)
{
ap.Add(new AwarePosts { title = web.Response.ToString() });
return ap;
}
catch (Exception ex)
{
ap.Add(new AwarePosts { title = ex.Message + "\n" + ex.StackTrace});
return ap;
}
}
public List<string> drawableImageToBase64String(Context context)//doing some local data collection here
{
List<string> images = new List<string>();
int[] imgs = new int[] { Resource.Drawable.first1, Resource.Drawable.second1, Resource.Drawable.third1, Resource.Drawable.fourth1, Resource.Drawable.fifth2 };
foreach(var item in imgs)
{
Bitmap bitmap = BitmapFactory.DecodeResource(context.Resources, item);
MemoryStream stream = new MemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
byte[] ba = stream.ToArray();
string bal = Convert.ToBase64String(ba);
images.Add(bal);
}
return images;
}
}
here's my edited asynctask code
public class retrievePosts : AsyncTask<Java.Lang.Void, Java.Lang.Void, List<AwarePosts>>
{
awarenessActivity aw;
List<AwarePosts> awr;
Context mContext;
RecyclerAdapter mAdapter;
public retrievePosts(awarenessActivity awre, Context context, RecyclerAdapter adapter)
{
aw = awre;
mContext = context;
mAdapter = adapter;
}
protected override void OnPreExecute()
{
AndroidHUD.AndHUD.Shared.ShowImage(mContext, Resource.Drawable.load2, "Getting Posts...");
}
protected override List<AwarePosts> RunInBackground(Java.Lang.Void[] #params)
{
List<string> img = aw.drawableImageToBase64String(mContext);
awr = aw.getPosts(img);
return awr;
}
protected override void OnPostExecute(List<AwarePosts> result)
{
base.OnPostExecute(result);
mAdapter = new RecyclerAdapter(result);
mAdapter.NotifyDataSetChanged();
AndroidHUD.AndHUD.Shared.Dismiss(mContext);
Toast.MakeText(mContext, "successful", ToastLength.Long).Show();
}
}
and i'm calling it with this
awarenessActivity aw;
ScrollView tabsitem;
ImageButton aware;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//preparing the datasource
aw = new awarenessActivity();
awrPosts = new List<AwarePosts>();
//set our view from the "Playlist" Layout resource
SetContentView(Resource.Layout.Main);
//get the linearlayout from the layout resource
tabsitem = (ScrollView)FindViewById(Resource.Id.scrollView1);
tabsitem.RemoveAllViews();
LayoutInflater.Inflate(Resource.Layout.awareness, tabsitem);
//this adds this layout to the main page
mRecyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);
//Create our layoutManager
mLayoutManager = new StaggeredGridLayoutManager(2, 1);
mRecyclerView.SetLayoutManager(mLayoutManager);
mRecyclerView.NestedScrollingEnabled = false;
//instantiate the adapter and pass in it the datasource
mAdapter = new RecyclerAdapter(awrPosts);
mAdapter.ItemClick += OnItemClick;
//plug the adapter into the recycler view
mRecyclerView.SetAdapter(mAdapter);
new retrievePosts(aw, this, mAdapter).Execute();}
You did wrong to new a awarenessActivity in your retrievePosts, you can pass the mAdapter as parameter to your retrievePosts, try to modify your retrievePosts like this:
public class retrievePosts : AsyncTask<string, string, List<AwarePosts>>
{
List<AwarePosts> awr;
Context mContext;
RecyclerAdapter mAdapter
public retrievePosts(Context context, RecyclerAdapter adapter)
{
mContext = context;
mAdapter = adapter;
}
protected override void OnPreExecute()
{
AndroidHUD.AndHUD.Shared.ShowImage(mContext, Resource.Drawable.load2, "Getting Posts...");
}
protected override List<AwarePosts> RunInBackground(params string[] #params)
{
List<string> img = aw.drawableImageToBase64String(mContext);
//not sure what are you doing here, if you want to get some objects from your awarenessActivity, still try to make it as a parameter and pass to here.
return awr;
}
protected override void OnPostExecute(List<AwarePosts> result)// this function is supposed to run on the UI thread
{
base.OnPostExecute(result);
mAdapter = new RecyclerAdapter(result); // assigning the data here
mAdapter.NotifyDataSetChanged();//y'all kn what i'm trying to do here
AndroidHUD.AndHUD.Shared.Dismiss(mContext);
Toast.MakeText(mContext, "successful", ToastLength.Long).Show();
}
}
And when you use it, try like this new retrievePosts(this, mAdapter).Execute();.
I didn't test this code, but it should be something like it. I noticed that in your RunInBackground method, you also tried to get some object from the awarenessActivity, try to pass it like RecyclerAdapter here as parameter to this class. Don't create a new Activity in it.
Finally, i got it to work #grace Feng's answer was correct. i just didn't set the recycler view adapter inside the onpostexecute method after mAdapter.NotifyDataSetChanged();
after adding this line, it worked and my recycler view was populated. Thanks grace feng
mRecyclerView.SetAdapter(mAdapter);

Filter pins and its value on a map with a searchbar

I am trying to filter the pins on a map depending on what you write in the searchbar. So if you write for example: "Unit" then only the pins with the adress "Unit....(ed states)" will show up. I have started with some code but I am not sure how I should carry on. When I type something now every pin loads instead of the ones that match with the inputted text on the searchbar. I guess I have to use the filterfunction before I add the pins.
This is my startPage:
public StartPage ()
{
searchBar.TextChanged += (sender2, e2) => FilterContacts(searchBar.Text);
searchBar.SearchButtonPressed += (sender2, e2) => FilterContacts(searchBar.Text);
}
This is where the filter is happening. I get the data from my DB.
private async void FilterContacts (string filter)
{
map.Pins.Clear ();
if (string.IsNullOrWhiteSpace (filter)) {
} else {
var getItems = await phpApi.getInfo ();
foreach (var currentItem in getItems["results"]) {
theName = currentItem ["Name"].ToString (); //theName = string
theAdress = currentItem ["Adress"].ToString (); //theAdress = String
var theUserPosition = theAdress;
Geocoder gc = new Geocoder ();
Task<IEnumerable<Position>> result =
gc.GetPositionsForAddressAsync (theUserPosition);
if (theAdress != null) {
IEnumerable<Position> data = await result;
foreach (Position p in data) {
var pin = new Pin ();
pin.Position = new Position (p.Latitude, p.Longitude);
pin.Label = theName;
pin.Address = theAdress;
map.Pins.Add (pin);
theAdress.ToLower ().Contains (filter.ToLower ());
}
}
}
}
}
load the data and geocode it ONCE and store it; then only call the filter logic
public StartPage ()
{
searchBar.TextChanged += (sender2, e2) => FilterPins(searchBar.Text);
searchBar.SearchButtonPressed += (sender2, e2) => FilterPins(searchBar.Text);
}
// create a list to store our Pins
List<Pin> myPins = new List<Pin>();
private async override void OnAppearing() {
if (myPins.Count == 0) {
myPins = await LoadData();
filterPins(string.Empty);
}
}
// load the data, geocode, store results
private async List<Pin> LoadData() {
var pins = new List<Pin>();
var getItems = await phpApi.getInfo ();
foreach (var currentItem in getItems["results"]) {
Geocoder gc = new Geocoder ();
var pos = await gc.GetPositionsForAddressAsync (theUserPosition);
foreach (Position p in pos) {
var pin = new Pin ();
pin.Position = new Position (p.Latitude, p.Longitude);
pin.Label = theName;
pin.Address = theAdress;
pins.Add(pin);
}
}
return pins;
}
private async void FilterPins (string filter)
{
map.Pins.Clear ();
foreach(Pin p in myPins) {
if (string.IsNullOrWhiteSpace(filter) || (p.Address.Contains(filter)) {
map.Pins.Add(p);
}
}
}

Google AdWords v201206 DotNet Client GetClientReport trouble

Here's what I'm doing:
Selector selector = new Selector();
selector.fields = new string[] {"CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "CriteriaDestinationUrl", "Clicks", "Impressions", "Cost"};
Predicate predicate = new Predicate();
predicate.field = "Status";
predicate.#operator = PredicateOperator.IN;
predicate.values = new string[] { "ACTIVE", "PAUSED" };
selector.predicates = new Predicate[] { predicate };
ReportDefinition definition = new ReportDefinition();
definition.reportName = "criteria report";
definition.reportType = ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT;
definition.downloadFormat = DownloadFormat.XML;
definition.dateRangeType = ReportDefinitionDateRangeType.YESTERDAY;
definition.selector = selector;
definition.includeZeroImpressions = true;
_handler.RunReport(new AdWordsUser(), definition);
And here's my handler method:
public void RunReport(AdWordsUser user, ReportDefinition definition)
{
if (definition != null)
{
string reportContents = string.Empty;
try
{
ReportUtilities utilities = new ReportUtilities(user);
utilities.ReportVersion = "v201206";
ClientReport report = utilities.GetClientReport(definition);
reportContents = report.Contents.ToString();
}
catch (Exception ex)
{
_errorHandler.AddError(ex);
}
}
}
Where I step through I get this error:
Report contents are invalid. - !!!2|||-1|||[ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH # selector]???
Been searching for hours trying to find a solution. Any hints?
It appears that the issue is indeed needing to pass in the customerClientID.
This document helped me picture what was going on.
I ended up modifying my code like this:
var configOptions = new Dictionary<string,string>();
configOptions.Add("clientCustomerID", customerID.ToString());
_handler.RunReport(new AdWordsUser(configOptions), definition);

Categories

Resources