Beispiel #1
0
        internal DirectoryInfo CreateContentDirectory(DirectoryInfo outputPath)
        {
            var model = new LaunchPageModel(Manifest, AppInfo)
            {
                ContentDirectory = "./Web Files",
                Launcher         = outputPath.GetFiles("*.application").First().Name,
                Installer        = outputPath.GetFiles("setup.exe").FirstOrDefault()?.Name ?? "#"
            };

            if (model.AppInfo.Links == null)
            {
                model.AppInfo.Links = new LinkList();
            }
            var webFilesDir = Directory.CreateDirectory(Path.Combine(WorkingDirectory.FullName, "Web Files"));
            var otherFiles  = SourceDirectory.EnumerateFiles("*", SearchOption.AllDirectories).Where(f => !f.Extension.Contains("cshtml"));

            foreach (var otherFile in otherFiles)
            {
                var targetRelativePath = otherFile.FullName.Replace(SourceDirectory.FullName, string.Empty).Substring(1);
                var fullPath           = Path.Combine(webFilesDir.FullName, targetRelativePath);
                Directory.CreateDirectory(new FileInfo(fullPath).Directory.FullName);
                otherFile.CopyTo(
                    fullPath, true);
            }

            var templateFiles = SourceDirectory.EnumerateFiles("*.cshtml", SearchOption.AllDirectories).Where(f => f.Name.ToLower() != "index.cshtml");

            foreach (var templateFile in templateFiles)
            {
                var targetRelativePath = templateFile.FullName.Replace(SourceDirectory.FullName, string.Empty).Substring(1);
                var fullPath           = Path.Combine(webFilesDir.FullName, targetRelativePath);
                Directory.CreateDirectory(new FileInfo(fullPath).Directory.FullName);
                var compile = Engine.RunCompile(templateFile.Name, typeof(LaunchPageModel), model);
                File.WriteAllText(compile, fullPath);
            }
            var indexFile = SourceDirectory.GetFiles("index.cshtml").FirstOrDefault();

            if (indexFile != null)
            {
                var indexDestPath = Path.Combine(WorkingDirectory.FullName,
                                                 indexFile.FullName.Replace(indexFile.Extension, ".html")
                                                 .Replace(SourceDirectory.FullName, string.Empty)
                                                 .Substring(1));

                var indexOutput = Engine.RunCompile(indexFile.Name, typeof(LaunchPageModel), model);
                File.WriteAllText(indexDestPath, indexOutput);
            }
            foreach (var file in WorkingDirectory.EnumerateFiles("*.cshtml", SearchOption.AllDirectories))
            {
                file.Delete();
            }
            return(WorkingDirectory);
        }
Beispiel #2
0
 private List <ObjectIndex.Image> GetIndex(out bool check, int inw, int inh)
 {
     if (Index.Count > 0)
     {
         check = false;
     }
     else
     {
         List <ObjectIndex> list = new List <ObjectIndex>();
         #region Load SourceImage
         if (SourceDirectory == null)
         {
             list.Add(new ObjectIndex(new ObjectIndex.Image(CreateNoizeImage(inw, inh))));
         }
         else
         {
             var files = SourceDirectory.GetFiles();
             int fcnt = files.Length, count = 0;
             var sellection = new List <int>();
             while (count != fcnt)
             {
                 var idx = State.RandomSource.Next(fcnt);
                 while (sellection.Contains(idx))
                 {
                     idx = State.RandomSource.Next(fcnt);
                 }
                 sellection.Add(idx);
                 list.Add(new ObjectIndex(new ObjectIndex.Image(files[idx])));
                 count++;
             }
         }
         #endregion
         #region Load ResultImage
         if (ResultDirectory == null)
         {
             #region CreateRandom
             foreach (var item in list)
             {
                 if (item.Images[0].Infomation == null)
                 {
                     item.Images.Add(new ObjectIndex.Image(CreateNoizeImage(inw, inh)));
                 }
                 else
                 {
                     item.Images.Add(new ObjectIndex.Image(item.Images[0].Infomation));
                 }
             }
             #endregion
         }
         else
         {
             var rlist = new List <System.IO.FileInfo>(ResultDirectory.GetFiles());
             if (rlist.Count == 0)
             {
                 #region CreateRandom
                 foreach (var item in list)
                 {
                     item.Images.Add(new ObjectIndex.Image(CreateNoizeImage(inw, inh)));
                 }
                 #endregion
             }
             else
             {
                 foreach (var item in list)
                 {
                     if (item.Images[0].Infomation == null)
                     {
                         #region LoadRandom
                         item.Images.Add(new ObjectIndex.Image(rlist[State.RandomSource.Next(rlist.Count)]));
                         #endregion
                     }
                     else
                     {
                         int idx = rlist.FindIndex(x => x.Name == item.Images[0].Infomation.Name);
                         if (idx >= 0)
                         {
                             item.Images.Add(new ObjectIndex.Image(rlist[idx]));
                         }
                         else
                         {
                             #region LoadRandom
                             item.Images.Add(new ObjectIndex.Image(rlist[State.RandomSource.Next(rlist.Count)]));
                             #endregion
                         }
                     }
                 }
             }
         }
         #endregion
         foreach (var item in list)
         {
             Index.Enqueue(item);
         }
         check = true;
     }
     return(Index.Dequeue().Images);
 }
Beispiel #3
0
        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            foreach (var di in DestinationDirectories)
            {
                var failed = false;

                if (!di.Exists)
                {
                    continue;
                }

                var dest = new DirectoryInfo(Path.Combine(di.FullName, Environment.MachineName));

                if (!dest.Exists)
                {
                    try
                    {
                        dest.Create();
                    } catch (Exception)
                    {
                        failed = true;
                    }
                }

                var files = SourceDirectory.GetFiles();

                foreach (var f in files)
                {
                    try
                    {
                        f.CopyTo(Path.Combine(dest.FullName, f.Name), true);
                    }
                    catch (Exception)
                    {
                        failed = true;
                    }
                }
                Status = failed ? DupliSyncStatus.UploadCopyFailed : DupliSyncStatus.OK;
            }

            if (DownloadDestinationDirectory != null && DownloadSourceDirectories != null)
            {
                bool failed = false;
                foreach (var di in DownloadSourceDirectories)
                {
                    if (di.Exists)
                    {
                        if (!DownloadDestinationDirectory.Exists)
                        {
                            try
                            {
                                DownloadDestinationDirectory.Create();
                            } catch (Exception)
                            {
                                failed = true;
                            }
                        }
                        foreach (var file in di.GetFiles())
                        {
                            try
                            {
                                file.CopyTo(Path.Combine(DownloadDestinationDirectory.FullName, file.Name), true);
                            }
                            catch (Exception)
                            {
                                failed = true;
                            }
                        }
                        break; // Sort après premier dossier trouvé
                    }
                }
                Status = failed ? DupliSyncStatus.DownloadCopyFailed : DupliSyncStatus.OK;
            }
        }