I'm attempting to compare two images using Visual Studio 2013 Pro. The MSDN provides information (http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.imagecomparer.compare.aspx) on ImageComparer.Compare, alas I'm failing to get it implemented in my code. On the last line of my code I'm told that "The name 'Compare' does not exist in the current context". Can someone please help? Thanks!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UITesting;
namespace Intranet.SmokeTests
{
public class Intranet_Login : Intranet_Setup
{
public List<string> IntranetLoginTest(string BrowserURL, string Host, int Port)
{
Image expected = Image.FromFile(#"\\webdriver\ImageVerification\Expected\IntranetHome.png");
Image actual = Image.FromFile(#"\\webdriver\ImageVerification\Actual\IntranetHome.png");
bool equal = Compare(actual, expected);
}
}
}
You must do it like this:
bool equal = ImageComparer.Compare(actual, expected);
When you want to use a class's static member in c# you must always qualify it with the class first. Otherwise the compiler will try to locate the member on the current class.
Another problem you might be having with your IntranetLoginTest is that it's supposed to return an instance of List<string>, but it doesn't. I must also say I find it strange that you are making an image comparison test in a method that would suggest it performs authentication mechanisms testing.
1- Using nuget Install System.Drawing.Common
2- Reference Microsoft.VisualStudio.TestTools.UITesting.dll from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform
Image expected = Image.FromFile(#"2020-09-01_15h31_24.png");
Image actual = Image.FromFile(#"2020-09-01_15h31_30.png");
Image difference = null;
var isTestPass = ImageComparer.Compare(actual, expected, out difference);
if (!isTestPass)
difference.Save("diff.png");
Console.ReadLine();
Expected
Actual
Difference
It turns out that the correct version of the referenced dll was not being added. The complete answer is here: How can I make the namespace locally match what is listed on MSDN?
Related
Needing to support CMS-user uploaded SVG images in Episerver 10.10.5.0. It was a schlep, but I was able to come right using Marija's solution (in which she documents several others having these issues...).
My difficulty now is with implementing the second bit of Marija's solution, in which thumbnails are made available (rather than default icons) for the SVG images and in which the SVG images render properly in the editor:
[ServiceConfiguration(typeof(IModelTransform), Lifecycle = ServiceInstanceScope.Singleton)]
public class ThumbnailModelTransform : StructureStoreModelTransform
{
public ThumbnailModelTransform(
IContentProviderManager contentProviderManager,
ILanguageBranchRepository languageBranchRepository,
IContentLanguageSettingsHandler contentLanguageSettingsHandler,
ISiteDefinitionRepository siteDefinitionRepository,
IEnumerable hasChildrenEvaluators,
LanguageResolver languageResolver, UrlResolver urlResolver, TemplateResolver templateResolver) :
base(
contentProviderManager,
languageBranchRepository,
contentLanguageSettingsHandler, siteDefinitionRepository,
hasChildrenEvaluators,
languageResolver,
urlResolver,
templateResolver)
{
}
public override void TransformInstance(IContent source, StructureStoreContentDataModel target, IModelTransformContext context)
{
base.TransformInstance(source, target, context);
var contentWithThumbnail = source as VectorFile;
if (contentWithThumbnail != null)
{
var urlResolver = ServiceLocator.Current.GetInstance();
var defaultUrl = urlResolver.GetUrl(contentWithThumbnail.ContentLink, null, new VirtualPathArguments { ContextMode = ContextMode.Default });
target.ThumbnailUrl = defaultUrl;
}
}
}
I get the dreaded error CS0246 for most of the terms in Marija's code (one example below):
The type or namespace name 'StructureStoreModelTransform' could not be found (are you missing a using directive or an assembly reference?)
Here are the terms for which I receive that error (or a similar one):
StructureStoreModelTransform
ServiceConfiguration
IModelTransform
Lifecycle
StructureStoreContentDataModel
IModelTransformContext
ISiteDefinitionRepository
IEnumerable
LanguageResolver
UrlResolver
TemplateResolver
I've tried adding a bunch of directives: (or dependencies? what are these called?)
using System.Collections.Generic;
using System.Linq;
using System.Web;
...and a laundry list of others that didn't work, which I won't include here.
My colleague's installation of VS community autofills in these 'using' statements once VS determines they're needed. Mine (Microsoft Visual Studio Community 2019 Preview, Version 16.7.0 Preview 2.0) is not so kind.
So, two questions I guess, but one or the other will likely sort me out:
Where on earth are these EPiServer namespaces documented??? For
real; I've worn Google out searching.
Alternatively, how can I get
my Visual Studio to kindly fill in the gaps, like my colleague's
does?
Thanks for any assistance. Banging my head against the wall here.
Hi I want to send a photo with my telegram bot but my VS doesn't recognize "FileToSend" and my error is :
int chatId = int.Parse(dgReport.CurrentRow.Cells[0].Value.ToString());
FileStream imageFile = System.IO.File.Open(txtFilePath.Text,FileMode.Open);
bot.SendPhotoAsync(chatId, new FileToSend("1234.jpg", imageFile), txtmessage.Text);
CS0246 The type or namespace name 'FileToSend' could not be found (are
you missing a using directive or an assembly reference?)
The FileToSend() function is removed, use InputOnlineFile():
FileStream imageFile = System.IO.File.Open(txtFilePath.Text,FileMode.Open);
bot.SendPhotoAsync(chatId, new InputOnlineFile(imageFile, "image.png"), txtmessage.Text);
Sounds like you are very new to Visual Studio and also C# so I'll share a general tip. If you see a red squiggly line in Visual Studio you have a compile error. Your program will not build/run until it is fixed.
Here's my tip. Find the code that is causing the compile error (the text with a red squiggle beneath it). Right click the text and choose "Quick Actions and Refactoring". You will see several suggestions that may fix the issue.
The problem you are describing can usually be fixed using this feature. One of the options may be something like "Using Telegram.Bot;". If you choose it, it will automatically put the using statement at the top of your file and fix the compilation error. This is definitely the #1 reason I use Quick Actions and Refactoring.
Actually, the question is quite OK. I think you just might be mixing up examples you've found and tried, which - if so - is an honest mistake. The FileToSend() function is related to a (deprecated) project on GitHub at ScottRFrost/TelegramBot.
The rest of your sample seems to be mixed up a bith with, I assume, the TelegramBots/Telegram.Bot package. If you use that, the following sample might help you a bit further:
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Telegram.Bot;
using Xunit;
namespace StackOverflowSupport
{
public class Tests
{
[Fact]
public async Task SendFileWithTelegramBot()
{
// Requires NuGet package `Telegram.Bot` (v15.0.0)
var token = "YOUR_TOKEN";
using (var http = new HttpClient())
{
int chatId = 42;
var imageFile = File.Open("filepath", FileMode.Open);
var bot = new TelegramBotClient(token, http);
await bot.SendPhotoAsync(chatId, photo: imageFile, caption: "This is a Caption");
}
}
}
}
As you can see, no FileToSend() in there, which might be the cause of your problem.
Note that this is just to help you in the right direction; it is not meant as code to be used in production. Especially reading out the stream through File.Open could be improved.
I'm working on a cross platform app using the GTK toolkit and when I'm trying to access the System.IO namespace to extract Path fields, I'm getting the following error:
Error CS0119: 'Widget.Path(out uint, out string, out string)' is a method, which is not valid in the given context (CS0119) (netmonmd)
I have using System.IO; in the source file and I'm using other namespaces without any issue (eg System.Console and System.Refelection without any issues further down in the code).
I have almost identical code in a console application working without an issue.
Here is the code, if I fully provide the Path it works, I just can't use it within the namespace (but I can use other things that are in the same namespace)
using Gtk;
using System;
using System.IO;
using static System.Console;
public partial class MainWindow : Gtk.Window
{
private netmonmd.iplabel[] ids;
private int fSize = 12;
public MainWindow() : base(Gtk.WindowType.Toplevel)
{
Build();
//char filesep = System.IO.Path.DirectorySeparatorChar; // works
char filesep = Path.DirectorySeparatorChar; // error
I'm trying to understand the error (I am new to C#) and think it has to do with calling it within the MainWindow function since it seems to be referring to Widget.Path and not System.Path
Is this a case of just having to fully qualify it each time?
I could move all the code out of the main window and process it elsewhere in the app.cs file, however it is a single window app that I was developing in the one space. If it is better practise to separate it out I will do that.
(as is usually the case in asking on stack, while writing this question out I'm becoming more aware of what's actually happening here, I just don't know how to work around it)
How to include one c# file into another c# file?
I have two c# file like one is test.cs and another one is main.cs. I want to include test.cs into main.cs.
test.cs file code
// you can use Console.WriteLine for debugging
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Solution
{
public bool solution(long number1, int[,] arr1,int dim_2,int dim_3)
{
//some code here
}
}
main.cs code
using System;
include test.cs;
class Group
{
public static void Main(String[] args)
{
long number1 = 5;
int [,] arr1 = new int[,] {{0, 0},{1, 1},{2, 2},{3, 3},{4, 4}};
int dim_2 = 5;
int dim_3 = 2;
Solution object_class = new Solution();
bool result = object_class.solution ( number1, arr1, dim_2, dim_3 );
Console.WriteLine("Return :");
Console.WriteLine( result );
}
}
what i am doing wrong here?? Please Help me.
Thank you in Advance
I guess your problem is because both files are not added in the same project.
If you are using Visual Studio.
To add test.cs in the Group class project.
Go to Solution Explorer -> Add Existing item -> Browse your file i.e.
test.cs -> OK
If you are using DOS mode.
Make sure that both files must be in same folder.
And in either case. first delete include test.cs; from Main file. then Compile & RUN
We create object of classes declared in other source code files with the way you have already followed:
Solution object_class = new Solution();
Provided that the Solution class is declared in a source code file in the same project (console application as I can infer from your post), you don't have to mark the Solution class as a public. Otherwise, you should mark it as a public. Actually, you have to do so in case of this class is going to be used outside of your current project.
Your problem, I think is about namespaces. You might have declared this class inside a folder. Anyways, the way to solve this is to right click on the name of the Solution and then click resolve references.
ASP.NET C# Classes
this solution was helpfull for class files outside the App_Code
you need add follow line in every page(aspx) or usercontrol(asc)
<%# Assembly Src="~/App_Ctrl/PraxisPdfs/class_pdf.cs" %>
If the current (most recent) item in the clipboard is a string, I want to take the string from the clipboard, and put each word in an array (just a simple loop which eliminates spaces and newlines, to take just words from the string). Then I simply want to print each item in the array (let's say each separated by a newline for testing purposes) to the terminal.
This is super easy, simple, etc. My trouble is that I cannot seem to find/use the Clipboard class that is built in to C#! Here is what I am using as my assembly references:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Object;
using System.Windows.Clipboard;
Note that the System.Windows.Clipboard; gets a red underline, because it is not lining up. Why could this be? http://msdn.microsoft.com/en-us/library/system.windows.clipboard.aspx shows the clipboard class information.
It's probably a fault on my end, but is it otherwise possible I have not set my paths correctly or something? I just installed Visual Studio 2012 For Desktop SP3 (although, I have had VS2012 for Web for quite some time, and it works properly).
System.Windows.Clipboard is a class and not a namespace, there is no point putting a class into a using directive.
The compiler error message should tell you the same.
First of all you must add a reference to System.Windows.Forms in your application. Go to Project -> Add reference, select System.Windows.Forms from .NET tab in the window that just opened. You must avoid the ThreadStateException by applying the STAThread attribute to your Main() function. Then you can use the Clipboard functions without any problems.
using System;
using System.Windows.Forms;
class Program {
[STAThread]
static void Main(string[] args) {
Clipboard.SetText("this is in clipboard now");
}
}
i hope this will help you
http://blog.another-d-mention.ro/programming/c/use-clipboard-copypaste-in-c-console-application/
it shows how to use the Clipboard functions in C# console application
You don't need this line: using System.Windows.Clipboard; using statements are for namespaces, and Clipboard is a class. That class is provided from the assembly PresentationCore.dll, and since you have WPF project, your project already has a reference to it.
You should have reference to System.Windows namespace only it has Class Clipboard in it.
You can set and get data from there
System.Windows.Clipboard.SetData();
You'll need a namespace declaration:
using System.Windows.Forms;
OR for WPF:
using System.Windows;
To copy an exact string
var dataObject = System.Windows.Clipboard.GetDataObject();
string text= dataObject.GetData("UnicodeText", true).ToString();