.NET MAUI - SELECT UUID FROM Win32_ComputerSystemProduct - xamarin.forms

Is posible using this code in .NET Maui ?
using System;
using System.Collections.Generic;
using System.Management;
using System.Text;
namespace GetWMI_Info
{
class Program
{
static void Main(string[] args)
{
string ComputerName = "localhost";
ManagementScope Scope;
Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName),
null);
Scope.Connect();
ObjectQuery Query = new ObjectQuery("SELECT UUID FROM Win32_ComputerSystemProduct");
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query);
foreach (ManagementObject WmiObject in Searcher.Get())
{
Console.WriteLine("{0,-35} {1,-40}", "UUID", WmiObject["UUID"]);// String
}
Console.Read();
}
}
}
Thank you.

Related

Core 2.1 SignalR and SQLDependency

Is there any Core 2.1 sample available for using SignalR with SQLDependency.
Did enable broker, etc. but never get any dependency onChange event firing. Just the event subscribe is triggered.
When the MS-SQL database table Cities changes on the back-end, I want to see the change reflected right-away on the client web page without having to refresh/reload the page.
//start the dependency when app start in ConfigureServices
SqlDependency.Start(Configuration.GetConnectionString("DefaultConnection"));
using Microsoft.AspNetCore.SignalR;
using SignalR_Test4.Data;
using SignalR_Test4.Hubs;
using System.Collections.Generic;
using System.Data.SqlClient;
namespace SignalR_Test4.Models
{
public class CityRepository
{
private readonly ApplicationDbContext _context;
private readonly IHubContext<CityHub> _hubcontext;
public CityRepository(ApplicationDbContext context, IHubContext<CityHub> hubcontext)
{
_context = context;
_hubcontext = hubcontext;
}
public IEnumerable<City> GetCities()
{
List<City> listOf = new List<City>();
//listOf = _context.Cities;
using (var conn = new SqlConnection(GlobalVar.connectionString))
{
conn.Open();
using (var cmd = new SqlCommand(#"SELECT * FROM Cities", conn))
{
cmd.Notification = null;
SqlDependency dependency = new SqlDependency(cmd);
dependency.OnChange += Dependency_OnChange;
if (conn.State == System.Data.ConnectionState.Closed)
conn.Open();
var reader = cmd.ExecuteReader();
while (reader.Read())
{
listOf.Add(new City { Id = (string)reader["Id"], Name_en = (string)reader["name_en"], CountryId = (string)reader["CountryId"], Code = (string)reader["Code"] });
}
}
}
return listOf;
}
private void Dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
_hubcontext.Clients.All.SendAsync("GetCities");
}
}
}
}
The issue was within the line:
var cmd = new SqlCommand(#"SELECT Id, Name_en, CountryId, Code from [dbo].Cities", conn)
It is required to use the field name (Not the *) and also the 2 part table name convention => [dbo].Cities

ASP.NET Identity AllowOnlyAlphanumericUserNames

Can someone please help me how can i use special characters in ASP.Net identity?
The problem is that my users cannot register with special characters: č,ć,š,ž,đ.
When you try to enter this characters in registration, i get following error:
User name Krešo is invalid, can only contain letters or digits.
Where and how can i change this.
Here is the code:
using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Pages_Account_Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPrijava_Click(object sender, EventArgs e)
{
UserStore<IdentityUser> userStore = new UserStore<IdentityUser>();
userStore.Context.Database.Connection.ConnectionString =
System.Configuration.ConfigurationManager.ConnectionStrings["SeminariConnectionString3"].ConnectionString;
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
IdentityUser user = new IdentityUser();
user.UserName = txtKorisnickoIme.Text;
if(txtLozinka.Text == txtPotvrdaLozinke.Text)
{
try
{
IdentityResult result = manager.Create(user, txtLozinka.Text);
if(result.Succeeded)
{
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
var userIdentity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties(), userIdentity);
Response.Redirect("Pocetna.aspx");
}
else
{
litStatus.Text = result.Errors.FirstOrDefault();
}
}
catch (Exception ex)
{
litStatus.Text = ex.ToString();
}
}
else
{
litStatus.Text = "Lozinke moraju biti identične.";
}
}
}
You should be able to change this behaviour as follows:
var manager = new UserManager<IdentityUser>(userStore); // existing code
var validator = manager.UserValidator as UserValidator<ApplicationUser>;
if (validator != null) validator.AllowOnlyAlphanumericUserNames = false;
Should validator turn out to be null, then debug a little to find the actual type used at runtime.

how to ignore default value(string) in the output of Json webservice

I need to neglect the default value(*string *) in the output which is displayed when executing the webservice JSON.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.ComponentModel;
namespace Webservice
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
//public string GetEmployees(string SearchTerm)
public string GetEmployees()
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NSConstr"].ToString());
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM Contact e ";
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand.Connection = con;
da.Fill(dt);
con.Close();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row = null;
foreach (DataRow rs in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, rs[col]);
}
rows.Add(row);
}
return "{ \"Cargo\": " + serializer.Serialize(rows) + "}";
}
public string errmsg(Exception ex)
{
return "[['ERROR','" + ex.Message + "']]";
}
}
}
Output is;
<string>
{ "Cargo": [{"Id":1,"FirstName":"devi","LastName":"priya ","Contactno":"965577796 "},{"Id":2,"FirstName":"arun","LastName":"kumar","Contactno":"9944142109"},{"Id":3,"FirstName":"karu","LastName":"ronald","Contactno":"8883205008"}]}
</string>
But the actual output i need is;
{ "Cargo": [{"Id":1,"FirstName":"devi","LastName":"priya ","Contactno":"965577796 "},{"Id":2,"FirstName":"arun","LastName":"kumar","Contactno":"9944142109"},{"Id":3,"FirstName":"karu","LastName":"ronald","Contactno":"8883205008"}]}
In the above output i dont want to see the string /string
is there is a way to omit that if so please suggest me.
Thanks in advance
Try replacing return "{ \"Cargo\": " + serializer.Serialize(rows) + "}"; with return serializer.Serialize(new { Cargo = rows });
Your question can be found here:
ResponseFormat.Json returns xml
And try to use this http://www.nuget.org/packages/Newtonsoft.Json/
it can be very helpful to deal with JSON.
Good Luck.

public class ImageHandler : IHttpHandler

cmd.Parameters.AddWithValue("#id", new system.Guid (imageid));
What using System reference would this require?
Here is the handler:
using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.Globalization;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Web.Profile;
using System.Drawing;
public class ImageHandler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string imageid;
if (context.Request.QueryString["id"] != null)
imageid = (context.Request.QueryString["id"]);
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
Stream strm = ShowProfileImage(imageid.ToString());
byte[] buffer = new byte[8192];
int byteSeq = strm.Read(buffer, 0, 8192);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 8192);
}
//context.Response.BinaryWrite(buffer);
}
public Stream ShowProfileImage(String imageid)
{
string conn = ConfigurationManager.ConnectionStrings["MyConnectionString1"].ConnectionString;
SqlConnection connection = new SqlConnection(conn);
string sql = "SELECT image FROM Profile WHERE UserId = #id";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("#id", new system.Guid (imageid));//Failing Here!!!!
connection.Open();
object img = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])img);
}
catch
{
return null;
}
finally
{
connection.Close();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Maybe typo. Capitalize the first letter of System namespace.
new System.Guid (imageid)

The type or namespace name 'Oracle' could not be found

work on vs05 C# web.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
//using System.Data.OracleClient;
// ODP.NET Import(s)
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
public partial class Default2 : System.Web.UI.Page
{
//private const string dbConnString = "Data Source=portal;User ID=aspalliancearticles; Password=minime;";
private const string dbConnString = "Data Source=IT;User ID=jubohrm; Password=jubohrm0;";
private const string empQuery = "select * from emp";
private const string deptQuery = "SELECT * FROM dept";
protected void Page_Load(object sender, EventArgs e)
{
PopulateTreeView();
}
public void PopulateTreeView()
{
DataSet myDataSet = GetData();
foreach (DataRow parentRow in myDataSet.Tables["dept"].Rows)
{
TreeNode parentNode = new TreeNode((string)parentRow["dname"]);
TreeView1.Nodes.Add(parentNode);
foreach (DataRow childRow in parentRow.GetChildRows("Child"))
{
TreeNode childNode = new TreeNode((string)childRow["ename"]);
parentNode.ChildNodes.Add(childNode);
}
}
}
public DataSet GetData()
{
OracleConnection dbConn = new OracleConnection(dbConnString);
OracleDataAdapter empDataAdapter = new OracleDataAdapter(empQuery, dbConn);
OracleDataAdapter deptDataAdapter = new OracleDataAdapter(deptQuery, dbConn);
DataSet myDataSet = new DataSet();
empDataAdapter.Fill(myDataSet, "emp");
deptDataAdapter.Fill(myDataSet, "dept");
myDataSet.Relations.Add("Child", myDataSet.Tables["dept"].Columns["deptno"],
myDataSet.Tables["emp"].Columns["deptno"]);
return myDataSet;
}
}
To run the code i get the error message"Error The type or namespace name 'Oracle' could not be found (are you missing a using directive or an assembly reference?)" .How to solve this error?
Add the reference to the appropriate Oracle DLL files and it should work!

Resources