I coded this simple service -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace MySimpleService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "C:\\Windows\\System32\\calc.exe";
psi.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo = psi;
p.Start();
}
protected override void OnStop()
{
}
}
}
And when I installed it with sc.exe create test_service bitPath="<my_path>.exe",
I got an error message Error 216 0xd8.
I compiled the program on the same computer I ran the service on, any thoughts?
Related
I would like to be able to customize the bottom tab bar. From what I understand this isn’t yet possible but it might be a future feature. Until that time has anyone come across any custom renderers for iOS and Android that would allow me to change the size of the images that display in the bottom tab area?
You could use Custom Renderer to reset the size of icon in specific platforms .
in iOS projet
In the renderer I set the first icon as 60pt *60pt . You need to set the size on each item
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using xxx;
using xxx.iOS;
using CoreGraphics;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(AppShell), typeof(MyShellRenderer))]
namespace xxx.iOS
{
public class MyShellRenderer : ShellRenderer
{
protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
{
var renderer = base.CreateShellSectionRenderer(shellSection);
if (renderer != null)
{
}
return renderer;
}
protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
{
return new CustomTabbarAppearance();
}
}
public class CustomTabbarAppearance : IShellTabBarAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(UITabBarController controller)
{
}
public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
{
UITabBar myTabBar = controller.TabBar;
if (myTabBar.Items != null)
{
UITabBarItem itemOne = myTabBar.Items[0];
itemOne.Image = ScalingImageToSize(UIImage.FromBundle("tab_feed.png"),new CGSize(60,60)); // set the size here if you want to customize it
itemOne.SelectedImage = ScalingImageToSize(UIImage.FromBundle("tab_feed.png"), new CGSize(60, 60));
UITabBarItem itemTwo = myTabBar.Items[1];
itemTwo.Image = UIImage.FromBundle("tab_about.png");
itemTwo.SelectedImage = UIImage.FromBundle("tab_about.png");
//The same logic if you have itemThree, itemFour....
}
}
public UIImage ScalingImageToSize(UIImage sourceImage, CGSize newSize)
{
UIGraphics.BeginImageContextWithOptions(newSize, false, UIScreen.MainScreen.Scale);
sourceImage.Draw(new CGRect(0, 0, newSize.Width, newSize.Height));
UIImage newImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return newImage;
}
public void UpdateLayout(UITabBarController controller)
{
}
}
}
in Android
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Views;
using Android.Widget;
using xxx;
using xxx.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(AppShell), typeof(MyShellRenderer))]
namespace xxx.Droid
{
public class MyShellRenderer : ShellRenderer
{
Context context;
public MyShellRenderer(Context context) : base(context)
{
this.context = context;
}
protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
{
return new CustomBottomNavAppearance(context);
}
}
public class CustomBottomNavAppearance : IShellBottomNavViewAppearanceTracker
{
Context context;
public CustomBottomNavAppearance(Context context)
{
this.context = context;
}
public void Dispose()
{
}
public void ResetAppearance(BottomNavigationView bottomView)
{
}
public void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
{
bottomView.ItemIconSize=250;
//The same logic if you have myItemTwo, myItemThree....
}
}
}
I made a progress bar customization (custom renderer) to change the progress bar color in iOS and Droid as seen in the following
Custom progress bar class in the PCL:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App2
{
public class ColorProgressBar : ProgressBar
{
public static BindableProperty BarColorProperty
= BindableProperty.Create<ColorProgressBar, Color>(p =>
p.BarColor, default(Color));
public Color BarColor
{
get { return (Color)GetValue(BarColorProperty); }
set { SetValue(BarColorProperty, value); }
}
}
}
Custom renderer for iOS:
using App2;
using App2.iOS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Xamarin.Forms;
//using MonoTouch.Foundation;
//using MonoTouch.UIKit;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ColorProgressBar),
typeof(ColorProgressBarRenderer))]
namespace App2.iOS
{
public class ColorProgressBarRenderer : ProgressBarRenderer
{
public ColorProgressBarRenderer()
{ }
protected override void
OnElementChanged(ElementChangedEventArgs<ProgressBar> e)
{
base.OnElementChanged(e);
if (e.NewElement == null)
return;
if (Control != null)
{
UpdateBarColor();
}
}
protected override void OnElementPropertyChanged(object sender,
PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName ==
ColorProgressBar.BarColorProperty.PropertyName)
{
UpdateBarColor();
}
}
private void UpdateBarColor()
{
var element = Element as ColorProgressBar;
Control.TintColor = element.BarColor.ToUIColor();
}
}
}
Custom renderer for Android:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Renderscripts;
using static Java.Util.ResourceBundle;
using Xamarin.Forms.Platform.Android;
using Android.Graphics;
using System.ComponentModel;
using Xamarin.Forms;
using App2;
using App2.Droid;
[assembly: ExportRenderer(typeof(ColorProgressBar),
typeof(ColorProgressBarRenderer))]
namespace App2.Droid
{
public class ColorProgressBarRenderer : ProgressBarRenderer
{
public ColorProgressBarRenderer()
{ }
protected override void
OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ProgressBar>
e)
{
base.OnElementChanged(e);
if (e.NewElement == null)
return;
if (Control != null)
{
UpdateBarColor();
}
}
protected override void OnElementPropertyChanged(object sender,
PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName ==
ColorProgressBar.BarColorProperty.PropertyName)
{
UpdateBarColor();
}
}
private void UpdateBarColor()
{
var element = Element as ColorProgressBar;
// http://stackoverflow.com/a/29199280
Control.IndeterminateDrawable.SetColorFilter(
element.BarColor.ToAndroid(), PorterDuff.Mode.SrcIn);
Control.ProgressDrawable.SetColorFilter(
element.BarColor.ToAndroid(), PorterDuff.Mode.SrcIn);
}
}
}
I'm setting the custom progress bar's color this way:
var progressBar = new ColorProgressBar();
progressBar.BarColor = Color.Red;
I don't understand how to make a custom renderer class for UWP that changes the color of the progress bar. Could someone please help me understand how to do this class?
You're going to want to update the Foreground property of the native Windows.UI.Xaml.Controls.ProgressBar control to change the color.
It should look something like this:
private void UpdateBarColor()
{
var element = Element as ColorProgressBar;
Control.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(
GetWindowsColor(element.BarColor));
}
Windows.UI.Color GetWindowsColor(Color color)
{
return Windows.UI.Color.FromArgb((byte)(255 * color.A), (byte)(255 * color.R), (byte)(255 * color.G), (byte)(255 * color.B));
}
This will take your BarColor, use it to make a SolidColorBrush of the right color, and then assign that to your native ProgressBar control.
I take NullReferenceException when I want to add addJsonFile. I made exaclty what lynda(http://www.lynda.com/ASP-NET-tutorials/Dynamically-control-behavior-custom-configuration/368051/431234-4.html) said.
(screenShot)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNet.Diagnostics;
using Microsoft.Framework.Internal;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.ConfigurationModel.Json;
namespace PortalDemo
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
var config = new Configuration();
config.AddEnvironmentVariables();
config.AddJsonFile("config.json");//Here
if (config.Get("debug") == "True")
{
app.UseRuntimeInfoPage();
app.UseDeveloperExceptionPage();
}
app.UseExceptionHandler("/home/errorPage");
app.UseMvc(routes=>
routes.MapRoute("Default","{controller=Home}/{action=Index}/{id?}"));
app.UseStaticFiles();
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
}
Try the following code.
public class Startup
{
public Startup(IApplicationEnvironment appEnv)
{
IConfigurationBuilder builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("config.json", false);
Configuration = builder.Build();
}
public IConfiguration Configuration { get; set; }
}
I am working on Google Apps for Education to integrate with my .net application.I want to integrate google contacts to my application.For that i am using below code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.Contacts;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public static DataSet GetGmailContacts(string App_Name, string Uname, string UPassword)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn C2 = new DataColumn();
C2.DataType = Type.GetType("System.String");
C2.ColumnName = "EmailID";
dt.Columns.Add(C2);
RequestSettings rs = new RequestSettings(App_Name, Uname, UPassword);
rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> f = cr.GetContacts();
foreach (Contact t in f.Entries)
{
foreach (EMail email in t.Emails)
{
DataRow dr1 = dt.NewRow();
dr1["EmailID"] = email.Address.ToString();
dt.Rows.Add(dr1);
}
}
ds.Tables.Add(dt);
return ds;
}
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = GetGmailContacts("MyNetwork Web Application!", txtgmailusername.Text, txtpassword.Text);
gvmails.DataSource = ds;
gvmails.DataBind();
}
}
When i execute the above code i am getting below error.
"Execution of authentication request returned unexpected result: 404"
How to solve this error.please help me on this...
I have implemented a module using Angular Js and TypeScript in DotNetNuke7 where i have implemented my all Input Forms and js in a web project named as customerNew and than added a Web APi into a another project named as CustomerNewController which is having my methods but when i hit the URL from my Web Project to Api.It doesn't processed.I have implemented a route mapper as well but still not able get success.
My Route Mapper Class is Given Below:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotNetNuke.Web.Api;
using System.Web.UI.WebControls;
namespace CustomerNewController
{
class RouteMapper : IServiceRouteMapper
{
public void RegisterRoutes(IMapRoute mapRouteManager)
{
mapRouteManager.MapHttpRoute("CustomerNewController", "default", "{controller}/{action}",
new[] { "CustomerNewController" });
}
}
}
Here is my WebApi
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Web.UI;
using System.Xml.Serialization;
using DotNetNuke.Entities.Users;
using System.Web.Services;
using DotNetNuke.Web.Api;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules.Communications;
using DotNetNuke.Entities.Modules;
namespace CustomerNewController
{
public class CreateController : DnnApiController
{
[AllowAnonymous]
[HttpGet]
public HttpResponseMessage HelloWorld()
{
return Request.CreateResponse(HttpStatusCode.OK, "Hello World!");
}
}}
My URL
http://localhost/dnn7/DesktopModules/CustomerNewController/Api/Create/HelloWorld
Here is my folder structure
An example of my WebAPI GET method:
[DnnExceptionFilter]
public class AuthorController : DnnApiController
{
#region Public RPC Methods
[HttpGet]
[AllowAnonymous]
public HttpResponseMessage GetAllAuthors()
{
var lstAuthors = AuthorRepository.GetAllAuthors();
return Request.CreateResponse(HttpStatusCode.OK, lstAuthors);
}
[HttpGet]
[AllowAnonymous]
public HttpResponseMessage GetAlphabet()
{
var lstAuthors = AuthorRepository.GetAlphabet();
return Request.CreateResponse(HttpStatusCode.OK, lstAuthors);
}
#endregion
}
Service route mapper example (only need to do this once):
public class ServiceRouteMapper : IServiceRouteMapper
{
#region IServiceRouteMapper Implementation
public void RegisterRoutes(IMapRoute mapRouteManager)
{
mapRouteManager.MapHttpRoute("ATKV.Commerce", "default", "{controller}/{action}", new[] { "ATKV.Commerce.Services" });
}
#endregion
}
Calling code:
// Service Paths
var servicesFramework = opts.servicesFramework;
var servicePath = servicesFramework.getServiceRoot('ATKV.Commerce') + 'Author/';
// Bind data
$.ajax({
type: "GET",
cache: false,
url: servicePath + "GetAllAuthors",
beforeSend: servicesFramework.setModuleHeaders
}).done(function (authors) {
if (typeof authors !== "undefined" && authors != null) {
var viewModel = new MasterViewModel(authors);
ko.applyBindings(viewModel, document.getElementById($(containerElement).attr('id')));
} else {
displayMessage("An error occurred", "dnnFormError");
}
}).fail(function (xhr, status) {
displayMessage(status, "dnnFormError");
return null;
});