Beispiel #1
0
        public IList <GameFileContainer> GetContainers(string path)
        {
            var fullPath = Path.Combine(path, RelativePath);

            var split = SearchPattern.Split(';');

            var result = new List <GameFileContainer>();

            if (Directory.Exists(fullPath))
            {
                foreach (var s in split)
                {
                    string[] searchResult;
                    if (TypeSearch == ContainerType.Folder)
                    {
                        searchResult = Directory.GetDirectories(fullPath, s,
                                                                RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                    }
                    else
                    {
                        searchResult = Directory.GetFiles(fullPath, s,
                                                          RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                    }

                    foreach (var f in searchResult)
                    {
                        var excluded = Exclusions.Any(exclusion => f.Contains(exclusion));

                        if (excluded)
                        {
                            continue;
                        }

                        var container = new GameFileContainer
                        {
                            Path         = PathHelper.GetRelativePath(path, f).Substring(2),
                            Type         = TypeSearch,
                            FileSearches = FileSearches
                        };

                        result.Add(container);
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        public string[] GetFiles(string path)
        {
            var result = new List <string>();

            var fullPath = Path.GetFullPath(Path.Combine(path, RelativePath));

            if (IsWildcard)
            {
                var split = SearchPattern.Split(';');

                foreach (var s in split)
                {
                    var files = Directory.GetFiles(fullPath, s,
                                                   RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

                    foreach (var file in files)
                    {
                        var excluded = Exclusions.Any(x => file.Contains(x));
                        if (!excluded)
                        {
                            result.Add(file);
                        }
                    }
                }
            }
            else
            {
                var files = Directory.GetFiles(fullPath, SearchPattern,
                                               RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

                foreach (var file in files)
                {
                    var excluded = Exclusions.Any(x => file.Contains(x));
                    if (!excluded)
                    {
                        result.Add(file);
                    }
                }
            }

            return(result.ToArray());
        }
Beispiel #3
0
        RowReadHierarchical[] Files(DirectoryInfo di, IRowReceive parent)
        {
            var ret = new List <RowReadHierarchical>();

            foreach (var searchSplitPattern in SearchPattern.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                foreach (var file in di.EnumerateFiles(searchSplitPattern))
                {
                    var item = new RowReadHierarchical();
                    item.Values.Add("Name", file.Name);
                    item.Values.Add("FullName", file.FullName);
                    item.Values.Add("RowType", "file");
                    item.Values.Add("CreationTimeUtc", file.CreationTimeUtc);
                    item.Values.Add("LastAccessTimeUtc", file.LastAccessTimeUtc);
                    item.Values.Add("LastWriteTimeUtc", file.LastWriteTimeUtc);
                    item.Parent = parent as IRowReceiveHierarchicalParent;
                    ret.Add(item);
                }
            }
            return(ret.ToArray());
        }
        protected override void ProcessRecord()
        {
            var missedWebResourcesCount = 0;
            var resourceFiles           = new HashSet <string>();
            var patterns = (string.IsNullOrWhiteSpace(SearchPattern)) ? new string[1] {
                "*"
            } :
            SearchPattern.Split(',');

            foreach (var pattern in patterns)
            {
                WriteVerbose($"Processing pattern {pattern}...");

                Directory.GetFiles(Path, pattern.Trim(), SearchOption.AllDirectories).ToList()
                .ForEach((item) => resourceFiles.Add(item));
            }

            if (resourceFiles.Count == 0)
            {
                WriteVerbose($"There are no files in folder '{Path}' matching patterns {SearchPattern}");
                return;
            }
            else
            {
                WriteVerbose($"Found {resourceFiles.Count} resource files.");
            }

            using (var context = new CIContext(OrganizationService))
            {
                WriteVerbose($"Retrieving web resources from CRM...");
                var query = from resource in context.WebResourceSet
                            select resource;
                var solutionId = GetSolutionId(context, SolutionName);
                if (!solutionId.Equals(Guid.Empty))
                {
                    query = from resource in context.WebResourceSet
                            join sol in context.SolutionComponentSet on resource.Id equals sol.ObjectId
                            where sol.SolutionId.Equals(solutionId)
                            select resource;
                }

                var allWebResources = query.ToList();
                WriteVerbose($"Found {allWebResources.Count}");

                var importexportxml = new StringBuilder();
                var webResource     = default(WebResource);
                foreach (var resourceFile in resourceFiles)
                {
                    WriteVerbose($"Processing file: {System.IO.Path.GetFileName(resourceFile)}");
                    try
                    {
                        webResource = allWebResources.Single(CompareCondition(resourceFile));
                        WriteVerbose($"Found web resource: {webResource.Name}");
                    }
                    catch (Exception ex)
                    {
                        missedWebResourcesCount++;
                        WriteWarning($"Cannot process {resourceFile}: {ex.Message}");
                        continue;
                    }

                    // update in context
                    var fileContent = Convert.ToBase64String(File.ReadAllBytes(resourceFile));
                    if (webResource.Content?.GetHashCode() != fileContent.GetHashCode())
                    {
                        webResource.Content = fileContent;
                        //context.UpdateObject(webResource);

                        // update web resource then add to a solution.
                        UpdateRequest update = new UpdateRequest
                        {
                            Target = webResource
                        };
                        update.Parameters.Add("SolutionUniqueName", SolutionName);

                        context.Execute(update);

                        // add id to publish xml
                        if (Publish)
                        {
                            importexportxml.Append($"<webresource>{webResource.Id}</webresource>");
                        }
                    }
                }

                // Update
                WriteVerbose("Saving changes...");
                context.SaveChanges();

                // Publish
                if (Publish)
                {
                    WriteVerbose("Publishing web resources...");
                    PublishXmlRequest req = new PublishXmlRequest()
                    {
                        ParameterXml = $"<importexportxml><webresources>{importexportxml.ToString()}</webresources></importexportxml>"
                    };
                    OrganizationService.Execute(req);
                }

                WriteObject($"{resourceFiles.Count - missedWebResourcesCount} out of {resourceFiles.Count} web resources were processed");

                if (FailIfWebResourceNotFound && missedWebResourcesCount > 0)
                {
                    ThrowTerminatingError(new ErrorRecord(
                                              new RuntimeException($"{missedWebResourcesCount} web resources were not found"),
                                              "", ErrorCategory.ObjectNotFound, null));
                }
            }
        }