My Requirement is i want to retry if the specific file exists,suppose like currently i'm doing svn installation / uninstallation so if the svn is installed then it will create RevisionNumber.txt and if the svn is uninstalled then ReveisionNumber.txt is deleted
So My Requirement is if RevisionNumber.txt exists / Svn exists i want to retry the process of svn uninstallation for 3 times.
can anyone please sort me out ? below is my code :
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SVNUNINSTALL
{
class Program
{
public void Process()
{
System.Diagnostics.Process.Start("C:\\Users\\sk185462\\Desktop\\SVNUPDATED\\SvnUninstallation.exe");
bool exists = File.Exists("C:\\Users\\sk185462\\Desktop\\SVNUPDATED\\RevisionNumber.txt");
Console.WriteLine(exists);
Console.ReadLine();
}
static void main(String[] args)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
}
}
}
public void Process()
{
bool exists = File.Exists("C:\\Users\\sk185462\\Desktop\\SVNUPDATED\\RevisionNumber.txt");
for(int i = 0; i < 3 && exists; i++)
{
System.Diagnostics.Process.Start("C:\\Users\\sk185462\\Desktop\\SVNUPDATED\\SvnUninstallation.exe");
Sleep(2000); // or long enough to ensure the uninstall process finishes executing
exists = File.Exists("C:\\Users\\sk185462\\Desktop\\SVNUPDATED\\RevisionNumber.txt");
}
Console.WriteLine(exists);
Console.ReadLine();
}
Related
I'm trying to build my first NserviceBus application, but I cannot get it to work. The message arrives on the "backend" but the handler uses DI and NServicebus claims it cannot find the service for the interface. But the code was lifted directly from the examples. I'm missing something and I cannot figure it out.
The Error:
dbug: NServiceBus.LoadHandlersConnector[0]
Processing message type: Messages.JobStartCommand
Message headers:
NServiceBus.MessageId : 0044f261-e3b3-4287-b6f0-ad7400ef43cb
NServiceBus.MessageIntent : Send
NServiceBus.ConversationId : bb4f276f-63fe-450b-b234-ad7400ef43cd
NServiceBus.CorrelationId : 0044f261-e3b3-4287-b6f0-ad7400ef43cb
NServiceBus.ReplyToAddress : ClientUI
NServiceBus.OriginatingMachine : L19002992
NServiceBus.OriginatingEndpoint : ClientUI
$.diagnostics.originating.hostid : e1fecb2b72b8185e47341bb4dfb37dd7
NServiceBus.ContentType : text/xml
NServiceBus.EnclosedMessageTypes : Messages.JobStartCommand, Messages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
NServiceBus.Version : 7.5.0
NServiceBus.TimeSent : 2021-07-29 14:31:08:228497 Z
NServiceBus.Retries : 3
NServiceBus.Retries.Timestamp : 2021-07-29 14:31:40:397277 Z
Handlers to invoke:
Extractor.JobStartHandler
Extractor.JobStartHandler
info: NServiceBus.RecoverabilityExecutor[0]
Immediate Retry is going to retry message '0044f261-e3b3-4287-b6f0-ad7400ef43cb' because of an exception:
System.InvalidOperationException: Unable to resolve service for type 'IExtract' while attempting to activate 'Extractor.JobStartHandler'.
at Microsoft.Extensi
My backend program.cs
using Microsoft.Extensions.Hosting;
using System;
using System.Diagnostics;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NServiceBus;
using System.Threading.Tasks;
using Messages;
using Extractor;
namespace ExtractorOsiris
{
class Program
{
static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
var builder = Host.CreateDefaultBuilder(args);
builder.UseWindowsService();
//builder.UseMicrosoftLogFactoryLogging();
builder.ConfigureLogging((ctx, logging) =>
{
logging.AddConfiguration(ctx.Configuration.GetSection("Logging"));
//logging.AddEventLog();
logging.AddConsole();
logging.SetMinimumLevel(LogLevel.Debug);
});
#region back-end-use-nservicebus
builder.UseNServiceBus(ctx =>
{
var endpointConfiguration = new EndpointConfiguration("Sample.Extractor");
endpointConfiguration.UseTransport<LearningTransport>();
var transport = endpointConfiguration.UseTransport<LearningTransport>();
transport.Routing().RouteToEndpoint(typeof(ProcessObjectCommand), "Sample.Processor");
endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);
return endpointConfiguration;
});
#endregion
#region back-end-register-service
builder.ConfigureServices(services =>
{
services.AddSingleton<IExtract, ExtractOsiris>();
});
#endregion
return builder;
}
private static Task OnCriticalError(ICriticalErrorContext arg)
{
throw new NotImplementedException();
}
}
}
The Interface
using Newtonsoft.Json.Linq;
using NServiceBus;
using System;
using System.Threading.Tasks;
namespace Extractor
{
public interface IExtract
{
Task<JArray> Extract(string #object, DateTime deltaTime);
}
}
The handler
using System.Threading.Tasks;
using Messages;
using Newtonsoft.Json.Linq;
using NServiceBus;
namespace Extractor
{
#region back-end-handler
public class JobStartHandler : IHandleMessages<JobStartCommand>
{
private readonly IExtract extractor;
public JobStartHandler(IExtract extractor)
{
this.extractor = extractor;
}
public async Task Handle(JobStartCommand message, IMessageHandlerContext context)
{
Task<JArray> result = extractor.Extract("Medewerkers", message.DeltaTime);
await result;
JArray test = result.Result;
foreach (JObject x in test)
{
// send the object to be processed.
//await context.Send(new ProcessObjectCommand(x.ToString()));
}
}
}
#endregion
}
The implementation of the interface
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Extractor;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NServiceBus;
namespace ExtractorOsiris
{
public class ExtractOsiris : IExtract
{
private readonly ILogger logger;
public ExtractOsiris(ILogger<ExtractOsiris> logger)
{
this.logger = logger;
}
public Task<JArray> Extract(string #object, DateTime deltaTime)
{
logger.LogInformation($"getting {#object} for delta time {deltaTime}");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://xx.yy");
WebResponse response = request.GetResponse();
JObject temp = JObject.Load(new JsonTextReader(new StreamReader(response.GetResponseStream())));
return Task<JArray>.FromResult(temp["items"] as JArray);
}
}
}
I know the code ain't pretty, but it's pure quick and dirty testing code.
I cleaned out the offending interface from the code and still got the error on an interface that was not even there anymore. I removed the bin folder and build everything back up step by step. Stupid thing is, source control says I am back where I started, without changes. And it just works....
So must have bin something stupid with VS2019. Sorry to anyone who's time I wasted
i've been trying for days to implement a simple server on HoloLens to receive HTTP packets sent from a smart object on a local network.
My code so far is the following (i report only the part of the code that actually runs on HoloLens):`
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.Networking;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.Text;
using UnityEngine.UI;
#if !UNITY_EDITOR
using Windows.Networking;
using Windows.Networking.Sockets;
using Windows.Storage.Streams;
using Windows.Networking.Connectivity;
#endif
public class DolphinManager : MonoBehaviour
{
private static string holoLensIpAddr = "192.168.0.147";
private static int holoLensPort = 12345;
#if UNITY_EDITOR
private HttpListener _listener;
#endif
#if !UNITY_EDITOR
private StreamReader reader;
private StreamSocketListener listener;
#endif
void Start()
{
#if UNITY_EDITOR
Invoke("InitializeUnityServer", 4f);
#else
Invoke("InitializeUWPServer", 4f);
#endif
}
#if !UNITY_EDITOR
private async void InitializeUWPServer()
{
try
{
listener = new StreamSocketListener();
serverHost = new Windows.Networking.HostName(anyIp);
listener.ConnectionReceived += Listener_ConnectionReceived;
listener.Control.KeepAlive = false;
await listener.BindServiceNameAsync(holoLensPort.ToString());
} catch(Exception e) { Debug.Log(e.Message); }
}
#endif
#if !UNITY_EDITOR
private async void Listener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
Debug.log("message received!");
}
The server starts correctly, but when i try to send a packet from my smart object, Listener_ConnectionReceived() is not triggered.
I have already set the PrivateNetworkClientServer capability on the app manifest.
What could be wrong?
Thank you in advance!
I am trying to Xamarin.uiTest to automate an application and I got this error in very initial stage.
System.InvalidOperationException : Sequence contains no elements
Code: AppInitializer.cs
using System;
using System.IO;
using System.Linq;
using Xamarin.UITest;
using Xamarin.UITest.Queries;
namespace MyXamarinApp1_Test1
{
public class AppInitializer
{
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp
.Android
//.InstalledApp("com.companyname.MyXamarinApp1")
.ApkFile("C:\\Users\\...\\Desktop\\com.companyname.MyXamarinApp1.apk")
.StartApp();
}
return ConfigureApp
.iOS.StartApp();
}
}
}
Code: Test.cs
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Queries;
namespace UITest1
{
[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
public class Tests
{
IApp app;
Platform platform;
public Tests(Platform platform)
{
this.platform = platform;
}
[SetUp]
public void BeforeEachTest()
{
app = AppInitializer.StartApp(platform);
}
[Test]
public void AppLaunches()
{
app.Screenshot("First screen.");
}
}
Any idea to resolve the issue is appreciated.
I am using the signed app, could it be an issue.
Xamarin version : 2.0.3
Nunit : 2.6.4
try downgrading or upgrading it to Xamarin 2.2.1 or less and try cleaning solution or delete debug folder and build and run the command in fresh command line window, it may fix.. not 100% sure
I am looking for a good way to find all folders that have contents that are say 500k or less. I think this involves recursively going to the lowest folder in a hierarchy and then "reading up" to get a size total. All ideas appreciated (something int he .NET framework or PowerShell if I really have to), thanks.
This could help you out.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace GetDirectorySize
{
class Program
{
static void Main(string[] args)
{
long maxFolderSizeInBytes = 20000000;
foreach (var directory in Directory.GetDirectories(#"C:\Projects\Visual Studio 2010\"))
{
string[] a = Directory.GetFiles(directory, "*.*");
long i = 0;
foreach (string name in a)
{
FileInfo info = new FileInfo(name);
i += info.Length;
}
if (i <= maxFolderSizeInBytes)
{
Console.WriteLine(directory);
}
}
Console.ReadLine();
}
}
}
Does anyone know any resources regarding to the creation of a custom scheduled task under Telligent 5.5 ?
From what I read, all I need to do is the following:
1.Create a type that implements the ITask2 interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telligent.Tasks;
namespace Project.ScheduledTasks
{
public class ReminderTask:ITask2
{
public void Execute()
{
string task = "Please hit the breakpoint here";
}
public void Load(System.Xml.XmlNode node)
{
throw new NotImplementedException();
}
}
}
2.Add the task description in the communityserver.config
<Thread minutes="1">
<task name="ReminderTask" type="Project.ScheduledTasks.ReminderTask, Project.ScheduledTasks" enabled="true" enableShutDown="false"></task>
</Thread>
Do I need to do anything else ?
Please help :).
Yes, that is all that you should need to do. Are you having issues?