Heartbeat Package WPF Unity Database Build

Source: Internet
Author: User

1. How heartbeat packets are sent:

The main client is sent to the server, the server received, and then reply.

Before doing the project, WPF communicates with U3d, the WPF side is on the listener side, and u3d belongs to the client, constantly sending a heartbeat packet to WPF

The WPF side code is as follows:

Embed U3d window
void Initu3d ()
{
To add a Exehost control to a Winformhost control
if (userdata.enableembu3d)
{
Exehost exehost = new Exehost ();

Formview.formHost.Child = Exehost;
Formhost.child = Exehost;
Exehost. Hold (Window_main.mainu3dpath);
}
Netparser = new Parser (this);
U3dmgr.setcallback (Netparser);
}
Parser Netparser;
ProgressBar ProgressBar;
public class Parser:u3dconnect. Iparser
{

Page_makeup_main page;
Public Parser (Page_makeup_main Page)
{
this.page = page;
}

public void Onhttpreq(string req, out U3dconnect.returninfo returndata)
{
throw new NotImplementedException ();
}

public void Onudprecv (Myjson.jsonnode_object json)
{

PAGE.ONRECVUDP (JSON);
}
}
BOOL bu3dinited = false;
BOOL Bloadscene = false;
BOOL M_ispicshow = false;


public void onrecvudp (Myjson.jsonnode_object JSON)//Receive a message from unity before sending a command to the past
{


IF (json["module"]. asstring () = = "Makeup")//is the module I want
{

Waitwindow.uiupdate ();

System.Diagnostics.Debug.WriteLine ("Window_wait:hide");
Waitwindow. Hide ();//Toggle Scene success, hidden wait interface
if (bu3dinited = = False | | json["CMD"]. asstring () = = "Init")
{
Bu3dinited = true;
Myjson.jsonnode_object loadlayout = new Myjson.jsonnode_object ();//load Room type
if (userdata.data["Scenetype"]. Asint () = = (int) scenetype.scene)
{
We've cut the scene.
Loadlayout. Setdictvalue ("module", "makeup");
Loadlayout. Setdictvalue ("cmd", "config_layout");
Loadlayout. Setdictvalue ("UserName", UserData.Data.asDict () ["UserName"]. Asstring ());
Loadlayout. Setdictvalue ("token", UserData.Data.asDict () ["token"]. Asstring ());
//loadlayout. Setdictvalue ("Defaultlayer", userdata.data["Defaultlayer"]. ToString ());
//To pass a field again to indicate whether to create a decoration or to open an existing decoration
Loadlayout. Setdictvalue ("EditMode", userdata.data["EditMode"]. ToString ());

U3dmgr.udpsend (loadlayout. ToString ());
}
Else
{
Loading room
Loadlayout. Setdictvalue ("module", "makeup");
Loadlayout. Setdictvalue ("cmd", "load_layout");//This also to change, different layers, hair different layers of the name of the past, initialized, the first layer of hair
Loadlayout. Setdictvalue ("Indexfile", userdata.data["Houselayoutindex"]);//Enter here, Nature will get this index
Loadlayout. Setdictvalue ("UserName", UserData.Data.asDict () ["UserName"]. Asstring ());
Loadlayout. Setdictvalue ("token", UserData.Data.asDict () ["token"]. Asstring ());
Loadlayout. Setdictvalue ("Defaultlayer", userdata.data["Defaultlayer"]. ToString ());
and pass it over again. A field that indicates whether to create a decoration or to open an existing decoration
Loadlayout. Setdictvalue ("EditMode", userdata.data["EditMode"]. ToString ());

U3dmgr.udpsend (loadlayout. ToString ());
}


String indexfile = userdata.data["Makeupindexfile"]. ToString ();//This is the judging click is
if (indexfile! = "" && indexfile! = "-1")
{
Reset to null again

Myjson.jsonnode_object load = new Myjson.jsonnode_object ();//load decoration
Loadlayout. Setdictvalue ("module", "makeup");
Loadlayout. Setdictvalue ("cmd", "load");
Loadlayout. Setdictvalue ("Indexfile", userdata.data["Makeupindexfile"]);
Loadlayout. Setdictvalue ("UserName", UserData.Data.asDict () ["UserName"]. Asstring ());
Loadlayout. Setdictvalue ("token", UserData.Data.asDict () ["token"]. Asstring ());
U3dmgr.udpsend (loadlayout. ToString ());
See if there are any renovations that can be loaded.
}

}
if (json["cmd"). asstring () = = "Updateindexfile")
{
userdata.data["Makeupindexfile"] = new Myjson.jsonnode_valuestring (json["Indexfile"]. Asstring ());//This is the existing decoration of the index file
userdata.data["Makeuppicindexfile"] = new Myjson.jsonnode_valuestring (json["Picindex"]. Asstring ());//This is the picindex of the decoration.
userdata.data["Isfix"] = new Myjson.jsonnode_valuenumber (json["isfixed"]. Asint ());//This is the picindex of the decoration.
if (Needtosave)
{
Onneedsave ();
Needtosave = false;
}
}

if (json["cmd"). asstring () = = "ResetIndex")
{

if (ProgressBar! = null)
{
ProgressBar. Visibility = System.Windows.Visibility.Hidden;
ProgressBar = null;
}
Initlayout (Itemcontainer);//Refresh Data again

Listpanel. Listbox_furniture_list.selectedindex =-1;

if (WindowState = = windowstate.panellist)
{
Listpanel. Visibility = System.Windows.Visibility.Visible;
}
if (WindowState = = Windowstate.panelinfo)
{
panelinfo.visibility = System.Windows.Visibility.Visible;
}
grid_makeup.visibility = System.Windows.Visibility.Visible;
if (houselayouttemp! = null)
{
houselayoutTemp.Image_Download.Visibility = System.Windows.Visibility.Hidden;
Houselayouttemp = null;
}
}

if (json["cmd"). asstring () = = "Price")//This is used in, gets to decorate the prices after the local display
{


if (ProgressBar! = null)
{
ProgressBar. Visibility = System.Windows.Visibility.Hidden;
ProgressBar = null;
}
Initlayout (Itemcontainer);//Refresh Data again

if (WindowState = = windowstate.panellist)
{
Listpanel. Visibility = System.Windows.Visibility.Visible;
}
if (WindowState = = Windowstate.panelinfo)
{
panelinfo.visibility = System.Windows.Visibility.Visible;
}
UserControlMakeUpMenuSecond.Label_AllPrice.Content = json["Makeup_price"]. ToString ();
Listpanel. Listbox_furniture_list.selectedindex =-1;

if (houselayouttemp! = null)
{
houselayoutTemp.Image_Download.Visibility = System.Windows.Visibility.Hidden;
Houselayouttemp = null;
}

}
if (json["cmd"). asstring () = = "Requestprice")//This is used to request the decoration price like the u3d end
{
Myjson.jsonnode_object news = new Myjson.jsonnode_object ();
News. Setdictvalue ("module", "makeup");
News. Setdictvalue ("cmd", "GetPrice");
U3dmgr.udpsend (news. ToString ());
}
if (json["cmd"). asstring () = = "ProgressBar")//progress bar increase
{
if (ProgressBar = = null)
Return

if (WindowState = = windowstate.panellist)
{
if (Listpanel. Visibility = = System.Windows.Visibility.Visible)
{
if (ProgressBar. Value >= 95)
{
ProgressBar. Value = 95;

if (ProgressBar! = null)
{
ProgressBar. Visibility = System.Windows.Visibility.Hidden;
ProgressBar = null;
}
}
Else
{
ProgressBar. Value + = 5;

}
}
}
if (WindowState = = Windowstate.panelinfo)
{
if (panelinfo.visibility = = System.Windows.Visibility.Visible)
{
if (ProgressBar. Value >= 95)
{
ProgressBar. Value = 95;

if (ProgressBar! = null)
{
ProgressBar. Visibility = System.Windows.Visibility.Hidden;
ProgressBar = null;
}

}
Else
{
ProgressBar. Value + = 5;
}
}
}


}
if (json["cmd"). asstring () = = "Progressbarfull")//progress bar becomes full
{
if (ProgressBar! = null)
{
ProgressBar. Visibility = System.Windows.Visibility.Hidden;
ProgressBar = null;
}


if (WindowState = = windowstate.panellist)
{
if (Listpanel. Visibility = = System.Windows.Visibility.Visible)
{
Listpanel. Visibility = System.Windows.Visibility.Hidden;

ProgressBar. Value = 0;
}

}
if (WindowState = = Windowstate.panelinfo)
{
if (panelinfo.visibility = = System.Windows.Visibility.Visible)
{

panelinfo.visibility = System.Windows.Visibility.Hidden;

}
}


}
if (json["cmd"). asstring () = = "Notneedsave")
{
Uri name1 = new Uri ("Ui/page_main_makeup2.xaml", urikind.relative);
Navigationservice.navigate (NAME1);
}
if (json["cmd"). asstring () = = "Needsave")
{
Popup dialog box
Save_layout save_makeup = new Save_layout ();
Save_makeup. ShowDialog ();
if (save_makeup.state = = Save_Layout.State.yes)
{
Save
There are two kinds of preservation, one is to fill in the name, the other is not required to fill in the name of
Savemakeupquit ();
}
else if (save_makeup.state = = Save_Layout.State.no)
{
Do not save
Uri name1 = new Uri ("Ui/page_main_makeup2.xaml", urikind.relative);
Navigationservice.navigate (NAME1);
}
}
if (json["cmd"). asstring () = = "Savequit")
{
userdata.data["Makeupindexfile"] = new Myjson.jsonnode_valuestring (json["Indexfile"]. Asstring ());//This is the existing decoration of the index file
userdata.data["Makeuppicindexfile"] = new Myjson.jsonnode_valuestring (json["Picindex"]. Asstring ());//This is the picindex of the decoration.
userdata.data["Isfix"] = new Myjson.jsonnode_valuenumber (json["isfixed"]. Asint ());//This is the picindex of the decoration.
Console.WriteLine (userdata.data["Isfix"]);
if (Needtosave)
{
Onneedsave ();
Needtosave = false;
}

Uri name1 = new Uri ("Ui/page_main_makeup2.xaml", urikind.relative);
Navigationservice.navigate (NAME1);
}

if (json["cmd"). asstring () = = "Getpanoramadone")
{
Userdata.pichash = json["pic"]. Asstring ();//panorama hash as thumbnail index
Userdata.picindex = json["Index"]. Asint ();//Panorama key
System.Diagnostics.Debug.WriteLine ("All pic Userdata.pichash:" + Userdata.pichash);
if (!m_ispicshow)
{
if (winanimation! = null && winanimation.isend)
{
This. Updateallpiclist ();
}
}

}
if (json["cmd"). asstring () = = "Getpanoramatip")
{
Popsure popsure = new Popsure ();
Popsure. Label_tip.content = "The photo has been taken at this location, please take another position." ";
Popsure. Label_tip.fontsize = 12;
Popsure. ShowDialog ();
MessageBox.Show ("The photo has been taken at this location, please change the position and then shoot.") ");
}
if (json["cmd"). asstring () = = "Pricesheet")
{
MessageBox.Show (json["info"). ToString ());
Myjson.jsonnode_array obj = (myjson.parse (json["info"). ToString ()) as Myjson.jsonnode_object) ["Makeupprice"] as Myjson.jsonnode_array;
Rf. Setgrid (obj);
RF = new Reportform (json["info"] as Myjson.jsonnode_array);
}

if (json["cmd"). asstring () = = "Getcapturecameradone")
{
Userdata.pichash = json["pic"]. Asstring ();
Userdata.picindex = json["Index"]. Asint ();
System.Diagnostics.Debug.WriteLine ("One pic Userdata.pichash:" + Userdata.pichash);
if (!m_ispicshow)
{
if (winanimation! = null && winanimation.isend)
{
This. Updatesinglepiclist ();


}
}
}
Here add a message event, there as long as there is mousebuttondown come over, put the pop-up box close off
if (json["cmd"). asstring () = = "Closemorepopup")
{
if (_screenliststore! = null)
{
_screenliststore.close ();
}
MessageBox.Show ("Off");
}
if (JSON. ContainsKey ("classindex") = = false) return; No classification number, return
Console.WriteLine ("Editmodel UDP recv:" + JSON. ToString ());
}
else//is not an edit module, it changes the scene
{
if (bloadscene) return;//does not allow multiple send switch scene commands
Myjson.jsonnode_object Changeto = new Myjson.jsonnode_object ();
if (userdata.data["Scenetype"]. Asint () = = (int) scenetype.scene)
{
Changeto. Setdictvalue ("module", "null");
Changeto. Setdictvalue ("cmd", "Changescenefix");
Changeto. Setdictvalue ("Sceneindex", userdata.data["Houselayoutindex"]);
Changeto. Setdictvalue ("Scene", "makeup");
}
Else
{
Changeto. Setdictvalue ("module", "null");
Changeto. Setdictvalue ("cmd", "Changescene");
Changeto. Setdictvalue ("Scene", "makeup");
}
Bloadscene = true;
U3dmgr.udpsend (Changeto. ToString ());
Console.WriteLine ("Editmodel UDP recv:" + JSON. ToString ());
}
}

The code for U3D is as follows:

In the ingress code of U3D, the update function sends a message every three seconds like WPF

void Update ()
{
if (bsleep)
{
System.Threading.Thread.Sleep (100);
}
if (nettools! = null)
{
NetTools. Update ();//Detection download
}
Connect.Instance.checkCallback ()///Here you need to check callback for real-time update of callbacks
fcount++;
//timed heartbeat packet delivery
Timer + = Time.deltatime;
if (Timer > 3.0f)
{
Timer = 0;
Fcount = 0;
Myjson.jsonnode_object Beatheart = new Myjson.jsonnode_object ();
Beatheart. Setdictvalue ("module", ModuleName);
Beatheart. Setdictvalue ("cmd", "Beatheart");
Connect.Instance.udpSend (Beatheart);
}
if (curstate! = null)
{
Curstate.onupdate (Time.deltatime);
}
}

Heartbeat Package WPF Unity Database Build

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.