Posts

Showing posts with the label c#

Regex - How to capture all iterations of a repeating pattern?

Image
Clash Royale CLAN TAG #URR8PPP Regex - How to capture all iterations of a repeating pattern? Take a look at this example, I want to capture not just the last iteration (which is 5), but also 2, 3 and 4. It says here: A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations... but I don't know how to do this. Since I need this in C++, I was looking for a way to get all iterations of capturing group using some regex functions in C++, but I always end up with same groups which the website finds. How about instruction d((,d)*) ? (IMHO, this is meant in the cited text.) Though, this leaves still the task to separate the inner matches... – Scheff 17 mins ago instruction d((,d)*) Thou...

fatal error LNK1104 'libboost_date_time_vc110-mt-gd-1.51.lib'

Image
Clash Royale CLAN TAG #URR8PPP fatal error LNK1104 'libboost_date_time_vc110-mt-gd-1.51.lib' I am trying to build a program made by someone else (VS2012) on visual studio 2017 and this isn't working. 1>LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc110-mt-gd-1_51.lib' I'm not even sure why it is searching for this file specifically, besides all the files are -vc141- and not -vc110- . Is there any way to specify to look for any libboost_xxxx_-vc141-xxxx.lib ? Is there any reason why it is searching for another vc format? I've checked the project's properties in C++General->Additionnal include directories , LinkerGeneral->Additional Library Directories and LinkerInput->additionnal dependencies and nothing mentions vc110 . -vc141- -vc110- libboost_xxxx_-vc141-xxxx.lib C++General->Additionnal include directories LinkerGeneral->Additional Library Directories LinkerInput->additionnal dependencies vc110 ...

WebAPI routing does not work

Image
Clash Royale CLAN TAG #URR8PPP WebAPI routing does not work I have WebApiConfig public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } } Web API controller: [RoutePrefix("api/Trip")] public class TripApiController : ApiController { [Route("SaveRouting")] [HttpPost] public async Task<HttpResponseMessage> SaveRouting(string points, int tripId, decimal totalMileage) { // ...... return Request.CreateResponse(HttpStatusCode.OK); } and call from jquery: $.post("/api/trip/SaveRouting", { points: JSON.stringify(arrayStops), tripId: $("#hdTripId").val(), totalMileage: tMiles }, fu...

Casting an object to a IList with an abstract type parameter

Image
Clash Royale CLAN TAG #URR8PPP Casting an object to a IList with an abstract type parameter In my code, I have an object: object obj = ... Which I know is of type MyListType, where MyListType is a subclass of IList and T is a subclass of MyAbstractClass. The type parameter of MyListType is constrained so that it is always a subclass of MyAbstractClass. However, trying to cast obj MyListType<MyAbstractClass> myList = (MyListType<MyAbstractClass>)obj; gives a runtime error. I tried to define an explicit operator public static explicit operator MyListType<MyAbstractClass>(MyListType<T> list) { MyListType<MyAbstractClass> newList = new MyListType<MyAbstractClass>(); foreach(T t in list) newList.Add((MyAbstractClass) t); return newList; } However, this operator doesn't get used by the cast since obj is an object, not a MyListType. Is there a workaround to successfully perform this cast? I've looked at this question, but their t...

Unique_ptr: pointer being freed was not allocated when emplaced in list

Image
Clash Royale CLAN TAG #URR8PPP Unique_ptr: pointer being freed was not allocated when emplaced in list I have a simple C++ program like so: #include <iostream> #include <list> #include <memory> int main(void) { std::list<std::unique_ptr<int>> l; int x = 5; // throws runtime error: pointer being freed was not allocated l.emplace_back(&x); } When the program is run I obtain the following output: a.out(59842,0x7fffb13d1380) malloc: *** error for object 0x7ffee81489ac: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug [1] 59842 abort ./a.out a.out(59842,0x7fffb13d1380) malloc: *** error for object 0x7ffee81489ac: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug [1] 59842 abort ./a.out This tells me that during the destruction of the list the unique_ptr object that had been created is being destroyed, and during that destruction the pointer to x is bein...

Calling angular 4 router with Multiple parameters from C#

Image
Clash Royale CLAN TAG #URR8PPP Calling angular 4 router with Multiple parameters from C# I want to call router with multiple parameters using C#.Here is i am making url var _email = UtilityConverter.Encrypt(Email); var _userId = UtilityConverter.Encrypt(Convert.ToString(UserId)); // this.router.navigate(['search', { term: term}]); var _subject = "Email Verification"; StringBuilder sb = new StringBuilder(); sb.Append("<html>"); sb.Append("<body>"); sb.Append("<p>Dear ,</p>"); sb.Append("<p>Please click the below link to verify your email.</p><br>"); sb.Append("<a href='http://localhost:4200/Emailverification/" + _email + "/" + _userId + "'>click here</a>"); sb.Append("<p>Sincerely,<br>-Offey</br>...

Why is an if statement working but not a switch statement

Image
Clash Royale CLAN TAG #URR8PPP Why is an if statement working but not a switch statement Title is terrible, but I wasn't too sure what to put. I'm trying to create Switch Statement using the char index of a string and an Enum using this wrapper to get the value of the selected enum from a Description, it pretty much allows you to store a string to an enum value. Here is my if statement Switch Statement if statement if (msgComingFromFoo[1] == Convert.ToChar(Message.Code.FOO_TRIGGER_SIGNAL.EnumDescriptionToString())) { //foo } and here is my Switch statement Switch statement switch (msgComingFromFoo[1]) { case Convert.ToChar(Message.Code.FOO_TRIGGER_SIGNAL.EnumDescriptionToString()): break; } Why is it accepting the if statement and not the switch statement ? I tried converting it to a char since I'm selected an index from a string, but unfortunately i didn't work. if statement switch statement Update: Here is the Message.Code Enum Message.Code public ...

ASP.NET Core Web API to connection Oracle 11 g database using ODP ORM

Image
Clash Royale CLAN TAG #URR8PPP ASP.NET Core Web API to connection Oracle 11 g database using ODP ORM I am new in .net core platform then i have no idea to connect oracle db to ASP .net WEB API. how to create ASP.NET Core Web API to get the data from an Oracle database using ODP ORM.? It's Code First Approach !! 1 Answer 1 you should consider to use NHibernate: Hibernate is a mature, open source object-relational mapper for the .NET framework. It's actively developed, fully featured and used in thousands of successful projects. It's built on top of ADO.NET and the current version is NHibernate 4.0.4. tutorialpoint NHibernate By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Send/Receive message To/From two running application

Image
Clash Royale CLAN TAG #URR8PPP Send/Receive message To/From two running application I have two application called SENDER and RECEIVER. RECEIVER will be launch by SENDER with System.Diagnostics.Process object System.Diagnostics.Process RECEIVER will be launched in hidden mode so it does not have MainWindowHandle . MainWindowHandle Then we could not use Win32.WM_COPYDATA in order send message to RECEIVER , because it needs MainWindowHandle . Win32.WM_COPYDATA MainWindowHandle What I need is ability to send and receive message periodically by any method. I was checked the following link for manual MainWindowHandle but it didn't help: MainWindowHandle Send message to a Windows process (not its main window) One solution might be a useful object of System.Diagnostics.Process which help us to send message to process. System.Diagnostics.Process Please suggest a solution which would not required an installation. like as MSMQ which might be not installed on en...

.NET Core (2.1) web API controller accepting all that follows within the request url as parameter

Image
Clash Royale CLAN TAG #URR8PPP .NET Core (2.1) web API controller accepting all that follows within the request url as parameter What I have is a .NET Core 2.1 web API controller (in the following the TestController) that should generate redirects to other urls when receiving GET requests. Example: The controller is called like: http://localhost/api/v1/Test/somedir/somesubdir/filename.extension and it should return a redirect to https://example-domain.com/somedir/somesubdir/filename.extension My example controller for this question looks like: [Authorize] [Route("api/v1/[controller]")] public class TestController : ControllerBase { [HttpGet("{path}")] public async Task<IActionResult> Get(string path) { //path e.g. is somedir/somesubdir/filename.extension string prefix = "https://example-domain.com/api/v1/Other/"; //string path2 = HttpContext.Request.Path.Value.Replace("/api/v1/Test/", "/api/v1/Othe...

QT Creator copies SQLite as empty database

Image
Clash Royale CLAN TAG #URR8PPP QT Creator copies SQLite as empty database I have a sqlite file in the folder of my QT creator app. I even did Projects (right click) -> add existing files, and added it to my project. The file gets copied to the build directory. However, it contains no tables or data. I need the data in my database file to persist during the copy. Is there any way to ensure this? do you mean you want to keep the data but change the schema? – Amfasis 2 hours ago 1 Answer 1 What happens is that the database is not being copied, since attaching it to the .pro does not imply that it will be moved to the build folder. And then why is there .db in the build folder? sqlite if it does not find the .db it will create it, so you get the empty fil...

How to SendKeys to input element that is created ad hoc when clicking in div element parent?

Image
Clash Royale CLAN TAG #URR8PPP How to SendKeys to input element that is created ad hoc when clicking in div element parent? I am stuck in this problem: our webpage has a dynamic table that will load values (students' marks) on a div element. If we click on said div , a new child element input will be appended to the div and we should be able to input a new mark using SendKeys method. However, when I try to SendKeys, a StaleElementReferenceException appears. div div input div SendKeys StaleElementReferenceException Here is the element when the input is added (had to use a breakpoint as the element disappears as soon as the div element loses focus): input div <tr> <td class="indice">1</td> <td id="accion-1-alumno-0" data-tooltip="" title="Bustos, Guido" class="has-tip titulo">Bustos, Guido</td> <td data-tooltip="" title="1º ESA" class="has-tip titulo"...

perf report shows this function “__memset_avx2_unaligned_erms” has overhead. does this mean memory is unaligned?

Image
Clash Royale CLAN TAG #URR8PPP perf report shows this function “__memset_avx2_unaligned_erms” has overhead. does this mean memory is unaligned? I am trying to profile my C++ code using perf tool. Implementation contains code with SSE/AVX/AVX2 instructions. In addition to that code is compiled with -O3 -mavx2 -march=native flags. I believe __memset_avx2_unaligned_erms function is a libc implementation of memset . perf shows that this function has considerable overhead. Function name indicates that memory is unaligned, however in the code I am explicitly aligning the memory using GCC built-in macro __attribute__((aligned (x))) What might be the reason for this function to have significant overhead and also why unaligned version is called although memory is aligned explicitly? -O3 -mavx2 -march=native __memset_avx2_unaligned_erms memset __attribute__((aligned (x))) I have attached the sample report as picture. memset happens to be implemented in a way that d...

Movement based on mouse click XNA

Image
Clash Royale CLAN TAG #URR8PPP Movement based on mouse click XNA I'm making a server/client game with movement similar to strategy games like Warcraft 1/2/3 etc.. where the player moves by right clicking on somewhere on the area and the character tries to move there. I'm trying to make the character always go in a straight line towards the point until it gets there (or close enough). The code I'm using now gets the character there but in a weird way. When I click somewhere under the character (higher Y coordinate) it moves in a straight line, but when I click above it (lower Y coordinate), the character moves like it's making a circle while moving, but it still gets there, only not the way I want it to. Here's the code that runs every update to move it. if (this.order == "Move") { if (Math.Abs(this.orderPos.X - this.warlockPos.X) < this.moveSpeed && Math.Abs(this.orderPos.Y - this.warlockPos.Y) < this.moveSpeed) ...

How does System.Diagnostics.Tracing.EventSource.IsEnabled work?

Image
Clash Royale CLAN TAG #URR8PPP How does System.Diagnostics.Tracing.EventSource.IsEnabled work? When using a custom event source e.g.: [EventSource(Name = "MyEventSource")] public partial class CustomEventSource : EventSource { } There is an IsEnabled method on the EventSource class: EventSource.IsEnabled(eventLevel, eventKeywords) https://msdn.microsoft.com/en-us/library/hh393402(v=vs.110).aspx How does this method determine whether the event is 'Enabled' for the level and keywords? There doesn't seem to be any solid documentation on this. On my implementation the method is returning false and I am not sure what needs to be done in order to make it return true. It takes two to do this tango, the event source and the event listener. The source doesn't do the work until a somebody signals interest in the events. If the listener is a .net program then you'd use EventListener.EnableEvents(). Or you'd for example use the Windo...

What are good ways to prevent SQL injection? [duplicate]

Image
Clash Royale CLAN TAG #URR8PPP What are good ways to prevent SQL injection? [duplicate] This question already has an answer here: I have to program an application management system for my OJT company. The front end will be done in C# and the back end in SQL. Now I have never done a project of this scope before; in school we had only basic lessons about SQL. Somehow our teacher completely failed to discuss SQL injections, something which I have only now come in contact with by reading about it on the net. So anyway my question is: how do you prevent SQL injections in C#? I vaguely think that it can be done by properly masking the text fields of the application so that it only accepts input in a specified format. For example: an e-mail textbox should be of the format "example@examplecompany.tld". Would this approach be sufficient? Or does .NET have pre-defined methods that handle stuff like this? Can I apply a filter to a textbox so it only accepts email-address format or a nam...