|
No, I mean what is the value of the startInfo.Arguments string when you call process.Start()? Use your debugger to see the exact values when you run the code, not what you think it will be.
|
|
|
|
|
Open a command line, and type in the command. Does it work? Try it until that works. Then tell us what you typed in the command line, and we might be able to figure out how to create that command from C#.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Hi, the command I type in command line thats works is this:
-s e16025f4 shell dumpsys battery
I am trying to figure out a way to use a string or anything to copy the text (the serial number text e16025f4) from the textbox and use it in the command line, because this value is dynamic and changes everytime I connect a different tablet or cellphone in the computer.
|
|
|
|
|
Then it is e.g.
startInfo.Arguments = $"-s {output} shell dumpsys battery";
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Hello
I need help to create a simple editor with intellisense in c# (should be used to format SSML files).
I imagine some kind of textbox where the user can write text and when pressing < a dropdown list is shown containing different elements. When an element is selectet the options for the elements is shown when typing (or something like that) and when < is press again the closing element should be shown as the first element in the dropdown list.
I would be nice if new element and options could be added to the editor in a simple way (list or xml file).
I do not know it it makes sense, if - can anyone tell me where to find samples or / opensource for it.
|
|
|
|
|
This site actually contains multiple articles on that topic. I'm using Scintilla.NET, as it also works nicely under Ubuntu. Ask Google for details.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have this method:
private async Task<QualificationTestResult> RunTest(Location bay, IBayQualificationTest test, CancellationTokenSource token, string baySerialNumber)
{
var _logger = new BayQualificationTestLogger(bay, baySerialNumber);
IEnumerable<string> details = null;
var testResult = new QualificationTestResult
{
Name = test.Name,
Version = test.Version,
};
testResult.Result = test.PerformTest(_logger,
((InstrumentService)_instrumentService).GetBayCommunicationService(bay),
token.Token,
out details);
return testResult;
}
I want to run it for a number of different tests, then get all QualificationTestResults back into a list.
So far I have this:
qualificationResult.TestResults.Clear();
IEnumerable<IBayQualificationTest> tests = GetQualificationTests().OrderBy(x => x.Priority).ToList();
List<Task> tasks = new List<Task>();
Task<QualificationTestResult> thermalTask = null;
Task<QualificationTestResult> eSensingTask = null;
var thermal = tests.Where(t => t.Name.ToLower().Contains("therm")).FirstOrDefault();
if (thermal != null)
{
thermalTask = Task.Factory.StartNew(() =>
RunTest(bay, thermal, token, baySerialNumber));
tasks.Add(thermalTask);
}
.
.
.
Task completionTask = Task.WhenAll(tasks);
foreach (var t in tasks)
{
qualificationResult.TestResults.Add(t);
}
This won't compile. On the Factory line I get
Cannot implicitly convert type 'System.Threading.Tasks.Task<System.Threading.Tasks.Task<...Core.Models.QualificationTestResult>>' to 'System.Threading.Tasks.Task<...Core.Models.QualificationTestResult>'
And on the FOR EACH at the bottom, the t.Result errors with "Task does not contain a definition for Result"
This is driving me nuts. What am I doing wrong here???
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
At a first pass, drop the async from your test method. It's not neccessary because you aren't awaiting anything in that method. Then, you can remove the Task part of it so you're only returning the QualificationTestResult. As you are creating your own external Task for this using the TaskFactory methods, you don't need to make that method return a Task.
This space for rent
|
|
|
|
|
OK, that fixed the Task.Factory problem..
Now, how do I get the results from all the tasks. here's what I have so far
qualificationResult.TestResults.Clear();
IEnumerable<IBayQualificationTest> tests = GetQualificationTests().OrderBy(x => x.Priority).ToList();
List<Task> tasks = new List<Task>();
Task<QualificationTestResult> thermalTask = null;
Task<QualificationTestResult> eSensingTask = null;
var thermal = tests.Where(t => t.Name.ToLower().Contains("therm")).FirstOrDefault();
if (thermal != null)
{
thermalTask = Task.Factory.StartNew(() =>
RunTest(bay, thermal, token, baySerialNumber));
tasks.Add(thermalTask);
};
Task completionTask = Task.WhenAll(tasks);
foreach (var t in tasks)
{
qualificationResult.TestResults.Add(t.Result);
}
The last part won't compile. Tells me there is no "Result" on the task.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
If the calling method is async :
QualificationTestResult[] results = await Task.WhenAll(tasks);
If it's not:
QualificationTestResult[] results = Task.WhenAll(tasks).GetAwaiter().GetResult();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: QualificationTestResult[] results = Task.WhenAll(tasks).GetAwaiter().GetResult();
This fails to compile with "Cannot implicitly convert type 'void' to QualificationTestResult[]"
[UPDATE]
This works
try
{
Task.WaitAll(tasks.ToArray());
}
catch (Exception e)
{
}
foreach (var task in tasks)
{
var result = ((Task<QualificationTestResult>)task).Result;
qualificationResult.TestResults.Add(result);
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 3-Oct-17 11:56am.
|
|
|
|
|
Ah, sorry - one more change to make it work:
List<Task<QualificationTestResult>> tasks = new List<Task<QualificationTestResult>>();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Just gonna throw a simple TPL Dataflow answer out there, since I've been having such a blast with it. Of course it loses a lot of it's utility since it's not part of a pipeline.
var xform = new TransformBlock<IBayQualificationTest,QualificationTestResult>(
thermal => {
try {
qualificationResult.TestResults.Add(RunTest(bay, thermal, token, baySerialNumber));
}catch{}
});
tests.Where(t => t.Name.ToLower().Contains("therm"))Select(x => xform.Post(x));
xform.Complete();
xform.Completion().Wait();
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I have an ObservableCollection bound to a collection of DatabaseTypeEntity. On the DatabaseTypeEntity is a string called "DatabaseTypeName".
I want to be able to insert a new item into the list so that it is alphabetical. How would you find the list's InsertAt index using the DatabaseTypeName?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Maybe you misunderstood my question.
I'm trying to find the alphabetical index position of where to insert an item.
So if I have
"An item"
"My Item"
"Some stuff"
and I want to insert "New Item", then it should have index position of 2 and be inserted between M and S.
[Update]
I could simply add it to the list, then do
DatabaseItems = new ObservableCollection(myTempList.OrderBy(x => x.DatabaseTypeName))
but this will recreate the list every time. It's cheaper to insert the new item into the list at the position it belongs at. I'm just not sure how to find that position
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
There's no such thing.
You would have to write the code to determine the insert location. The quick'n'dirty method would be to just for(index...) over the collection until you find the alphabetical position and then do an Insert(index, object) to insert into the collection. Keep in mind, this doesn't scale well. The larger the collection, the more expensive this operation becomes.
Really, if an alphabetical collection had to be maintained, I would probably write my own version of ObservableCollection and add the support to it along with b-tree support to keep the CPU workload down when inserting items.
But, I really wouldn't do that because a "sorted view" is the realm of the view of the collection, not of the collection itself.
|
|
|
|
|
I guess a SortedSet<t> would work.
I'll give it a try
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Dave, your "A guide to posting questions on CodeProject" link no longer works:
This www.codeproject.com page can’t be found
No webpage was found for the web address: http://www.codeproject.com/scrapbook/ForumGuidelines.asp
Go to http://www.codeproject.com/
Search Google for codeproject scrapbook Forum Guidelines
HTTP ERROR 404 The "Asking questions" one is fine, though.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Damn it Chris, stop moving my cheese!
|
|
|
|
|
He's just trying to keep you on your toes!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Your current list l :
{"A","C","D"}
your instruction:
l .Add("B");
your new list l :
{"A","B","C","D"}
I believe that this is what's your mind trying to achieve.
In fact, I can only think of 2 appropriate ways to fulfil such a task.
1. SORT IT:
Yes, just add your new item normally. Once you do, sort your collection.
Tip: do not call the sorting instruction each time you update the ObservaleCollection, do it once you add all your items.
c# - How to sort ObservableCollection alphabetically? - Stack Overflow[^]
2. PLAY WITH IT:
Write a for loop that runs through the contents of your ObservableCollection. Within each step, a comparison will be done. You will compare your new item's name with each item, once you find a match, push all your items starting from that position to the right side of your collection.
Sample:
Here is your list:
• A
• C
you add a new item: l.Add("B"):
• A
•
• C
the C got pushed down because C's position is greater than B's.
C's old position will be reserved, B will be added to it.
• A
• B
• C
|
|
|
|
|
Use design patterns in the game and ensure a rollback
Send a console implementation of the game patches. Ensure that the size of the field is selected and the level of difficulty (how much the board differs from the state of the "victory"), make it possible for the game to become more complicated when a certain amount of random moves takes place instead of the user's turn. Realize the possibility of canceling moves.
The patterns are expected: Singleton, Factory method, Team, Memento.
<pre>
using System;
namespace 15puzzle
{
class Points
{
public readonly int x, y;
public Points(int x, int y)
{
this.x = x;
this.y = y;
}
}
class Game
{
public int Length=0;
const int nw = 4, height = 4;
int[,] field = new int[nw, height];
Points[] FieldValue = new Points[16];
public Game(int[] point)
{
int r = 0;
string[] file = new string[4];
Length = 16;
mixer(point);
for (int j = 0; j < height; j++)
{
for (int i = 0; i < nw; i++)
{
field[j, i] = point[r];
FieldValue[point[r]] = new Points(j, i);
r++;
}
}
}
public void mixer(int[] p)
{
int tmp = 0;
Random rnd = new Random();
for (int i = 0; i < 16; i++)
{
bool isExist = false;
do
{
isExist = false;
tmp = rnd.Next(0, 16);
for (int j = 0; j < i; j++)
{
if (tmp == p[j]) { isExist = true; }
}
}
while (isExist);
p[i] = tmp;
}
}
private Points GetLocation(int value)
{
return FieldValue[value];
}
public void drawField()
{
Console.WriteLine("----------------------------");
for (int i = 0; i < nw; i++)
{
for (int j = 0; j < height; j++)
{
Console.Write(field[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("----------------------------");
}
public bool repeat(double Length,int[] point)
{
for (int i = 0; i < Length; ++i)
{
for (int y = i + 1; y < Length; ++y)
{
if (point[i] == point[y])
{
Console.WriteLine(point[i] + " ==" + point[y]);
throw new ArgumentException("Numbers should not be repeated");
}
}
}
return true;
}
public Boolean finish()
{
bool temp = false;
int value = 1;
for (int i = 0; i < nw; ++i)
{
for (int j = 0; j < height; ++j)
{
if (field[i, j] == value)
{
temp = true;
++value;
if (value == Length)
{
value = 0;
}
}
else
{
return false;
}
}
}
return temp;
}
public void Move(int value)
{
try
{
Console.WriteLine(value);
if (value > 15 || value < 0)
{
throw new ArgumentException();
}
int x = GetLocation(0).x;
int y = GetLocation(0).y;
int ValueX = GetLocation(value).x;
int ValueY = GetLocation(value).y;
if ((ValueX == x && (ValueY == y - 1 || ValueY == y + 1))||(ValueY == y && (ValueX == x - 1 || ValueX == x + 1)))
{
field[x, y] = value;
field[ValueX, ValueY] = 0;
var vere = FieldValue[0];
FieldValue[0] = FieldValue[value];
FieldValue[value] = vere;
}
}
catch (ArgumentException)
{
Console.WriteLine("There is no such number, try again: ");
}
catch (Exception)
{
Console.WriteLine("Next to this number is not 0, try again: ");
}
}
}
class Points2
{
public readonly int x, y;
public Points2(int x, int y)
{
this.x = x;
this.y = y;
}
}
class Game2
{
public int Length = 0;
const int nw = 3, height = 3;
int[,] field = new int[nw, height];
Points[] FieldValue = new Points[9];
public Game2(int[] point)
{
int r = 0;
string[] file = new string[3];
Length = 9;
mixer(point);
for (int j = 0; j < height; j++)
{
for (int i = 0; i < nw; i++)
{
field[j, i] = point[r];
FieldValue[point[r]] = new Points(j, i);
r++;
}
}
}
public void mixer(int[] p)
{
int tmp = 0;
Random rnd = new Random();
for (int i = 0; i < 9; i++)
{
bool isExist = false;
do
{
isExist = false;
tmp = rnd.Next(0, 9);
for (int j = 0; j < i; j++)
{
if (tmp == p[j]) { isExist = true; }
}
}
while (isExist);
p[i] = tmp;
}
}
private Points GetLocation(int value)
{
return FieldValue[value];
}
public void drawField()
{
Console.WriteLine("----------------------------");
for (int i = 0; i < nw; i++)
{
for (int j = 0; j < height; j++)
{
Console.Write(field[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("----------------------------");
}
public bool repeat(double Length, int[] point)
{
for (int i = 0; i < Length; ++i)
{
for (int y = i + 1; y < Length; ++y)
{
if (point[i] == point[y])
{
Console.WriteLine(point[i] + " ==" + point[y]);
throw new ArgumentException("Numbers should not be repeated");
}
}
}
return true;
}
public Boolean finish()
{
bool temp = false;
int value = 1;
for (int i = 0; i < nw; ++i)
{
for (int j = 0; j < height; ++j)
{
if (field[i, j] == value)
{
temp = true;
++value;
if (value == Length)
{
value = 0;
}
}
else
{
return false;
}
}
}
return temp;
}
public void Move(int value)
{
try
{
Console.WriteLine(value);
if (value > 15 || value < 0)
{
throw new ArgumentException();
}
int x = GetLocation(0).x;
int y = GetLocation(0).y;
int ValueX = GetLocation(value).x;
int ValueY = GetLocation(value).y;
if ((ValueX == x && (ValueY == y - 1 || ValueY == y + 1)) || (ValueY == y && (ValueX == x - 1 || ValueX == x + 1)))
{
field[x, y] = value;
field[ValueX, ValueY] = 0;
var vere = FieldValue[0];
FieldValue[0] = FieldValue[value];
FieldValue[value] = vere;
}
}
catch (ArgumentException)
{
Console.WriteLine("There is no such number, try again: ");
}
catch (Exception)
{
Console.WriteLine("Next to this number is not 0, try again: ");
}
}
}
}
<pre>using System;
using System.Collections.Generic;
namespace ConsoleApplication9
{
class program
{
static void Main()
{
int i;
int[] p = new int[16];
for (i = 0; i < 16; i++)
{
p[i] = i + 1;
}
p[15] = 0;
int n;
Console.WriteLine("Input integer number size: 4-4x4, 3-3x3 ");
n = int.Parse(Console.ReadLine());
if(n == 4)
{
puzzle4.game1();
}
if(n == 3)
{
puzzle3.game2();
}
}
}
class puzzle3
{
public static void game2()
{
int i;
int[] p = new int[9];
for (i = 0; i < 9; i++)
{
p[i] = i + 1;
}
p[8] = 0;
Console.WriteLine("15 Puzzle");
Game2 MyGame = new Game2(p);
int score = 0;
MyGame.mixer(p);
for (;;)
{
MyGame.drawField();
int a;
Console.WriteLine("Change number: ");
string input = Console.ReadLine();
if (Int32.TryParse(input, out a))
{
MyGame.Move(a);
}
else
{
Console.WriteLine("Error input");
}
if (MyGame.finish())
{
MyGame.drawField();
Console.WriteLine("Winner");
Console.WriteLine("Game end");
break;
}
score++;
Console.WriteLine("Number of moves: " + score);
}
}
}
class puzzle4
{
public static void game1()
{
int i;
int[] p = new int[16];
for (i = 0; i < 16; i++)
{
p[i] = i + 1;
}
p[15] = 0;
Console.WriteLine("15 Puzzle");
Game MyGame = new Game(p);
int score = 0;
MyGame.mixer(p);
for (;;)
{
MyGame.drawField();
int a;
Console.WriteLine("Change number: ");
string input = Console.ReadLine();
if (Int32.TryParse(input, out a))
{
MyGame.Move(a);
}
else
{
Console.WriteLine("Error input");
}
if (MyGame.finish())
{
MyGame.drawField();
Console.WriteLine("Winner");
Console.WriteLine("Game end");
break;
}
score++;
Console.WriteLine("Number of moves: " + score);
}
}
}
class GameHistory
{
public Stack<Game> History { get; private set; }
public GameHistory()
{
History = new Stack<Game>();
}
}
}
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
What OG said, with two addendum that will keep other developers from murdering you in the future:
- Use meaningful names in your source code. When you find yourself naming classes things like "repeat" or "Game2" you need to re-evaluate life a little.
- Don't use exceptions for flow control. Never. Never ever.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|