Using Linq in .NET Handlers - linq

I have a Handler and I am trying to perform LINQ operations. However I cannot. Is it possible to do this in .ASHX files?
using (UserDataContext userDataContext = new UserDataContext)
{
User user = userDataContext.Users.Single -- Does not show up as an option in intellisense.
}
Thanks

Have you added import?
using System.Linq;

Related

Any ideas on how I can implement the .Bind extension that was available with Xamarin.Forms.Markup when using Xamarin.CommunityToolkit in XF 5 -pre 5

Here is the code that I have:
using Xamarin.Forms;
using Xamarin.CommunityToolkit;
namespace Templates
{
public partial class LinkGrid : Grid
{
public LinkGrid()
{
var TL1 = new Label()
{
}.Bind(Label.TextProperty, nameof(Text1), source: this);
I was using "using Xamarin.Forms.Markup;" but now I am trying 5.0 - pre5 this is no longer available so I added Xamarin.CommunityToolkit and it would appear it's still not available. Does anyone know the history behind this. Has that functionality just been dropped?
As mentioned in my comment using Xamarin.CommunityToolkit.Markup; and not using Xamarin.CommunityToolkit; they don't come from the same package even that it looks like it is the case.
in other words Xamarin.CommunityToolkit.Markup is not included in Xamarin.CommunityToolkit.
Xamarin.CommunityToolkit is the namespace that comes from Xamarin.CommunityToolkit package.
Xamarin.CommunityToolkit.Markup is the namespace that comes from Xamarin.CommunityToolkit.Markup package.
you need to include the correct namespace
using Xamarin.CommunityToolkit.Markup;

Run and compile vba script in visual studio

I've been working with macros on VBA for a while, and there's some information on them that I want to hide. As excel is a very unsafe language, I've come with the idea of creating an .exe file of the compiled script to avoid people from accessing my code.
I've been looking for the way to do this with Visual Studio, but can't get the answer.
Can someone show me how to do this?
Many thanks in advance :)
I dont think that you can create EXEs/DLLs by using vba. EXEs/DLLs are compiled assemblies, therefore you need a programming language/environment that can be compiled. Compiled means "pre-translated to machine language". VBA is just an interpreted language, that means that it will be translated on the fly in the VBA environment. I think you have to use C#, C++ etc. to do this. For further infromation please see:
Create a DLL using VBA editor
http://www.geeksengine.com/article/create-dll.html
https://msdn.microsoft.com/en-us/library/dt232c9t(VS.80).aspx
You can lock and hide your VBA code without creating a DLL:
http://www.excel-easy.com/vba/examples/protect-macro.html
http://www.ozgrid.com/VBA/protect-vba-code.htm
Best way to protect Excel VBA code?
But I am not sure if that solves your problem: You say, that excel VBA seems to be an unsafe language. I am not sure if I understand what you mean. If you just want to hide the contents of the script, see above. Up to now this will protect your code better than in further versions of excel. But I think there is still a way to crack that, e. g. Brute Force attack etc. Usually that are enhanced methods but if you want to be sure you (or better an experienced programmer have to create a programm (exe) for that. If secure means something different (why do you want to hide your code?) than let me know, maybe there is a other way to achieve what you want to do.
using ADODB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace HiddenConnectionString
{
[InterfaceType(ComInterfaceType.InterfaceIsDual),
Guid("2FCEF713-CD2E-4ACB-A9CE-E57E7F51E72E")]
public interface IMyServer
{
Connection GetConnection();
void Shutdown();
}
[ClassInterface(ClassInterfaceType.None)]
[Guid("57BBEC44-C6E6-4E14-989A-B6DB7CF6FBEB")]
public class MyServer : IMyServer
{
private Connection cn;
private string cnStr = "Provider=MSDAORA.1;Password=YourPass;User ID=YourID;Data Source=YourServer";
public MyServer()
{
}
public Connection GetConnection()
{
cn = new Connection();
cn.ConnectionString = cnStr;
cn.Open();
return cn;
}
public void Shutdown()
{
cn.Close();
}
}
}
You might get this error... It is because of the InterfaceType Guid
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Check this link for the solution:
https://social.msdn.microsoft.com/Forums/en-US/26accc30-9cfb-4d86-9c27-780f51929ecb/access-is-denied-exception-from-hresult-0x80070005-eaccessdenied?forum=vsreportcontrols
This is the code but I would visit the link that Stefan suggested.

MVC Entity Framework Conundrum: "missing using directive or an assembley reference?"

This project used to work. I fuddled with the connection string in Web.Config trying to get it to work with .accdb file. Forget that.
But now I can't get back home to a working project.
HomeController.cs code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using oesac.Models;
namespace oesac.Controllers
{
[HandleError]
public class HomeController : Controller
{
oesacEntities_connection _db;
public HomeController()
{
_db = new oesacEntities_connection();
}
=============================
E:\oesac_MVC\Controllers\HomeController.cs(52,42): error CS1061: 'oesac.Models.oesacEntities_connection' does not contain a definition for 'Courses' and no extension method 'Courses' accepting a first argument of type 'oesac.Models.oesacEntities_connection' could be found (are you missing a using directive or an assembly reference?)
(_db.Courses is underlined, just Courses has the underline)
//SEARCH BY COURSE TITLE
var courses = (from m in _db.Courses select m);
=======================
The Entity Container Name is:
"oesacEntities_connection"
It has 2 tables, Courses and Sponsors, and refreshes tables when I right click in .edmx window and select "Update Model From Database".
So database is there and VS 2010 sees it.
But for some reason there is a disconnect in referencing all this.
If I breeze through the popup after the errors that says "would you like to continue" I get a webpage with this error:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'oesac.MvcApplication'.
Source Error:
Line 1: <%# Application Codebehind="Global.asax.cs" Inherits="oesac.MvcApplication" Language="C#" %>
And this is what is in Global.asax.cs:
namespace oesac
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
I'm thinking if it was snake it would have bit me. But a little too new at this MVC dreamworld.
Ok, if someone else understands this better I can give them the green checkmark for correct answer. However, a friend at work said sometimes with EF you just have to wipe the slate clean and add a new Entity Framework class. And not get too clever. I had changed the names of the tables in VS 2010 .edmx file like it says you can and somehow the Gremlins took over.
Friend at work and 2 other people came to realize this after pulling out all their hair on one of there first major MVC projects.
And, yes, I did try all the mumbo jumbo of "Update Model From Database" right click in the .edmx in VS.

How to programmatically set COM+ Component -> Transactions to Not Supported?

I am looking for a solution to programmatically modify Com+ Component Property -> Transaction Support to “Not Supported”
The manual steps are the following:
Open Component Services dialog (comexp.msc)
Expand Component Services -> Computers -> My Computer
Find and expand COM+ QC Dead Letter Queue Listener
Expand folder Components inside the opened component
Find component QC.DLQListener and open context menu for this component and select properties
On the Properties screen, select “Transactions” tab and set Transactions Support to Not Supported
Click “OK” to Save the changes
After I spent several hours on this problem, I've finally got a solution on C#.
I've got a huge insight from the following articles:
Changin the transaction atribute using COMAdminCatalog
Retrieve settings from COM+ components via C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COMAdmin;
namespace SetComPlusTransactionsToNotRequired
{
class Program
{
static void Main(string[] args)
{
COMAdminCatalog catalog;
COMAdminCatalogCollection applications;
// Get the catalog
catalog = new COMAdminCatalog();
// Get the list of all COM+ applications contained within this catalog
applications = (COMAdminCatalogCollection)catalog.GetCollection("Applications");
applications.Populate();
foreach (COMAdminCatalogObject application in applications)
{
if (application.get_Value("Name") == "COM+ QC Dead Letter Queue Listener")
{
COMAdminCatalogCollection components;
components = (COMAdminCatalogCollection)applications.GetCollection("Components", application.Key);
components.Populate();
foreach (COMAdminCatalogObject component in components)
{
Console.WriteLine("Component: " + component.Name);
component.set_Value("Transaction", COMAdminTransactionOptions.COMAdminTransactionNone);
}
components.SaveChanges();
}
}
}
}
}

Windows bluetooth autopairing or disable authentication

I need windows to automatically pair with bluetooth devices. I don't want the user to have to click anything on the windows side. The server will be physically located somewhere the user cannot get to. Having to pair on the user side is fine. Windows just needs to accept any requests that come in without user input.
How can I accomplish this? Registry hacks? Replace a dll? A Hardware change (autopairing dongle or something)?
Is there any SDK that will give me the tools take care of this?
Currently I am using bluecove on the windows machine on top of Microsoft stack. I tried the Widcomm stack also with no luck.
The primary protocol that devices will use to connect is RFCOMM.
EDIT:
using the accepted answer below I came up with this code, that auto-pairs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InTheHand.Net.Bluetooth;
using System.Threading;
namespace BT
{
class BluetoothAutoSSP
{
public static void Main()
{
BluetoothAutoSSP c = new BluetoothAutoSSP();
EventHandler<BluetoothWin32AuthenticationEventArgs> handler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(c.handleRequests);
BluetoothWin32Authentication authenticator = new BluetoothWin32Authentication(handler);
while (true)
{
Thread.Sleep(10);
}
}
public void handleRequests(Object thing, BluetoothWin32AuthenticationEventArgs args)
{
args.Confirm = true;
}
}
}
For the Microsoft Bluetooth stack: To support both traditional Bluetooth pairing as well as v2.1's Secure Simple Pairing use the BluetoothRegisterForAuthenticationEx function and in your callback function respond by calling BluetoothSendAuthenticationResponseEx.
See more at BluetoothWin32Authentication 32feet.NET docs which describes the way to handle that in the 32feet.NET Bluetooth library for .NET, my doc Bluetooth in Windows 7, and MSDN e.g. BluetoothRegisterForAuthenticationEx etc.
BTW Widcomm does not have a programatic way to respond to pairing (it does have a method to initiate pairing). BlueSoleil does have an API apparently.

Resources