Пример #1
0
 public void FileAdded(string file)
 {
     if (FileAddedEvent != null)
     {
         FileAddedEvent.Invoke(file);
     }
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileWatcher"/> class.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="add">The add.</param>
 /// <param name="delete">The delete.</param>
 public FileWatcher(string path, FileAddedEvent add, FileDeletedEvent delete)
 {
     this.path = path;
     callbackAdded = add;
     callbackDeleted = delete;
     fileWatcher = new FileSystemWatcher(path, "*.*");
     fileWatcher.Created += new FileSystemEventHandler(FileWatcherCreated);
     fileWatcher.Deleted += new FileSystemEventHandler(FileWatcherDeleted);
     fileWatcher.EnableRaisingEvents = true;
 }
Пример #3
0
 private static Validation <Error, Document> Apply(this Document document, Event evt)
 {
     return(evt switch
     {
         DocumentApprovedEvent approvedEvent => document.Approve(approvedEvent.Comment),
         FileAddedEvent fileAddedEvent => document.AddFile(fileAddedEvent.FileId, fileAddedEvent.Name,
                                                           fileAddedEvent.Description),
         DocumentSentForApprovalEvent _ => document.SendForApproval(),
         DocumentRejectedEvent rejectedEvent => document.Reject(rejectedEvent.Reason),
         DocumentUpdatedEvent updatedEvent => document.Update(updatedEvent.Number, updatedEvent.Description),
         _ => new Error($"Unknown event type: {evt.GetType().Name}")
     });
        private void ProcessFile(string path)
        {
            var fiSource = new FileInfo(path);

            Logging.Log($"ADD: {path}", this, LoggingType.Status, 3);
            var pathTemp    = Path.Combine(_pathTemp, fiSource.Name);
            var pathTempNew = Path.Combine(_pathTemp, fiSource.Name + "processed");

            var relativeSrc = fiSource.DirectoryName.Substring(_pathPictures.Length);

            if (relativeSrc.StartsWith(@"\"))
            {
                relativeSrc = relativeSrc.Substring(1);
            }
            var pathDest = Path.Combine(_pathDestination, relativeSrc);

            try
            {
                //file needs to be processed. copy the file to a local dir
                _fileOperation.FileCopy(fiSource.FullName, pathTemp);

                ImageUtil.ResizeFile(pathTemp, pathTempNew, Settings.Default.LongSideLength);

                _fileOperation.CreateDirectory(pathDest);
                pathDest = Path.Combine(pathDest, fiSource.Name);
                _fileOperation.FileCopy(pathTempNew, pathDest);
            }
            finally
            {
                if (File.Exists(pathTemp))
                {
                    File.Delete(pathTemp);
                }

                if (File.Exists(pathTempNew))
                {
                    File.Delete(pathTempNew);
                }
            }

            FileAddedEvent?.Invoke(this, ++_filesAdded);
        }
Пример #5
0
        private void WebsocketSync()
        {
            string            temporarystorage = "";
            var               buffer           = new byte[8096];
            CancellationToken cancellation     = CancellationToken.None;
            //var awaiter = task.GetAwaiter();
            WebSocketReceiveResult received;// = WebSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellation).GetAwaiter().GetResult();

            while (!WebSocket.CloseStatus.HasValue && listening)
            {
                received = WebSocket.ReceiveAsync(new ArraySegment <byte>(buffer), cancellation).GetAwaiter().GetResult();

                string text = System.Text.Encoding.UTF8.GetString(buffer, 0, received.Count);

                JObject obj = null;// = JObject(text);
                //JObject.Parse(text);
                try
                {
                    obj = JObject.Parse(text);
                }
                catch
                {
                    temporarystorage += text;
                    try
                    {
                        obj = JObject.Parse(temporarystorage);
                        temporarystorage = "";
                    }
                    catch
                    {
                    }
                }

                if (obj != null)
                {
                    JToken events = obj.Value <JToken>("event");

                    if (events != null)
                    {
                        string eventName = events.Value <string>("type");
                        if (!string.IsNullOrEmpty(eventName) && eventName == "FileAdded")
                        {
                            JToken eventpayload = events.Value <JToken>("payload");

                            FileAddedEvent fileEvent = new FileAddedEvent(eventName, eventpayload);

                            try
                            {
                                var tempPath      = Path.GetTempPath();
                                var directoryInfo = Directory.CreateDirectory(Path.Combine(tempPath, "Octobroker"));
                                tempFolderPath = directoryInfo.FullName + "\\";
                                var downloadpath = tempFolderPath;
                                ////

                                if (fileEvent.Type == "stl")
                                //fileEvent.DownloadAndSliceAndUploadAssociatedFile("local", downloadpath, this);
                                {
                                    fileEvent.DownloadAssociatedOnlineFile("local", downloadpath, this);
                                    fileEvent.SliceAndUpload(fileEvent.LocalFilePath, fileEvent.SlicedFilePath);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                            //substituted with helper method  OnWorkcompleted  to delete everything at the end, to let files upload in the background
                            finally
                            {
                                Directory.Delete(tempFolderPath, true);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// イベントを発生させる
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnFileAdded(FileAddedEventArgs e)
 {
     FileAddedEvent?.Invoke(this, e);
 }