I'm trying to connect to facebook using my xamarin app, and then posting thing.
I got this working so far, however when I use the Map layout for my custom graph story, I cannot attach the coordinates I need to use.
I'm currently using a dictionary:
Dictionary<string, string> results = new Dictionary<string, string>
{
{"route", DictionaryToJson(routeObject)},
{"location_start", DictionaryToJson(point1)},
{"distance", "5.2"},
{"duration", "01:05:36"},
{"maxspeed", "12.4"},
{"message", "Blargh"},
};
var newRequest = new OAuth2Request("POST",
new Uri("https://graph.facebook.com/me/tracker:obj"),
results, Account);
DictionaryToJson:
private string DictionaryToJson(Dictionary<string, string> dict)
{
var entries = dict.Select(d =>
string.Format("\"{0}\": \"{1}\"", d.Key, string.Join(",", d.Value)));
return "{" + string.Join(",", entries) + "}";
}
This works fine for all objects that can be converted to a string, however I cannot use this for the GeoPoint collection I need to pass to it, for it to draw the route.
Anyone knows how this can be done? I've been trying to get this working for an entire day by now, and no progress.
Related
I wanted to update Chrome Profile preferences in Selenium C# to make a popup disappear by adding following line as part of Chrome Options.
string url = "https://google.com";
string envName = "xyz.qa";
ChromeOptions.AddUserProfilePreference("protocol_handler.allowed_origin_protocol_pairs." + url + "." + envName, true);
However the above line is resulting in updating chrome profile preference file in a wrong format i.e., when it encounters .(dot) in preference name it is not getting suppressed.
Expected:
"protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com":{"xyz.qa":true}}}
Actual:
"protocol_handler":{"allowed_origin_protocol_pairs":{"https://google" {"com":{"xyz" {"qa":true}}}}}
Second approach:
string jsonValue = "{ " + url + ":{ " + envName + ":true} }";
var obj = JObject.Parse(jsonValue);
ChromeOptions.AddUserProfilePreference("protocol_handler.allowed_origin_protocol_pairs", obj);
Expected: "protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com":{"xyz.qa":true}}}
Actual: "protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com" :{"xyz.qa":[] }}}
Everything looks good except the value true, it is getting replaced with [].
I tried different ways to correct the format but not able to get it corrected. Please suggest how do I update the preference file in expected format.
Finally, able to figure out how to update the ChromeProfile preferences when the url or app name contains . (dot). Hope this helps someone to handle the Chrome Security popup through code.
var first = new Dictionary<string, object> { };
var second = new Dictionary<string, object> { };
options.prefs = new Dictionary<string, object> { };
first.Add("<<ApplicationName>>." + "<<Environment>>", false);
second.Add("<<ApplicationURL>>", first);
options.AddUserProfilePreference("protocol_handler.allowed_origin_protocol_pairs", second);
in my case i wanted to display items from local SQLite database which i created as shown below:
public string CreateDB() //create database
{
var output = "";
string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "IsoModule.db3");
output = "Database Created";
return output;
}
public string CreateTable() //create table
{
try
{
string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "IsoModule.db3");
var db = new SQLiteConnection(dbPath);
db.CreateTable<UserInfo>();
db.CreateTable<TableInfo>();
string result = "Table(s) created";
return result;
}
catch (Exception ex)
{
return ("Error" + ex.Message);
}
}
and this is my code where i wish to retrieve data
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "IsoModule.db3");
var tablelistout = new SQLiteConnection(path);
var alltables = tablelistout.Table<TableInfo>();
foreach (var listing in alltables)
{
var from = new string[]
{
listing.tname + " - " + listing.status
};
ListView listtable = (ListView)FindViewById(Resource.Id.listtable);
listtable.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, from);
}
the code runs with NO ERROR but it only display last item in the table. it is confusing me, so i would like to ask how can i retrieve all the data from specific table?
or if someone has asked the same question please share me the link. many appreciate.
var alltables = tablelistout.Table<TableInfo>();
var data = new List<string>();
foreach (var listing in alltables)
{
data.Add(listing.tname + " - " + listing.status);
}
ListView listtable = (ListView)FindViewById(Resource.Id.listtable);
listtable.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, data.ToArray());
All I did was move 2 things out of the loop. First, I moved out the initialization of the array. Second, I moved out the listView + assignation of the adapter.
Your issue is that in the loop, you were always overriding everything you had done in the previous iteration (leaving you with the last item like you said).
Also, You should take note that it will be important for you to create a custom adapter if you plan on having a decent amount of data. ArrayAdapter is a native Android class which is then wrapped by a C# Xamarin object, meaning you will have both a C# and Java object per row. It adds overhead as both garbage collectors will have work to do and can cause performance issues. Xamarin devs tend to generally avoid it with the exception of quick prototyping.
On another note, I would use the FindViewById<T>(Int32) instead of the FindViewById(Int32) and casting it. FindViewById<ListView>(Resource.Id.listtable) in your case. Just taking advantage of the power of generics.
we are working on a project where we are using Storm on HDInsight to analyze real-time data. We are using event hubs as input and output and we are having some problems passing the data through the topology. We are currently having one JavaSpout as input handler, one custom Bolt (Bolt1) that is suppose to do some analysis on the data, and one JavaBolt that is suppose to take the analyzed data and send it to the output event hub. Passing data through the JavaSpout and JavaBolts works like a charm, but when we indroduce the custom Bolt the data gets encapsulated or something, its not showing what it should. the output is supposed to show a JSON string, but is shows some random stuff that looks like: [B#6d645e45
Most part of this is code from this tutorial: http://azure.microsoft.com/sv-se/documentation/articles/hdinsight-storm-develop-csharp-event-hub-topology/
This is our topology builder:
TopologyBuilder topologyBuilder = new TopologyBuilder("EventHubReaderTest");
int partitionCount = Properties.Settings.Default.EventHubPartitionCount;
JavaComponentConstructor constructor = JavaComponentConstructor.CreateFromClojureExpr(
String.Format(#"(com.microsoft.eventhubs.spout.EventHubSpout. (com.microsoft.eventhubs.spout.EventHubSpoutConfig. " +
#"""{0}"" ""{1}"" ""{2}"" ""{3}"" {4} ""{5}""))",
Properties.Settings.Default.EventHubPolicyName,
Properties.Settings.Default.EventHubPolicyKey,
Properties.Settings.Default.EventHubNamespace,
Properties.Settings.Default.EventHubNameInput,
partitionCount,
""));
topologyBuilder.SetJavaSpout(
"EventHubSpout",
constructor,
partitionCount);
List<string> javaSerializerInfo = new List<string>() { "microsoft.scp.storm.multilang.CustomizedInteropJSONSerializer" };
topologyBuilder.SetBolt(
"bolten",
Bolt1.Get,
new Dictionary<string, List<string>>()
{
{Constants.DEFAULT_STREAM_ID, new List<string>(){"Event"}}
},
partitionCount).
DeclareCustomizedJavaSerializer(javaSerializerInfo).
shuffleGrouping("EventHubSpout");
JavaComponentConstructor constructorout =
JavaComponentConstructor.CreateFromClojureExpr(
String.Format(#"(com.microsoft.eventhubs.bolt.EventHubBolt. (com.microsoft.eventhubs.bolt.EventHubBoltConfig. " +
#"""{0}"" ""{1}"" ""{2}"" ""{3}"" ""{4}"" {5}))",
Properties.Settings.Default.EventHubPolicyName,
Properties.Settings.Default.EventHubPolicyKey,
Properties.Settings.Default.EventHubNamespace,
"servicebus.windows.net", //suffix for servicebus fqdn
Properties.Settings.Default.EventHubNameOutput,
"true"));
topologyBuilder.SetJavaBolt(
"EventHubBolt",
constructorout,
partitionCount).
shuffleGrouping("bolten");
return topologyBuilder;
This is the Bolt that is suppose to do some work
public Bolt1(Context ctx)
{
this.ctx = ctx;
Dictionary<string, List<Type>> inputSchema = new Dictionary<string, List<Type>>();
inputSchema.Add("default", new List<Type>() { typeof(string) });
Dictionary<string, List<Type>> outputSchema = new Dictionary<string, List<Type>>();
outputSchema.Add("default", new List<Type>() { typeof(string) });
this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema));
this.ctx.DeclareCustomizedDeserializer(new CustomizedInteropJSONDeserializer());
}
public static Bolt1 Get(Context ctx, Dictionary<string, Object> parms)
{
return new Bolt1(ctx);
}
//this is there the magic should happen
public void Execute(SCPTuple tuple)
{
string test = "something";
//we are currently just trying to emit a string
ctx.Emit(new Values(test));
}
We hope that we explained the problem good enough, we dont quite grasp how the topology works so its hard to troubleshoot.
EDIT
We solved it by declaring a deserializer in our topology:
List javaSerializerInfo = new List() { "microsoft.scp.storm.multilang.CustomizedInteropJSONSerializer" };
List javaDeserializerInfo = new List() { "microsoft.scp.storm.multilang.CustomizedInteropJSONDeserializer", "java.lang.String" };
topologyBuilder.SetBolt(
"bolten",
Bolt1.Get,
new Dictionary<string, List<string>>()
{
{Constants.DEFAULT_STREAM_ID, new List<string>(){"Event"}}
},
partitionCount).
DeclareCustomizedJavaSerializer(javaSerializerInfo).
DeclareCustomizedJavaDeserializer(javaDeserializerInfo).
shuffleGrouping("EventHubSpout");
And in the custom C# bolt we declared a serializer:
this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema));
this.ctx.DeclareCustomizedDeserializer(new CustomizedInteropJSONDeserializer());
this.ctx.DeclareCustomizedSerializer(new CustomizedInteropJSONSerializer());
Im new with WP8.
Im asking which class i should use to get data from a webservice.
I need to launch many Asynchronous requests. 1request=1 image and i need a lot of image in my UI.
in a first time i tried with the webclient class but i can't manage the content type "application/octet-stream" with it so at this time im trying to use the HttpClient class but I need your help. I also need to use Authentication with credantials to connect to the webservice.
In a second time i need to convert the data obtained in Bitmapimage.But i think it's an easier part.I would probably use the Stream class for that.*
thanks for your help
Sry for my english BTW :p
Im not sure it would help but i join a sample of the code,i used a dictionnary of HttpClient because i encountered an error while trying to launch several async requests on the same instance of a Webclient... the 2 lists remain empty...
Dictionary<string, HttpClient> HttpClientDic = new Dictionary<string, HttpClient>();
List<byte[]> imageDataBlocksPresta = new List<byte[]>();
List<byte[]> imageDataBlocksCollab = new List<byte[]>();
public async Task< List<byte[]>> DownloadAsyncRecherchePhoto(string uri,string critere = "")
{
string password = Authentification.MainPage.Password;
string user = Authentification.MainPage.User;
string domain = Authentification.MainPage.Domain;
i++;
var handler = new HttpClientHandler { Credentials = new NetworkCredential(user, password, domain) };
HttpClientDic.Add("Client" + i.ToString(), new HttpClient(handler));
if (critere == "presta")
{
imageDataBlocksPresta.Add(await HttpClientDic["Client" + i.ToString()].GetByteArrayAsync(uri));
return imageDataBlocksPresta;
}
else if (critere == "collab")
{
imageDataBlocksCollab.Add(await HttpClientDic["Client" + i.ToString()].GetByteArrayAsync(uri));
return imageDataBlocksCollab;
}
//gérer l'erreur
else return null;
I want to delete videos from my YouTube channel which video ids are selected, though MultiSelection property of ListBox is on, code doesn't work, is there any other solution? I get such an error as follows:
Execution of request failed: http://gdata.youtube.com/feeds/api/users/xxxxxx/uploads/System.Windows.Forms.ListBox+SelectedObjectCollection
Here is my code:
public void delete()
{
YouTubeRequestSettings settings = new YouTubeRequestSettings(my app name,
my dev key,
my username,
my password);
YouTubeRequest request = new YouTubeRequest(settings);
Uri videoEntryUrl = new Uri(String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads/{1}", my channel name, list.checkedItems));
Video video = request.Retrieve<Video>(videoEntryUrl);
request.Delete(video);
}
Code for Populating the CheckedListBox
Feed<Video> videoFeed;
string feedUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads";
videoFeed = request.Get<Video>(new Uri(feedUrl));
foreach (Video entry in videoFeed.Entries)
{
list.Items.Add(entry.VideoId,0);
}
Ok...I think the key here is to get the data out of the object collection - and an easy way to do that is with a foreach loop. I'm not familiar with the YouTube API so I don't know what format it expects the video ID in (for multiple videos), but for purposes of this example I'll use a comma.
string videoIDs = "";
foreach (object vidID in list.CheckedItems)
{
videoIDs = videoIDs + vidID.ToString() + ",";
}
videoIDs = videoIDs.Substring(0, videoIDs.Length - 1);
Basically, the above code loops through the CheckedListBox.CheckedItemCollection and gets the video IDs, which is what you are storing in the CheckedBoxList from the code you provided.
Then you can simply use the videoIDs string in your code:
Uri videoEntryUrl = new Uri(String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads/{1}", my channel name, videoIDs));
Again, this is a general approach - you will need to modify the code to fit the YouTube API.
Feed<Video> videoFeed;
string feedUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads";
videoFeed = request.Get<Video>(new Uri(feedUrl));
foreach (Video entry in videoFeed.Entries)
{
list.Items.Add(entry.VideoId,0);
}