Ejemplo n.º 1
0
 public void Copy(PimixFile destination)
 {
     if (Spec == destination.Spec)
     {
         Client.Copy(Path, destination.Path);
     }
     else
     {
         destination.Write(OpenRead());
     }
 }
Ejemplo n.º 2
0
 public void Move(PimixFile destination)
 {
     if (Spec == destination.Spec)
     {
         Client.Move(Path, destination.Path);
     }
     else
     {
         Copy(destination);
         Delete();
     }
 }
Ejemplo n.º 3
0
        public override int Execute()
        {
            var source = new PimixFile(SourceUri);
            var destination = new PimixFile(DestinationUri);

            if (NeedsPrecheck(source))
            {
                var result = new InfoCommand { Update = true, VerifyAll = true, FileUri = SourceUri }.Execute();
                if (result != 0)
                {
                    Console.Error.WriteLine("Precheck failed!");
                    return 1;
                }
            }

            if (DestinationCheck)
            {
                try
                {
                    var result = new InfoCommand { Update = true, VerifyAll = VerifyAll, FieldsToVerify = FieldsToVerify, FileUri = DestinationUri }.Execute();
                    if (result == 0)
                    {
                        return 0;
                    }
                }
                catch
                {
                    // Ignore the error for now.
                }
            }

            source.Copy(destination);

            // Wait 5 seconds to ensure server sync.
            Thread.Sleep(TimeSpan.FromSeconds(5));

            return Update ? new InfoCommand { Update = true, VerifyAll = VerifyAll, FieldsToVerify = FieldsToVerify, FileUri = DestinationUri }.Execute() : 0;
        }
Ejemplo n.º 4
0
        public override int Execute()
        {
            var f = new PimixFile(FileUri);

            var info = f.GetInfo(FilePropertiesToVerify);
            var oldInfo = f.GetInfo(FileProperties.None, FileProperties.None);

            var compareResult = info.CompareProperties(oldInfo, FilePropertiesToVerify);
            if (compareResult == FileProperties.None)
            {
                if (Update)
                {
                    FileInformation.Patch(info);
                }
                else
                {
                    Console.WriteLine(JsonConvert.SerializeObject(info, Formatting.Indented));
                }

                return 0;
            }
            else
            {
                logger.Warn("Verify failed! The following fields differ: {0}", compareResult);
                logger.Warn(
                    "Expected data:\n{0}",
                    JsonConvert.SerializeObject(
                        oldInfo.RemoveProperties(FileProperties.All ^ compareResult),
                        Formatting.Indented));
                logger.Warn(
                    "Actual data:\n{0}",
                    JsonConvert.SerializeObject(
                        info.RemoveProperties(FileProperties.All ^ compareResult),
                        Formatting.Indented));
                return 1;
            }
        }
Ejemplo n.º 5
0
 bool NeedsPrecheck(PimixFile file)
 {
     var info = FileInformation.Get(file.Path);
     return !info.GetProperties().HasFlag(FileProperties.All) || !info.Locations.ContainsKey(file.Spec);
 }