コード例 #1
0
ファイル: PackageManagerImpl.cs プロジェクト: virmitio/coapp
 public Task GetAtomFeed(IEnumerable<CanonicalName> canonicalNames)
 {
     var response = Event<GetResponseInterface>.RaiseFirst();
     var feed = new AtomFeed();
     var pkgs = canonicalNames.Select(each => SearchForPackages(each).FirstOrDefault()).Where(each => null != each);
     feed.Add(pkgs);
     response.AtomFeedText(feed.ToString());
     return FinishedSynchronously;
 }
コード例 #2
0
        private void Create()
        {
            Feed = new AtomFeed();
            AtomFeed originalFeed = null;

            if( !string.IsNullOrEmpty(_input) ) {
                Logger.Message("Loading existing feed.");
                if( _input.IsWebUrl()) {
                    var inputFilename = "feed.atom.xml".GenerateTemporaryFilename();

                    RemoteFile.GetRemoteFile(_input, inputFilename).Get(new RemoteFileMessages() {
                        Completed = (uri) => { },
                        Failed = (uri) => { inputFilename.TryHardToDelete(); },
                        Progress = (uri, progress) => { }
                    }).Wait();

                    if( !File.Exists(inputFilename) ) {
                        throw new ConsoleException("Failed to get input feed from '{0}' ", _input);
                    }
                    originalFeed = AtomFeed.LoadFile(inputFilename);
                }
                else {
                    originalFeed = AtomFeed.LoadFile(_input);
                }
            }

            if( originalFeed != null ) {
                Feed.Add(originalFeed.Items.Where(each => each is AtomItem).Select(each => each as AtomItem));
            }

            Logger.Message("Selecting local packages");
            var files = _packages.FindFilesSmarter();

            _pm.GetPackages(files, null, null, false, null, null, null, null, false, null, null, _messages).ContinueWith((antecedent) => {
                var packages = antecedent.Result;

                foreach (var pkg in packages) {
                    _pm.GetPackageDetails(pkg.CanonicalName, _messages).Wait();

                    if (!string.IsNullOrEmpty(pkg.PackageItemText)) {
                        var item = SyndicationItem.Load<AtomItem>(XmlReader.Create(new StringReader(pkg.PackageItemText)));

                        var feedItem = Feed.Add(item);

                        // first, make sure that the feeds contains the intended feed location.
                        if( feedItem.Model.Feeds == null ) {
                            feedItem.Model.Feeds  = new List<Uri>();
                        }

                        if( !feedItem.Model.Feeds.Contains(_feedLocation) ) {
                            feedItem.Model.Feeds.Insert(0, _feedLocation);
                        }

                        var location = new Uri(_baseUrl, Path.GetFileName(pkg.LocalPackagePath));

                        if (feedItem.Model.Locations== null) {
                            feedItem.Model.Locations = new List<Uri>();
                        }

                        if (!feedItem.Model.Locations.Contains(location)) {
                            feedItem.Model.Locations.Insert(0, location);
                        }

                    } else {
                        throw new ConsoleException("Missing ATOM data for '{0}'", pkg.Name);
                    }
                }
            }).Wait();

            Feed.Save(_output);

            // Feed.ToString()
            // PackageFeed.Add(PackageModel);
        }
コード例 #3
0
        private void CreatePackageModel()
        {
            PackageFeed = new AtomFeed();
            PackageModel = new AutopackageModel(PackageSource, PackageFeed);
            PackageFeed.Add(PackageModel);

            PackageModel.ProcessCertificateInformation();

            // find the xml templates that we're going to generate content with
            PackageModel.ProcessPackageTemplates();

            // Run through the file lists and gather in all the files that we're going to include in the package.
            PackageModel.ProcessFileLists();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            PackageModel.ProcessCosmeticMetadata();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            // Ensure digital signatures and strong names are all good to go
            // this doesn't commit the files to disk tho' ...
            PackageModel.ProcessDigitalSigning();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            PackageModel.ProcessApplicationRole();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            PackageModel.ProcessFauxRoles();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            PackageModel.ProcessDeveloperLibraryRoles();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            PackageModel.ProcessServiceRoles();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            PackageModel.ProcessDriverRoles();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            PackageModel.ProcessWebApplicationRoles();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            PackageModel.ProcessSourceCodeRoles();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            // identify all assemblies to create in the package
            PackageModel.ProcessAssemblyRules();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            // Validate the basic information of this package
            PackageModel.ProcessBasicPackageInformation();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            // Gather the dependency information for the package
            PackageModel.ProcessDependencyInformation();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            // update manifests for things that need them.
            PackageModel.UpdateApplicationManifests();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            // Build Assembly policy files
            PackageModel.CreateAssemblyPolicies();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

            // persist all the changes to any binaries that we've touched.
            PackageModel.SaveModifiedBinaries();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();

               // here

            PackageModel.ProcessCompositionRules();
            // at the end of the step, if there are any errors, let's print them out and exit now.
            FailOnErrors();
        }
コード例 #4
0
        /*
        public override Task Post(HttpListenerResponse response, string relativePath, Toolkit.Pipes.UrlEncodedMessage message) {
            var fileData = message["file"].ToString();
            if( string.IsNullOrEmpty(fileData) ) {
                response.StatusCode = 500;
                response.Close();
                return "".AsResultTask();
            }

            var data = fileData.UrlDecode();
        }
        */
        public override Task Put(HttpListenerResponse response, string relativePath, byte[] data)
        {
            if( data.Length < 1 ) {
                response.StatusCode = 500;
                response.Close();
                return "".AsResultTask();
            }

            var result = Task.Factory.StartNew(
                () => {
                    var filename = "UploadedFile.bin".GenerateTemporaryFilename();
                    File.WriteAllBytes(filename, data);

                    PackageManager.Instance.ConnectAndWait("RepositoryService", null, 5000);

                    // verify that the file is actually a valid package
                    PackageManager.Instance.GetPackages(filename, messages: RepositoryServiceMain._messages).ContinueWith(
                        antecedent => {
                            if( antecedent.IsFaulted ) {
                                Console.WriteLine("Fault occurred after upload: {0}", filename);
                                filename.TryHardToDelete();
                                response.StatusCode = 400;
                                response.Close();
                                return;
                            }

                            if( antecedent.IsCanceled) {
                                Console.WriteLine("Request was cancelled");
                                filename.TryHardToDelete();
                                response.StatusCode = 400;
                                response.Close();
                                return;
                            }

                            var pkg = antecedent.Result.FirstOrDefault();
                            if( pkg == null ) {
                                Console.WriteLine("File uploaded is not recognized as a package: {0}", filename);
                                filename.TryHardToDelete();
                                response.StatusCode = 400;
                                response.Close();
                                return;
                            }

                            var targetFilename = (pkg.CanonicalName + ".msi").ToLower();
                            var location = new Uri(_packagePrefixUrl, targetFilename);
                            PackageManager.Instance.GetPackageDetails(pkg.CanonicalName, RepositoryServiceMain._messages).Wait();

                            //copy the package to the destination
                            if (_cloudFileSystem != null) {
                                // copy file to azure storage
                                _cloudFileSystem.WriteBlob(_packageStorageFolder, targetFilename, filename, false, (progress) => {
                                    ConsoleExtensions.PrintProgressBar("{0} => {1}".format(pkg.CanonicalName, _packageStorageFolder), progress);
                                });

                                if (pkg.Name.Equals("coapp.toolkit", StringComparison.CurrentCultureIgnoreCase) && pkg.PublicKeyToken.Equals("1e373a58e25250cb", StringComparison.CurrentCultureIgnoreCase)) {
                                    // update the default toolkit too
                                    _cloudFileSystem.WriteBlob(_packageStorageFolder, "coapp.toolkit.msi", filename, false, (progress) => {
                                        ConsoleExtensions.PrintProgressBar("{0} => {1}".format(_localfeedLocation, _packageStorageFolder), progress);
                                    });
                                    Console.WriteLine();
                                }

                                if (pkg.Name.Equals("coapp.devtools", StringComparison.CurrentCultureIgnoreCase) && pkg.PublicKeyToken.Equals("1e373a58e25250cb", StringComparison.CurrentCultureIgnoreCase)) {
                                    // update the default toolkit too
                                    _cloudFileSystem.WriteBlob(_packageStorageFolder, "coapp.devtools.msi", filename, false, (progress) => {
                                        ConsoleExtensions.PrintProgressBar("{0} => {1}".format(_localfeedLocation, _packageStorageFolder), progress);
                                    });
                                    Console.WriteLine();
                                }

                                // remove the local file, since we don't need it anymore.
                                filename.TryHardToDelete();

                                Console.WriteLine();
                            } else {
                                var targetLocation = Path.Combine(_packageStorageFolder, targetFilename);
                                if( File.Exists(targetLocation)) {
                                    targetLocation.TryHardToDelete();
                                }

                                File.Copy(filename, targetLocation);
                            }

                            lock(typeof(UploadedFileHandler)) {
                                // update the feed
                                var Feed = new AtomFeed();

                                if (!string.IsNullOrEmpty(_localfeedLocation) && File.Exists(_localfeedLocation)) {
                                    var originalFeed = AtomFeed.LoadFile(_localfeedLocation);
                                    Feed.Add(originalFeed.Items.Where(each => each is AtomItem).Select(each => each as AtomItem));
                                }

                                if (!string.IsNullOrEmpty(pkg.PackageItemText)) {
                                    var item = SyndicationItem.Load<AtomItem>(XmlReader.Create(new StringReader(pkg.PackageItemText)));

                                    var feedItem = Feed.Add(item);

                                    // first, make sure that the feeds contains the intended feed location.
                                    if (feedItem.Model.Feeds == null) {
                                        feedItem.Model.Feeds = new List<Uri>();
                                    }

                                    if (!feedItem.Model.Feeds.Contains(_canonicalFeedUrl)) {
                                        feedItem.Model.Feeds.Insert(0, _canonicalFeedUrl);
                                    }

                                    if (feedItem.Model.Locations == null) {
                                        feedItem.Model.Locations = new List<Uri>();
                                    }

                                    if (!feedItem.Model.Locations.Contains(location)) {
                                        feedItem.Model.Locations.Insert(0, location);
                                    }
                                }

                                Feed.Save(_localfeedLocation);
                                if (_cloudFileSystem != null) {
                                    _cloudFileSystem.WriteBlob(_packageStorageFolder, Path.GetFileName(_localfeedLocation).ToLower() , _localfeedLocation, false, (progress) => {
                                        ConsoleExtensions.PrintProgressBar("{0} => {1}".format(_localfeedLocation, _packageStorageFolder), progress);
                                    });
                                    Console.WriteLine();

                                    _cloudFileSystem.WriteBlob(_packageStorageFolder, Path.GetFileName(_localfeedLocation).ToLower()+".gz", _localfeedLocation, true, (progress) => {
                                        ConsoleExtensions.PrintProgressBar("{0} => {1}".format(_localfeedLocation+".gz", _packageStorageFolder), progress);
                                    });
                                    Console.WriteLine();

                                }
                            }

                            // Advertise the package on twitter
                            if (_tweeter != null) {
                                // pkg.Name
                                Bitly.Shorten(location.AbsoluteUri).ContinueWith(
                                    (x) => {
                                        var name = "[{0}-{1}-{2}]".format(pkg.Name, pkg.Version, pkg.Architecture);

                                        var summary = pkg.Summary;
                                        var l1 = 138 - (name.Length + x.Result.Length);
                                        if( summary.Length > l1 ) {
                                            summary = summary.Substring(0, l1 - 1) + "\u2026";
                                        }
                                        var text = "{0} {1} {2}".format(name, summary, x.Result);
                                        Console.WriteLine("Tweet: {0}",text);
                                        _tweeter.Tweet(text);
                                    });
                            }

                            response.StatusCode = 200;
                            response.Close();
                        }, TaskContinuationOptions.AttachedToParent);

                });

            result.ContinueWith(
                antecedent => {
                    if (result.IsFaulted) {
                        var e = antecedent.Exception.InnerException;
                        Console.WriteLine("Error handling uploaded package: {0} -- {1}\r\n{2}", e.GetType(), e.Message, e.StackTrace);
                        response.StatusCode = 500;
                        response.Close();
                    }
                }, TaskContinuationOptions.OnlyOnFaulted);

            return result;
        }
コード例 #5
0
 private Task<int> Validate()
 {
     return Task.Factory.StartNew(() => {
         var feed = new AtomFeed();
         //load the feed from the _canonicalFeedUrl if we can
         try {
             var originalFeed = LoadFeed();
             foreach (AtomItem i in originalFeed.Items.Where(each => each is AtomItem)) {
                 // drop dead urls
                 i.Model.Feeds = i.Model.Feeds.Distinct().Where(Peek).ToXList();
                 i.Model.Locations = i.Model.Locations.Distinct().Where(Peek).ToXList();
                 foreach (var l in i.Links.ToArray().Where(each => !Peek(each.Uri))) {
                     i.Links.Remove(l);
                 }
                 if (i.Model.Locations.Any()) {
                     feed.Add(i);
                 }
             }
             SaveFeed(feed);
         } catch {
             return 500;
         }
         return 200;
     });
 }
コード例 #6
0
        private void InsertIntoFeed(CanonicalName pkgCanonicalName, FourPartVersion pkgVersion,  Uri location , AtomItem item = null)
        {
            lock (typeof(UploadedFileHandler)) {
                // update the feed
                var feed = new AtomFeed();

                //load the feed from the _canonicalFeedUrl if we can
                try {
                    var originalFeed = LoadFeed();

                    foreach (AtomItem i in originalFeed.Items.Where(each => each is AtomItem)) {
                        if (_feedName == "current") {
                            // if an older version of this package is in the current feed,
                            if (i.Model.CanonicalName.DiffersOnlyByVersion(pkgCanonicalName) && i.Model.CanonicalName.Version < pkgVersion) {
                                // push it to the archive feed.
                                FeedHandlers["archive"].InsertIntoFeed(i.Model.CanonicalName, i.Model.Version, i.Model.Locations[0]);
                                // and skip it
                                continue;
                            }
                        }
                        feed.Add(i);
                    }
                } catch {

                }
                item = item ?? _packageManager.GetAtomItem(pkgCanonicalName).Result;

                if (item != null) {
                    // first, make sure that the feeds contains the intended feed location.

                    item.Model.Feeds = item.Model.Feeds  ??new XList<Uri>();
                    if (!item.Model.Feeds.Contains(_canonicalFeedUrl)) {
                        item.Model.Feeds.Insert(0, _canonicalFeedUrl);
                    }

                    item.Model.Locations = item.Model.Locations  ?? new XList<Uri>();
                    if (!item.Model.Locations.Contains(location)) {
                        item.Model.Locations.Insert(0, location);
                    }

                    // drop dead urls
                    item.Model.Feeds = item.Model.Feeds.Distinct().Where(Peek).ToXList();
                    item.Model.Locations = item.Model.Locations.Distinct().Where(Peek).ToXList();
                    foreach( var l in item.Links.ToArray().Where( each => !Peek(each.Uri) ) ) {
                        item.Links.Remove(l);
                    }

                    if (item.Model.Locations.Any()) {
                        // if we've got at least one valid location, add the item to the feed.
                        feed.Add(item);
                    }
                }
                SaveFeed( feed);
            }
        }
コード例 #7
0
ファイル: mkRepoMain.cs プロジェクト: virmitio/devtools
        private void Create()
        {
            Feed = new AtomFeed();
            AtomFeed originalFeed = null;

            if (!string.IsNullOrEmpty(_input)) {
                Logger.Message("Loading existing feed.");
                if (_input.IsWebUri()) {
                    var inputFilename = "feed.atom.xml".GenerateTemporaryFilename();

                    var rf = new RemoteFile(_input, inputFilename, (uri) => {
                    },
                        (uri) => {
                            inputFilename.TryHardToDelete();
                        },
                        (uri, progress) => {
                            "Downloading {0}".format(uri).PrintProgressBar(progress);
                        });
                    rf.Get();

                    if (!File.Exists(inputFilename)) {
                        throw new ConsoleException("Failed to get input feed from '{0}' ", _input);
                    }
                    originalFeed = AtomFeed.LoadFile(inputFilename);
                } else {
                    originalFeed = AtomFeed.LoadFile(_input);
                }
            }

            if (originalFeed != null) {
                Feed.Add(originalFeed.Items.Where(each => each is AtomItem).Select(each => each as AtomItem));
            }
            ;

            Logger.Message("Selecting local packages");

            _packageManager.RecognizeFiles(_packageFiles.FindFilesSmarter()).Continue(packages => {
                var names = packages.Select(each => each.CanonicalName); //  .ToArray();

                var feed = _packageManager.GetAtomFeed(names).Result;

                foreach( var i in feed.Items) {
                    var feedItem = i as AtomItem;
                    if (feedItem != null) {
                        var pkg = _packageManager.GetPackage(feedItem.Model.CanonicalName).Result;
                        // first, make sure that the feeds contains the intended feed location.
                        if (feedItem.Model.Feeds == null) {
                            feedItem.Model.Feeds = new XList<Uri>();
                        }

                        if (!feedItem.Model.Feeds.Contains(_feedLocation)) {
                            feedItem.Model.Feeds.Insert(0, _feedLocation);
                        }

                        var location = new Uri(_baseUrl, Path.GetFileName(pkg.LocalPackagePath));

                        if (feedItem.Model.Locations == null) {
                            feedItem.Model.Locations = new XList<Uri>();
                        }

                        if (!feedItem.Model.Locations.Contains(location)) {
                            feedItem.Model.Locations.Insert(0, location);
                        }

                        // add it to our feed.
                        Feed.Add(feedItem);
                    }
                }
            }).Wait();

            Feed.Save(_output);

            // Feed.ToString()
            // PackageFeed.Add(PackageModel);
        }