Exemplo n.º 1
0
        void QueueItems(DirectoryInfo source, string dest)
        {
            foreach (FileInfo file in source.GetFiles())
            {
                if (m_im.IsIgored(file))
                {
                    continue;
                }

                SrcFiles.Add(file.FullName);
                DestFiles.Add(dest + "\\" + file.Name);
            }

            foreach (DirectoryInfo sub in source.GetDirectories())
            {
                if (m_im.IsIgored(sub))
                {
                    continue;
                }

                string destSub = dest + "\\" + sub.Name;
                Directory.CreateDirectory(destSub);
                QueueItems(sub, destSub);
            }
        }
        private void RunTaskAsync()
        {
            try
            {
                ProcessedObjects = 0;
                ObjectsCount     = 0;
                ErrorMap.Clear();

                List <string> allLinkedFiles = new List <string>();
                foreach (string path in SrcFiles)
                {
                    if (File.Exists(path))
                    {
                        List <String> linkedFiles = _support.GetChildFiles(path, TaskType);
                        if (linkedFiles != null && linkedFiles.Count > 0)
                        {
                            var linkedFilesLowercase = (from s in linkedFiles
                                                        select s.ToLowerInvariant()).ToList();

                            allLinkedFiles.AddRange(linkedFilesLowercase);
                        }
                    }
                }

                List <string> srcFilesClone = new List <string>(SrcFiles);

                foreach (string srcFile in srcFilesClone)
                {
                    if (allLinkedFiles.Contains(srcFile.ToLowerInvariant()))
                    {
                        SrcFiles.Remove(srcFile);
                    }
                }

                foreach (string path in SrcFiles)
                {
                    if (Directory.Exists(path))
                    {
                        List <string> entries = PathUtils.EnumFileSystemEntries(path, "*", SearchOption.AllDirectories);
                        if (entries != null && entries.Count > 0)
                        {
                            ObjectsCount += entries.Count;
                        }
                    }
                    else
                    {
                        ObjectsCount++;
                    }
                }

                ObjectsCount += allLinkedFiles.Count;

                FireTaskProgress(ProgressEventType.Started, string.Empty, UpdateProgressData.Empty);

                _currentPath = string.Empty;
                _timer.Start();

                try
                {
                    foreach (string path in SrcFiles)
                    {
                        _currentPath = path;
                        FireTaskProgress(ProgressEventType.Progress, path, UpdateProgressData.Empty);

                        switch (TaskType)
                        {
                        case FileTaskType.Copy:
                            CopyObject(path);
                            break;

                        case FileTaskType.Move:
                            MoveObject(path);
                            break;

                        case FileTaskType.Delete:
                            DeleteObject(path);
                            break;
                        }
                    }
                }
                catch (TaskInterruptedException)
                {
                    FireTaskProgress(ProgressEventType.Aborted, string.Empty, UpdateProgressData.Empty);
                    return;
                }
                finally
                {
                    _timer.Stop();
                    _currentPath = string.Empty;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            finally
            {
                IsFinished = true;
            }

            FireTaskProgress(ProgressEventType.Finished, string.Empty, UpdateProgressData.Empty);
            _requiresRefresh = _support.RequiresRefresh;
            _support         = null;
        }
Exemplo n.º 3
0
 public void Release()
 {
     SrcFiles.Clear();
     DestFiles.Clear();
 }
Exemplo n.º 4
0
        public Data SavePage(Save Obj, string siteName, string pageName)
        {
            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    string root = Server.MapPath(".") + "/Sites/";

                    var entities = new WAG_Login_Page.WebPageEntities();

                    var user = entities.AspNetUsers.Where(i => i.UserName == User.Identity.Name).FirstOrDefault();

                    if (user != null)
                    {
                        var userFolder = Path.Combine(root, user.Id);

                        if (Directory.Exists(userFolder))
                        {
                            var siteFolder = Path.Combine(userFolder, siteName);

                            if (Directory.Exists(siteFolder))
                            {
                                string filePath = Path.Combine(siteFolder, pageName);

                                if (File.Exists(filePath))
                                {
                                    try
                                    {
                                        ////////////////////////////////////////////////
                                        string targetThemeFolder = Path.Combine(siteFolder, "Theme");

                                        string[] themeFile = { "theme.css", "jQuery.js" };

                                        SrcFiles theme = new SrcFiles();
                                        theme.fileName   = "theme.css";
                                        theme.FolderPath = Path.Combine(Server.MapPath("."), "../Themes/457/");
                                        theme.DestPath   = Path.Combine(siteFolder, "Theme/");

                                        SrcFiles jquery = new SrcFiles();
                                        jquery.fileName   = "jquery-1.11.2.min.js";
                                        jquery.FolderPath = Path.Combine(Server.MapPath("."), "../Library/");
                                        jquery.DestPath   = Path.Combine(siteFolder, "jQuery/");


                                        SrcFiles jqPlus = new SrcFiles();
                                        jqPlus.fileName   = "jqPlus.css";
                                        jqPlus.FolderPath = Path.Combine(Server.MapPath("."), "../");
                                        jqPlus.DestPath   = Path.Combine(siteFolder, "Theme/");

                                        SrcFiles bootstrap = new SrcFiles();
                                        bootstrap.fileName   = "bootstrap-customzed-48.min.css";
                                        bootstrap.FolderPath = Path.Combine(Server.MapPath("."), "../Content/bootstrap-3.3.5-dist/css/");
                                        bootstrap.DestPath   = Path.Combine(siteFolder, "Bootstrap/");


                                        List <SrcFiles> copy = new List <SrcFiles>();

                                        copy.Add(theme);
                                        copy.Add(jquery);
                                        copy.Add(bootstrap);
                                        copy.Add(jqPlus);

                                        for (int i = 0; i < copy.Count(); i++)
                                        {
                                            if (!Directory.Exists(copy[i].DestPath))
                                            {
                                                Directory.CreateDirectory(copy[i].DestPath);
                                            }

                                            string sourcePath = Path.Combine(copy[i].FolderPath, copy[i].fileName);
                                            string targetPath = Path.Combine(copy[i].DestPath, copy[i].fileName);

                                            File.Copy(sourcePath, targetPath, true);
                                        }

                                        ///////////////////// theme file //////////////////

                                        ///////////////////// Save Images /////////////////

                                        try
                                        {
                                            string destDirFullPath = Path.Combine(siteFolder, "iimages");

                                            if (!Directory.Exists(destDirFullPath))
                                            {
                                                Directory.CreateDirectory(destDirFullPath);
                                            }

                                            Regex imagePat    = new Regex("(<img [^>]+|image: *url[^)]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                                            Regex imageSrcPat = new Regex("src=(\"[^\"]+\"|'[^']+'| *[^ ]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                                            //Regex imageAltPat = new Regex("alt=(\"[^\"]+\"|'[^']+'| *[^ ]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                                            //Regex imageWidthPat = new Regex("width=(\"[^\"]+\"|'[^']+'| *[^ ]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                                            //Regex imageHeightPat = new Regex("height=(\"[^\"]+\"|'[^']+'| *[^ ]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                                            Regex imageUrlPat = new Regex(@"url\(([^)]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);

                                            Match mImg;
                                            foreach (Match match in imagePat.Matches(Obj.page))
                                            {
                                                int    pos    = match.Index;
                                                string imgStr = Obj.page.Substring(pos, match.Length);

                                                imgStr = imgStr.Replace("'", "\"").Replace("&quot;", "\"");

                                                switch (char.ToLower(imgStr[0]))
                                                {
                                                case 'i':       // background-image: url(foo.png);
                                                    mImg = imageUrlPat.Match(imgStr);
                                                    break;

                                                case '<':       // <img src="foo.png">
                                                    mImg = imageSrcPat.Match(imgStr);
                                                    break;

                                                default:
                                                    mImg = null;
                                                    break;
                                                }

                                                if (mImg != null)
                                                {
                                                    string imagePath = mImg.Groups[1].Value.Trim().Replace("'", "").Replace("\"", "");


                                                    if (imagePath != null && imagePath.Trim() != "")
                                                    {
                                                        //"/Content/Images/User_1/12.png"

                                                        imagePath = imagePath.ToLower();

                                                        imagePath = imagePath.Replace("\\", "/");

                                                        string srcImage = Path.Combine(Server.MapPath("."), "../shiv/" + imagePath);

                                                        string destPath = imagePath;

                                                        string destFileFullPath = Path.Combine(siteFolder, destPath);

                                                        try
                                                        {
                                                            File.Copy(srcImage, destFileFullPath, true);
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                        ////////////////////////////////////////////////////

                                        string pageText = "";

                                        pageText  = Obj.scripts.ToString();
                                        pageText += Obj.styles.ToString();
                                        pageText += Obj.page.ToString();


                                        File.WriteAllText(filePath, pageText);


                                        return(new Data {
                                            Success = true
                                        });
                                    }
                                    catch (Exception ex)
                                    {
                                        return(new Data {
                                            Success = false, ExceptionError = ex.Message
                                        });
                                    }
                                }
                                else
                                {
                                    return(new Data {
                                        Success = false, Error = "Page Does Not Exist"
                                    });
                                }
                            }
                        }
                    }
                }

                return(new Data {
                    Success = false
                });
            }
            catch (Exception ex)
            {
                return(new Data {
                    Success = false, Error = "", ExceptionError = ex.Message
                });
            }
        }