Umbraco 8.17 How to get page id of a different page? - umbraco8

I needed to get to a different page if certain conditions were meet within my SurfaceController. If you have the page ID of the page you need to get to this is ease. The problem was I did not want to hard code a page id in the action method in the controller. I had a lot of problems trying to figure it out, so I thought I would provide my solution in case someone else is having the same issue.
int homePageID = 0;
try
{
homePageID = Umbraco.ContentAtXPath("//home").FirstOrDefault().Id;
}
catch(Exception e) { }
if(homePageID > 0)
{
return RedirectToUmbracoPage(homePageID);
}
else
{
return CurrentUmbracoPage();
}
Note that for this line "homePageID = Umbraco.ContentAtXPath("//home").FirstOrDefault().Id;" you use the page alias not the page name.
I hope this helps.

int homePageID = 0;
try
{
homePageID = Umbraco.ContentAtXPath("//home").FirstOrDefault().Id;
}
catch(Exception e) { }
if(homePageID > 0)
{
return RedirectToUmbracoPage(homePageID);
}
else
{
return CurrentUmbracoPage();
}

Related

How to properly forward/redirect calls with pjsua2

I can't find info on the net how to forward a call with pjsua2.
Currently Im trying with the xfer method but Im getting:
../src/pjsip-ua/sip_inv.c:3942: inv_on_state_null: Assertion `!"Unexpected transaction type"' failed.
There is no information about this error.
This is my code Im trying:
void MyAccount::onIncomingCall(OnIncomingCallParam &iprm)
{
MyCall *call = new MyCall(*this, iprm.callId);
...
calls.push_back(call);
...
QString fwd_to = fwd(QString::fromStdString(ci.remoteUri));
if(fwd_to != "NO_FWD")
{
info+="*** Xfer Call: ";
info+=QString::fromStdString(ci.remoteUri);
info+=" [";
info+=QString::fromStdString(ci.stateText);
info+="]\n";
infoChanged=true;
CallOpParam prm1;
prm1.statusCode = (pjsip_status_code)200;
call->answer(prm1);
pj_thread_sleep(2000);
CallOpParam prm2(true);
call->xfer(fwd_to.toStdString(), prm2);
}
else
{
// standart incoming
...
}
}
fwd is my own function which search a database if it needs to forward the call
I did something like this and works, dont know if some other way exist:
(answering with no media, setting flag and in other thread xfering call to fwd_to string)
if(fwd_to != "NO_FWD")
{
CallOpParam prm1;
prm1.statusCode = (pjsip_status_code)200;
call->answer(prm1);
call->fwd_to = fwd_to;
call->fwd=true;
}
FwdThread *fwd_thread = new FwdThread();
fwd_thread->start();
void FwdThread::run()
{
static pj_thread_desc s_desc;
static pj_thread_t *s_thread;
pj_thread_register("FwdThread", s_desc, &s_thread);
loop();
}
void FwdThread::loop()
{
while(1)
{
for(auto &call : pjt->v_calls)
{
if(call->fwd && call->answered)
{
call->fwd=false;
CallOpParam prm2(true);
call->xfer(call->fwd_to.toStdString(), prm2);
}
}
if(pjt->Stop)
break;
pj_thread_sleep(500);
}
}

Set prefilled text content in Facebook using SDK via SharePhotoContent

I need to post both text and images on a Facebook wall. For that, I can't use intent sharing because I want to share text too. So I implemented the Facebook SDK. But I still can't see my text content / caption on the wall. Here is my code.
private void publishImage() {
ArrayList<SharePhoto> sharePhotos = new ArrayList<>();
int imageFolderSize;
File imageFolder = new File(getActivity().getExternalCacheDir(), "attachments/images");
if( imageFolder.exists()) {
imageFolderSize = imageFolder.listFiles().length;
ArrayList<File> attachments = new ArrayList<>();
if (imageFolder.exists()) {
Collections.addAll(attachments, imageFolder.listFiles());
}
if (imageFolderSize > 0) {
for (int i = 0; i < attachments.size(); i++) {
File file = attachments.get(i);
if (file.exists()) {
if (file.getAbsolutePath().endsWith(".png")) {
try {
SharePhoto photo = new SharePhoto.Builder().setBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()))
.setCaption("Welcome To Facebook Photo Sharing on steroids!")
.build();
sharePhotos.add(photo);
}catch (Exception e){
RMLog.debug("Execp: e"+e.toString());
}
}
}
}
}
}
SharePhotoContent scontent = new SharePhotoContent.Builder().addPhotos(sharePhotos ).build();
if(ShareDialog.canShow(SharePhotoContent.class))
{
shareDialog.show(scontent);
Toast.makeText(getActivity(), "Succsesfully posted on your wall",
Toast.LENGTH_LONG).show();
}
}

Facebook SDK: SharePhotoContent Not Working

am developing an app with sharing text and multiple images in a single post using facebook sdk. I used the following code, but nothing happens in my fb wall post. Whats wrong in the code please anybody help. thanks in advance.
private void publishImage() {
ArrayList<SharePhoto> sharePhotos = new ArrayList<>();
int imageFolderSize;
File imageFolder = new File(getActivity().getExternalCacheDir(), "attachments/images");
if( imageFolder.exists()) {
imageFolderSize = imageFolder.listFiles().length;
ArrayList<File> attachments = new ArrayList<>();
if (imageFolder.exists()) {
Collections.addAll(attachments, imageFolder.listFiles());
}
if (imageFolderSize > 0) {
for (int i = 0; i < attachments.size(); i++) {
File file = attachments.get(i);
if (file.exists()) {
if (file.getAbsolutePath().endsWith(".png")) {
try {
SharePhoto photo = new SharePhoto.Builder().setBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()))
.setCaption("Welcome To Facebook Photo Sharing on steroids!")
.build();
sharePhotos.add(photo);
}catch (Exception e){
RMLog.debug("Execp: e"+e.toString());
}
}
}
}
}
}
SharePhotoContent scontent = new SharePhotoContent.Builder().addPhotos(sharePhotos
).build();
if(ShareDialog.canShow(SharePhotoContent.class))
{ ShareApi.share(scontent, null);
Toast.makeText(getActivity(), "Succsesfully posted on your wall",
Toast.LENGTH_LONG).show();
}
}

[Unity 5]matchmaking : matches not visible

I need your help please because I have an issue about matchmaking. I try to make a Pong playable online. When i use NetworkHUD, and I use Matchmaker, I can create a match, and the other app (on the same computer for now) detach it and can join it. But, when I don't use it, but I use matchmaker manually, I can create a match, I have a success response, I can find this match in the same app, but, in my second app, I can't find match created by the first app.
Can you help me?
Here are two functions in which I create match :
public void matchmaking()
{
nm.StartMatchMaker();
networkMatch.ListMatches(0, 20, "", OnMatchList);
Debug.LogError ("NBR MATCH " +matchList.Count);
if (matchList.Count == 0)
{
CreateMatchRequest match = new CreateMatchRequest();
match.name = "OrionPongRoom";
match.size = 2;
match.advertise = true;
match.password = "";
networkMatch.CreateMatch(match, OnMatchCreate);
}
else
Debug.Log ("******matches found"+matchList.Count);
}
void OnMatchCreate(CreateMatchResponse matchResponse)
{
if (matchResponse.success)
{
Debug.LogError("Create match succeeded");
matchCreated = true;
MatchInfo matchInfo = new MatchInfo(matchResponse);
Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
nm.StartHost(matchInfo);
NetworkServer.Listen(9000);
//NetworkServer.Listen(new MatchInfo(matchResponse), 9000);
}
else
{
Debug.LogError ("Create match failed");
}
}
You need to write
if (matchList.Count == 0)
{
CreateMatchRequest match = new CreateMatchRequest();
match.name = "OrionPongRoom";
match.size = 2;
match.advertise = true;
match.password = "";
networkMatch.CreateMatch(match, OnMatchCreate);
}
else
Debug.Log ("******matches found"+matchList.Count);
in OnMatchList method.
void OnMatchList(ListMatchResponse matchList)
{
if (matchList.Count == 0)
{
CreateMatchRequest match = new CreateMatchRequest();
match.name = "OrionPongRoom";
match.size = 2;
match.advertise = true;
match.password = "";
networkMatch.CreateMatch(match, OnMatchCreate);
}
else
Debug.Log ("******matches found"+matchList.Count);
}
Because of Network Delays etc, matchmaking server can not send response synchronous.

<epubreder in mono touch using C#>

i want epubreder source code in mono touch c# for iPad i got it in Xcode but need to convert in c#...
problem of conversion is that i want to parse the container.xml to get the .opf file path and again parse the .opf file....
can any one please help me out to solve this problem...
public void parseXMLFileAt(string strUrl)
{
try
{
NSMutableDictionary dict=new NSMutableDictionary();
XmlTextReader reader = new XmlTextReader("/Users/krunal/Desktop/container.xml");
string strAttribute="";
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
Hashtable attributes = new Hashtable();
string strURI= reader.NamespaceURI;
string strName= reader.Name;
if (reader.HasAttributes)
{
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
attributes.Add(reader.Name,reader.Value);
}
}
parser(_parser,strUrl,strURI,strName,dict);
enter code here
StartElement(strURI,strName,strName,attributes);
break;
default:
break;
}
}
}
catch (XmlException e)
{
Console.WriteLine("error occured: " + e.Message);
}
}
Thanks in advance