|
I have an incoming json object that I can successfully deserialize into an object. However, I now need to send that object back to the UI and to do this we use Google Proto objects.
This is what the json string looks like coming in and what it should look like going back out:
"lang\":{\"en-US\":{\"name\":\"AS Test Assembly Activity\",\"description\":\"Activity to test assembly activities\"}
I am trying to organize my proto messages that would output the same but I am having no luck. Here is what I have so far.
Proto Messages:
message CustomActivityConfig {
optional CustomActivityLanguage lang = 5;
}
message CustomActivityLanguage {
required string key = 1;
repeated LanguageData lang = 2;
}
message LanguageData {
optional string name = 1;
optional string description = 2;
}
This gives me an output of:
"lang":{"key":"en-US","lang":[{"name":"AS Test Assembly Activity","description":"Activity to test assembly activities"}
My Class structure which holds the correct data from the json at the top looks like this:
[Serializable]
public class CustomAssemblyData
{
public Dictionary<string, LangData> Lang { get; set; }
}
[Serializable]
public class LangData
{
public string Name { get; set; }
public string Description { get; set; }
}
So what I am doing is iterating through the KeyValuePair in my class above and trying to pack it into my proto message.
I feel if I can get the proto right that it should work as expected
If this helps, here is how I am currently trying to pack the proto (which gives the second incorrect json output:
var cac = new CustomActivityConfig.Builder();
foreach (KeyValuePair<string, LangData> kvp in genericAssembly.CustomActivityConfig.Lang)
{
var culture = kvp.Key;
var name = kvp.Value.Name;
var desc = kvp.Value.Description;
var langData = new LanguageData.Builder()
{
Name = name,
Description = desc
}.Build();
var customActivityLanguage = new CustomActivityLanguage.Builder()
{
Key = culture
};
customActivityLanguage.AddLang(langData);
cac.Lang = customActivityLanguage.Build();
}
Also, if anyone can answer me this: Is there any way to get rid of the field names? 'Key', 'Lang' for instance and just show the values?
Hope this makes sense. Appreciate the time.
|
|
|
|
|
What are you actually using to build the protobuf? Are you using Jon Skeet's implementation[^]?
|
|
|
|
|
I believe that is what we are using but am not 100% on it. Reason being is that the implementation is a part of our framework here and we don't touch it but rather implement it. I cannot be certain how the core framework is using it.
I've determined that the 'dataType' so to speak is a Dictionary<string, class=""> and that will allow me to deserialize the json into an object correctly.
When it comes into my area it is a json, I deserialize into a class, now I need to pack it back into a proto and send it out in the exact same format it comes in at. I can't seem to order my proto in a way that does this.
modified 21-Mar-14 10:37am.
|
|
|
|
|
Is there much overhead in WCF SSL (wsHttpBinding)? I have a web service that returns 1MB - 4MB TIFs. I originally had it on http during dev and got 3 - 5 / min (generation takes a while). Same code, but on SSL drops to 1 - 2 / min. Surely SSL can't have 50% overhead???
|
|
|
|
|
Post your question in the WCF forum.
|
|
|
|
|
Hi everyone,
I have a problem with my project.
I must to do a calendar with days and hours.
On the first's datagridview row I want to write this hour (07:00:00).
At this hour I want to add 30 minutes automatically.
I want that my output is like this:
07:00:00
07:30:00
08:00:00
08:30:00
...
But, it didn't works correctly.
This is my code:
TimeSpan ora = TimeSpan.FromHours(7);
TimeSpan mezzora = TimeSpan.FromMinutes(0);
TimeSpan orario;
for (int i = 0; i < 20; i++)
{
dataGridView2.Rows.Add("");
orario = ora + mezzora;
dataGridView2[0, i].Value = orario;
mezzora = TimeSpan.FromMinutes(30);
}
In output I have this:
07:00:00
07:30:00
07:30:00
07:30:00
Can you help me?
|
|
|
|
|
The issue that you have is that you never allocate the new time increment to ora, and mezzora never changes. Fortunately, you can update mezzora with no problem using the following:
mezzora = TimeSpan.FromMinutes(30 * (i + 1)); What you're doing here is multiplying the minutes by the increment of i (you need to add 1 to the count because you have a zero offset here.
|
|
|
|
|
It works !
Thanks so much Pete O'Hanlon !
|
|
|
|
|
You're welcome. I'm glad that I could help.
|
|
|
|
|
I have a datagrid and I set the ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" in file XAML. The Horizontal it works but the Vertical not works.
I tryed to drag the bottom of the window upward and the vertical scrollbar it doesn't work.
|
|
|
|
|
Can we see your XAML code?
|
|
|
|
|
Please use the WPF forum for questions on WPF.
|
|
|
|
|
Sorry!!! I move the question in WPF forum!
|
|
|
|
|
How could I change my code to use in every form. At the moment it only works on the main one and I need to send the main form's instance.
Could I change my code so that it can be used in every form?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SefelecTester
{
public class WC
{
private MainWin _main;
public WC(MainWin _main)
{
this._main=_main;
}
public void ConWrite(string text, int select=0)
{
Console.WriteLine(text);
if (select>0)
{
if (select == 1)
{
InvokeC.SynchronizedInvoke(_main, () => _main.OutputConsole.Items.Add(text));
InvokeC.SynchronizedInvoke(_main, () => _main.OutputConsole.SelectedIndex = -1);
}
else if (select == 2)
{
InvokeC.SynchronizedInvoke(_main, () => _main.ErrorConsole.Items.Add(text));
InvokeC.SynchronizedInvoke(_main, () => _main.ErrorConsole.SelectedIndex = -1);
}
}
}
}
}
modified 21-Mar-14 7:45am.
|
|
|
|
|
If you want it to be available to all forms, and you are using windows forms, you could always change the constructor to accept a Form instead (and store this in a field of type Form obviously):
public class WC
{
private Form _form;
public WC(Form form)
{
_form = form;
}
}
|
|
|
|
|
Pete's right - but the other way to do it is to derive your new class from Form, and then derive your forms from your new class. That way, you don't need to construct an instance of your class separately, and the code you add is available to operate on the form immediately, without passing a form reference to it.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
There is an implicit interface here: this code can never work in a form which doesn't have an OutputConsole and an ErrorConsole, as well as working with InvokeC (I don't know what that requires but presumably BeginInvoke).
So the most general you can get would be to make the thing passed to the constructor be an instance of that interface:
interface IMessageLogger {
void LogToOutput(string message);
void LogToError(string message);
void InvokeAsync(Action<string> method, string method);
}
class WC {
private IMessageLogger logger;
public WC(IMessageLogger logger) { this.logger = logger; }
public void ConWrite(string text, int target = 0) {
Console.WriteLine(text);
switch(target) {
case 1: logger.InvokeAsync(logger.LogToOutput, text); break;
case 2: logger.InvokeAsync(logger.LogToError, text); break;
}
}
There's a design decision here about whether that asynchroneity should be hidden inside the implementation of LogToOutput; I'd say it probably should, but I wanted to leave this code recognisably derived from yours.
Your MainWin would then need to implement IMessageLogger (writing items to the OutputConsole and ErrorConsole in the LogToOutput and LogToError methods). InvokeAsync would be a thin cover on BeginInvoke or Invoke:
public void InvokeAsync(Action<string> method, string text) {
BeginInvoke(delegate() { method(text) });
}
|
|
|
|
|
Good idea but I couldn't get interface to work.
Managed to solve it with events.
|
|
|
|
|
Message Removed
modified 20-Mar-14 10:11am.
|
|
|
|
|
Hi
how to use Response.Clear() in c#
|
|
|
|
|
Context?
Regards,
Rob Philpott.
|
|
|
|
|
Hi,
I have a pivot table in excel sheet 1. I need to write a C# code to copy and paste whole pivot table in sheet 2 of same excel file. While copying, I need to expand all columns data also.
Please help me in doing this.
Thanks
|
|
|
|
|
rajnknit07 wrote: Please help me in doing this. Help with what exactly?
As is, you only specified what the finished solution should do. Divide your problem in smaller things, like reading an Excel file using C#, writing a file, and then move on to modifying data.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi all,
I would like to know what is the best way to manage the passage of events between WinForms.
I have to click on the MainForm 6 buttons with either the mouse or using 6 corresponding digital inputs.
Obviously with the mouse there are no problems, but to use the digital inputs as mouse-clicks, I have written a class that runs a background timer-thread that reads the digital inputs and uses delegates to notify the MainForm on the changes of the digital inputs (from 0 to 1) so that his handlers can perform the function:
key-x.PerformClick()
to call the method linked to the x button.
My problem is: how can I do it as fast, clean and safe using MainForm modal-forms childs ? And overall, what about with the children of the children that can be up to the 4-th level depth ? The 6 buttons have form by form always to perform different operations.
OK, I can use a chain of delegates among the various modal-form-childs but it is ugly and not so simple, fast and very safe to realize.
Any idea ?
modified 24-Mar-14 12:20pm.
|
|
|
|
|
What do you mean with a "digital input"? I'd assume you'd loop through your forms, and hook up any buttons using reflection.
Am I right that you want to see an event raised in the mainform when one of the buttons on the child-forms is clicked?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|