コード例 #1
0
        public static bool Exists(string path)
        {
#if DOTNET5_4
            return(File.Exists(path));
#else
            try
            {
                if (String.IsNullOrEmpty(path))
                {
                    return(false);
                }
                path = LongPath.ToUncPath(path);
                bool success = NativeMethods.PathFileExistsW(path);
                if (!success)
                {
                    NativeMethods.ThrowExceptionForLastWin32ErrorIfExists(new int[] { 0, NativeMethods.ERROR_DIRECTORY_NOT_FOUND, NativeMethods.ERROR_FILE_NOT_FOUND });
                }
                var fileAttributes = Microsoft.Azure.Storage.DataMovement.LongPathFile.GetAttributes(path);
                return(success && (FileAttributes.Directory != (fileAttributes & FileAttributes.Directory)));
            }
            catch (ArgumentException) { }
            catch (NotSupportedException) { }  // Security can throw this on ":"
            catch (System.Security.SecurityException) { }
            catch (IOException) { }
            catch (UnauthorizedAccessException) { }

            return(false);
#endif
        }
コード例 #2
0
        protected override bool WriteList(List list, string targetPath, out string listPath)
        {
            var listFileName  = LongPath.ToValidFileName(string.Format(Options.ListFileNameFormat, list.DisplayName));
            var listBlobsPath = LongPath.Combine(targetPath, LongPath.ToValidFileName(string.Format(Options.ListBlobsFolderNameFormat, list.DisplayName)));

            var lwr = new ListWithRows(list);

            foreach (var row in lwr.Rows)
            {
                foreach (var column in list.Columns)
                {
                    if (column.DataType == ColumnDataType.Blob)
                    {
                        row.Values[column.Name] = ExtractBlobFromRow(list, row, column, listBlobsPath);
                    }
                }
            }

            listPath = LongPath.Combine(targetPath, listFileName);
            using (var writer = new StreamWriter(listPath, false, Options.Encoding))
            {
                JsonUtilities.Serialize(writer, lwr, Options.SerializationOptions);
            }
            return(true);
        }
コード例 #3
0
        protected virtual string ExtractBlobFromRow(List list, Row row, Column column, string listBlobsPath)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }

            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }

            if (listBlobsPath == null)
            {
                throw new ArgumentNullException(nameof(listBlobsPath));
            }

            var blobProperties = row.GetValue <Dictionary <string, object> >(column.Name, null);

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

            var blob = new Blob(blobProperties, column, row, list.Parent.Server);

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

            blob.DownloadFile();
            if (blob.TempFilePath == null)
            {
                return(null);
            }

            LongPath.DirectoryCreate(listBlobsPath);

            var blobFilePath = GetUniqueBlobFilePath(blob, listBlobsPath);

            LongPath.FileCopy(blob.TempFilePath, blobFilePath, true);

            AddMessage("Blob extracted",
                       folderId: list.Parent.IdN,
                       folderName: list.Parent.DisplayName,
                       listId: list.IdN,
                       listName: list.DisplayName,
                       rowId: row.IdN,
                       rowName: row.DisplayName,
                       blobId: blob.ImageUrl,
                       blobName: ((IUploadableFile)blob).FormName);

            return(blobFilePath);
        }
コード例 #4
0
        protected override bool WriteFolder(Folder folder, string targetPath, out string folderPath)
        {
            var folderFolderName = LongPath.ToValidFileName(folder.DisplayName);

            folderPath = LongPath.Combine(targetPath, folderFolderName);
            return(true);
        }
コード例 #5
0
        public static string Combine(string path1, string path2)
        {
#if DOTNET5_4
            return(Path.Combine(path1, path2));
#else
            return(LongPath.Combine(path1, path2));
#endif
        }
コード例 #6
0
        public static string GetFileNameWithoutExtension(string path)
        {
#if DOTNET5_4
            return(Path.GetFileNameWithoutExtension(path));
#else
            return(LongPath.GetFileNameWithoutExtension(path));
#endif
        }
コード例 #7
0
        public static string GetFullPath(string path)
        {
#if DOTNET5_4
            return(Path.GetFullPath(path));
#else
            return(LongPath.GetFullPath(path));
#endif
        }
コード例 #8
0
        public static string GetFileName(string path)
        {
#if DOTNET5_4
            return(Path.GetFileName(path));
#else
            return(LongPath.GetFileName(path));
#endif
        }
コード例 #9
0
ファイル: HtmlExporter.cs プロジェクト: RowShare/developers
        protected override bool WriteList(List list, string targetPath, out string listPath)
        {
            var listFileName  = LongPath.ToValidFileName(string.Format(Options.ListFileNameFormat, list.DisplayName));
            var listBlobsPath = LongPath.Combine(targetPath, LongPath.ToValidFileName(string.Format(Options.ListBlobsFolderNameFormat, list.DisplayName)));

            listPath = LongPath.Combine(targetPath, listFileName);
            using (var writer = new StreamWriter(listPath, false, Options.Encoding))
            {
                WriteHeader(writer, list);

                writer.Write("<tr>");
                var columns = list.Columns.OrderBy(c => c.SortOrder).ToArray();
                foreach (var column in columns)
                {
                    writer.Write("<td>" + HtmlEncode(column.DisplayName) + "</td>");
                }
                writer.Write("</tr>");

                var rows = list.LoadRows();
                foreach (var row in rows)
                {
                    writer.Write("<tr>");
                    foreach (var column in columns)
                    {
                        string value = null;
                        if (column.DataType == ColumnDataType.Blob)
                        {
                            var blobProperties = row.GetValue <Dictionary <string, object> >(column.Name, null);
                            if (blobProperties != null)
                            {
                                var fileName    = blobProperties.GetValue <string>("FileName", null);
                                var contentType = blobProperties.GetValue <string>("ContentType", null);

                                value = ExtractBlobFromRow(list, row, column, listBlobsPath);
                                if (value != null)
                                {
                                    var isImage = (column.Options & ColumnOptions.IsImage) == ColumnOptions.IsImage ||
                                                  contentType != null && contentType.StartsWith("image/");

                                    value = string.Format("<a href=\"{0}\">{1}</a>", value, isImage ? string.Format("<img src=\"{0}\" alt=\"{1}\" />", value, fileName) : fileName);
                                }
                            }
                        }
                        else
                        {
                            value = HtmlEncode(row.GetValue <string>(column.Name, null));
                        }
                        writer.Write(string.Format("<td>{0}</td>", value));
                    }
                    writer.Write("</tr>");
                }

                WriteFooter(writer);
            }
            return(true);
        }
コード例 #10
0
        private void SetPackagePath(string extractionPathWithLanguageFolder, string packagePrefix, ref LongPath packagePath)
        {
            string path  = string.Format("{0}.{1}.msi", packagePrefix, base.Language.ToString());
            string path2 = Path.Combine(extractionPathWithLanguageFolder, path);

            if (!LongPath.TryParse(path2, out packagePath))
            {
                packagePath = null;
                base.WriteError(new TaskException(Strings.UmLanguagePackPackagePathNotSpecified), ErrorCategory.NotSpecified, 0);
            }
        }
 public static void SetFileSecurityInfo(string path, string portableSDDL, PreserveSMBPermissions preserveSMBPermissions)
 {
     try
     {
         path = DMLibTestConstants.SupportUNCPath ?
                LongPath.GetFullPath(LongPath.ToUncPath(path)) :
                LongPath.GetFullPath(path);
     }
     catch (Exception)
     { }
     FileSecurityOperations.SetFileSecurity(path, portableSDDL, preserveSMBPermissions);
 }
 public static string GetFilePortableSDDL(string path, PreserveSMBPermissions preserveSMBPermissions)
 {
     try
     {
         path = DMLibTestConstants.SupportUNCPath ?
                LongPath.GetFullPath(LongPath.ToUncPath(path)) :
                LongPath.GetFullPath(path);
     }
     catch (Exception)
     { }
     return(FileSecurityOperations.GetFilePortableSDDL(path, preserveSMBPermissions));
 }
 public static void SetAttributes(string path, FileAttributes fileAttributes)
 {
     try
     {
         path = DMLibTestConstants.SupportUNCPath ?
                LongPath.GetFullPath(LongPath.ToUncPath(path)) :
                LongPath.GetFullPath(path);
     }
     catch (Exception)
     { }
     LongPathFile.SetAttributes(path, fileAttributes);
 }
        public static bool Exists(string path)
        {
#if DOTNET5_4
            return(Directory.Exists(path));
#else
            if (DMLibTestConstants.SupportUNCPath)
            {
                path = LongPath.ToUncPath(path);
            }
            return(LongPathDirectory.Exists(path));
#endif
        }
コード例 #15
0
        public static void GetFileProperties(string path, out DateTimeOffset?creationTime, out DateTimeOffset?lastWriteTime, out FileAttributes?fileAttributes
#if DOTNET5_4
                                             , bool isDirectory = false
#endif
                                             )
        {
#if DOTNET5_4
            LongPathFile.GetFileProperties(path, out creationTime, out lastWriteTime, out fileAttributes, isDirectory);
#else
            path = LongPath.ToUncPath(path);
            LongPathFile.GetFileProperties(path, out creationTime, out lastWriteTime, out fileAttributes);
#endif
        }
コード例 #16
0
        protected override bool WriteFolder(Folder folder, string targetPath, out string folderPath)
        {
            var folderFolderName = LongPath.ToValidFileName(folder.DisplayName);
            var folderFileName   = LongPath.Combine(targetPath, string.Format(Options.FolderFileNameFormat, folder.DisplayName));

            using (var writer = new StreamWriter(folderFileName, false, Options.Encoding))
            {
                JsonUtilities.Serialize(writer, folder, Options.SerializationOptions);
            }

            folderPath = LongPath.Combine(targetPath, folderFolderName);
            return(true);
        }
        public static FileStream Open(string path, FileMode mode)
        {
            try
            {
                path = DMLibTestConstants.SupportUNCPath ?
                       LongPath.GetFullPath(LongPath.ToUncPath(path)) :
                       LongPath.GetFullPath(path);
            }
            catch (Exception)
            { }

            return(LongPathFile.Open(path, mode, FileAccess.ReadWrite, FileShare.ReadWrite));
        }
コード例 #18
0
ファイル: Server.cs プロジェクト: RowShare/developers
        public string DownloadCall(ServerCallParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using (var client = new CookieWebClient())
            {
                if (Cookie != null)
                {
                    client.Cookies.Add(new Cookie(CookieName, Cookie, "/", new Uri(Url).Host));
                }


                string url = parameters.Api;
                if (parameters.Api != null && !parameters.Api.StartsWith("/"))
                {
                    url = "/" + url;
                }

                var uri =
                    new EditableUri(Url + url);
                if (!string.IsNullOrWhiteSpace(parameters.Format))
                {
                    uri.Parameters["f"] = parameters.Format;
                }

                if (parameters.Lcid != 0)
                {
                    uri.Parameters["l"] = parameters.Lcid;
                }

                try
                {
                    var filePath = LongPath.GetTempFileName();
                    client.DownloadFile(uri.ToString(), filePath);
                    return(filePath);
                }
                catch (WebException e)
                {
                    if (ShowMessageBoxOnError)
                    {
                        var eb = new ErrorBox(e, e.GetErrorText(null));
                        eb.ShowDialog();
                    }
                    throw;
                }
            }
        }
コード例 #19
0
 static DMLibTestConstants()
 {
     SupportUNCPath = false;
     if (CrossPlatformHelpers.IsWindows)
     {
         try
         {
             LongPath.GetFullPath(LongPath.ToUncPath("F:\\"));
             SupportUNCPath = true;
         }
         catch (Exception)
         { }
     }
 }
コード例 #20
0
        protected override void InternalProcessRecord()
        {
            LongPath packagePath      = null;
            LongPath telePackagePath  = null;
            LongPath transPackagePath = null;
            LongPath ttsPackagePath   = null;

            try
            {
                DirectoryInfo directoryInfo = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
                this.extractionDirectory = directoryInfo.FullName;
                EmbeddedCabWrapper.ExtractFiles(this.LanguagePackExecutablePath.PathName, this.extractionDirectory, null);
                string[] directories = Directory.GetDirectories(this.extractionDirectory);
                if (directories.Length != 1)
                {
                    base.WriteError(new TaskException(Strings.UmLanguagePackInvalidExtraction), ErrorCategory.NotSpecified, 0);
                }
                string extractionPathWithLanguageFolder = directories[0];
                this.SetPackagePath(extractionPathWithLanguageFolder, "UMLanguagePack", ref packagePath);
                this.SetPackagePath(extractionPathWithLanguageFolder, "MSSpeech_SR_TELE", ref telePackagePath);
                this.SetPackagePath(extractionPathWithLanguageFolder, "MSSpeech_SR_TRANS", ref transPackagePath);
                this.SetPackagePath(extractionPathWithLanguageFolder, "MSSpeech_TTS", ref ttsPackagePath);
            }
            catch (Exception ex)
            {
                base.WriteError(new TaskException(Strings.UmLanguagePackException(ex.Message)), ErrorCategory.NotSpecified, 0);
            }
            this.PackagePath      = packagePath;
            this.TelePackagePath  = telePackagePath;
            this.TransPackagePath = transPackagePath;
            this.TtsPackagePath   = ttsPackagePath;
            if (!File.Exists(this.PackagePath.PathName))
            {
                base.WriteError(new TaskException(Strings.UmLanguagePackMsiFileNotFound(this.PackagePath.PathName)), ErrorCategory.InvalidArgument, 0);
            }
            if (!File.Exists(this.TelePackagePath.PathName))
            {
                base.WriteError(new TaskException(Strings.UmLanguagePackMsiFileNotFound(this.TelePackagePath.PathName)), ErrorCategory.InvalidArgument, 0);
            }
            if (!File.Exists(this.TransPackagePath.PathName))
            {
                this.TransPackagePath = null;
            }
            if (!File.Exists(this.TtsPackagePath.PathName))
            {
                base.WriteError(new TaskException(Strings.UmLanguagePackMsiFileNotFound(this.TtsPackagePath.PathName)), ErrorCategory.InvalidArgument, 0);
            }
            base.InternalProcessRecord();
        }
コード例 #21
0
        private static EnumerateFileEntryInfo GetFileEntryInfo(string filePath)
        {
            EnumerateFileEntryInfo fileEntryInfo = new EnumerateFileEntryInfo()
            {
                FileName       = LongPath.GetFileName(filePath),
                FileAttributes = FileAttributes.Normal,
                SymlinkTarget  = null
            };

#if DOTNET5_4
            try
            {
                UnixFileSystemInfo fileSystemInfo = UnixFileSystemInfo.GetFileSystemEntry(filePath);
                if (fileSystemInfo.IsSymbolicLink)
                {
                    fileEntryInfo.FileAttributes |= FileAttributes.ReparsePoint;
                    fileEntryInfo.SymlinkTarget   = Path.GetFullPath(Path.Combine(GetParentPath(filePath), (fileSystemInfo as UnixSymbolicLinkInfo).ContentsPath));

                    UnixSymbolicLinkInfo symlinkInfo = fileSystemInfo as UnixSymbolicLinkInfo;

                    try
                    {
                        if (symlinkInfo.HasContents && symlinkInfo.GetContents().IsDirectory)
                        {
                            fileEntryInfo.FileAttributes |= FileAttributes.Directory;
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        // Just ignore exception thrown here.
                        // later there will be "FileNotFoundException" thrown out when trying to open the file before transferring.
                    }
                }

                if (fileSystemInfo.IsDirectory)
                {
                    fileEntryInfo.FileAttributes |= FileAttributes.Directory;
                }
            }
            catch (DllNotFoundException ex)
            {
                throw new TransferException(TransferErrorCode.FailToEnumerateDirectory,
                                            Resources.UnableToLoadDLL,
                                            ex);
            }
#endif
            return(fileEntryInfo);
        }
コード例 #22
0
        protected void LogBytecodeOutput(String typeName, String bytecodeOutput)
        {
#if SILVERLIGHT
            DirectoryInfo outputFileDir = new DirectoryInfo(TraceDir + Path.DirectorySeparatorChar + GetType().FullName);
            outputFileDir.Create();
            String formattedName = outputFileDir.FullName + Path.DirectorySeparatorChar + typeName + ".txt";
            try
            {
                using (FileStream outputFile = new FileStream(formattedName, FileMode.Create, FileAccess.Write, FileShare.Read))
#else
            // the following code allows to write to directories with a length > 260 chars
            char sep             = System.IO.Path.DirectorySeparatorChar;
            String dirName       = LongPath.CreateDir(TraceDir + sep + GetType().FullName);
            String formattedName = dirName + sep + typeName + ".txt";
            try
            {
                // Create a file with generic write access
                SafeFileHandle fileHandle = LongPath.CreateFile(formattedName, FileAccess.ReadWrite, FileShare.ReadWrite, FileMode.OpenOrCreate);
                try
                {
                    using (FileStream outputFile = new FileStream(fileHandle, FileAccess.Write))
#endif
                {
                    System.IO.StreamWriter fw = new System.IO.StreamWriter(outputFile);
                    try
                    {
                        fw.Write(bytecodeOutput);
                    }
                    finally
                    {
                        fw.Close();
                    }
                }
#if SILVERLIGHT
#else
            }
            finally
            {
                fileHandle.Close();
            }
#endif
            }
            catch (Exception e)
            {
                throw RuntimeExceptionUtil.Mask(e, "Error occurred while trying to write to '" + formattedName + "'");
            }
        }
        /// <summary>
        /// Creates all directories and subdirectories in the specified path unless they already exist.
        /// </summary>
        /// <param name="path">The directory to create.</param>
        public static void CreateDirectory(string path)
        {
            try
            {
                path = DMLibTestConstants.SupportUNCPath ?
                       LongPath.GetFullPath(LongPath.ToUncPath(path)) :
                       LongPath.GetFullPath(path);
            }
            catch (Exception)
            { }

#if DOTNET5_4
            Directory.CreateDirectory(path);
#else
            LongPathDirectory.CreateDirectory(path);
#endif
        }
コード例 #24
0
 private static void LoadConfigurations(string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         path = LongPath.Combine(AssemblyExtensions.ApplicationDirectory, "WebServiceLibraries");
     }
     try
     {
         var allFiles = LongPathDirectory.EnumerateFiles(path, "*.config", System.IO.SearchOption.AllDirectories);
         foreach (var file in allFiles)
         {
             try
             {
                 var info    = WebServiceRegistrationInfo.LoadFromFile(file);
                 var gllName = LongPath.ChangeExtension(file, ".gll");
                 if (info.RegisteredVIs != null)
                 {
                     foreach (var item in info.RegisteredVIs)
                     {
                         if (item.Type == WebServiceType.HttpGetMethod)
                         {
                             var registeredExecutable = new RegisteredHttpGetVI(
                                 _connectionManager,
                                 _httpServer,
                                 gllName,
                                 item.VIComponentName,
                                 item.UrlPath);
                             _connectionManager.AddConnectionType(registeredExecutable);
                         }
                     }
                 }
             }
             catch (Exception e)
             {
                 Log.LogError(0, e, $"Failed to load configuration: {file}");
             }
         }
     }
     catch (Exception enumerateException)
     {
         Log.LogError(0, enumerateException, "Failed to enumerate configuration files");
     }
 }
コード例 #25
0
        public virtual void ExportFolder(Folder folder, string targetPath, bool recursive)
        {
            if (folder == null)
            {
                throw new ArgumentNullException(nameof(folder));
            }

            if (targetPath == null)
            {
                throw new ArgumentNullException(nameof(targetPath));
            }

            if (!LongPath.DirectoryExists(targetPath))
            {
                throw new ArgumentException("Invalid path.", nameof(targetPath));
            }

            _errorMessages.Clear();
            ExportFolderContent(folder, targetPath, recursive);
        }
        public static void GetFileProperties(string path, out DateTimeOffset?creationTime, out DateTimeOffset?lastWriteTime, out FileAttributes?fileAttributes
#if DOTNET5_4
                                             , bool isDirectory = false
#endif
                                             )
        {
            try
            {
                path = DMLibTestConstants.SupportUNCPath ?
                       LongPath.GetFullPath(LongPath.ToUncPath(path)) :
                       LongPath.GetFullPath(path);
            }
            catch (Exception)
            { }

#if DOTNET5_4
            LongPathFile.GetFileProperties(path, out creationTime, out lastWriteTime, out fileAttributes, isDirectory);
#else
            LongPathFile.GetFileProperties(path, out creationTime, out lastWriteTime, out fileAttributes);
#endif
        }
コード例 #27
0
        /// <inheritdoc />
        protected override async Task <int> RunAsync(IEnumerable <string> extraArguments, ProjectAndHostCreator projectAndHostCreator)
        {
            if (!LongPath.IsPathRooted(ProjectPath))
            {
                ProjectPath = LongPath.GetFullPath(LongPath.Combine(Environment.CurrentDirectory, ProjectPath));
            }

            Project project = await projectAndHostCreator.OpenProjectAsync(ProjectPath);

            CommandLineInterfaceApplication.WriteLineVerbose($"Opened project at {ProjectPath}");

            Envoy componentEnvoy = await ResolveComponentToBuildAsync(project);

            if (componentEnvoy == null)
            {
                return(1);
            }

            bool buildSucceeded = await LoadAndBuildComponentEnvoyAsync(componentEnvoy);

            return(buildSucceeded ? 0 : 1);
        }
コード例 #28
0
        public virtual void ExportList(List list, string targetPath)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            if (targetPath == null)
            {
                throw new ArgumentNullException(nameof(targetPath));
            }

            if (!LongPath.DirectoryExists(targetPath))
            {
                throw new ArgumentException("Invalid path.", nameof(targetPath));
            }

            _errorMessages.Clear();
            string listPath;

            WriteList(list, targetPath, out listPath);
        }
コード例 #29
0
        public bool ExportTo(string targetPath)
        {
            if (targetPath == null)
            {
                throw new ArgumentNullException(nameof(targetPath));
            }

            if (!LongPath.DirectoryExists(targetPath))
            {
                throw new ArgumentException("Invalid path.", nameof(targetPath));
            }

            _folder.Server.ShowMessageBoxOnError = false;
            try
            {
                DataExporter.ExportFolder(_folder, targetPath, true);
            }
            finally
            {
                _folder.Server.ShowMessageBoxOnError = true;
            }
            return(DataExporter.ErrorMessages.Count == 0);
        }
コード例 #30
0
        private string GetUniqueBlobFilePath(Blob blob, string blobsPath)
        {
            var i = 0;

            do
            {
                string path;
                if (i == 0)
                {
                    path = LongPath.Combine(blobsPath, blob.FileName);
                }
                else
                {
                    path = LongPath.Combine(blobsPath, string.Format("{0} ({1}){2}", blob.FileNameWithoutExtension, i, blob.FileExtension));
                }

                if (!LongPath.FileExists(path))
                {
                    return(path);
                }

                i++;
            }while (true);
        }