static void SendPicture(ImageServiceModel image) { var factory = new ConnectionFactory() { HostName = "localhost", DispatchConsumersAsync = true }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { //channel.ExchangeDeclare("CP", ExchangeType.Direct); channel.QueueDeclare(QUEUENAME, true, false, false, null); //channel.QueueBind(QUEUENAME, "CP", "", null); var props = channel.CreateBasicProperties(); var bf = new BinaryFormatter(); using (var ms = new MemoryStream()) { bf.Serialize(ms, image); while (true) { channel.BasicPublish("", QUEUENAME, props, ms.ToArray()); Thread.Sleep(10000); } } } }
/// <summary> /// ImageService Constructor. /// </summary> /// <param name="args"></param> public ImageService(string[] args) { // init components (eventLog) InitializeComponent(); AppConfigParser appConfigParser = new AppConfigParser(); if (!EventLog.SourceExists(appConfigParser.LogName)) { EventLog.CreateEventSource( appConfigParser.SourceName, appConfigParser.LogName); } // assign parameters to log after init eventLog.Source = appConfigParser.SourceName; eventLog.Log = appConfigParser.LogName; // init image model IImageServiceModel imageServiceModel = new ImageServiceModel(appConfigParser.OutputDirectory, appConfigParser.ThumbnailSize); // init loggingModel ILoggingService loggingModel = new LoggingService(); // subscribe our main Service to the LoggingService loggingModel.MessageRecieved += OnMsg; this.imageServer = new ImageServer(loggingModel, imageServiceModel); // add directory handler for each directory from AppConfig foreach (string directoryPath in appConfigParser.Handler) { this.imageServer.AddDirectoryHandler(directoryPath); } }
/// <summary> /// When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or /// when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts. /// </summary> /// <param name="args">Data passed by the start command.</param> protected override void OnStart(string[] args) { // Update the service state to Start Pending. try { Thread.Sleep(10000); ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING; serviceStatus.dwWaitHint = 100000; SetServiceStatus(this.ServiceHandle, ref serviceStatus); eventLog1.WriteEntry("In OnStart"); System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = 60000; // 60 seconds timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer); timer.Start(); // Update the service state to Running. serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; SetServiceStatus(this.ServiceHandle, ref serviceStatus); //creating the server IImageServiceModel serviceModel = new ImageServiceModel(outputDir, Int32.Parse(thumbnailSize)); IImageController m_controller = new ImageController(serviceModel); server = new ImageServer(m_logging, m_controller, outputDir, Int32.Parse(thumbnailSize), handler); m_controller.Server = server; //IServerConnection connection = new ServerConnection(m_controller, m_logging, 8600); AndroidConnection androidConnection = new AndroidConnection(m_logging, 8600); } catch (Exception e) { this.m_logging.Log(e.ToString(), MessageTypeEnum.FAIL); } }
public void TestAddFile() { int thumbnailSize = 5; bool result; IImageServiceModel imageModel = new ImageServiceModel(@"C:\Users\Iosi\Desktop\Test", thumbnailSize); string error = imageModel.AddFile(@"C:\Users\Iosi\Pictures\TMlogo.png", out result); Assert.AreEqual(result, true, error); }
static void Main(string[] args) { //Take photo //IPictureService picture = new PictureService(); //var fileName = picture.TakePicture(); //Process photo Mat src = new Mat(@"./10f93c15-3b5d-4449-af0a-ec8e3b0ef655.png", ImreadModes.Grayscale); Mat src2 = new Mat(@"./1.png", ImreadModes.Grayscale); Mat dst = new Mat(); Mat srcDst = new Mat(); Cv2.Canny(src, dst, 50, 200); Cv2.Canny(src2, srcDst, 50, 200); Mat result = new Mat(); Cv2.Subtract(dst, srcDst, result); //using (new Window("srcDst image", srcDst)) //using (new Window("dst image", dst)) //using (new Window("result image", result)) //{ // Cv2.WaitKey(); //} //Stream stream = new MemoryStream(result.ToBytes()); //var snapshot = new Bitmap(stream); //var fileName = Guid.NewGuid() + ".png"; //snapshot.Save($@".\{fileName}", ImageFormat.Png); var messageBusModel = new ImageServiceModel { OriginalImagePath = Path.GetFullPath(@"./1.png"), ProcessedImagePath = Path.GetFullPath(@"./10f93c15-3b5d-4449-af0a-ec8e3b0ef655.png"), ResultImagePath = Path.GetFullPath($@"./5ef1a985-ab2b-4607-af75-dfed895e33e7.png") }; //Send photo SendPicture(messageBusModel); }
//endregion /// <summary> /// Initializes a new instance of the <see cref="ImageServer"/> class. /// </summary> /// <param name="logging">The logging.</param> /// <param name="outputDir">The output dir.</param> /// <param name="thumbnailSize">Size of the thumbnail.</param> /// <param name="handler">The handler.</param> public ImageServer(ILoggingService logging, IImageController controller, string outputDir, int thumbnailSize, string handler) { IImageServiceModel serviceModel = new ImageServiceModel(outputDir, thumbnailSize); m_controller = new ImageController(serviceModel); //m_controller.Server = this; handlers = new Dictionary <string, IDirectoryHandler>(); m_logging = logging; string[] directoriesToHandle = handler.Split(';'); foreach (string path in directoriesToHandle) { try { CreateHandler(path); } catch (Exception e) { this.m_logging.Log("Error creating handler for directory: " + path + "due to " + e.Message, MessageTypeEnum.FAIL); } } }
/// <summary> /// ImageServer Constructor /// </summary> /// <param name="logging">logging</param> /// <param name="dir_output">directory</param> /// <param name="size_of_thumb">thumbnail size</param> /// <param name="handler">handler</param> public ImageServer(ILoggingService logging, IImageController controller, string dir_output, int size_of_thumb, string handler) { //creates a new image service IImageServiceModel img_services = new ImageServiceModel(dir_output, size_of_thumb); model_controller = new ImageController(img_services); handlers_list = new Dictionary <string, IDirectoryHandler>(); model_logging = logging; //creates array of dirs string[] dirs = handler.Split(';'); foreach (string path in dirs) { try { CreateHandler(path); } catch (Exception e) { this.model_logging.Log("handler creation error for: " + path + "because of " + e.Message, MessageTypeEnum.FAIL); } } }