Exemplo n.º 1
0
        private void AddDuplicateNumberToLastEntry()
        {
            string lastKey = Composition.Keys.Last();

            Composition.Remove(lastKey);
            Composition.Add(lastKey, $"{tempFile.Directory}{Separator}{tempFile.BaseName}_({duplicateCounter}){tempFile.Extension}");
        }
Exemplo n.º 2
0
        public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            string truncationText = instructions.CustomText;

            if (!instructions.Files.Any(x => x.Path.Contains(truncationText)))
            {
                return(ErrorMessage("Custom text to truncate not found in any filename."));
            }

            foreach (var file in instructions.Files)
            {
                string path    = file.Path;
                string newPath = string.Empty;

                if (Path.GetFileName(path).Contains(truncationText))
                {
                    string directory = Path.GetDirectoryName(path);
                    var    extension = Path.GetExtension(path);

                    int index = path.IndexOf(truncationText);
                    int count = truncationText.Length;
                    newPath = path.Remove(index, count);
                }
                else
                {
                    continue;
                }

                Composition.Add(path, newPath);
            }

            return(Composition);
        }
Exemplo n.º 3
0
        public Dictionary <string, string> Compose(ComposeInstructions input)
        {
            instructions = input;

            instructions.Files.Sort(delegate(FileInformation first, FileInformation second)
            {
                return(first.CreationDateTime.CompareTo(second.CreationDateTime));
            });

            foreach (var file in instructions.Files)
            {
                GetTempFileInfo(file);

                ComposeBaseName();

                if (Composition.Any())
                {
                    HandleDuplicates();
                }

                Composition.Add(tempFile.Path, GetNewPath());
            }

            return(Composition);
        }
Exemplo n.º 4
0
        private void Init()
        {
            //var compositeRoot = new Composite("composite1");

            //compositeRoot.Add(new ComponentContactGroup("CG_C", null));
            //compositeRoot.Add(new ComponentAbsence("Abs1", null));
            //compositeRoot.Add(new ComponentContactGroup("CG_A", null));
            //compositeRoot.Add(new ComponentAbsence("Abs2", null));
            //compositeRoot.Add(new ComponentContactGroup("CG_B", null));

            //Composite composite2 = new Composite("composite2");
            //composite2.Add(new ComponentInterval("Interval", null));

            //composite2.Add(new ComponentContactGroup("CG_A", null));
            //composite2.Add(new ComponentAbsence("Abs2", null));
            //composite2.Add(new ComponentContactGroup("CG_B", null));

            //compositeRoot.Add(composite2);


            CompositorSeparateLine compositor  = new CompositorSeparateLine(this.Width);
            Composition            composition = new Composition(compositor);

            composition.Add(new ComponentText("TEXT_1"));

            composition.Add(new ComponentContactGroup("CG_A", new IntervalType(DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), "TEST_COMMENT")));
            composition.Add(new ComponentAbsence("Abs1", new IntervalType(DateTime.Now.AddDays(-13), DateTime.Now.AddDays(8), "TEST_COMMENT")));
            composition.Add(new ComponentContactGroup("CG_A1", new IntervalType(DateTime.Now.AddDays(-130), DateTime.Now.AddDays(80), "TEST_COMMENT")));
            composition.Add(new ComponentAbsence("Abs2", new IntervalType(DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), "TEST_COMMENT")));
            composition.Add(new ComponentContactGroup("CG_B", new IntervalType(DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), "TEST_COMMENT")));

            composition.Add(new ComponentInterval("Interval", new IntervalType(DateTime.Now.AddDays(-12), DateTime.Now.AddDays(120), "TEST_COMMENT")));

            composition.Add(new ComponentContactGroup("CG_A2", new IntervalType(DateTime.Now.AddDays(-12), DateTime.Now.AddDays(120), "TEST_COMMENT")));
            composition.Add(new ComponentAbsence("Abs2", new IntervalType(DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), "TEST_COMMENT")));
            composition.Add(new ComponentContactGroup("CG_C", new IntervalType(DateTime.Now.AddDays(-10), DateTime.Now.AddDays(10), "TEST_COMMENT")));


            Graphics formGraphics = this.CreateGraphics();

            formGraphics.Clear(this.BackColor);

            composition.Draw(formGraphics);

            formGraphics.Dispose();
        }
Exemplo n.º 5
0
        public void AddingFunctionToCompositionTest()
        {
            Executeable<int> identity = (Func<int, int>)((int x) => x);

            Composition<int> comp = new Composition<int>(identity);
            Assert.AreEqual(0, (int)comp.Execute(0));
            Assert.AreEqual(2, (int)comp.Execute(2));

            Executeable<int> linearfunction = (Func<int, int>)((int x) => x + 2);

            comp.Add(linearfunction);
            Assert.AreEqual(2, (int)comp.Execute(0));
            Assert.AreEqual(4, (int)comp.Execute(2));

            Executeable<int> cubicfunction = (Func<int, int>)((int x) => x * x * x);

            comp.Add(cubicfunction);
            Assert.AreEqual(8, (int)comp.Execute(0));
            Assert.AreEqual(64, (int)comp.Execute(2));
        }
        public void AddingFunctionToComposition()
        {
            IExecute<int> identity = new SingleFunction<int>(x => x);

            var comp = new Composition<int>(identity);
            Assert.AreEqual(0, comp.Execute(0));
            Assert.AreEqual(2, comp.Execute(2));

            IExecute<int> linearFunction = new SingleFunction<int>(x => x + 2);

            comp.Add(linearFunction);
            Assert.AreEqual(2, comp.Execute(0));
            Assert.AreEqual(4, comp.Execute(2));

            IExecute<int> cubicfunction = new SingleFunction<int>(x => x * x * x);

            comp.Add(cubicfunction);
            Assert.AreEqual(8, comp.Execute(0));
            Assert.AreEqual(64, comp.Execute(2));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="WaterToCopy"></param>
        public WaterPacket(WaterPacket WaterToCopy)
        {
            RelativeTimeTag = WaterToCopy.RelativeTimeTag;
            WaterAge        = WaterToCopy.WaterAge;
            LogString       = new StringBuilder(WaterToCopy.LogString.ToString());

            //Copy the properties
            foreach (var KVP in WaterToCopy.Composition)
            {
                Composition.Add(KVP.Key, KVP.Value);
            }
        }
Exemplo n.º 8
0
 private void ComposeBaseName()
 {
     switch (instructions.Mode2)
     {
     case ComposeMode2.Replace:
     case ComposeMode2.Unknown:
     default:
         Composition.Add(tempFile.Path, tempFile.Path.Replace(textToReplace, customText));
         //throw new UnknownComposeModeException("Invalid mode.");
         break;
     }
 }
Exemplo n.º 9
0
        public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            int duplicateCounter = 1;

            foreach (var file in instructions.Files)
            {
                var path      = file.Path;
                var directory = Path.GetDirectoryName(path);
                var extension = Path.GetExtension(path);

                string dateFormat;
                if (instructions.Mode == ComposeMode.Date)
                {
                    dateFormat = "yyyyMMdd";
                }
                else
                {
                    dateFormat = "yyyyMMdd_HHmmss";
                }
                var creationDate = file.CreationDateTime.ToString(dateFormat);

                if (Composition.Any())
                {
                    if (Composition.Values.Last().EndsWith($"{creationDate}{extension}"))
                    {
                        string lastKey = Composition.Keys.Last();
                        Composition.Remove(lastKey);
                        Composition.Add(lastKey, $"{directory}{Separator}{creationDate}_({duplicateCounter}){extension}");

                        duplicateCounter++;
                        creationDate += $"_({duplicateCounter})";
                        duplicateCounter++;
                    }
                    else if (Composition.Values.Last().Contains(creationDate))
                    {
                        creationDate += $"_({duplicateCounter})";
                        duplicateCounter++;
                    }
                    else
                    {
                        duplicateCounter = 1;
                    }
                }

                string newPath = $"{directory}{Separator}{creationDate}{extension}";

                Composition.Add(path, newPath);
            }

            return(Composition);
        }
Exemplo n.º 10
0
        public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            string customText = instructions.CustomText;
            string directory  = Path.GetDirectoryName(instructions.Files[0].Path);

            int counter = 1;

            foreach (var file in instructions.Files)
            {
                string extension = Path.GetExtension(file.Path);
                string newPath   = $"{directory}{Separator}{customText}_({counter++}){extension}";
                Composition.Add(file.Path, newPath);
            }

            return(Composition);
        }
Exemplo n.º 11
0
        public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            foreach (var file in instructions.Files)
            {
                string newExtension = instructions.CustomText.Trim('.');

                string path    = file.Path;
                string newPath = Path.GetDirectoryName(path)
                                 + Separator
                                 + Path.GetFileNameWithoutExtension(path)
                                 + $".{newExtension}";

                Composition.Add(path, newPath);
            }

            return(Composition);
        }
Exemplo n.º 12
0
        public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            instructions.Files.Sort((x, y) => DateTime.Compare(x.CreationDateTime, y.CreationDateTime));

            for (int i = 0; i < instructions.Files.Count; i++)
            {
                var path      = instructions.Files[i].Path;
                var directory = Path.GetDirectoryName(path);
                var extension = Path.GetExtension(path);

                string newPath = $"{directory}{Separator}{i + 1}{extension}";

                Composition.Add(path, newPath);
            }

            return(Composition);
        }
Exemplo n.º 13
0
        public Dictionary <string, string> Compose(ComposeInstructions input)
        {
            instructions = input;
            instructions.Files.Sort((x, y) => DateTime.Compare(x.CreationDateTime, y.CreationDateTime));

            foreach (var file in instructions.Files)
            {
                GetTempFileInfo(file);

                ComposeBaseName();
                string newPath = GetNewFileName();
                Composition.Add(tempFile.Path, newPath);

                counter++;
            }

            return(Composition);
        }
Exemplo n.º 14
0
        public static void LoadFromYaml(this CompositionExecutor executor, FileInfo file)
        {
            if (executor is null)
            {
                throw new ArgumentNullException(nameof(executor));
            }
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var    serializer = new Deserializer();
            string yaml       = File.ReadAllText(file.FullName);
            var    config     = serializer.Deserialize <YamlConfig>(yaml);

            foreach ((string name, CompositionConfig compositionCfg) in config.Compositions)
            {
                if (compositionCfg.Steps is null)
                {
                    continue;
                }

                var composition = new Composition(name, compositionCfg.Description);

                foreach ((string stepName, StepConfig stepCfg) in compositionCfg.Steps)
                {
                    if (!config.Composers.TryGetValue(stepCfg.Composer, out string composerTypeName))
                    {
                        throw new InvalidOperationException($"Cannot find composer named '{stepCfg.Composer}.");
                    }
                    Type composerType = Type.GetType(composerTypeName);
                    var  step         = new Step(stepName, composerType);
                    foreach (var(key, value) in stepCfg.Properties)
                    {
                        step.Add(key.Pascalize(), value);
                    }
                    composition.Add(step);
                }

                executor.Add(composition);
            }
        }
Exemplo n.º 15
0
        public Dictionary <string, string> Compose(ComposeInstructions input)
        {
            instructions = input;
            customText   = instructions.CustomText;

            foreach (var file in instructions.Files)
            {
                GetTempFileInfo(file);

                ComposeBaseName();

                if (Composition.Any())
                {
                    HandleDuplicates();
                }

                Composition.Add(file.Path, GetNewPath());
            }

            return(Composition);
        }