public static XmlDocument GetPackageXml(this List<SalesforceFileProxy> fileProxies)
        {
            // save a mater package xml with all types
            var grouped = fileProxies
                            .Where(w => !String.IsNullOrWhiteSpace(w.FullName))
                            .GroupBy(g => g.Type)
                            .Where(gw => gw.Key.ToLowerInvariant() != "package" && gw.Key.ToLowerInvariant() != "zip")
                            .Select(s => new PackageTypeEntity
                            {
                                Name = s.Key,
                                Members = s.Select(sm => sm.FullName).ToArray()
                            }).ToArray();

            var pe = new PackageEntity { Version = "29.0", Types = grouped };

            return pe.GetXml();
        }
        public static XmlDocument GetPackageXml(this List <SalesforceFileProxy> fileProxies)
        {
            // save a mater package xml with all types
            var grouped = fileProxies
                          .Where(w => !String.IsNullOrWhiteSpace(w.FullName))
                          .GroupBy(g => g.Type)
                          .Where(gw => gw.Key.ToLowerInvariant() != "package" && gw.Key.ToLowerInvariant() != "zip")
                          .Select(s => new PackageTypeEntity
            {
                Name    = s.Key,
                Members = s.Select(sm => sm.FullName).ToArray()
            }).ToArray();

            var pe = new PackageEntity {
                Version = "29.0", Types = grouped
            };

            return(pe.GetXml());
        }
        public string Deploy(string folder, DeployOptions options)
        {
            if (!Directory.Exists(folder))
            {
                throw new DirectoryNotFoundException();
            }

            var staticResourceFolder = Path.Combine(folder, "package\\staticresources");

            if (!Directory.Exists(staticResourceFolder))
            {
                throw new DirectoryNotFoundException("Couldn't find static resources subfolder under package folder.");
            }

            var directories = Directory.EnumerateDirectories(staticResourceFolder);

            IList <IDeployableItem> members = new List <IDeployableItem>();

            foreach (var directory in directories)
            {
                var      splits  = directory.Split('\\');
                var      zipName = splits[splits.Length - 1];
                string[] files   = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories);

                var directoryPlusZipName = Path.Combine(staticResourceFolder, zipName);

                using (ZipFile zip = new ZipFile())
                {
                    foreach (var file in files)
                    {
                        var zipFileNamePlusDirectory = file.Replace(directoryPlusZipName, String.Empty);
                        var zipDirectory             = Path.GetDirectoryName(zipFileNamePlusDirectory);
                        zip.AddFile(file, zipDirectory);
                    }

                    MemoryStream memoryStream = new MemoryStream();
                    zip.Save(memoryStream);

                    members.Add(new StaticResourceDeployableItem
                    {
                        FileBody = memoryStream.ToArray(),
                        FileName = String.Format("{0}\\{1}.resource", directory, zipName),
                        FileNameWithoutExtension = String.Format("{0}", zipName)
                    });

                    XmlOutput xo = new XmlOutput()
                                   .XmlDeclaration()
                                   .Node("StaticResource").Attribute("xmlns", "http://soap.sforce.com/2006/04/metadata").Within()
                                   .Node("cacheControl").InnerText("Public")
                                   .Node("contentType").InnerText("application/zip").EndWithin();

                    members.Add(new StaticResourceDeployableItem
                    {
                        FileBody = System.Text.Encoding.Default.GetBytes(xo.GetOuterXml()),
                        FileName = String.Format("{0}\\{1}.resource-meta.xml", directory, zipName),
                        FileNameWithoutExtension = String.Format("{0}.resource-meta.xml", zipName),
                        AddToPackage             = false
                    });
                }
            }

            PackageEntity pe = new PackageEntity
            {
                Types = new[]
                {
                    new PackageTypeEntity
                    {
                        Members = members.Where(w => w.AddToPackage).Select(s => s.FileNameWithoutExtension).ToArray(),
                        Name    = "StaticResource"
                    }
                },
                Version = "29.0"
            };

            var zipFile = UnzipPackageFilesHelper.ZipObjectsForDeploy(members, pe.GetXml().OuterXml);

            SalesforceFileProcessing.SaveByteArray(String.Format("{0}\\package_{1}.zip", folder, Guid.NewGuid()), zipFile);

            var id = Context.MetadataServiceAdapter.Deploy(zipFile, options).id;

            return(id);
        }