Пример #1
0
 public static bool TryDeleteFolder(ref FileSystemProtocol protocol)
 {
     try
     {
         Directory.Delete(protocol.Path);
         return(true);
     }
     catch (Exception ex) { return(false); }
 }
Пример #2
0
 public static bool TryCreateFile(ref FileSystemProtocol protocol)
 {
     try
     {
         File.Create(protocol.Path);
         return(true);
     }
     catch (Exception ex) { return(false); }
 }
Пример #3
0
 public static bool TryMoveFolder(ref FileSystemProtocol protocol)
 {
     try
     {
         Directory.Move(protocol.Path, protocol.Options[0].ToString());
         return(true);
     }
     catch (Exception ex) { return(false); }
 }
Пример #4
0
 public static bool TryDelete(ref FileSystemProtocol protocol)
 {
     if (File.Exists(protocol.Path))
     {
         return(TryDeleteFile(ref protocol));
     }
     else
     {
         return(TryDeleteFolder(ref protocol));
     }
 }
Пример #5
0
        public override void Run()
        {
            lock (protocolQueueLock)
            {
                if (protocolQueue.Count < 1)
                {
                    this.Suspend();
                }

                DateTime now = DateTime.Now;
                for (int i = 0; i < protocolQueue.Count; i++)
                {
                    // no more present and past-due manipulations ahead in the list
                    if (protocolQueue[i].Timestamp > now)
                    {
                        break;
                    }

                    // manipulate the valid protocol after all those checks
                    FileSystemProtocol protocol = protocolQueue[i];

                    FileSystemManipulationHandler manipulate;
                    if (ManipulationToHandler.TryGetValue(protocolQueue[i].Manipulation, out manipulate))
                    {
                        protocol.Tries++;

                        if (manipulate(ref protocol))
                        {
                            // successful manipulation
                            protocolQueue.RemoveAt(i);
                            i--;
                            protocol.InvokeProtocollApplication(ProtocolStatus.FinalSuccess);
                            continue;
                        }

                        if (protocolQueue[i].Tries >= protocolQueue[i].MaxTries)
                        {
                            // final fail at manipulating the file or folder
                            protocolQueue.RemoveAt(i);
                            i--;
                            protocol.InvokeProtocollApplication(ProtocolStatus.FinalFail);
                            continue;
                        }

                        // still tries left to succeed in manipulating the file or folder
                        protocol.InvokeProtocollApplication(ProtocolStatus.Fail);
                        // assign new iterated value to protocolQueue
                        protocolQueue[i] = protocol;
                    }
                }
            }
        }
Пример #6
0
        public void DeleteFile(string path, DateTime executionTime, int maxTries = -1,
                               List <object> options = null, FileSystemProtocol.ProtocollApplicationEventHandler handler = null)
        {
            if (maxTries < 0)
            {
                maxTries = deleteTries;
            }

            FileSystemProtocol protocol = new FileSystemProtocol(FileSystemManipulation.DeleteFile,
                                                                 GetRealPath(path), executionTime, maxTries, options, handler);

            AddProtocol(ref protocol);
        }
Пример #7
0
        // adds a new protocol at the timestamp-position it belongs in the queue
        public void AddProtocol(ref FileSystemProtocol protocol)
        {
            int index = 0;

            lock (protocolQueueLock)
            {
                for (int i = protocolQueue.Count; i > 0; i--)
                {
                    if (protocol.Timestamp > protocolQueue[i].Timestamp)
                    {
                        // insert new protocol after the other
                        index = i;
                        //protocolQueue.Insert(i + 1, protocol);
                    }
                }

                protocolQueue.Insert(index, protocol);
                this.Resume();
            }
        }