Exemple #1
0
        public static FileMap FromTempFile(int length)
        {
            FileStream stream = new FileStream(Path.GetTempFileName(), FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 8, FileOptions.RandomAccess | FileOptions.DeleteOnClose);

            try { FileMap m = FromStreamInternal(stream, FileMapProtect.ReadWrite, 0, length); stream.Dispose(); return(m); }
            catch (Exception x) { stream.Dispose(); throw; }
        }
 private void GetOutputSatellites(PublishInfo[] publishInfos, ref List<ITaskItem> assemblyList)
 {
     FileMap map = new FileMap();
     if (this.satelliteAssemblies != null)
     {
         foreach (ITaskItem item in this.satelliteAssemblies)
         {
             item.SetMetadata("AssemblyType", "Satellite");
             map.Add(item, true);
         }
     }
     foreach (PublishInfo info in publishInfos)
     {
         string str = info.key + ".dll";
         MapEntry entry = map[str];
         if (entry != null)
         {
             entry.publishInfo = info;
         }
         else
         {
             base.Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", new object[] { info.key });
         }
     }
     foreach (MapEntry entry2 in (IEnumerable) map)
     {
         if (entry2.publishInfo == null)
         {
             entry2.publishInfo = new PublishInfo();
         }
         CultureInfo itemCulture = GetItemCulture(entry2.item);
         PublishFlags flags = PublishFlags.GetSatelliteFlags(entry2.publishInfo.state, itemCulture, this.targetCulture, this.includeAllSatellites);
         if ((flags.IsPublished && string.Equals(entry2.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase)) && this.SigningManifests)
         {
             this.canPublish = false;
         }
         if (flags.IsPublished)
         {
             assemblyList.Add(CreateAssemblyItem(entry2.item, entry2.publishInfo.group, entry2.publishInfo.targetPath, entry2.publishInfo.includeHash));
         }
         else if (flags.IsPrerequisite)
         {
             assemblyList.Add(CreatePrerequisiteItem(entry2.item));
         }
     }
 }
 private ITaskItem[] GetOutputFiles(PublishInfo[] publishInfos)
 {
     List<ITaskItem> list = new List<ITaskItem>();
     FileMap map = new FileMap();
     if (this.Files != null)
     {
         foreach (ITaskItem item in this.Files)
         {
             map.Add(item, true);
         }
     }
     if (this.ExtraFiles != null)
     {
         foreach (ITaskItem item2 in this.ExtraFiles)
         {
             map.Add(item2, false);
         }
     }
     foreach (PublishInfo info in publishInfos)
     {
         MapEntry entry = map[info.key];
         if (entry != null)
         {
             entry.publishInfo = info;
         }
         else
         {
             base.Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", new object[] { info.key });
         }
     }
     foreach (MapEntry entry2 in (IEnumerable) map)
     {
         if (entry2.publishInfo == null)
         {
             entry2.publishInfo = new PublishInfo();
         }
         string extension = Path.GetExtension(entry2.item.ItemSpec);
         PublishFlags flags = PublishFlags.GetFileFlags(entry2.publishInfo.state, extension, entry2.includedByDefault);
         if ((flags.IsPublished && string.Equals(entry2.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase)) && this.SigningManifests)
         {
             this.canPublish = false;
         }
         if (flags.IsPublished)
         {
             list.Add(CreateFileItem(entry2.item, entry2.publishInfo.group, entry2.publishInfo.targetPath, entry2.publishInfo.includeHash, flags.IsDataFile));
         }
     }
     return list.ToArray();
 }
        private void GetOutputSatellites(PublishInfo[] publishInfos, ref List<ITaskItem> assemblyList)
        {
            FileMap satelliteMap = new FileMap();

            if (_satelliteAssemblies != null)
                foreach (ITaskItem item in _satelliteAssemblies)
                {
                    item.SetMetadata("AssemblyType", "Satellite");
                    satelliteMap.Add(item, true);
                }

            // Apply PublishInfo state from PublishFile items...
            foreach (PublishInfo publishInfo in publishInfos)
            {
                string key = publishInfo.key + ".dll";
                MapEntry entry = satelliteMap[key];
                if (entry != null)
                    entry.publishInfo = publishInfo;
                else
                    Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", publishInfo.key);
            }

            // Go through the AssemblyMap and determine which items get added to ouput SatelliteList based
            // on computed PublishFlags for each item...
            foreach (MapEntry entry in satelliteMap)
            {
                // If PublishInfo didn't come from a PublishFile item, then construct PublishInfo from the item
                if (entry.publishInfo == null)
                {
                    entry.publishInfo = new PublishInfo();
                }

                CultureInfo satelliteCulture = GetItemCulture(entry.item);
                PublishFlags flags = PublishFlags.GetSatelliteFlags(entry.publishInfo.state, satelliteCulture, _targetCulture, _includeAllSatellites);

                if (flags.IsPublished &&
                    string.Equals(entry.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase) &&
                    SigningManifests == true)
                    _canPublish = false;

                if (flags.IsPublished)
                {
                    assemblyList.Add(CreateAssemblyItem(entry.item, entry.publishInfo.group, entry.publishInfo.targetPath, entry.publishInfo.includeHash));
                }
                else if (flags.IsPrerequisite)
                {
                    assemblyList.Add(CreatePrerequisiteItem(entry.item));
                }
            }
        }
        private void MakeDirectories(FileMap script)
        {
            using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024))
            {
                stream.WriteLine(string.Format("sudo bash {0} \"{1}\"", script.RemotePath, Settings.RemoteServerDir));

                var output = stream.Expect(Settings.InstallationSuccessPattern);

                InstallationProgress.ProgressText += output;
            }
        }
        private ITaskItem[] GetOutputFiles(PublishInfo[] publishInfos)
        {
            List<ITaskItem> fileList = new List<ITaskItem>();
            FileMap fileMap = new FileMap();

            // Add all input Files to the FileMap, flagging them to be published by default...
            if (Files != null)
                foreach (ITaskItem item in Files)
                    fileMap.Add(item, true);

            // Add all input ExtraFiles to the FileMap, flagging them to NOT be published by default...
            if (ExtraFiles != null)
                foreach (ITaskItem item in ExtraFiles)
                    fileMap.Add(item, false);

            // Apply PublishInfo state from PublishFile items...
            foreach (PublishInfo publishInfo in publishInfos)
            {
                MapEntry entry = fileMap[publishInfo.key];
                if (entry != null)
                    entry.publishInfo = publishInfo;
                else
                    Log.LogWarningWithCodeFromResources("ResolveManifestFiles.PublishFileNotFound", publishInfo.key);
            }

            // Go through the FileMap and determine which items get added to ouput FileList based
            // on computed PublishFlags for each item...
            foreach (MapEntry entry in fileMap)
            {
                // If PublishInfo didn't come from a PublishFile item, then construct PublishInfo from the item
                if (entry.publishInfo == null)
                    entry.publishInfo = new PublishInfo();

                string fileExtension = Path.GetExtension(entry.item.ItemSpec);
                PublishFlags flags = PublishFlags.GetFileFlags(entry.publishInfo.state, fileExtension, entry.includedByDefault);

                if (flags.IsPublished &&
                    string.Equals(entry.publishInfo.includeHash, "false", StringComparison.OrdinalIgnoreCase) &&
                    SigningManifests == true)
                    _canPublish = false;

                if (flags.IsPublished)
                    fileList.Add(CreateFileItem(entry.item, entry.publishInfo.group, entry.publishInfo.targetPath, entry.publishInfo.includeHash, flags.IsDataFile));
            }

            return fileList.ToArray();
        }
        private void InstallServer(InstallationProgressStep progressStep, FileMap runServerScript, string serverScriptParam = "")
        {
            InstallationProgress.Step = progressStep;
            CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

            using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024))
            {
                stream.WriteLine(!string.IsNullOrEmpty(serverScriptParam)
                                     ? string.Format("sudo bash {0} \"{1}\"", runServerScript.RemotePath, serverScriptParam)
                                     : string.Format("sudo bash {0}", runServerScript.RemotePath));

                var output = stream.Expect(Settings.InstallationStopPattern);

                if (output.Contains(Settings.InstallationSuccessPattern))
                    InstallationProgress.ProgressText += output;

                if (output.Contains(Settings.InstallationErrorPattern))
                    throw new Exception(output);
            }
        }
        private OsInfo GetOsInfo(FileMap script)
        {
            InstallationProgress.Step = InstallationProgressStep.GetOsInfo;
            CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

            using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024))
            {
                stream.WriteLine(string.Format("sudo bash {0}", script.RemotePath));

                var output = stream.Expect(Settings.InstallationStopPattern);

                if (output.Contains(Settings.InstallationSuccessPattern))
                    InstallationProgress.ProgressText += output;

                if (output.Contains(Settings.InstallationErrorPattern))
                    throw new Exception(output);
            }

            var osInfo = new OsInfo
                                {
                                    Dist = GetTerminalParam(InstallationProgress.ProgressText, "DIST"),
                                    Ver = GetTerminalParam(InstallationProgress.ProgressText, "REV"),
                                    Type = GetTerminalParam(InstallationProgress.ProgressText, "MACH"),
                                    Kernel = GetTerminalParam(InstallationProgress.ProgressText, "KERNEL")
                                };

            return osInfo;
        }
        private void CreateDirectories()
        {
            var tmpScript = new FileMap("~/Executables/tools/make-dir.sh", "./");

            UploadFile(tmpScript);

            MakeDirectories(tmpScript);

            SftpClient.DeleteFile(tmpScript.RemotePath);
        }
        private void CheckPreviousVersion(FileMap script)
        {
            using (var stream = SshClient.CreateShellStream("terminal", 150, 24, 800, 600, 1024))
            {
                stream.WriteLine(string.Format("bash {0}", script.RemotePath));

                var output = stream.Expect(Settings.InstallationStopPattern);

                if (output.Contains(Settings.InstallationSuccessPattern))
                {
                    InstallationComponents = new InstallationComponentsModel
                    {
                        MailServer = !string.IsNullOrEmpty(GetTerminalParam(output, "MAIL_SERVER_ID")),
                        DocumentServer = !string.IsNullOrEmpty(GetTerminalParam(output, "DOCUMENT_SERVER_ID")),
                        CommunityServer = !string.IsNullOrEmpty(GetTerminalParam(output, "COMMUNITY_SERVER_ID"))
                    };

                    InstallationProgress.ProgressText += output;
                }

                if (output.Contains(Settings.InstallationErrorPattern))
                    throw new Exception(output);
            }

            CacheHelper.SetInstalledComponents(UserId, InstallationComponents.IsEmpty ? null : InstallationComponents);
        }
        public InstallationComponentsModel Connect()
        {
            var tmpCheckPreviousVersionScript = new FileMap("~/Executables/tools/check-previous-version.sh", "./");

            UploadFile(tmpCheckPreviousVersionScript);

            CheckPreviousVersion(tmpCheckPreviousVersionScript);

            SftpClient.DeleteFile(tmpCheckPreviousVersionScript.RemotePath);

            return CacheHelper.GetInstalledComponents(UserId);
        }