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));
            }
        }
        private ICollection <PackageFragmentValidationResult> FinalizeProcess(bool install)
        {
            try
            {
                if (_zipFilename != null && C1File.Exists(_zipFilename))
                {
                    C1File.Delete(_zipFilename);
                }

                Func <IList <PackageFragmentValidationResult>, bool> isNotEmpty = list => list != null && list.Count > 0;

                bool installationFailed = isNotEmpty(_preInstallValidationResult) ||
                                          isNotEmpty(_validationResult) ||
                                          isNotEmpty(_installationResult);

                if (installationFailed && C1Directory.Exists(_packageInstallDirectory))
                {
                    C1Directory.Delete(_packageInstallDirectory, true);
                }

                if (!installationFailed && install)
                {
                    Log.LogInformation(LogTitle, "Package successfully installed");

                    C1File.WriteAllText(Path.Combine(_packageInstallDirectory, PackageSystemSettings.InstalledFilename), "");

                    // Moving package files to a proper location, if an newer version of an already installed package is installed
                    if (_originalPackageInstallDirectory != null)
                    {
                        C1Directory.Delete(_originalPackageInstallDirectory, true);

                        C1Directory.Move(_packageInstallDirectory, _originalPackageInstallDirectory);
                    }
                }

                return(new PackageFragmentValidationResult[0]);
            }
            catch (Exception ex)
            {
                return(new [] { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex) });
            }
        }
        public void Update(IEnumerable <IData> datas)
        {
            foreach (IData data in datas)
            {
                if (data == null)
                {
                    throw new ArgumentException("Data in list to update must be non-null");
                }
            }

            foreach (IData data in datas)
            {
                MediaDataId dataId = data.DataSourceId.DataId as MediaDataId;
                if (dataId == null)
                {
                    throw new ArgumentException("Invalid IData");
                }

                if (dataId.MediaType == _fileType)
                {
                    IMediaFile updatedFile = (IMediaFile)data;

                    if (updatedFile.StoreId != this.Store.Id)
                    {
                        continue;
                    }
                    if (updatedFile.IsReadOnly)
                    {
                        throw new ArgumentException("Cannot update read only media file " + dataId.FileName);
                    }

                    if (updatedFile.FileName != dataId.FileName || updatedFile.FolderPath != dataId.Path)
                    {
                        string oldPos = GetAbsolutePath(dataId);
                        string newPos = GetAbsolutePath(updatedFile);
                        C1File.Move(oldPos, newPos);
                    }

                    using (Stream readStream = updatedFile.GetReadStream())
                    {
                        using (Stream writeStream = C1File.Open(GetAbsolutePath(updatedFile), FileMode.Create))
                        {
                            readStream.CopyTo(writeStream);
                        }
                    }
                }
                else
                {
                    IMediaFileFolder updatedFolder = (IMediaFileFolder)data;
                    if (updatedFolder.StoreId != this.Store.Id)
                    {
                        continue;
                    }
                    if (updatedFolder.IsReadOnly)
                    {
                        throw new ArgumentException("Cannot update read only media folder " + dataId.Path);
                    }
                    C1Directory.Move(GetAbsolutePath(dataId), GetAbsolutePath(updatedFolder));
                }
            }
        }