I'm wondering what the MySQL eqivalent of the SQLiteConnectionContext class is. I need this to be able to have a common connection context for my program. I'm creating an entity based solution that will push and pull data from a MySQL database. If there is a better way to do this I'm open to that as well. Below is the SQLite version of what I am looking for.
/// <summary>
/// A ConnectionContext common for all of the Inventory project
/// </summary>
public class InventoryConnectionContext : SQLiteConnectionContext
{
public InventoryConnectionContext(bool connect = true)
: base(InventoryConnectionString, connect)
{
}
/// <summary>
/// Constructs a BudgetConnectionContext and optionally opens the connection
/// </summary>
/// <param name="connectString">Connection string that points to a connection aside from the default connection</param>
/// <param name="connect">Specifies whether or not to open the connection</param>
public InventoryConnectionContext(string connectString, bool connect = true)
: base(connectString)
{
if (connect)
Connect();
}
}
They are dynamically generated under the .edmx file in the entities project you put them in. It seems to follow this format *(nameofdb)*Entities and is an instantiable class.
To get this to generate you need to drop the EntityFrameWork, MySQL.Data, MySQL.Data.Entities NuGets and then pull your server in. You do this by clicking View->Server Explorer then right click on SharePoint Connections (may be named slightly differently) and add your server that way. You can then import all of your tables and Entities. They will show up under the .tt file and are also autogenerated instantiable classes. All of these can be worked with together by knowing that you need a context and an entity to modify a db. [context].[table].Add/Delete; An example context.test_table.Add(myEntity);.
;tldr : Add the server, it shows up under the .edmx file as a .context.tt with the classes under that.
Related
I am trying to set up an auto-versioning update on TortoiseSVN for a project I'm working on. It's very straightforward; the code is supposed to pull the SVN revision and display the date & location whenever anyone does a checkout/update from the repo.
Below I have a template class
public static class SvnRevision
{
/// <summary>
/// SVN repo revision
/// </summary>
public const string REVISION = "$WCREV$";
/// <summary>
/// SVN repo location
/// </summary>
public const string REPOSITORY_URL = #"$WCURL$";
/// <summary>
/// SVN repo date
/// </summary>
public const string REPOSITORY_DATE = "$WCDATE$";
}
I want to know the background steps necessary to get this program to work. Appreciate if anyone could provide a walk through or tutorial. I am trying to do this on Visual Studio 2022.
I made commits using this class to SVN without any luck, a search indicates that I need to set up versioning and provide some kind of source/destination files that I don't know how to do. Below is a link I've referenced.
https://docs.huihoo.com/tortoisesvn/1.5.7-en/tsvn-subwcrev-keywords.html
Before selecting The Right Thing (tm) for your task and|or using SubWCRev (which you try to use, according to used subwcrev-specific keywords) you have to know some things
Best (and, really, single correct place) for reading updated, relevant to latest release docs about SubWCRev is TortoiseSVN website (SubWCRev is part of TortoiseSVN distribution and is not of pure SVN per se)
"...whenever anyone does a checkout/update from the repo" such person with WC of your repo have more natural way to know, which revision he|she got and whence: ordinary svn info tells it, instead of reading your code or compiling it in order to see message-box with collected data
Contrary to SVN-keywords, which work from a box (when inserted into files) and updated automagically on the fly, subwcrev's keywords have to have "release" stage (read docs): you insert keywords in template-file, which, after processing by SubWCRev, will produce new file, in which template-placeholders are replaced by data, actual only for this moment and not updated automatically after WC-changes (you must to refresh files from templates again)
In your case you can
move public static class SvnRevision into somename.cs.tpl with all needed keywords
Before all other steps in your compile-chain add call of SubWCRev, smth.like SubWCRev.exe path\to\WC somename.cs.tpl somename.cs
In you code use references to somename.cs, which also have to be in svn-ignore and not versioned, while template have to be versioned
HTH
Thanks for all the help everyone. Likely my line of questioning was not clear or I worked it wrong, but the problem was that I needed to set a command line as a prebuild event so that the SVN keywords would update.
Prebuild event command line: "C:\Program Files\TortoiseSVN\bin\SubWCRev.exe" "$(ProjectDir)." "$(ProjectDir)SvnRevision_Template.cs" "$(ProjectDir)SvnRevision.cs"
Background: We have a custom tool which takes the xml input and generates the cs output. A custom tool needs to register with the Visual studio in order to make it work with that version of visual studio.
What we have done: We have done the custom tool registration with the Visual Studio 2015 which is working fine. But now the problem is with Visual Studio 2017.
Problem: So far in my research, I found until Visual Studio 2015, VS had the direct registry entries which were allowing to register the tool but from VS 2017, Microsoft has made changes in the way how registry entries are stored (a good read to understand changes in VS2017).
If I open up the VS 2017 and try to run the custom tool then I get the error
Cannot find custom tool "Tool Name" on this system.
This is obvious because custom tool is not yet registered with VS 2017 to work.
I tried to follow this guy which says to load .bin file in to the registries but he also says that it disables to launch the VS 2017. In order to launch VS, we have to unload hive. Research says, .bin file can be on different location based on type of VS installed (enterprise, pro etc.).
Has anyone done this before?
TIA
You may have to follow different approach here by creating a Visual Studio extension (VSIX), below I have explained it in detail, hope it helps.
How to create a Custom Tool or Single File Generator in Visual Studio 2017:
Prior to VS2017 creating a custom tool required implementing Interface IVsSingleFileGenerator and code to register and unregister the custom tool in the system registry, but in VS2017, Microsoft has changed entire registry structure. The change is, VS will make registry entries to a private registry so that system registry is not messed up. While previously the registry entries were made in the system registry, now they are made to
C:\Users\xyz\AppData\Local\Microsoft\VisualStudio\15.0_xx\privateregistry.bin
Visual studio 2017 also supports testing your tool directly by running it from the visual studio itself (F5), which starts another instance of Visual Studio called Visual Studio Experimental Instance and your tool can be tested in it since it makes registry entries to
C:\Users\xyz\AppData\Local\Microsoft\VisualStudio\15.0_xxExp\privateregistry.bin
Follow below steps to create a Custom Tool in VS2017:
We need to create a VSIX extension
Add new Visual Studio Package
Implement IVsSingleFileGenerator
Add the registry entry code
Compile and test the tool by running it in VS2017
Install the tool by double clicking the generated .VSIX file
We will create an extension/custom tool as an example named "CountLines" which will read a file (having Custom Tool property set to CountLines) and generate an XML file containing the number of lines in the file. e.g. <LineCount>1050</LineCount>
1. Create a VSIX extension
In order to create an extension you must have installed Visual Studio Extensibility Tools which is included as an optional feature in Visual Studio setup. If it is not installed you can also install it by modifying VS 2017 setup.
Create new VSIX (Visual Studio Extension) project by selecting
New Project -> Extensibility -> VSIX Project
give it some name like "CountLinesVSIX".
2. Add new Visual Studio Package
Once VSIX project is created, add new Visual Studio Package to it by selecting
Add -> New Item -> Extensibility -> Visual Studio Package
give it name "CountLines.cs". In CountLines.cs we need to delete existing code and replace it with our code for IVsSingleFileGenerator implementation
3. Implement IVsSingleFileGenerator
Write your custom implementation for interface IVsSingleFileGenerator, our example code is as below
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System.Text;
namespace CountLinesVSIX
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration( "CountLines", "Generate XML with line count", "1.0")]
[Guid("202E7E8B-557E-46CB-8A1D-3024AD68F44A")]
[ComVisible(true)]
[ProvideObject(typeof(CountLines))]
[CodeGeneratorRegistration(typeof(CountLines), "CountLines", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", GeneratesDesignTimeSource = true)]
public sealed class CountLines : IVsSingleFileGenerator
{
#region IVsSingleFileGenerator Members
public int DefaultExtension(out string pbstrDefaultExtension)
{
pbstrDefaultExtension = ".xml";
return pbstrDefaultExtension.Length;
}
public int Generate(string wszInputFilePath, string bstrInputFileContents,
string wszDefaultNamespace, IntPtr[] rgbOutputFileContents,
out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
{
try
{
int lineCount = bstrInputFileContents.Split('\n').Length;
byte[] bytes = Encoding.UTF8.GetBytes("<LineCount>" + lineCount.ToString() + "</LineCount>" );
int length = bytes.Length;
rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(length);
Marshal.Copy(bytes, 0, rgbOutputFileContents[0], length);
pcbOutput = (uint)length;
}
catch (Exception ex)
{
pcbOutput = 0;
}
return VSConstants.S_OK;
}
#endregion
}
}
We need to provide an unique GUID for our extension such as one in above code [Guid("202E7E8B-557E-46CB-8A1D-3024AD68F44A")]. GUID can be created from VS2017 by selecting "Tools -> Create GUID". Select GUID format as Registry format. Note that GUID mentioned above code is without curly braces.
[ComVisible(true)] is required for COM Interops
[CodeGeneratorRegistration(typeof(CountLines), "CountLines", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", GeneratesDesignTimeSource = true)] is a class attribute with code to register the tool. Params being GeneratorType, GeneratorName, and C# language GUID
You can also derive from "TemplatedCodeGenerator" which supports custom TextTemplate formatting, which may require some additional code implementation.
4. Add the registry entry code
Create new class file with below code, name it CodeGeneratorRegistrationAttribute.cs
using System;
using System.Globalization;
using Microsoft.VisualStudio.Shell;
namespace CountLinesVSIX
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class CodeGeneratorRegistrationAttribute : RegistrationAttribute
{
private string _contextGuid;
private Type _generatorType;
private Guid _generatorGuid;
private string _generatorName;
private string _generatorRegKeyName;
private bool _generatesDesignTimeSource = false;
private bool _generatesSharedDesignTimeSource = false;
public CodeGeneratorRegistrationAttribute(Type generatorType, string generatorName, string contextGuid)
{
if (generatorType == null)
throw new ArgumentNullException("generatorType");
if (generatorName == null)
throw new ArgumentNullException("generatorName");
if (contextGuid == null)
throw new ArgumentNullException("contextGuid");
_contextGuid = contextGuid;
_generatorType = generatorType;
_generatorName = generatorName;
_generatorRegKeyName = generatorType.Name;
_generatorGuid = generatorType.GUID;
}
/// <summary>
/// Get the generator Type
/// </summary>
public Type GeneratorType
{
get { return _generatorType; }
}
/// <summary>
/// Get the Guid representing the project type
/// </summary>
public string ContextGuid
{
get { return _contextGuid; }
}
/// <summary>
/// Get the Guid representing the generator type
/// </summary>
public Guid GeneratorGuid
{
get { return _generatorGuid; }
}
/// <summary>
/// Get or Set the GeneratesDesignTimeSource value
/// </summary>
public bool GeneratesDesignTimeSource
{
get { return _generatesDesignTimeSource; }
set { _generatesDesignTimeSource = value; }
}
/// <summary>
/// Get or Set the GeneratesSharedDesignTimeSource value
/// </summary>
public bool GeneratesSharedDesignTimeSource
{
get { return _generatesSharedDesignTimeSource; }
set { _generatesSharedDesignTimeSource = value; }
}
/// <summary>
/// Gets the Generator name
/// </summary>
public string GeneratorName
{
get { return _generatorName; }
}
/// <summary>
/// Gets the Generator reg key name under
/// </summary>
public string GeneratorRegKeyName
{
get { return _generatorRegKeyName; }
set { _generatorRegKeyName = value; }
}
/// <summary>
/// Property that gets the generator base key name
/// </summary>
private string GeneratorRegKey
{
get { return string.Format(CultureInfo.InvariantCulture, #"Generators\{0}\{1}", ContextGuid, GeneratorRegKeyName); }
}
/// <summary>
/// Called to register this attribute with the given context. The context
/// contains the location where the registration inforomation should be placed.
/// It also contains other information such as the type being registered and path information.
/// </summary>
public override void Register(RegistrationContext context)
{
using (Key childKey = context.CreateKey(GeneratorRegKey))
{
childKey.SetValue(string.Empty, GeneratorName);
childKey.SetValue("CLSID", GeneratorGuid.ToString("B"));
if (GeneratesDesignTimeSource)
childKey.SetValue("GeneratesDesignTimeSource", 1);
if (GeneratesSharedDesignTimeSource)
childKey.SetValue("GeneratesSharedDesignTimeSource", 1);
}
}
/// <summary>
/// Unregister this file extension.
/// </summary>
/// <param name="context"></param>
public override void Unregister(RegistrationContext context)
{
context.RemoveKey(GeneratorRegKey);
}
}
}
Above code will make sure your entries are made to VS private registry
5. Compile and test the tool by running it in VS2017
You may add "Install targets" in "source.extension.vsixmanifest" to ensure different VS2017 editions are supported by your extesion.
Run your tool in VS 2017 to test if it is working as expected. Once you Run the VSIX, the Visual Studio Experimental Instance will install the extension and register it in registry "C:\Users\xyz\AppData\Local\Microsoft\VisualStudio\15.0_xxExp\privateregistry.bin". You can see the installed extension by selecting "Tools -> Extensions and updates". To test the tool we will have to open a dummy project, select a file in solution explorer, go to its properties and update Custom Tool property to "CountLines". Once this is done VS will run the tool in background and generate the output, in our example it will generate a xml file under the selected file. Alternatively, once Custom Tool property is set, your can right click the file and select "Run Custom Tool"
6. Install the tool by double clicking the generated .VSIX file
Once tested successfully, try installing the VSIX which can be found at location "projectName/bin/debug". Install the VSIX by double clicking the file, follow the installation steps. Now your tool will be available for use in VS2017. Using tool is similar, right click the file on which you want to run the custom tool and select "Run Custom Tool"
In case you want to uninstall the extention, go to "Tools -> Extensions and updates -> select your extension" and click uninstall. Note that tool will not get uninstalled until VS is closed. Once closeed you will get a popup window to uninstall, select "Modify" to uninstall.
Well, during research, I got the answer of this problem.
Solution:
We have to load the the .bin file (via load hiv).
Make the changes or edit the bin to register your tool.
Unload hive.
Step#1: Load Hive.
a) Open registry (regedit). Select node HKEY_LOCAL_MACHINE.
b) Go to | File -> Load Hive
c) Select the bin file which is available at -> %LocalAppData%\ Microsoft\ VisualStudio\ 15.0_'instance_id'\privateregistry.bin.
d) Provide a key name. This will create a new key entry in HKEY_LOCAL_MACHINE with your key name.
e) You can check the .bin file at HKEY_LOCAL_MACHINE\YourKeyName\Software\Microsoft\VisualStudio\
Step#2: Edit the bin: You can now register your custom tool by following the same way as you were doing for other VS versions. Actually the only problem was to get the VS2017 keys in to the global registry and that is solved using Step#1 above.
Step#3: Unload Hive.
a) select your key under HKEY_LOCAL_MACHINE.
b) Go to | File menu
c) Unload Hive.
I incorporated a WLAN API given from Codeplex's Managed WiFi site into my C# project (Windows Form Application). In the API, different functions are given to retrieve various aspects of the machine's current WiFi profile. I am only interested in retrieving the RSSI strength given in the function below. I then want to take that value and stick it in a text box on my form.
(Visual Studio 2008)
In WlanAPI.cs file, the function I am interested in exists as such:
namespace NativeWifi
{
public class WlanClient
{
/// <summary>
/// Represents a Wifi network interface.
/// </summary>
public class WlanInterface
{
/// <summary>
/// Gets the RSSI.
/// </summary>
/// <value>The RSSI.</value>
/// <remarks>Not supported on Windows XP SP2.</remarks>
public int RSSI
{
get
{
return GetInterfaceInt(Wlan.WlanIntfOpcode.RSSI);
}
}
In myApp.cs I have a textbox simply named 'wifi' that will display the current RSSI.
I have included : 'using NativeWifi' in myApp.cs header, but can't seem to get the data from the RSSI function in the WlanAPI.csproj. The project builds and compiles just fine. I'm just snagged on getting the RSSI value.
In myApp.cs I have a statement to the effect of:
wifi.Text = (GetInterfaceInt(Wlan.WlanIntfOpcode.RSSI)); //app form txt_box=RSSI value
I know this is incorrect, but shows what I am trying to do.
Any ideas?
Thanks.
You should be able to solve the problems you are facing by
Adding a reference to WlanAPI.dll or WlanAPI project (if you add it to your solution)
Using code like following:
Using NativeWifi;
Class MyAPP : Form
{
public void PrintRSSI()
{
WlanClient client = new WlanClient();
var interfaces = client.Interfaces;
//Now chose an interface out of all the available interfaces. Usually there would be zero or 1 interfaces available
if(interfaces.Length > 0)
{
//Select first available interface. A more complicated logic can present the list of available interfaces to the user and and then display RSSI for the selected interface
wifi.Text = interfaces[0].RSSI.ToString();
}
}
//Other code for the class
}
To optimize my application, I create a SharedResourceDictionary. With this, I save about 250 mb of memory at run-time, so it works well.
My problem is in design-time, in Blend 4, I have no more access to my resource. To modify a template (witch is in my resource file), I usually right click on my control and I choose Edit Template --> Edit Current, like in this image:
I need to modify my template that way, it's 100x faster then to go in my resource file and find the good one... I have A LOT of resources...
My SharedResourceDictionary is implemented like this (found on the web):
public class SharedResourceDictionary : ResourceDictionary
{
/// <summary>
/// Internal cache of loaded dictionaries
/// </summary>
public static Dictionary<Uri, ResourceDictionary> _sharedDictionaries =
new Dictionary<Uri, ResourceDictionary>();
/// <summary>
/// Local member of the source uri
/// </summary>
private Uri _sourceUri;
/// <summary>
/// Gets or sets the uniform resource identifier (URI) to load resources from.
/// </summary>
public new Uri Source
{
get
{
if (IsInDesignMode)
return base.Source;
return _sourceUri;
}
set
{
_sourceUri = value;
if (!_sharedDictionaries.ContainsKey(value))
{
// If the dictionary is not yet loaded, load it by setting
// the source of the base class
base.Source = value;
// add it to the cache
_sharedDictionaries.Add(value, this);
}
else
{
// If the dictionary is already loaded, get it from the cache
MergedDictionaries.Add(_sharedDictionaries[value]);
}
}
}
/// <summary>
/// Check if we are in Blend to prevent error
/// </summary>
public bool IsInDesignMode
{
get
{
return
(bool)
DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty,
typeof(DependencyObject)).Metadata.DefaultValue;
}
}
}
Someone have an idea if there is a solution for this? I really want to keep this shared dictionary due to the memory improvement, but I also want to modify my resource easily...
Any clue will be appreciated. Thank you.
EDIT:
Doing this (SharedResourceDictionary), I also have an issue with static resource:
Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.
And when I change them to dynamic resource it works, or if I change the SharedResourceDictionary by a simple ResourceDictionary it also works. The project can compile but I cannot edit the resource without a modification as I said.
Are you compiling for .NET 4?
You might be hitting the bug where it fails to scan your ResourceDictionaries properly.
There's talk that you have to add your ResourceDictionaries at the the App.xaml level (in Application.Resources) level, and add a dummy default style.
This might not work for you as you seem to be adding your resources in your control.
http://blogs.windowsclient.net/rob_relyea/archive/2010/04/26/my-staticresource-reference-worked-differently-with-wpf-4-rc-than-it-does-with-wpf-4-rtm.aspx
Adding a Merged Dictionary to a Merged Dictionary
Trouble referencing a Resource Dictionary that contains a Merged Dictionary
http://connect.microsoft.com/VisualStudio/feedback/details/553528/defaultstylekey-style-not-found-in-inner-mergeddictionaries
Actually it is problematic to use this feature. =(
Maybe in the future things will get better, do not know if will help, but you can try a different implementation:
WPF SharedResourceDictionary
(but do not guarantee it will work)
I gave up using the SharedResourceDictionary because of problems at design time, only when the project is 100% completed I'll be back to use.
I have a project called InversionOfControl. That project has a class called IOC. It looks like this:
/// <summary>
/// This class is used to expose the unity container to the application.
/// </summary>
public class IOC
{
/// <summary>
/// The actual unity container for the app.
/// </summary>
public static IUnityContainer Container { get; set; }
}
All my projects that need to resolve unity injections have a reference to this class. Lately I have started getting this error:
Value cannot be null.
Parameter name: container
on normal resolves:
ITransmitModel transmitModel = IOC.Container.Resolve<ITransmitModel>();
When I try to inspect IOC.Container, the value in the watch window is:
The type 'InversionOfControl.IOC' exists in both 'InversionOfControl.dll' and 'InversionOfControl.dll'
I have looked in my output folder and there is only one InversionOfControl.dll file. (I even cleaned my solution and double checked the folder was empty. I then rebuilt and checked again that there is only one.)
Why does it think there are two dlls called InversionOfControl.dll?
A way to check what module is loaded at run-time is "Debug->Windows->Modules" and check out where the DLL in question is loaded from. Make sure you are not loading 2 assemblies with different versions.
As a next step I would do search for all files with this name to see if there are suspicious copies ("cd /d c:\ & dir /s /b InversionOfControl.dll").