|
As Dave and and Richard said, there are quite a few libraries out there, and adding too many points is probably not a good idea.
However, it may be that the library is optimized for this. Have you checked the lib's documentation?
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
Why are you replying to me instead of the OP?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry, it was my mistake.
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
You might not know what you said.
This space for rent
|
|
|
|
|
public class GcmSender
{
private const string GcmUri = "https://android.googleapis.com/gcm/send";
#region Properties
public string DeviceToken { get; set; }
public string ApiKey { get; set; }
public string ResultJson { get; private set; }
#endregion
HttpWebRequest _gcmRequest;
HttpWebResponse _gcmResponse;
public GcmSender()
{
}
public GcmSender(string deviceToken, string apiKey)
{
DeviceToken = deviceToken;
ApiKey = apiKey;
}
public string Send(string message)
{
if (DeviceToken == null || ApiKey == null)
{
return "[ERROR] Device Token or API Key has not been set";
}
InitGcmClient();
PostPayload(message);
try
{
_gcmResponse = _gcmRequest.GetResponse() as HttpWebResponse;
}
catch (WebException we)
{
return "[ERROR] There is a problem within processing GCM message \n" + we.Message;
}
ResultJson = ReadResponse(_gcmResponse);
return ResultJson;
}
private string ReadResponse(HttpWebResponse response)
{
StreamReader responseReader = new StreamReader(response.GetResponseStream());
return responseReader.ReadToEnd();
}
private void InitGcmClient()
{
_gcmRequest = WebRequest.Create(GcmUri) as HttpWebRequest;
if (_gcmRequest != null)
{
_gcmRequest.ContentType = "application/json";
_gcmRequest.UserAgent = "Android GCM Message Sender Client 1.0";
_gcmRequest.Method = "POST";
_gcmRequest.Headers.Add("Authorization", "key=" + ApiKey);
}
}
private void PostPayload(string message)
{
string payloadString = AssembleJSONPayload(DeviceToken, message);
byte[] payloadByte = Encoding.UTF8.GetBytes(payloadString);
_gcmRequest.ContentLength = payloadByte.Length;
using (Stream payloadStream = _gcmRequest.GetRequestStream())
{
payloadStream.Write(payloadByte, 0, payloadByte.Length);
payloadStream.Close();
}
}
private string AssembleJSONPayload(string gcmDeviceToken, string gcmBody)
{
string payloadFormatJSON =
"{{" +
"\"registration_ids\" : [\"{0}\"]," +
"\"data\" : {{" +
" {1} " +
"}}" +
"}}";
string payload = string.Format(payloadFormatJSON, gcmDeviceToken, gcmBody);
Debug.WriteLine("payload : " + payload);
return payload;
}
}
This code works fine in WPF application. when I try this code in wcf it crashes at
_gcmResponse = _gcmRequest.GetResponse() as HttpWebResponse; and says
The remote server returned an error: (400) Bad Request. . Can anyone help me?
|
|
|
|
|
Try some sniffer (like Fiddler) to see what the actual HTTP request is, that may give you a hint why it is 400!
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Well, on the surface of it looks ok. What do you mean 'try it in wcf'?
One observation is you are storing the web request and response as class members - this seems unusual to me, and means that if you call Send() in a multithreaded manner things are likely to go very wrong.
Other things it could be - proxy connections perhaps although I'd expect a different error and its usual to apply some credentials to the request. Check the account the WCF host is running under..?
Regards,
Rob Philpott.
|
|
|
|
|
I've been struggling with this one for half-a-day and I'm still not figuring out how to do this correctly.
What I am trying to do is set up a popup control that will reactive the owning window in the event that the window looses focus but the user then clicks the popup. The trouble is that, normally, the popup looses focus with the window and the user cannot interact with it until the window is reactivated. Since the popup is always 'On Top', it is always shown even if the parent window gets covered up. This makes it the natural choice for users to return to the application.
This code works only half way.
public partial class App : Application
{
private bool _active;
public bool Active { get { return _active; } }
private void Application_Activated(object sender, EventArgs e)
{
_active = true;
}
private void Application_Deactivated(object sender, EventArgs e)
{
_active = false;
}
}
public void PopupBase_MouseDown(object sender, EventArgs e)
{
App currentApp = Application.Current as App;
if (currentApp != null)
{
if (!currentApp.Active)
{
_owner.Activate();
}
}
}
This only works when the parent object is clicked but I'm having trouble wiring the child controls to trigger the event. If the user clicks anywhere in the popup except directly on a child element it works.
I tried this but it didn't work. The Popup's Child in all cases is a Border class.
public void PopupChild_Loaded(object sender, EventArgs e)
{
AddActivationHandler(this.Child.Child);
}
private void AddActivationHandler(UIElement element)
{
if (element is Panel)
{
Panel pElement = element as Panel;
foreach (UIElement child in pElement.Children)
{
AddActivationHandler(child);
}
}
element.MouseDown += PopupBase_MouseDown;
{
I stepped through and the event handlers do get added but they were never called. Is there another way to have all of a parent's children pass their events back up to a specific control?
After some further reading, is this something that could be handled with Routed Events?
modified 24-Nov-15 17:17pm.
|
|
|
|
|
Well i want to make my progressbar updating dynamicly.
So i know the distance and speed but in my while loop should i work with steps for updating my progress bar?
Well each step should be 10% because i have to update another progress in steps between 0 and 1.
double totalDistance = 7.3
double speed = 1;
double progress = (speed / totalDistance);
double step = progress / 10;
while (progress <= totalDistance)
{
progress += step;
Dispatcher.Invoke(new Action(() => {
SetProgress(0.1);
}));
}
modified 24-Nov-15 13:48pm.
|
|
|
|
|
You have great dreams - but follow the path[^] that leads you toward the light...
|
|
|
|
|
Kris Saelen wrote: So i know the distance and speed but in my while loop should i work with steps
for updating my progress bar? I prefer to use time-intervals; that way the actual process does not need to report each N times. Works best with long distances and small steps.
Would be done by checking in the loop if 250 or 500ms passed, and if true, update the progress.
--edit
Ignore that answer; this is the Lounge, and *all the other forums* are for code. Not this one.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Yes.
Wait.... No.
Hmm... Maybe?
|
|
|
|
|
Your "work" should be done on a different (worker) thread. After you compute each step, you update the value of "progress".
The main thread should have a timer (like, 50ms or so). It should query the value of "progress", and update the progress bar.
Easy peasy
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
thanks that did the trick !
|
|
|
|
|
Case:
1. While running loop to browse handle each record in Form1 and assign into cell with string: "processing" it is not assign "processing" when it runs through, when loop end new assignment string "xxx.." into cell, are you know why ? , While tracking Debug.Print command ("Processing... "); ran pass
[CODE]
...
bool bCalculator = false;
while (i < gridView1.RowCount)
{
...
gridView1.SetRowCellValue(i, "Status", "Processing...");
gridView1.RefreshRow(i); // Not working
//gridView1.RefreshData(); // Not working
Debug.Print("Processing... ");
Thread.Sleep(100);
bCalculator = objclsProcessing.Calculator(row);
...
}
[/CODE]
2. While running GridView1 not show the flow (row of gridview) is running?
|
|
|
|
|
|
Member 2458467 wrote: Thread.Sleep(100);
You should never sleep in the UI thread.
You should have one or more worker threads that do the work, and have a way to notify the UI thread when the work is complete. At which point you refresh each row in the grid.
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
I would of done somthing similar as
foreach(dataGridViewRow dr in GridView1.Rows)
{
dr.cells["thisCellName"].Value = "Processing..";
}
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
I also tried your way and then when the run was faulty on
[CODE]
while (i < dataGridView1.Rows.Count) //
{
...
dataGridView1["Status", i].Value = "Processing...";
Debug.Print("Processing...");
Thread.Sleep(100);
...
}
[/CODE]
|
|
|
|
|
As I stated earlier I use a foreach loop over the datagridview and not a while loop
foreach(DataGridviewRow dr in dataGridView1.Rows)
{
dr.Cell["CellName"].Value = "Processing..";
Debug.Print("Processing...");
}
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
I also tried your way but still not be
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
dr.Cell["CellName"].Value = "Processing..";
Debug.Print("Processing...");
}
|
|
|
|
|
Whats happening?
What is the datasource?
Is there an error message?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
I find examples of the GridView (or datagridview) handled by each line as follows:
including field: "ID", "CONTRACT", "COMPANY", "STATUS"
assuming there is processor Class and Form contains the GridView (or datagridview) will browser each row by a for loop or while loop, ... if not press the Play button, the column: "STATUS" value = empty (), when press the Play button to start running and treats each row, when browsing to at row, the row that are colored and that cell is assigned the phrase "processing...", if the process is complete by Class Process, the cell run assign the word "success", the reverse cell assigned word "not process", if the data fails to assign the cell words: "faulty data", noting that the data assigned to the cell of the column "STATUS "is in the function or procedure of handling class grade is assigned ("processing... ","not processing ", ...). you see attach file
modified 29-Nov-15 21:36pm.
|
|
|
|
|
Hello,
I currently have C++ server and C# client which communicate well using sockets.
But I may need to add some functionality on server side, and I prefer to do that using C# - so can I write a proxy c# application which will receive requests from client, do some processing and forward that to C++ server? and then back to client? is it possible?
|
|
|
|