Ejemplo n.º 1
0
        public Task Run()
        {
            return(Task.Run(() =>
            {
                if (!TargetDirectory.Exists)
                {
                    TargetDirectory.Create();
                }

                SemaphoreSlim semaphore = new SemaphoreSlim(ThreadCount);

                int filenameCount = 0;
                int finished = 0;
                var tasks = new List <Task>();

                int max = ImageQueue.Count;

                while (!ImageQueue.IsEmpty)
                {
                    semaphore.Wait();
                    if (!ImageQueue.TryDequeue(out var address))
                    {
                        continue;
                    }

                    string extension = address.ToString().Split(".")[^ 1];
Ejemplo n.º 2
0
        public bool IsValidTarget(bool createIfMissing = true)
        {
            TargetDirectory.Refresh();
            if (!TargetDirectory.Exists)
            {
                if (createIfMissing)
                {
                    try
                    {
                        TargetDirectory.Create();
                        return(true); // If we were able to create the directory, it should be valid
                    }
#pragma warning disable CA1031        // Do not catch general exception types
                    catch (IOException)
                    { return(false); }
#pragma warning restore CA1031 // Do not catch general exception types
                }
                else
                {
                    return(false);
                }
            }
            try
            {
                var testDir = TargetDirectory.CreateSubdirectory("dirTest");
                testDir.Refresh();
                if (testDir.Exists)
                {
                    testDir.Delete();
                    return(true);
                }
            }
            catch (IOException)
            {
                return(false);
            }
            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create the directory and every parent that is not already created.
 /// </summary>
 public void Create()
 {
     TargetDirectory.Create();
 }
Ejemplo n.º 4
0
        protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options)
        {
            CloneVerbOptions localOptions = options as CloneVerbOptions;

            if (localOptions.Path.Count > 1)
            {
                Printer.PrintError("#e#Error:## Clone path is invalid. Please specify a subfolder to clone in to or leave empty to clone into the current directory.");
                return(false);
            }

            // Choose target directory from server name or path
            if (localOptions.Path != null && localOptions.Path.Count == 1)
            {
                string subdir = localOptions.Path[0];
                if (!string.IsNullOrEmpty(subdir))
                {
                    System.IO.DirectoryInfo info;
                    try
                    {
                        info = new System.IO.DirectoryInfo(System.IO.Path.Combine(TargetDirectory.FullName, subdir));
                    }
                    catch
                    {
                        Printer.PrintError("#e#Error - invalid subdirectory \"{0}\"##", subdir);
                        return(false);
                    }
                    Printer.PrintMessage("Target directory: #b#{0}##.", info);
                    TargetDirectory = info;
                }
            }

            if (localOptions.QuietFail && new System.IO.DirectoryInfo(System.IO.Path.Combine(TargetDirectory.FullName, ".versionr")).Exists)
            {
                return(true);
            }

            try
            {
                var ws = Area.Load(TargetDirectory, Headless, localOptions.BreachContainment);
                if (ws != null)
                {
                    CloneVerbOptions cloneOptions = options as CloneVerbOptions;
                    if (cloneOptions != null && cloneOptions.QuietFail)
                    {
                        Printer.PrintMessage("Directory already contains a vault. Skipping.");
                        return(false);
                    }
                    Printer.PrintError("This command cannot function with an active Versionr vault.");
                    return(false);
                }
            }
            catch
            {
            }
            bool result = false;

            try
            {
                TargetDirectory.Create();
            }
            catch
            {
                Printer.PrintError("#e#Error - couldn't create subdirectory \"{0}\"##", TargetDirectory);
                return(false);
            }
            client.BaseDirectory = TargetDirectory;
            if (localOptions.Full.HasValue)
            {
                result = client.Clone(localOptions.Full.Value);
            }
            else
            {
                result = client.Clone(true);
                if (!result)
                {
                    result = client.Clone(false);
                }
            }
            if (result)
            {
                Printer.PrintMessage("Successfully cloned from remote vault. Initializing default remote.");
                string remoteName = "default";

                if (client.Workspace.SetRemote(client.URL, remoteName))
                {
                    Printer.PrintMessage("Configured remote \"#b#{0}##\" as: #b#{1}##", remoteName, client.URL);
                }

                if (localOptions.Partial != null)
                {
                    client.Workspace.SetPartialPath(localOptions.Partial);
                }

                if (localOptions.Update)
                {
                    client.Pull(false, string.IsNullOrEmpty(localOptions.Branch) ? client.Workspace.CurrentBranch.ID.ToString() : localOptions.Branch);
                    Area area = Area.Load(client.Workspace.Root);
                    area.Checkout(localOptions.Branch, false, false);
                }

                if (localOptions.Synchronize)
                {
                    return(client.SyncAllRecords());
                }
            }
            return(result);
        }