Esempio n. 1
0
        private static void CompressFolder(string absolutePath, ZipArchive zipArchive, int folderOffset)
        {
            var files = C1Directory.GetFiles(absolutePath);

            foreach (string filename in files)
            {
                try
                {
                    using (var streamReader = File.OpenRead(filename))
                    {
                        var fi = new FileInfo(filename);

                        var entryName = filename.Remove(0, folderOffset);
                        var zipEntry  = zipArchive.CreateEntry(entryName, CompressionLevel.Fastest);

                        zipEntry.LastWriteTime = fi.LastWriteTime;

                        using (var stream = zipEntry.Open())
                        {
                            streamReader.CopyTo(stream, 4096);
                        }
                    }
                }
                catch (IOException) { }
            }

            var folders = C1Directory.GetDirectories(absolutePath);

            foreach (var folder in folders)
            {
                CompressFolder(folder, zipArchive, folderOffset);
            }
        }
Esempio n. 2
0
        internal static Dictionary <Guid, string> GetInstalledPackages()
        {
            var result = new Dictionary <Guid, string>();

            string baseDirectory = PathUtil.Resolve(GlobalSettingsFacade.PackageDirectory);

            if (!C1Directory.Exists(baseDirectory))
            {
                return(result);
            }

            string[] packageDirectories = C1Directory.GetDirectories(baseDirectory);
            foreach (string packageDirecoty in packageDirectories)
            {
                if (C1File.Exists(Path.Combine(packageDirecoty, PackageSystemSettings.InstalledFilename)))
                {
                    string filename = Path.Combine(packageDirecoty, PackageSystemSettings.PackageInformationFilename);

                    if (C1File.Exists(filename))
                    {
                        string path = packageDirecoty.Remove(0, baseDirectory.Length);
                        if (path.StartsWith("\\"))
                        {
                            path = path.Remove(0, 1);
                        }

                        Guid id = new Guid(path);

                        result.Add(id, filename);
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
        private IEnumerable <WebsiteFolder> GetFoldersOnPath(string parentPath, SearchToken searchToken)
        {
            IEnumerable <WebsiteFolder> folders =
                from folderPath in C1Directory.GetDirectories(parentPath)
                orderby folderPath
                select new WebsiteFolder(folderPath);

            if (searchToken.IsValidKeyword())
            {
                folders =
                    from folder in folders
                    where folder.FolderName.ToLowerInvariant().Contains(searchToken.Keyword.ToLowerInvariant())
                    select folder;
            }

            if (string.IsNullOrEmpty(_folderWhiteListKeyName) == false)
            {
                List <IFolderWhiteList> whiteList = DataFacade.GetData <IFolderWhiteList>().Where(f => f.KeyName == _folderWhiteListKeyName).ToList();

                folders =
                    from folder in folders.ToList()
                    where whiteList.Any(f => folder.FullPath.StartsWith(f.GetFullPath()) || f.GetFullPath().StartsWith(folder.FullPath))
                    select folder;
            }

            return(folders);
        }
        internal static void DeleteEmptyAncestorFolders(string filePath)
        {
            string folder = Path.GetDirectoryName(filePath);

            while (!C1Directory.GetFiles(folder).Any() && !C1Directory.GetDirectories(folder).Any())
            {
                C1Directory.Delete(folder);

                folder = folder.Substring(0, folder.LastIndexOf('\\'));
            }
        }
        private static void MoveSubfoldersToRoot(string rootFolder, string subFolder)
        {
            foreach (var directory in C1Directory.GetDirectories(subFolder))
            {
                var name = new C1DirectoryInfo(directory).Name;
                if (!name.Contains("."))
                {
                    continue;
                }

                C1Directory.Move(directory, Path.Combine(rootFolder, name));
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        string size = Request.QueryString["size"];

        if (String.IsNullOrEmpty(size))
        {
            size = "24";
        }

        string path = Path.Combine(PathUtil.Resolve(PathUtil.BaseDirectory), "Composite\\images\\icons\\harmony");

        string[] dirEntries = C1Directory.GetDirectories(path);

        StringBuilder builder = new StringBuilder();

        foreach (string dirName in dirEntries)
        {
            int index  = dirName.LastIndexOf("\\");
            int length = dirName.Length - index;

            builder.AppendLine(
                "<ui:pageheading>" +
                dirName.Substring(index + 1, length - 1) +
                "</ui:pageheading>"
                );

            string[] fileEntries = C1Directory.GetFiles(dirName);
            foreach (string fileName in fileEntries)
            {
                if (fileName.Contains("_" + size))
                {
                    string url = fileName.Remove(0, PathUtil.Resolve(PathUtil.BaseDirectory).Length).Replace("\\", "/");

                    url = Composite.Core.WebClient.UrlUtils.ResolvePublicUrl(url);

                    string s = url.Substring(url.LastIndexOf("/") + 1);
                    s = s.Substring(0, (s.LastIndexOf("_")));



                    builder.AppendLine("<div class=\"img\"><img src=\"" + url + "\"/><span>" + s + "</span></div>");
                }
            }
        }

        dynamicOutputPlaceHolder.Controls.Add(new LiteralControl(builder.ToString()));
    }
        public T GetData <T>(IDataId dataId) where T : class, IData
        {
            if (dataId == null)
            {
                throw new ArgumentNullException("dataId");
            }
            CheckInterface(typeof(T));
            MediaDataId mediaDataId = dataId as MediaDataId;

            if (mediaDataId == null)
            {
                return(null);
            }

            if (mediaDataId.MediaType == _folderType)
            {
                if (typeof(T) != typeof(IMediaFileFolder))
                {
                    throw new ArgumentException("The dataId specifies a IMediaFileFolder, but the generic method was invoked with different type");
                }

                FileSystemMediaFileFolder folder = (from dirInfo in C1Directory.GetDirectories(_rootDir, "*", SearchOption.AllDirectories)
                                                    where GetRelativePath(dirInfo) == mediaDataId.Path
                                                    select CreateFolder(dirInfo)).FirstOrDefault();
                return(folder as T);
            }
            else if (mediaDataId.MediaType == _fileType)
            {
                if (typeof(T) != typeof(IMediaFile))
                {
                    throw new ArgumentException("The dataId specifies a IMediaFile, but the generic method was invoked with different type");
                }

                FileSystemMediaFile file = (from fileInfo in C1Directory.GetFiles(_rootDir, "*", SearchOption.AllDirectories)
                                            where GetRelativePath(Path.GetDirectoryName(fileInfo)) == mediaDataId.Path && Path.GetFileName(fileInfo) == mediaDataId.FileName
                                            select CreateFile(fileInfo)).FirstOrDefault();

                return(file as T);
            }
            else
            {
                return(Store as T);
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        string size = Request.QueryString ["size"];

        if (String.IsNullOrEmpty(size))
        {
            size = "24";
        }

        string path = Server.MapPath("../../../../../images/icons/republic");

        string [] dirEntries = C1Directory.GetDirectories(path);

        StringBuilder builder = new StringBuilder();

        foreach (string dirName in dirEntries)
        {
            // do something with fileName
            if (dirName.Contains("republic_"))
            {
                string [] fileEntries = C1Directory.GetFiles(dirName);
                foreach (string fileName in fileEntries)
                {
                    if (fileName.Contains("_" + size + "px_"))
                    {
                        string string1 = fileName.Replace("\\", "/").ToLowerInvariant();
                        string string2 = string1.Substring(
                            string1.IndexOf("images")                                // Website
                            );
                        string string3 = string1.Substring(
                            string1.LastIndexOf("/") + 1
                            );
                        string3 = string3.Substring(0, 4);

                        builder.AppendLine(string.Format(@"<div class=""img""><img src=""{0}/{1}"" /><span>{2}</span></div>", Composite.Core.WebClient.UrlUtils.AdminRootPath, HttpUtility.HtmlAttributeEncode(string2), HttpUtility.HtmlEncode(string3)));
                    }
                }
            }
        }

        dynamicOutputPlaceHolder.Controls.Add(new LiteralControl(builder.ToString()));
    }
Esempio n. 9
0
        /// <exclude />
        public static void OnApplicationEnd()
        {
            // Deleting everything that is older than 24 hours
            string tempDirectoryName = TempDirectoryPath;

            if (!C1Directory.Exists(tempDirectoryName))
            {
                return;
            }



            foreach (string filename in C1Directory.GetFiles(tempDirectoryName))
            {
                try
                {
                    if (DateTime.Now > C1File.GetLastWriteTime(filename) + TemporaryFileExpirationTimeSpan)
                    {
                        C1File.Delete(filename);
                    }
                }
                catch
                {
                }
            }

            foreach (string directoryPath in C1Directory.GetDirectories(tempDirectoryName))
            {
                try
                {
                    if (DateTime.Now > C1Directory.GetCreationTime(directoryPath) + TemporaryFileExpirationTimeSpan)
                    {
                        C1Directory.Delete(directoryPath, true);
                    }
                }
                catch
                {
                }
            }
        }
        public IQueryable <T> GetData <T>() where T : class, IData
        {
            CheckInterface(typeof(T));

            if (typeof(T) == typeof(IMediaFile))
            {
                var excludePaths =
                    (from dir in _excludedDirs
                     select PathUtil.Resolve(_rootDir + dir.Replace('/', '\\')) + @"\").ToList();

                var matches =
                    from filePath in C1Directory.GetFiles(_rootDir, "*", SearchOption.AllDirectories)
                    where excludePaths.Where(f => filePath.StartsWith(f)).Count() == 0
                    select CreateFile(filePath);

                return(matches.Cast <T>().AsQueryable());
            }
            else if (typeof(T) == typeof(IMediaFileFolder))
            {
                var excludePaths =
                    (from dir in _excludedDirs
                     select PathUtil.Resolve(_rootDir + dir.Replace('/', '\\')) + @"\").ToList();

                var matches =
                    from dirPath in C1Directory.GetDirectories(_rootDir, "*", SearchOption.AllDirectories)
                    where excludePaths.Where(f => (dirPath + @"\").StartsWith(f)).Count() == 0
                    select CreateFolder(dirPath);

                return(matches.Cast <T>().AsQueryable());
            }
            else
            {
                return(new List <T>()
                {
                    Store as T
                }.AsQueryable <T>());
            }
        }
Esempio n. 11
0
    public List <string> GetDirectoriesRecursive(string rootDirectory)
    {
        List <string>  result = new List <string>();
        Stack <string> stack  = new Stack <string>();

        stack.Push(rootDirectory);
        while (stack.Count > 0)
        {
            string dir = stack.Pop();
            try
            {
                result.AddRange(C1Directory.GetDirectories(dir, "*.*"));
                foreach (string dn in C1Directory.GetDirectories(dir))
                {
                    stack.Push(dn);
                }
            }
            catch (Exception e)
            {
                this.Validators.Add(new ErrorSummary(e.Message));
            }
        }
        return(result);
    }
Esempio n. 12
0
        /// <exclude />
        public static IEnumerable <InstalledPackageInformation> GetInstalledPackages()
        {
            string baseDirectory = PathUtil.Resolve(GlobalSettingsFacade.PackageDirectory);

            if (!C1Directory.Exists(baseDirectory))
            {
                yield break;
            }

            string[] packageDirectories = C1Directory.GetDirectories(baseDirectory);
            foreach (string packageDirectory in packageDirectories)
            {
                if (C1File.Exists(Path.Combine(packageDirectory, PackageSystemSettings.InstalledFilename)))
                {
                    string filename = Path.Combine(packageDirectory, PackageSystemSettings.PackageInformationFilename);

                    if (C1File.Exists(filename))
                    {
                        XDocument doc = XDocumentUtils.Load(filename);

                        XElement packageInfoElement = doc.Root;
                        if (packageInfoElement.Name != XmlUtils.GetXName(PackageSystemSettings.XmlNamespace, PackageSystemSettings.PackageInfoElementName))
                        {
                            throw new InvalidOperationException(string.Format("{0} is wrongly formattet", filename));
                        }

                        XAttribute nameAttribute                      = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_NameAttributeName);
                        XAttribute groupNameAttribute                 = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_GroupNameAttributeName);
                        XAttribute versionAttribute                   = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_VersionAttributeName);
                        XAttribute authorAttribute                    = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_AuthorAttributeName);
                        XAttribute websiteAttribute                   = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_WebsiteAttributeName);
                        XAttribute descriptionAttribute               = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_DescriptionAttributeName);
                        XAttribute installDateAttribute               = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_InstallDateAttributeName);
                        XAttribute installedByAttribute               = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_InstalledByAttributeName);
                        XAttribute isLocalInstalledAttribute          = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_IsLocalInstalledAttributeName);
                        XAttribute canBeUninstalledAttribute          = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_CanBeUninstalledAttributeName);
                        XAttribute flushOnCompletionAttribute         = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_FlushOnCompletionAttributeName);
                        XAttribute reloadConsoleOnCompletionAttribute = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_ReloadConsoleOnCompletionAttributeName);
                        XAttribute systemLockingAttribute             = GetAttributeNotNull(filename, packageInfoElement, PackageSystemSettings.PackageInfo_SystemLockingAttributeName);

                        XAttribute packageServerAddressAttribute = packageInfoElement.Attribute(PackageSystemSettings.PackageInfo_PackageServerAddressAttributeName);


                        SystemLockingType systemLockingType;
                        if (systemLockingAttribute.TryDeserialize(out systemLockingType) == false)
                        {
                            throw new InvalidOperationException("The systemLocking attibute value is wrong");
                        }

                        string path = packageDirectory.Remove(0, baseDirectory.Length);
                        if (path.StartsWith("\\"))
                        {
                            path = path.Remove(0, 1);
                        }

                        Guid packageId;
                        if (!Guid.TryParse(path, out packageId))
                        {
                            continue;
                        }

                        yield return(new InstalledPackageInformation
                        {
                            Id = packageId,
                            Name = nameAttribute.Value,
                            GroupName = groupNameAttribute.Value,
                            Version = versionAttribute.Value,
                            Author = authorAttribute.Value,
                            Website = websiteAttribute.Value,
                            Description = descriptionAttribute.Value,
                            InstallDate = (DateTime)installDateAttribute,
                            InstalledBy = installedByAttribute.Value,
                            IsLocalInstalled = (bool)isLocalInstalledAttribute,
                            CanBeUninstalled = (bool)canBeUninstalledAttribute,
                            FlushOnCompletion = (bool)flushOnCompletionAttribute,
                            ReloadConsoleOnCompletion = (bool)reloadConsoleOnCompletionAttribute,
                            SystemLockingType = systemLockingType,
                            PackageServerAddress = packageServerAddressAttribute?.Value,
                            PackageInstallPath = packageDirectory
                        });
                    }
                    else
                    {
                        throw new InvalidOperationException($"'{filename}' does not exist");
                    }
                }
                else
                {
                    // Make this cleanup in an other way, it works correctly if it is done between validation and installation.
                    //LoggingService.LogVerbose("PackageManager", string.Format("Uncomlete installed add on found ('{0}'), deleting it", Path.GetFileName(packageDirecoty)));
                    //try
                    //{
                    //    Directory.Delete(packageDirecoty, true);
                    //}
                    //catch (Exception)
                    //{
                    //}
                }
            }
        }