<epubreder in mono touch using C#> - iphone

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

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);
}
}

How to setting firebase remote config for unity?

lets to the point, so i want to make some configuration with my game to show Ads but I avoid to update game version too much, because of that I choose firebase remote config with this I can update setting/configuration without update the game version.
there is document for this but not very clear for newbie like me, you can check it here https://firebase.google.com/docs/remote-config/use-config-unity
I already make the script like on doc, but I don't understand how its work on show data because error string format, which is what I know on this firebase console is int format
the script like this :
public static _FirebaseRemoteConfig instance;
private void Awake()
{
instance = this;
}
Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;
// Use this for initialization
void Start()
{
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
{
dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available)
{
InitializeFirebase();
}
else
{
Debug.LogError(
"Could not resolve all Firebase dependencies: " + dependencyStatus);
}
});
}
public void InitializeFirebase()
{
System.Collections.Generic.Dictionary<string, object> defaults =
new System.Collections.Generic.Dictionary<string, object>();
defaults.Add("config_test_string", "default local string");
defaults.Add("config_test_int", 1);
defaults.Add("config_test_float", 1.0);
defaults.Add("config_test_bool", false);
Firebase.RemoteConfig.FirebaseRemoteConfig.SetDefaults(defaults);
Debug.Log("Remote config ready!");
}
public void FetchFireBase()
{
FetchDataAsync();
}
public void ShowData()
{
Debug.Log("maxCountToShowAdmob: " +
Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("MaxCountShowIntersitialAds").LongValue);
}
// Start a fetch request.
public Task FetchDataAsync()
{
Debug.Log("Fetching data...");
System.Threading.Tasks.Task fetchTask = Firebase.RemoteConfig.FirebaseRemoteConfig.FetchAsync(
TimeSpan.Zero);
return fetchTask.ContinueWith(FetchComplete);
}
void FetchComplete(Task fetchTask)
{
if (fetchTask.IsCanceled)
{
Debug.Log("Fetch canceled.");
}
else if (fetchTask.IsFaulted)
{
Debug.Log("Fetch encountered an error.");
}
else if (fetchTask.IsCompleted)
{
Debug.Log("Fetch completed successfully!");
}
var info = Firebase.RemoteConfig.FirebaseRemoteConfig.Info;
switch (info.LastFetchStatus)
{
case Firebase.RemoteConfig.LastFetchStatus.Success:
Firebase.RemoteConfig.FirebaseRemoteConfig.ActivateFetched();
Debug.Log(String.Format("Remote data loaded and ready (last fetch time {0}).",
info.FetchTime));
break;
case Firebase.RemoteConfig.LastFetchStatus.Failure:
switch (info.LastFetchFailureReason)
{
case Firebase.RemoteConfig.FetchFailureReason.Error:
Debug.Log("Fetch failed for unknown reason");
break;
case Firebase.RemoteConfig.FetchFailureReason.Throttled:
Debug.Log("Fetch throttled until " + info.ThrottledEndTime);
break;
}
break;
case Firebase.RemoteConfig.LastFetchStatus.Pending:
Debug.Log("Latest Fetch call still pending.");
break;
}
}

Method listDuplicates() error

Can somebody help me with this problem here. I'm a newbie . I'm trying to find file duplicates or files with the same content in a directory and write texfile to display duplicates but now it says input string was not in a correct format
public static List<FileInfo> files = new List<FileInfo>();
public static void ListDrive(string drive)
{
try
{
DirectoryInfo di = new DirectoryInfo(drive);
foreach (FileInfo fi in di.GetFiles())
{
files.Add(fi);
}
}
catch (UnauthorizedAccessException)
{ }
}
//Find duplicates
public static void ListDuplicates()
{
var duplicatedFiles = files.GroupBy(x => new { x.Length }).Where(t => t.Count() > 1).ToList();
Console.WriteLine("Total items: {0}", files.Count);
Console.WriteLine("Probably duplicates {0} ", duplicatedFiles.Count());
StreamWriter duplicatesFoundLog = new StreamWriter("log.txt");
foreach (var filter in duplicatedFiles)
{
duplicatesFoundLog.WriteLine("Probably duplicated item: Name: { 0}, Length: { 1}",
filter.Key.Length);
var items = files.Where(x => x.Length == filter.Key.Length).ToList();
int c = 1;
foreach (var suspected in items)
{
duplicatesFoundLog.WriteLine("{3},{ 0}- { 1}, Creation date { 2}",
suspected.Name, suspected.FullName, suspected.CreationTime, c);
c++;
}
duplicatesFoundLog.WriteLine();
}
duplicatesFoundLog.Flush();
duplicatesFoundLog.Close();
}
Here is my client method that invokes the two methods
try
{
Console.WriteLine("Enter the path");
string path = Console.ReadLine();
ListDrive(path);
ListDuplicates();
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
Your help will be high appreciated...
Please eliminate the space, for example change { 0} to {0}. If you do this for all locations the error should go away.
If you want spaces, make the code "{3}, {0}- {1}, Creation date {2}". i.e. Add the space before the opening {, not after. The format items need have no space after the first opening brace to be interpreted as a formatting item correctly.

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();
}
}

How to solve ConnectionNotFoundException in JavaME

I'm trying to connect to the internet via my J2ME application on my Netbeans emulator with the following function which connects to a webpage and prints out its HTML using System.out.println().
function getHTML(String url)
{
HttpConnection httpConn = null;
InputStream is = null;
OutputStream os = null;
try
{
httpConn = (HttpConnection)Connector.open(url);
int respCode = httpConn.getResponseCode();
if (respCode == httpConn.HTTP_OK)
{
StringBuffer sb = new StringBuffer();
os = httpConn.openOutputStream();
is = httpConn.openDataInputStream();
int chr;
while ((chr = is.read()) != -1)
sb.append((char) chr);
System.out.println(sb.toString());
os.close();
is.close();
}
else
{
System.out.println("Error " + respCode);
}
httpConn.close();
}
catch(IOException ioex)
{
ioex.printStackTrace();
}
}
But I've been getting the following error;
javax.microedition.io.ConnectionNotFoundException: error 10051 in socket::open
at com.sun.midp.io.j2me.socket.Protocol.open0(), bci=0
at com.sun.midp.io.j2me.socket.Protocol.connect(), bci=209
at com.sun.midp.io.j2me.socket.Protocol.open(), bci=216
at com.sun.midp.io.j2me.socket.Protocol.openPrim(), bci=4
at com.sun.midp.io.j2me.http.Protocol.createConnection(), bci=41
at com.sun.midp.io.j2me.http.Protocol.connect(), bci=41
at com.sun.midp.io.j2me.http.Protocol.streamConnect(), bci=164
at com.sun.midp.io.j2me.http.Protocol.startRequest(), bci=7
at com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=33
at com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=3
at com.sun.midp.io.j2me.http.Protocol.getResponseCode(), bci=5
I know my code isn't the problem because this used to work on my old laptop, but it hasn't worked since I installed Netbeans on my new laptop. Is it because of my internet connection, or my firewall settings, or my settings in Netbeans, or did I just not install Netbeans properly?
If you want to send some data and receive means then try the coding
try
{
httpConn = (HttpConnection)Connector.open(url);
os = httpConn.openOutputStream();
//Writing data to os
os.write(b); //Here b is a byte array
os.flush();
int respCode = httpConn.getResponseCode();
if (respCode == httpConn.HTTP_OK)
{
StringBuffer sb = new StringBuffer();
is = httpConn.openDataInputStream();
int chr;
while ((chr = is.read()) != -1)
sb.append((char) chr);
System.out.println(sb.toString());
}
else
{
System.out.println("Error " + respCode);
}
}
catch(IOException ioex)
{
ioex.printStackTrace();
}
if(os!=null) os.close();
if(is!=null) is.close();
if(httpConn!=null) httpConn.close();
os=null;is=null;httpConn=null;
}