当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.StartsWith方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.StartsWith方法的具体用法?C# DirectoryInfo.StartsWith怎么用?C# DirectoryInfo.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.StartsWith方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Find

 public static BackupRestore Find(string Root, string Product, string Id)
 {
     var Result = default(BackupRestore);
     var Dir = Path.Combine(Root, BackupDirectory);
     var FullId = GetFullId(Product, Id);
     if (Directory.Exists(Dir))
     {
         var DirList = new List<DirectoryTag>();
         foreach (var DateItem in Directory.GetDirectories(Dir))
         {
             DateTime date;
             var DateName = new DirectoryInfo(DateItem).Name;
             if (DateTime.TryParseExact(DateName, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
             {
                 foreach (var VersionItem in Directory.GetDirectories(DateItem))
                 {
                     var VersionName = new DirectoryInfo(VersionItem).Name;
                     if (VersionName.StartsWith(FullId, StringComparison.InvariantCultureIgnoreCase))
                     {
                         Version BckpVersion;
                         var StrVersion = VersionName.Substring(FullId.Length);
                         if (Version.TryParse(StrVersion, out BckpVersion))
                             DirList.Add(new DirectoryTag { Name = VersionItem, Date = date, Version = BckpVersion });
                     }
                 }
             }
         }
         var ByVersion = from i in DirList where i.Version == (from v in DirList select v.Version).Max() select i;
         var ByDate = from i in ByVersion where i.Date == (from v in ByVersion select v.Date).Max() select i;
         var SrcTag = ByDate.First();
         Result = new BackupRestore { Id = Id, Root = GetComponentRoot(SrcTag, Id), BackupFile = Path.Combine(SrcTag.Name, AppZip), BackupMainConfigFile = GetMainConfig(SrcTag) };
     }
     return Result;
 }
开发者ID:lwhitelock,项目名称:Websitepanel,代码行数:34,代码来源:BackupRestore.cs

示例2: Deploy

        public void Deploy(Deployment deployment)
        {
            var existingDeployment = _deploymentInstances.SingleOrDefault(x => x.DeploymentId == deployment.Id);
            if (existingDeployment != null)
            {
                if (existingDeployment.RollbackCompleted) // Deployment have been rolled back by other server  already.
                {
                    return;
                }

                _deploymentInstances.RemoveAll(x => x.DeploymentId == deployment.Id);
            }

            var sw = new Stopwatch();
            var fullSw = new Stopwatch();

            fullSw.Start();
            SendResponse(deployment.Id, DeploymentResponseType.DeploymentRequestReceived,  "Received deployment request.");
            IisSite site = SiteManager.GetSiteByName(deployment.SiteName);
            var originalPath = site.SitePath;

            var rootPath = site.SitePath;
            var directoryName = new DirectoryInfo(rootPath).Name;

            if (directoryName.StartsWith("servant-"))
            {
                rootPath = rootPath.Substring(0, rootPath.LastIndexOf(@"\", System.StringComparison.Ordinal));
            }
            var newPath = Path.Combine(rootPath, "servant-" + deployment.Guid);

            var fullPath = Environment.ExpandEnvironmentVariables(newPath);
            Directory.CreateDirectory(fullPath);
            SendResponse(deployment.Id, DeploymentResponseType.CreateDirectory, "Created directory: " + fullPath);

            sw.Start();
            var zipFile = DownloadUrl(deployment.Url);
            sw.Stop();
            SendResponse(deployment.Id, DeploymentResponseType.PackageDownload, string.Format("Completed package download in {0} seconds.", sw.Elapsed.TotalSeconds));

            var fastZip = new FastZip();
            var stream = new MemoryStream(zipFile);
            fastZip.ExtractZip(stream, fullPath, FastZip.Overwrite.Always, null, null, null, true, true);
            SendResponse(deployment.Id, DeploymentResponseType.PackageUnzipping, "Completed package extracting.");

            site.SitePath = newPath;
            SiteManager.UpdateSite(site);
            if (site.ApplicationPoolState == InstanceState.Started)
            {
                SiteManager.RecycleApplicationPool(site.ApplicationPool);
            }
            fullSw.Stop();

            SendResponse(deployment.Id, DeploymentResponseType.ChangeSitePath, string.Format("Changed site path to {0}. Deployment completed in {1} seconds.", fullPath, fullSw.Elapsed.TotalSeconds));

            var rollbackCompleted = false;
            if (deployment.WarmupAfterDeploy)
            {
                System.Threading.Thread.Sleep(1000); // Waits for IIS to complete
                var warmupResult = Warmup(site, deployment.WarmupUrl);
                SendResponse(deployment.Id, DeploymentResponseType.WarmupResult, Json.SerializeToString(warmupResult));
                var msg = warmupResult == null ? "Could not contact IIS site" : string.Format("Site locally returned HTTP {0} {1}.", (int) warmupResult.StatusCode, warmupResult.StatusCode);

                SendResponse(deployment.Id, DeploymentResponseType.Warmup, msg, warmupResult.StatusCode == HttpStatusCode.OK);

                if (deployment.RollbackOnError)
                {
                    // Roll-back if not 200 OK
                    if (warmupResult.StatusCode != HttpStatusCode.OK)
                    {
                        site.SitePath = originalPath;
                        SiteManager.UpdateSite(site);
                        if (site.ApplicationPoolState == InstanceState.Started)
                        {
                            SiteManager.RecycleApplicationPool(site.ApplicationPool);
                        }
                        rollbackCompleted = true;
                        Warmup(site, deployment.WarmupUrl);

                        SendResponse(deployment.Id, DeploymentResponseType.Rollback, string.Format("Rollback completed. Site path is now: {0}.", originalPath));
                    }
                }
            }

            _deploymentInstances.Add(new DeploymentInstance() { DeploymentId = deployment.Id, DeploymentGuid = deployment.Guid, NewPath = newPath, OriginalPath = originalPath, RollbackCompleted = rollbackCompleted, IisSiteId = site.IisId });
        }
开发者ID:jango2015,项目名称:servant-agent,代码行数:85,代码来源:Deployer.cs

示例3: ApiModule


//.........这里部分代码省略.........
                return Response.AsJson(site);
            };

            Post["/sites/{id}/recycle/"] = p =>
            {
                var id = (int?)p.id;

                if (!id.HasValue)
                {
                    return new NotFoundResponse();
                }

                Site site = SiteManager.GetSiteById(p.Id);
                SiteManager.RecycleApplicationPoolBySite(site.IisId);
                return Response.AsJson(site);
            };

            Post["/sites/create/"] = p =>
            {
                Site site = serializer.Deserialize<Site>(Request.Form.Data);
                var result = SiteManager.CreateSite(site);

                return Response.AsText(result.IisSiteId.ToString());
            };

            Post["/sites/update/"] = p =>
            {
                string name = Request.Query.Name;

                if (name == null)
                {
                    return new NotFoundResponse();
                }

                Site site = SiteManager.GetSiteByName(name);
                var postedSite = serializer.Deserialize<Site>(Request.Form.Data);

                site.ApplicationPool = postedSite.ApplicationPool;
                site.Name = postedSite.Name;
                site.SiteState = postedSite.SiteState;
                site.Bindings = postedSite.Bindings;
                site.LogFileDirectory = postedSite.LogFileDirectory;
                site.SitePath = postedSite.SitePath;
                site.Bindings = postedSite.Bindings;

                SiteManager.UpdateSite(site);

                return Response.AsJson(site);
            };

            Post["/sites/{id}/delete/"] = p =>
            {
                var id = (int?)p.id;

                if (!id.HasValue)
                {
                    return new NotFoundResponse();
                }
                Site site = SiteManager.GetSiteById(p.Id);

                SiteManager.DeleteSite(site.IisId);

                return Response.AsJson(new { Success = true});
            };

            Post["/sites/{id}/deploy/"] = p =>
            {
                var id = (int?) p.id;
                if (!id.HasValue)
                {
                    return Response.AsText("IIS Site ID is missing.").WithStatusCode(HttpStatusCode.BadRequest);
                }

                if (!Request.Files.Any())
                {
                    return Response.AsText("Zipfile is missing.").WithStatusCode(HttpStatusCode.BadRequest);
                }

                Site site = SiteManager.GetSiteById(p.Id);
                var rootPath = site.SitePath;
                var directoryName = new DirectoryInfo(rootPath).Name;
                if (directoryName.StartsWith("servant-"))
                {
                    rootPath = Directory.GetParent(rootPath).FullName;
                }

                var newPath = Path.Combine(rootPath, "servant-" + Path.GetFileNameWithoutExtension(Request.Files.First().Name));
                Directory.CreateDirectory(newPath);

                var zip = Request.Files.First().Value;
                var fastZip = new FastZip();
                fastZip.ExtractZip(zip, newPath, FastZip.Overwrite.Always, null, null, null, true, true);

                site.SitePath = newPath;
                SiteManager.UpdateSite(site);

                return Response.AsJson(site);
            };
            #endregion
        }
开发者ID:ohde,项目名称:servant,代码行数:101,代码来源:ApiModule.cs

示例4: CheckUntrackedDirectory

        private void CheckUntrackedDirectory(string path, string relative_path)
        {
            var files = Directory.GetFiles(path);
            foreach (string file in files)
                CheckUntrackedFile(new FileInfo(file), relative_path);

            var dirs = Directory.GetDirectories(path);
            foreach (string dir in dirs)
            {
                var dirname = new DirectoryInfo(dir).Name;
                if (dirname.StartsWith(".git"))
                    continue;

                CheckUntrackedDirectory(dir, (relative_path.Length == 0 ? dirname : relative_path + "/" + dirname));
            }
        }
开发者ID:jagregory,项目名称:GitSharp,代码行数:16,代码来源:IndexDiff.cs

示例5: IsIgnoredDirectory

        private static bool IsIgnoredDirectory(string sourcePath)
        {
            var sourcePathLowerAbsolute = new DirectoryInfo(sourcePath).FullName.ToLower();
            var apiPath =
                new DirectoryInfo(
                    Path.Combine(
                        Directory.GetCurrentDirectory(),
                        Settings.Default.SourceDirectory,
                        Settings.Default.APIFolderLocation)).FullName.ToLower();

            return !sourcePathLowerAbsolute.StartsWith(apiPath)
                   && IgnoredFolders.Any(e => sourcePathLowerAbsolute.EndsWith(Path.DirectorySeparatorChar + e));
        }
开发者ID:Art1stical,项目名称:AHRUnrealEngine,代码行数:13,代码来源:Program.cs


注:本文中的System.IO.DirectoryInfo.StartsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。