Geolocation dont work on a desktop emulator (uwp) - geolocation

Hello im trying to make a view containing a map in a Universal Windows platform
i did the fellowing :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Geolocation;
namespace Project
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Geolocation : Page
{
public Geolocation()
{
this.InitializeComponent();
}
public async void GetCords()
{
Geolocator locator = new Geolocator();
Geoposition pos = await locator.GetGeopositionAsync();
await new Windows.UI.Popups.MessageDialog(pos.CivicAddress.City).ShowAsync();
}
}
}
but i got a blank page! what am I missing here?

If you want to add a MapControl in your page, you must:
Create a key for your map
xmlns:maps="using:Windows.UI.Xaml.Controls.Maps <maps:MapControl
<maps:MapControl x:Name="map" MapServiceToken="YOUR_TOKEN_HERE" />

Related

Unable to generate path to save image in iOS

I created a delegate on iOS (it works on Android) to save an image using the CrossDownloadManager plugin. I copied the code from the Xamarin documentation but when I run the method, "path" returns an empty string:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YHTS.iOS;
using Foundation;
using UIKit;
using System.IO;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: Dependency(typeof(ImageSaver_IOS))]
namespace YHTS.iOS
{
public class ImageSaver_IOS : IImageSaver
{
public ImageSaver_IOS() { }
public string Save(string imageName)
{
string fileName = (new NSUrl(imageName, false)).LastPathComponent;
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName);
return path;
}
}
}

How to detect IIS events in windows event logs and detemine its application pool according to this code?

I try to make a listener on windows event logs, but I need to recognize IIS events in it and determine its application pool.
could I do that according to this code ??? by process id for example or any thing else.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
using System.DirectoryServices;
using Microsoft.Web;
using Microsoft.Web.Administration;
namespace EventLogEnt
{
class Program
{
static AutoResetEvent signal;
static void Main(string[] args)
{
// create new log
signal = new AutoResetEvent(false);
EventLog myNewLog = new EventLog("Application", "TIS3", "Outlook");
myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = true;
myNewLog.WriteEntry("Test message", EventLogEntryType.Information);
signal.WaitOne();
Console.ReadKey();
}
public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e)
{
Console.WriteLine(e.Entry.Message);
Console.WriteLine("the entry type: " + e.Entry.EntryType);
Console.WriteLine("---------------------------------------------");
signal.Set();
}
}
}

Object reference not set to an instance of an object MVC 5

I'm new to MVC working on 3-tier MVC project and i am using a ready database.
now i need to write a query using linq in Business Layer to bring list of doctors like this :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DoctorsSheet.DataAccess;
namespace DoctorsSheet.Business
{
class Doctor : IDoctor
{
DoctorsSheetDBEntities db = new DoctorsSheetDBEntities();
public IQueryable<Doctors> GetDoctors()
{
var doctors = from d in db.Doctors
select d;
return doctors.AsQueryable<Doctors>();
}
}
}
and when i call GetDoctors() from DoctorsController
it tell me Object reference not set to an instance of an object
this is the Controller :
public ActionResult Index()
{
var doctors = obj.GetDoctors().AsQueryable<Doctors>();
return View(doctors);
}
please help me how to fix it.
Make your class public -
public class Doctor : IDoctor
And then initiate obj variable as shown below and then use obj.
IDoctor obj = new Doctor();
NOTE: As #Sippy explained there is no need for you to use GetDoctors().AsQueryable<Doctors>();.

How to use .cs Class DataFunctions Inside MVC Controller Classes

I have an asp.net web application, now i am trying to convert it to ASP.NET MVC. The problem is my old project has some .cs classes i, Example one class that handle all user data operations , one handle database operations , one will handle some priority properties like... I had included those classes in mvc Project , i had created a new Folder named Project_Class and copy all of my classes to it, my problem is how to access these classes in mvc controller class, how can i call a function of this class in mvc controller class.
I had include a sample .cs class structure below
**class1.cs**
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace xyz.abc
{
public class AssignValues:SSS
{
Process Objdb;
SqlCommand sqlcom;
SqlConnection sqlcon;
private int _EId;
private int _CId;
XmlDocument PXML, OutputXML;
XmlElement Root, ParameterElement, InputParamIdNode, OperatorIdNode, OutputParamIdNode, OutputParamValueNode, ConditionStatusNode, ModeNode, InputTypeNode, OutputTypeNode, InputRegisterIdNode, InputRegisterHeaderIdNode, OutputRegisterIdNode, OutputRegisterHeaderIdNode, UIdNode, orderNode;
public int iCount = 0;
public int EId
{
set
{
_EId = value;
}
get
{
return _EId;
}
}
public int CId
{
set
{
_CId = value;
}
get
{
return _CId;
}
}
public AssignValues()
{
}
public AssignValues(SqlCommand SqlComm,SqlConnection SqlConn)
{
Objdb = new Process();
sqlcom=SqlComm;
sqlcon = SqlConn;
}
public string check()
{
string x="hai";
return x
}
}
}
my Controller class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XYZ.ABC.Controllers;
using XYZ.ABC;
namespace XYZ.ABC.Controllers
{
public class XYZ_Controller :Controller
{
public ActionResult XYZ_Checklist()
{
return View();
}
}
}
i want to call "public string check()" method in my controller class,is it possible? ,i am newbie in mvc, please help me to solve this.
You can simply call that in your MVC controller class
Follow the steps
1) Include the namespace of the class in MVC controller class
2) Inherit old class in Your MVC Controller
Public Class MVCCOntrollerclassname: Class1
3) Create object of the .cs class
like
class1 c=new class1();
4) Create a constructor of MVC controller class
like
MVCCOntrollerclassname()
{
c.methodname();
}
Note : You say you are migrating asp.net to MVC , so if you have any asp.net dll then must change it as MVC Compitable dll
The MVC Framework just instantiates your Controller class and invokes an action method using some defined configuration or convention. So with that in mind ask yourself the question how would I invoke this method if you instantiated the controller yourself and called XYZ_Checklist().
The answer may look something like this:
public ActionResult XYZ_Checklist()
{
var assignValues = new AssignValues();
var result = assignValues.check();
// Do something here with the result ...
return View();
}
That's the short and simple answer. Once you start to understand that the framework isn't magic and is simply calling your code, you can start to delve into better ways to arrange your code (IoC/DI, etc.).
Hope this helps!

Does it make sense to have Business Logic within a ViewModel in MVC?

At the moment I'm working on Asp.Net MVC using: Repository, Unit-Of-Work patterns, Service Layer and ViewModels.
In this project every View is linked to a ViewModel Class, the Controllers are thin-one, so the Business Layer reside on a Service Layer.
I create instances of ViewModel class in the Controller and pass it to the view like this
public ActionResult Create()
{
EventCreateViewModel eventViewModel = new EventCreateViewModel();
return View(eventViewModel);
}
In some ViewModel I use to call the Service Layer.
The system works, but I would like to know if it is a good idea adding call to a Service Layer in the ViewModel or better would be leave this operation only to the Controller.
public class EventCreateViewModel
{
public CandidateListViewModel CandidateList = new CandidateListViewModel();
public EventCreateViewModel()
{
DateTimeStart = DateTime.UtcNow; // Add a default value when a Date is not selected
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using XXX.Models;
using XXX.Service;
namespace XXX.ViewModels
{
public class CandidateListViewModel
{
// We are using the Service Layer
private ICandidateBL serviceCandidate;
// Property
public IDictionary<string, string> Candidates = new Dictionary<string, string>();
// An utility method that convert a list of Canddates from Enumerable to SortedDictionary
// and save the result to an inner SortedDictionary for store
public void ConvertSave(IEnumerable<Candidate> candidates)
{
Candidates.Add("None", "0"); // Add option for no candidate
foreach (var candidate in candidates)
Candidates.Add(candidate.Nominative, candidate.CandidateId.ToString());
}
#region Costructors
public CandidateListViewModel()
{
serviceCandidate = new CandidateBL();
ConvertSave(serviceCandidate.GetCandidates());
}
// Dependency Injection enabled constructors
public CandidateListViewModel(ICandidateBL serviceCandidate)
{
this.serviceCandidate = serviceCandidate;
}
public CandidateListViewModel(IEnumerable<Candidate> candidates)
{
serviceCandidate = new CandidateBL();
ConvertSave(candidates);
}
#endregion
}
}
The controller is the component that should be in control, so to say. The ViewModel should just be a data container, nothing more.
Remember the Single Responsibility Principle. Once you start distributing logic it will become increasingly difficult to remember and understand all the moving parts.

Resources