private static async Task UploadAppToLocalPath(this IServiceFabricClient Client, string imageStore, string imageStorep, ServiceFabricApplicationSpec app)
        {
            var name = app.Manifest.ApplicationTypeName + "." + app.Manifest.ApplicationTypeVersion;

            try
            {
                Symlink.CreateSymbolicLink(Path.Combine(imageStorep, name), app.PackagePath, SymbolicLink.Directory);
                await Client.ApplicationTypes.ProvisionApplicationTypeAsync(new ProvisionApplicationTypeDescription(name), 240, CancellationToken.None);

                Symlink.DeleteIfExists(Path.Combine(imageStorep, name));
            }
            catch (FileNotFoundException)
            {
                Symlink.DeleteIfExists(Path.Combine(imageStorep, name));
                await Client.UploadApp(imageStore, app);
            }
        }
        public static async Task <bool> CreateDiffPackage(this IServiceFabricClient Client, string packagePath, ILogger Logger = null)
        {
            var localAppManifest = FabricSerializers.AppManifestFromFile(Path.Combine(packagePath, "ApplicationManifest.xml"));
            var appTypes         = await Client.ApplicationTypes.GetApplicationTypeInfoListAsync();

            var appManifestTasks = appTypes.Data.Where(type => type.Name == localAppManifest.ApplicationTypeName).Select(type => Client.ApplicationTypes.GetApplicationManifestAsync(type.Name, type.Version));
            await Task.WhenAll(appManifestTasks);

            var    serverAppManifests = appManifestTasks.Select(task => FabricSerializers.AppManifestFromString(task.Result.Manifest)).ToList();
            string pkgPAth            = null;

            if (serverAppManifests.Any(serverAppManifest => serverAppManifest.ApplicationTypeVersion == localAppManifest.ApplicationTypeVersion))
            {
                Logger?.LogInfo($"Application {localAppManifest.ApplicationTypeName} {localAppManifest.ApplicationTypeVersion} is already provisioned");
                return(false);
            }

            foreach (var serverAppManifest in serverAppManifests)
            {
                foreach (var serviceImport in serverAppManifest.ServiceManifestImport)
                {
                    var localService = localAppManifest.ServiceManifestImport.FirstOrDefault(s => s.ServiceManifestRef.ServiceManifestName == serviceImport.ServiceManifestRef.ServiceManifestName);
                    if (localService != null && localService.ServiceManifestRef.ServiceManifestVersion == serviceImport.ServiceManifestRef.ServiceManifestVersion)
                    {
                        Logger?.LogInfo($"Service {localAppManifest.ApplicationTypeName}.{localService.ServiceManifestRef.ServiceManifestName} {localService.ServiceManifestRef.ServiceManifestVersion} is already provisioned");
                        foreach (var dir in Directory.GetDirectories(Path.Combine(packagePath, serviceImport.ServiceManifestRef.ServiceManifestName)))
                        {
                            Symlink.DeleteIfExists(dir);
                        }
                    }
                    else
                    {
                        var serverServiceManifest    = FabricSerializers.ServiceManifestFromString((await Client.ServiceTypes.GetServiceManifestAsync(serverAppManifest.ApplicationTypeName, serverAppManifest.ApplicationTypeVersion, serviceImport.ServiceManifestRef.ServiceManifestName)).Manifest);
                        var localServiceManifestPath = Path.Combine(packagePath, serviceImport.ServiceManifestRef.ServiceManifestName, "ServiceManifest.xml");
                        if (!File.Exists(localServiceManifestPath))
                        {
                            continue;
                        }
                        var localServiceManifest = FabricSerializers.ServiceManifestFromFile(localServiceManifestPath);

                        // Logger?.LogInfo($"{serverAppManifest.ApplicationTypeName}.{localService.ServiceManifestRef.ServiceManifestName} {localService.ServiceManifestRef.ServiceManifestVersion} not found on server, checking packages");
                        if (serverServiceManifest.CodePackage != null && localServiceManifest.CodePackage != null)
                        {
                            foreach (var package in serverServiceManifest.CodePackage.Where(sp => localServiceManifest.CodePackage.Any(lp => lp.Name == sp.Name && lp.Version == sp.Version)))
                            {
                                pkgPAth = Path.Combine(packagePath, localService.ServiceManifestRef.ServiceManifestName, package.Name);
                                if (Directory.Exists(pkgPAth))
                                {
                                    Logger?.LogInfo($"Deleting {localAppManifest.ApplicationTypeName}.{localService.ServiceManifestRef.ServiceManifestName}.{package.Name} {package.Version}");
                                    Symlink.DeleteIfExists(pkgPAth);
                                }
                            }
                        }

                        if (serverServiceManifest.ConfigPackage != null && localServiceManifest.ConfigPackage != null)
                        {
                            foreach (var package in serverServiceManifest.ConfigPackage.Where(sp => localServiceManifest.ConfigPackage.Any(lp => lp.Name == sp.Name && lp.Version == sp.Version)))
                            {
                                pkgPAth = Path.Combine(packagePath, localService.ServiceManifestRef.ServiceManifestName, package.Name);
                                if (Directory.Exists(pkgPAth))
                                {
                                    Logger?.LogInfo($"Deleting {localAppManifest.ApplicationTypeName}.{localService.ServiceManifestRef.ServiceManifestName}.{package.Name} {package.Version}");
                                    Symlink.DeleteIfExists(pkgPAth);
                                }
                            }
                        }

                        if (serverServiceManifest.DataPackage != null && localServiceManifest.DataPackage != null)
                        {
                            foreach (var package in serverServiceManifest.DataPackage.Where(sp => localServiceManifest.DataPackage.Any(lp => lp.Name == sp.Name && lp.Version == sp.Version)))
                            {
                                pkgPAth = Path.Combine(packagePath, localService.ServiceManifestRef.ServiceManifestName, package.Name);
                                if (Directory.Exists(pkgPAth))
                                {
                                    Logger?.LogInfo($"Deleting {localAppManifest.ApplicationTypeName}.{localService.ServiceManifestRef.ServiceManifestName}.{package.Name} {package.Version}");
                                    Symlink.DeleteIfExists(pkgPAth);
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }