Example #1
0
        /// <summary>
        /// Sends the trackback or pingback message.
        ///     <remarks>
        /// It will try to send a trackback message first, and if the refered web page
        ///         doesn't support trackbacks, a pingback is sent.
        ///     </remarks>
        /// </summary>
        /// <param name="item">
        /// The publishable item.
        /// </param>
        /// <param name="itemUrl">
        /// The item Url.
        /// </param>
        public static void Send(IPublishable item, Uri itemUrl)
        {
            foreach (var url in GetUrlsFromContent(item.Content))
            {
                var trackbackSent = false;

                if (BlogSettings.Instance.EnableTrackBackSend)
                {
                    // ignoreRemoteDownloadSettings should be set to true
                    // for backwards compatibilty with Utils.DownloadWebPage.
                    var remoteFile   = new RemoteFile(url, true);
                    var pageContent  = remoteFile.GetFileAsString(); // ReadFromWeb(url);
                    var trackbackUrl = GetTrackBackUrlFromPage(pageContent);

                    if (trackbackUrl != null)
                    {
                        var message = new TrackbackMessage(item, trackbackUrl, itemUrl);
                        trackbackSent = Trackback.Send(message);
                    }
                }

                if (!trackbackSent && BlogSettings.Instance.EnablePingBackSend)
                {
                    Pingback.Send(itemUrl, url);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Retrieves and caches the specified remote CSS.
        /// </summary>
        /// <param name="file">
        /// The remote URL
        /// </param>
        /// <param name="cacheKey">
        /// The key used to insert this script into the cache.
        /// </param>
        /// <returns>
        /// The retrieve remote css.
        /// </returns>
        private static string RetrieveRemoteCss(string file, string cacheKey)
        {
            Uri url;

            if (Uri.TryCreate(file, UriKind.Absolute, out url))
            {
                try
                {
                    var    remoteFile = new RemoteFile(url, false);
                    string css        = remoteFile.GetFileAsString();
                    css = ProcessCss(css);

                    // Insert into cache
                    Applications.CurrentInstance.Cache.Insert(
                        cacheKey,
                        css,
                        null,
                        Cache.NoAbsoluteExpiration,
                        new TimeSpan(3, 0, 0, 0));

                    return(css);
                }
                catch (SocketException)
                {
                    // The remote site is currently down. Try again next time.
                }
            }

            return(string.Empty);
        }
        /// <summary>
        /// Copies the remote item to the path specified. If this is a directory then it
        /// will recursively copy it down.
        /// </summary>
        /// <param name="path">Returns the full local path (i.e. localPath + [file/dir]name)</param>
        public string Get(string localPath, bool overwrite)
        {
            string fullLocalPath = Path.Combine(localPath, Path.GetFileName(Name));

            if (IsApplication || IsRemoteStore || RemoteFile.IsDirectory())
            {
                Directory.CreateDirectory(fullLocalPath);

                // make sure we know about all of our children
                Update();

                foreach (RemoteAppIsoStoreItem item in Children)
                {
                    item.Get(fullLocalPath, overwrite);
                }
            }
            else
            {
                if (overwrite || !File.Exists(fullLocalPath))
                {
                    _remoteStore.ReceiveFile(_path, fullLocalPath, true);
                }
            }

            return(fullLocalPath);
        }
Example #4
0
        void ttserver_OnFileDeleted(ref RemoteFile lpRemoteFile, ref User lpUser)
        {
            String str = String.Format("File {0} deleted from channel #{1}",
                                       lpRemoteFile.szFileName, lpRemoteFile.nChannelID);

            Console.WriteLine(str);
        }
Example #5
0
        private void SendFileList(SimpleSocketSession <SocketData> session, FileListRequest request)
        {
            string            path  = request.Path;
            List <RemoteFile> files = new List <RemoteFile>();

            if (string.IsNullOrEmpty(path))
            {
                files = DriveInfo.GetDrives().Select(p => p.RootDirectory).Select(p => new RemoteFile(p, false)).ToList();
            }
            else
            {
                foreach (var dir in new DirectoryInfo(path).EnumerateFileSystemInfos())
                {
                    var file = new RemoteFile(dir, true);
                    files.Add(file);
                }
            }
            var data = new FileListResponse()
            {
                Files = files.OrderByDescending(p => p.IsDir).ToList(), Path = path
            };
            SocketData resp = new SocketData(Response, SocketDataAction.FileListResponse, data);

            Send(session, resp);
        }
Example #6
0
        public static void Send(IPublishable item, Uri itemUrl)
        {
            foreach (var url in GetUrlsFromContent(item.Content))
            {
                var trackbackSent = false;

                if (BlogSettings.Instance.EnableTrackBackSend)
                {
                    var remoteFile = new RemoteFile(url, true);
                    var pageContent = remoteFile.GetFileAsString();
                    var trackbackUrl = GetTrackBackUrlFromPage(pageContent);

                    if (trackbackUrl != null)
                    {
                        var message = new TrackbackMessage(item, trackbackUrl, itemUrl);
                        trackbackSent = Trackback.Send(message);
                    }
                }

                if (!trackbackSent && BlogSettings.Instance.EnablePingBackSend)
                {
                    Pingback.Send(itemUrl, url);
                }
            }
        }
Example #7
0
        void ttserver_OnFileDownloaded(ref RemoteFile lpRemoteFile, ref User lpUser)
        {
            String str = String.Format("File {0} downloaded to channel #{1}",
                                       lpRemoteFile.szFileName, lpRemoteFile.nChannelID);

            Console.WriteLine(str);;
        }
Example #8
0
        public void GetFilename_WithoutDate()
        {
            const string expectedResult = "CCDS2Sequence.20160908.txt";
            var          observedResult = RemoteFile.GetFilename("ftp://ftp.ncbi.nlm.nih.gov/pub/CCDS/current_human/CCDS2Sequence.20160908.txt", false);

            Assert.Equal(expectedResult, observedResult);
        }
Example #9
0
        public static void Send(IPublishable item, Uri itemUrl)
        {
            foreach (var url in GetUrlsFromContent(item.Content))
            {
                var trackbackSent = false;

                if (BlogSettings.Instance.EnableTrackBackSend)
                {
                    var remoteFile   = new RemoteFile(url, true);
                    var pageContent  = remoteFile.GetFileAsString();
                    var trackbackUrl = GetTrackBackUrlFromPage(pageContent);

                    if (trackbackUrl != null)
                    {
                        var message = new TrackbackMessage(item, trackbackUrl, itemUrl);
                        trackbackSent = Trackback.Send(message);
                    }
                }

                if (!trackbackSent && BlogSettings.Instance.EnablePingBackSend)
                {
                    Pingback.Send(itemUrl, url);
                }
            }
        }
        private static string RetrieveRemoteFile(string file)
        {
            file = Utils.AbsoluteWebRoot.ToString() + file.Substring(1);
            Uri url;

            if (Uri.TryCreate(file, UriKind.Absolute, out url))
            {
                try
                {
                    var script = new RemoteFile(url, false).GetFileAsString();

                    if (BlogSettings.Instance.CompressWebResource)
                    {
                        var min = new JavascriptMinifier();
                        return(min.Minify(script));
                    }

                    return(script);
                }
                catch (SocketException)
                {
                    // The remote site is currently down. Try again next time.
                }
            }
            return(string.Empty);
        }
Example #11
0
        public void GetFilename_WithUrlPrefix()
        {
            string expectedResult = $"CCDS2Sequence.20160908_{Date.GetDate(DateTime.Now.Ticks)}.txt";
            var    observedResult = RemoteFile.GetFilename("ftp://ftp.ncbi.nlm.nih.gov/pub/CCDS/current_human/CCDS2Sequence.20160908.txt", true);

            Assert.Equal(expectedResult, observedResult);
        }
Example #12
0
        public void GetFilename_WithoutUrlPrefix()
        {
            string expectedResult = $"ccds_1000_{Date.GetDate(DateTime.Now.Ticks)}.txt";
            var    observedResult = RemoteFile.GetFilename("ccds_1000.txt", true);

            Assert.Equal(expectedResult, observedResult);
        }
        /// <summary>
        /// Sends the trackback or pingback message.
        ///     <remarks>
        /// It will try to send a trackback message first, and if the refered web page
        ///         doesn't support trackbacks, a pingback is sent.
        ///     </remarks>
        /// </summary>
        /// <param name="item">
        /// The publishable item.
        /// </param>
        /// <param name="itemUrl">
        /// The item Url.
        /// </param>
        public static void Send(IPublishable item, Uri itemUrl)
        {
            foreach (var url in GetUrlsFromContent(item.Content))
            {
                var trackbackSent = false;

                if (BlogSettings.Instance.EnableTrackBackSend)
                {
                    // ignoreRemoteDownloadSettings should be set to true
                    // for backwards compatibilty with Utils.DownloadWebPage.
                    var remoteFile = new RemoteFile(url, true);
                    var pageContent = remoteFile.GetFileAsString(); // ReadFromWeb(url);
                    var trackbackUrl = GetTrackBackUrlFromPage(pageContent);

                    if (trackbackUrl != null)
                    {
                        var message = new TrackbackMessage(item, trackbackUrl, itemUrl);
                        trackbackSent = Trackback.Send(message);
                    }
                }

                if (!trackbackSent && BlogSettings.Instance.EnablePingBackSend)
                {
                    Pingback.Send(itemUrl, url);
                }
            }
        }
Example #14
0
        private static int GetNumGenbankFiles(ILogger logger)
        {
            var fileList = new RemoteFile("RefSeq filelist", "ftp://ftp.ncbi.nlm.nih.gov/refseq/H_sapiens/mRNA_Prot/human.files.installed");

            fileList.Download(logger);

            var maxNum = 0;

            using (var reader = FileUtilities.GetStreamReader(FileUtilities.GetReadStream(fileList.FilePath)))
            {
                while (true)
                {
                    string line = reader.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    string filename = line.OptimizedSplit('\t')[1];
                    if (!filename.EndsWith(".rna.gbff.gz"))
                    {
                        continue;
                    }

                    int num = int.Parse(filename.Substring(6, filename.Length - 18));
                    if (num > maxNum)
                    {
                        maxNum = num;
                    }
                }
            }

            return(maxNum);
        }
Example #15
0
        /// <summary>
        /// �������ͻ�ȡ�汾��
        /// </summary>
        /// <param name="url">Զ��Ŀ¼�ĸ�Ŀ¼</param>
        /// <param name="systemType">���� 0 Fedoreϵͳ 1 Redhatϵͳ</param>
        /// <returns>��ǰ�İ汾��</returns>
        public static string GetVersion( int systemType)
        {
            string temp = string.Empty;
            if (systemType == 0)
            {
                temp = URL +  FEDORE+ "/version.txt";
            }
            else if (systemType == 1)
            {
                temp = URL + REDHAT + "/version.txt";
            }
            else if (systemType == 2)
            {
                temp = URL + WINDOWS + "/version.txt";
            }

            RemoteFile rf = new RemoteFile();

            byte[] bytes = rf.GetRemoteFileByteContent(temp);

            if (bytes == null)
                return null;

            string str = Encoding.Default.GetString(bytes);

            return str;
        }
        private bool DownloadFile(RemoteFile file, string to)
        {
            var completion = new ManualResetEvent(false);
            var response   = new WebexApiEventArgs();

            webex.Messages.DownloadFile(file, to, rsp =>
            {
                if (!rsp.IsSuccess || (rsp.IsSuccess && rsp.Data == 100))
                {
                    response = rsp;
                    completion.Set();
                }
            });
            if (!completion.WaitOne(30000))
            {
                return(false);
            }

            if (response.IsSuccess)
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Call when you are ready to pull down the data associated with this object
        /// </summary>
        public void Update(bool force = false)
        {
            if (!force && (Opened || (RemoteFile != null && !RemoteFile.IsDirectory())))
            {
                return;
            }

            // if we are forcing an update then the assumption is that we want an update
            // of either the current item or its container. If this is not a directory and
            // we have been forced, force an update on the parent
            if (force && !IsApplication && (RemoteFile != null && !RemoteFile.IsDirectory()))
            {
                if (this.Parent != null)
                {
                    this.Parent.Update(force: true);
                }

                return;
            }

            Children.Clear();

            //Opened = true;
            Opened = true;

            IRemoteIsolatedStorageFile remoteIso = _remoteStore;

            if (remoteIso == null)
            {
                if (RemoteApp.InstanceID == Guid.Empty)
                {
                    // 8.1
                    UpdateModern(force);
                    return;
                }
                else
                {
                    remoteIso = RemoteApp.GetIsolatedStore("Local");
                }
            }

            List <IRemoteFileInfo> remoteFiles;

            try
            {
                if (remoteIso != null)
                {
                    remoteFiles = remoteIso.GetDirectoryListing(_path);

                    foreach (IRemoteFileInfo remoteFile in remoteFiles)
                    {
                        Children.Add(new RemoteAppIsoStoreItem(_appEx, remoteFile, remoteIso, this));
                    }
                }
            }
            catch (FileNotFoundException)
            {
                // no files, oh well :)
            }
        }
Example #18
0
        public override async Task <int> RunAsync(string[] remainingArguments)
        {
            var result = await RemoteFile.UploadFile(LocalPath, Path, await GetOptions());

            Console.WriteLine(result);

            return(0);
        }
Example #19
0
 IEnumerator InstantiateAsset(string remoteAsset, string localFile)
 {
     RemoteFile rf = new RemoteFile(remoteAsset, localFile);
     yield return StartCoroutine(rf.Download());
     yield return StartCoroutine(rf.LoadLocalBundle());
     Instantiate(rf.LocalBundle.mainAsset);
     rf.UnloadLocalBundle ();
 }
Example #20
0
        public async Task TestGetRemoteFileThatIsNotPresentLocallyAsync()
        {
            // todo: would be better to externalize the download part so that can be mocked for test
            string urlToDownload = @"https://raw.githubusercontent.com/sayedihashimi/dotnet-new-web/master/src/template-report.json";
            string filename      = Guid.NewGuid().ToString();
            var    remoteFile    = new RemoteFile();
            var    localFile     = await remoteFile.GetRemoteFileAsync(urlToDownload, filename);

            Assert.True(File.Exists(localFile), $"local file not found at '{localFile}'");
        }
Example #21
0
        protected virtual Uri GetTrackbackUrl(Uri url)
        {
            // ignoreRemoteDownloadSettings should be set to true
            // for backwards compatibilty with Utils.DownloadWebPage.
            var remoteFile   = new RemoteFile(url, true);
            var pageContent  = remoteFile.GetFileAsString(); // ReadFromWeb(url);
            var trackbackUrl = GetTrackBackUrlFromPage(pageContent);

            return(trackbackUrl);
        }
Example #22
0
 private UploadSpecificationRequest BuildUploadSpecificationRequest(RemoteFile file, Uri sfParent, models.UploadMethod method)
 {
     return(new UploadSpecificationRequest
     {
         FileName = file.Name,
         FileSize = file.Size,
         Method = method,
         Parent = sfParent,
     });
 }
Example #23
0
        public void SyncThrowsWhenRemotePathNotPopulated([Values("", " ", null)] string remotePath)
        {
            var remoteFile = new RemoteFile(_managedProcessFactory);
            var result     = Assert.ThrowsAsync <ArgumentNullException>(
                async() => await remoteFile.SyncAsync(null, _localPath, remotePath, null));
            var message = "Remote path should be specified when running ggp_rsync\r\n" +
                          "Parameter name: remotePath";

            Assert.That(result.Message, Is.EqualTo(message));
        }
Example #24
0
        static void ttclient_OnCmdFileNew(RemoteFile fileinfo)
        {
            string chanpath = "";

            if (ttclient.GetChannelPath(fileinfo.nChannelID, ref chanpath))
            {
                Console.WriteLine("File #{0} {1} added to channel {2}",
                                  fileinfo.nFileID, fileinfo.szFileName, chanpath);
            }
        }
            public void ProcessMessages()
            {
                while (Client.TryReceiveMessage(out var message))
                {
                    switch (message.MessageType)
                    {
                    case NetworkMessageType.DeviceName:
                        SetName((NetworkDeviceName)message);
                        break;

                    case NetworkMessageType.Text:
                        var networkText = (NetworkText)message;
                        AppendApplicationOutput(networkText.Text);
                        break;

                    case NetworkMessageType.RemoteFileRequest:
                        var fileRequest = (NetworkRemoteFileRequest)message;
                        AppendApplicationOutput($"Remote file request: \"{fileRequest.Data.Path}\"");
                        var absFilePath = Path.Combine(ProjectPreferences.Instance.RemoteStoragePath, fileRequest.Data.Path);
                        if (File.Exists(absFilePath))
                        {
                            async void SendFileAsync()
                            {
                                byte[] bytes;
                                using (var fileStream = File.Open(absFilePath, FileMode.Open)) {
                                    bytes = new byte[fileStream.Length];
                                    await fileStream.ReadAsync(bytes, 0, (int)fileStream.Length);
                                }
                                var remoteFile = new RemoteFile {
                                    Path  = fileRequest.Data.Path,
                                    Bytes = bytes
                                };

                                Client.SendMessage(new NetworkRemoteFile(remoteFile));
                                AppendApplicationOutput($"Requested file \"{fileRequest.Data.Path}\" was sended.");
                            }

                            SendFileAsync();
                        }
                        else
                        {
                            var remoteFile = new RemoteFile {
                                Path  = fileRequest.Data.Path,
                                Bytes = null
                            };
                            Client.SendMessage(new NetworkRemoteFile(remoteFile));
                            AppendApplicationOutput($"Can not send requested file: \"{fileRequest.Data.Path}\". File not found!");
                        }
                        break;

                    default:
                        throw new NotSupportedException($"Unknown message type: {message.MessageType}");
                    }
                }
            }
Example #26
0
        /// <summary>
        /// Gets the image using the given identifier.
        /// </summary>
        /// <param name="id">
        /// The value identifying the image to fetch.
        /// </param>
        /// <returns>
        /// The <see cref="System.Byte"/> array containing the image data.
        /// </returns>
        public virtual async Task <byte[]> GetImage(object id)
        {
            string host      = this.Settings["Host"];
            string container = this.Settings.ContainsKey("Container") ? this.Settings["Container"] : string.Empty;
            Uri    baseUri   = new Uri(host);

            string relativeResourceUrl = id.ToString();

            if (!string.IsNullOrEmpty(container))
            {
                // TODO: Check me.
                container = $"{container.TrimEnd('/')}/";
                if (!relativeResourceUrl.StartsWith($"{container}/"))
                {
                    relativeResourceUrl = $"{container}{relativeResourceUrl.TrimStart('/')}";
                }
            }

            Uri        uri        = new Uri(baseUri, relativeResourceUrl);
            RemoteFile remoteFile = new RemoteFile(uri)
            {
                MaxDownloadSize = int.Parse(this.Settings["MaxBytes"]),
                TimeoutLength   = int.Parse(this.Settings["Timeout"])
            };

            byte[] buffer;

            // Prevent response blocking.
            WebResponse webResponse = await remoteFile.GetWebResponseAsync().ConfigureAwait(false);

            using (MemoryStream memoryStream = MemoryStreamPool.Shared.GetStream())
            {
                using (WebResponse response = webResponse)
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        if (responseStream != null)
                        {
                            responseStream.CopyTo(memoryStream);

                            // Reset the position of the stream to ensure we're reading the correct part.
                            memoryStream.Position = 0;

                            buffer = memoryStream.GetBuffer();
                        }
                        else
                        {
                            throw new HttpException((int)HttpStatusCode.NotFound, $"No image exists at {uri}");
                        }
                    }
                }
            }

            return(buffer);
        }
Example #27
0
    IEnumerator InstantiateAsset(string remoteAsset, string localFile)
    {
        RemoteFile rf = new RemoteFile(remoteAsset, localFile);

        yield return(StartCoroutine(rf.Download()));

        yield return(StartCoroutine(rf.LoadLocalBundle()));

        Instantiate(rf.LocalBundle.mainAsset);
        rf.UnloadLocalBundle();
    }
Example #28
0
 private async Task <models.File> UploadThreaded(RemoteFile file, Uri parent)
 {
     using (await threadedUploadQueue.EnterAsync())
         using (var platformFile = new LazyPlatformFileStream(file))
         {
             var uploader = api.GetAsyncFileUploader(
                 BuildUploadSpecificationRequest(file, parent, models.UploadMethod.Threaded),
                 platformFile, threadedUploaderConfig);
             return(UploadResultToModel((await uploader.UploadAsync()).First()));
         }
 }
Example #29
0
 private bool containsExtentions(RemoteFile file, string[] extentions)
 {
     foreach (string ext in extentions)
     {
         if (file.name.EndsWith(ext))
         {
             return(true);
         }
     }
     return(false);
 }
        public static Task <FileObjectResponse> AddRemoteFileAsync(SlackClient slackClient)
        {
            var remoteFile = new RemoteFile
            {
                ExternalId  = Guid.NewGuid().ToString(),
                ExternalUrl = new Uri("https://unsplash.com/photos/Dl39g6QhOIM"),
                Title       = "Beautiful cat",
                FileType    = "jpg",
            };

            return(slackClient.FilesRemote.AddAsync(remoteFile));
        }
        public void Put(string localFile, bool overwrite = false)
        {
            // relative directory is:
            // "" - if it's an application
            // _path - if it's a directory (since Path.GetDirectoryName will actually strip out the directory name)
            // Path.GetDirectoryName(_path) - if it's a file, since this will strip out the file name and leave us with a directory
            string relativeDirectory =
                (RemoteFile == null ? "" :
                 (RemoteFile.IsDirectory() ? _path : Path.GetDirectoryName(_path)));

            Put(localFile, relativeDirectory, overwrite);
        }
Example #32
0
        private bool IsInCollection(RemoteFile file)
        {
            foreach (ListViewItem instant in lvFilesList.Items)
            {
                if (file.Equals(instant.Tag))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #33
0
        public void TestGetRemoteFileThatIsPresentLocally()
        {
            string filename   = "knownfilename.txt";
            var    remoteFile = new RemoteFile();
            // make sure that the file exists in the cachefolder
            var expectedFilepath = remoteFile.GetLocalFilepathFor(filename);

            if (!File.Exists(expectedFilepath))
            {
                // create a dummy file
                File.WriteAllText(expectedFilepath, "12345");
            }
        }
Example #34
0
        public async Task TestExtractZipLocallyAsync()
        {
            // todo: extract from resource
            string urltodownload = @"https://www.nuget.org/api/v2/package/Take.Blip.Client.Templates/0.6.15-beta";
            string filename      = "Take.Blip.Client.Templates.0.6.15-beta.zip";
            var    remoteFile    = new RemoteFile();
            var    downloadPath  = await remoteFile.GetRemoteFileAsync(urltodownload, filename);

            var extractPath = remoteFile.ExtractZipLocally(downloadPath);

            Assert.True(!string.IsNullOrEmpty(extractPath));
            Assert.True(Directory.Exists(extractPath));
        }
Example #35
0
        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");
            var files = _packages.FindFilesSmarter();

            _packageManager.QueryPackages(files).ContinueWith((antecedent) => {
                var packages = antecedent.Result;

                foreach (var pkg in packages) {
                    _packageManager.GetPackageDetails(pkg.CanonicalName).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 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);
                        }
                    } else {
                        throw new ConsoleException("Missing ATOM data for '{0}'", pkg.Name);
                    }
                }
            }).Wait();

            Feed.Save(_output);

            // Feed.ToString()
            // PackageFeed.Add(PackageModel);
        }
Example #36
0
        public override Task Get(HttpListenerResponse response, string relativePath, Toolkit.Pipes.UrlEncodedMessage message)
        {
            switch (message.Command) {
                case "add":
                    if (!string.IsNullOrEmpty(message["location"])) {
                        try {
                            var uri = new Uri(message["location"]);
                            if (Peek(uri)) {
                                var filename = "UploadedFile.bin".GenerateTemporaryFilename();
                                var rf = new RemoteFile(uri, filename);
                                rf.Get();
                                if (File.Exists(filename)) {
                                    return HandleFile(filename).ContinueWith(antecedent => {
                                        if (antecedent.IsFaulted) {
                                            var e = antecedent.Exception.InnerException;
                                            Listener.HandleException(e);
                                            response.StatusCode = 500;
                                            response.Close();
                                        } else {
                                            response.StatusCode = antecedent.Result;
                                            response.Close();
                                        }
                                    });
                                }
                            }
                        } catch {
                        }
                    }
                    break;

                case "validate":
                    return Validate().ContinueWith(antecedent => {
                        if (antecedent.IsFaulted) {
                            var e = antecedent.Exception.InnerException;
                            Listener.HandleException(e);
                            response.StatusCode = 500;
                            response.Close();
                        }
                        else {
                            response.StatusCode = antecedent.Result;
                            response.Close();
                        }
                    });

            }

            response.StatusCode = 500;
            response.Close();
            return "".AsResultTask();
        }
Example #37
0
        /// <summary>
        ///   The (non-static) startup method
        /// </summary>
        /// <param name = "args">
        ///   The command line arguments.
        /// </param>
        /// <returns>
        ///   Process return code.
        /// </returns>
        protected override int Main(IEnumerable<string> args)
        {
            try {
                _pkgManager = new PackageManager();

                bool waitforbreak = false;

                #region commane line parsing

                // default:
                _pkgManager.SessionFeedLocations = new[] {Environment.CurrentDirectory};

                var options = args.Switches();
                var parameters = args.Parameters();

                foreach (var arg in options.Keys) {
                    var argumentParameters = options[arg];

                    switch (arg) {
                            /* options  */
                        case "pretend":
                            _pkgManager.Pretend = true;
                            break;

                        case "wait-for-break":
                            waitforbreak = true;
                            break;

                        case "maximum":
                            _pkgManager.MaximumPackagesToProcess = argumentParameters.Last().ToInt32(10);
                            break;

                        case "as-specified":
                            _pkgManager.PackagesAsSpecified = string.IsNullOrEmpty(argumentParameters.FirstOrDefault())
                                ? new[] {"*"}
                                : argumentParameters;
                            break;

                        case "upgrade":
                            _pkgManager.PackagesAreUpgradable = string.IsNullOrEmpty(argumentParameters.FirstOrDefault())
                                ? new[] {"*"}
                                : argumentParameters;
                            break;

                        case "no-scan":
                            _pkgManager.DoNotScanLocations = string.IsNullOrEmpty(argumentParameters.FirstOrDefault())
                                ? new[] {"*"}
                                : argumentParameters;
                            break;

                        case "no-network":
                            _pkgManager.DoNotScanLocations = new[] {"*://*"};
                            break;

                        case "scan":
                            if (string.IsNullOrEmpty(argumentParameters.FirstOrDefault())) {
                                throw new ConsoleException(Resources.OptionRequiresLocation.format("--scan"));
                            }
                            _pkgManager.SessionFeedLocations = argumentParameters;
                            break;

                        case "flush-cache":
                            _pkgManager.FlushCache();
                            break;

                            /* global switches */
                        case "load-config":
                            // all ready done, but don't get too picky.
                            break;

                        case "nologo":
                            this.Assembly().SetLogo(string.Empty);
                            break;

                        case "feed-output-file":
                            _feedOutputFile = argumentParameters.LastOrDefault();
                            break;
                        case "feed-root-url":
                            _feedRootUrl = argumentParameters.LastOrDefault();
                            break;
                        case "feed-actual-url":
                            _feedActualUrl = argumentParameters.LastOrDefault();
                            break;
                        case "feed-package-source":
                            _feedPackageSource = argumentParameters.LastOrDefault();
                            break;
                        case "feed-recursive":
                            _feedRecursive = true;
                            break;
                        case "feed-package-url":
                            _feedPackageUrl = argumentParameters.LastOrDefault();
                            break;
                        case "feed-title":
                            _feedTitle = argumentParameters.LastOrDefault();
                            break;

                        case "help":
                            return Help();

                        default:
                            throw new ConsoleException(Resources.UnknownParameter, arg);
                    }
                }

                Logo();

                if (parameters.Count() < 1) {
                    throw new ConsoleException(Resources.MissingCommand);
                }

                #endregion

                // GS01: I'm putting this in here so that feed resoltion happens before we actually get around to doing something.
                // Look into the necessity later.
                Tasklet.WaitforCurrentChildTasks();

                var command = parameters.FirstOrDefault().ToLower();
                parameters = parameters.Skip(1);

                if (File.Exists(command)) {
                    // assume install if the only thing given is a filename.
                    Install(command.SingleItemAsEnumerable());
                }
                else {
                    switch (command) {
                        case "download":
                            var remoteFileUri = new Uri(parameters.First());
                            // create the remote file reference
                            var remoteFile = new RemoteFile(remoteFileUri, CancellationTokenSource.Token);
                            var previewTask = remoteFile.Preview();
                            previewTask.Wait();
                            // Tell it to download it
                            var getTask = remoteFile.Get();

                            // monitor the progress.
                            remoteFile.DownloadProgress.Notification += progress => {
                                // this executes when the download progress value changes.
                                Console.Write(progress <= 100 ? "..{0}% " : "bytes: [{0}]", progress);
                            };

                            // when it's done, do this:
                            getTask.ContinueWithParent(t => {
                                // this executes when the Get() operation completes.
                                Console.WriteLine("File {0} has finished downloading", remoteFile.LocalFullPath);
                            });
                            break;

                        case "verify-package":
                            var r = Verifier.HasValidSignature(parameters.First());
                            Console.WriteLine("Has Valid Signature: {0}", r);
                            Console.WriteLine("Name: {0}", Verifier.GetPublisherInformation(parameters.First())["PublisherName"]);
                            break;

                        case "install":
                            if (parameters.Count() < 1) {
                                throw new ConsoleException(Resources.InstallRequiresPackageName);
                            }

                            Tasklet.WaitforCurrentChildTasks(); // HACK HACK HACK ???

                            Install(parameters);
                            break;

                        case "remove":
                            if (parameters.Count() < 1) {
                                throw new ConsoleException(Resources.RemoveRequiresPackageName);
                            }
                            Remove(parameters);
                            break;

                        case "list":
                            if (parameters.Count() != 1) {
                                throw new ConsoleException(Resources.MissingParameterForList);
                            }
                            switch (parameters.FirstOrDefault().ToLower()) {
                                case "packages":
                                case "package":
                                    ListPackages(parameters);
                                    break;

                                case "feed":
                                case "feeds":
                                case "repo":
                                case "repos":
                                case "repositories":
                                case "repository":
                                    ListFeeds(parameters);
                                    break;
                            }
                            break;

                        case "upgrade":
                            if (parameters.Count() != 1) {
                                throw new ConsoleException(Resources.MissingParameterForUpgrade);
                            }

                            Upgrade(parameters);
                            break;

                        case "add":
                            if (parameters.Count() < 1) {
                                throw new ConsoleException(Resources.AddFeedRequiresLocation);
                            }
                            CoTask.Factory.StartNew(() => AddFeed(parameters));
                            break;

                        case "delete":
                            if (parameters.Count() < 1) {
                                throw new ConsoleException(Resources.DeleteFeedRequiresLocation);
                            }
                            CoTask.Factory.StartNew(() => DeleteFeed(parameters));
                            break;

                        case "trim":
                            if (parameters.Count() != 0) {
                                throw new ConsoleException(Resources.TrimErrorMessage);
                            }

                            CoTask.Factory.StartNew(() => Trim(parameters));
                            break;

                        case "generate-feed":
                            CoTask.Factory.StartNew(() => GenerateFeed(parameters));
                            break;

                        default:
                            throw new ConsoleException(Resources.UnknownCommand, command);
                    }
                }

                while (waitforbreak && !CancellationTokenSource.IsCancellationRequested) {
                    Thread.Sleep(100);
                }
            }
            catch (ConsoleException failure) {
                CancellationTokenSource.Cancel();
                Fail("{0}\r\n\r\n    {1}", failure.Message, Resources.ForCommandLineHelp);
            }
            return 0;
        }
Example #38
0
        /// <summary>
        /// ���±����ļ�
        /// </summary>
        /// <param name="url">Զ�̻���Ŀ¼</param>
        /// <param name="systemType">���� 0 Fedoreϵͳ 1 Redhatϵͳ</param>
        /// <param name="currVersion">��ǰ�汾</param>
        /// <param name="saveDic">������ļ�Ŀ¼</param>
        /// <returns>
        /// true �ɹ� ; 
        /// false ʧ��
        /// </returns>
        public static string UpdateFile(int systemType, int currVersion)
        {
            string version = GetVersion(systemType);

            if (version == null)
                return null;

            if (Convert.ToInt32(version) <= currVersion)
                return null;

            string temp = string.Empty;
            string dic = SAVEDIC;

            if (systemType == 0)
            {
                temp = URL + FEDORE + "/update.tgz";
                dic = dic + FEDORE;
            }
            else if (systemType == 1)
            {
                temp = URL + REDHAT + "/update.tgz";
                dic = dic + REDHAT;
            }
            else if (systemType == 2)
            {
                temp = URL + WINDOWS + "/MainProc.exe";
                dic = dic + WINDOWS;
            }

            RemoteFile rf = new RemoteFile();
            rf.SaveDic = dic;

            if (rf.SaveRemoteFile(temp))
                return rf.DownPath;

            return null;
        }
        /// <summary>
        /// Parse the HTML of the source page.
        /// </summary>
        /// <param name="sourceUrl">
        /// The source Url.
        /// </param>
        /// <param name="targetUrl">
        /// The target Url.
        /// </param>
        private void ExamineSourcePage(string sourceUrl, string targetUrl)
        {
            try
            {
                var remoteFile = new RemoteFile(new Uri(sourceUrl), true);
                var html = remoteFile.GetFileAsString();
                this.sourceHasLink = html.ToUpperInvariant().Contains(targetUrl.ToUpperInvariant());
                
            }
            catch (WebException)
            {
                this.sourceHasLink = false;

                // throw new ArgumentException("Trackback sender does not exists: " + sourceUrl, ex);
            }
        }
Example #40
0
        /// <summary>
        /// Retrieves and cached the specified remote script.
        /// </summary>
        /// <param name="file">
        /// The remote URL
        /// </param>
        /// <param name="cacheKey">The key used to insert this script into the cache.</param>
        /// <param name="minify">Whether or not the remote script should be minified</param>
        /// <returns>
        /// The retrieve remote script.
        /// </returns>
        private static string RetrieveRemoteScript(string file, string cacheKey, bool minify)
        {
            Uri url;

            if (Uri.TryCreate(file, UriKind.Absolute, out url))
            {
                try
                {

                    var remoteFile = new RemoteFile(url, false);
                    string script = remoteFile.GetFileAsString();
                    script = ProcessScript(script, file, minify);
                    HttpContext.Current.Cache.Insert(cacheKey, script, null, Cache.NoAbsoluteExpiration, new TimeSpan(3, 0, 0, 0));
                    return script;
                }
                catch (SocketException)
                {
                    // The remote site is currently down. Try again next time.
                }
            }

            return String.Empty;
        }
 public static RemoteFile CreateRemoteFile(int version, string resource, string localFileName)
 {
     RemoteFile remoteFile = new RemoteFile();
     remoteFile.Version = version;
     remoteFile.Resource = resource;
     remoteFile.LocalFileName = localFileName;
     return remoteFile;
 }
Example #42
0
        /// <summary>
        /// Retrieves and caches the specified remote CSS.
        /// </summary>
        /// <param name="file">
        /// The remote URL
        /// </param>
        /// <param name="cacheKey">
        /// The key used to insert this script into the cache.
        /// </param>
        /// <returns>
        /// The retrieve remote css.
        /// </returns>
        private static string RetrieveRemoteCss(string file, string cacheKey)
        {
            Uri url;

            if (Uri.TryCreate(file, UriKind.Absolute, out url))
            {
                try
                {
                    var remoteFile = new RemoteFile(url, false);
                    string css = remoteFile.GetFileAsString();
                    css = ProcessCss(css);

                    // Insert into cache
                    HttpContext.Current.Cache.Insert(
                        cacheKey,
                        css,
                        null,
                        Cache.NoAbsoluteExpiration,
                        new TimeSpan(3, 0, 0, 0));

                    return css;
                }
                catch (SocketException)
                {
                    // The remote site is currently down. Try again next time.
                }
            }

            return string.Empty;
        }
        /// <summary>
        /// The (non-static) startup method
        /// </summary>
        /// <param name="args">The command line arguments.</param>
        /// <returns>Process return code.</returns>
        /// <remarks></remarks>
        protected override int Main(IEnumerable<string> args)
        {
            _messages = new PackageManagerMessages {
                UnexpectedFailure = UnexpectedFailure,
                NoPackagesFound = NoPackagesFound,
                PermissionRequired = OperationRequiresPermission,
                Error = MessageArgumentError,
                RequireRemoteFile = (canonicalName, remoteLocations, localFolder, force ) => Downloader.GetRemoteFile(canonicalName, remoteLocations, localFolder, force, new RemoteFileMessages {
                    Progress = (itemUri, percent) => {
                        "Downloading {0}".format(itemUri.AbsoluteUri).PrintProgressBar(percent);
                    }, Completed = (itemUri) => {
                        Console.WriteLine();
                    }
                } ,_messages),
                OperationCancelled = CancellationRequested,
                PackageSatisfiedBy = (original, satisfiedBy) => {
                    original.SatisfiedBy = satisfiedBy;
                },
                PackageBlocked = BlockedPackage,
                UnknownPackage = UnknownPackage,
            };

            try {
                #region command line parsing

                var options = args.Where(each => each.StartsWith("--")).Switches();
                var parameters = args.Where(each => !each.StartsWith("--")).Parameters();

                foreach (var arg in options.Keys) {
                    var argumentParameters = options[arg];
                    var last = argumentParameters.LastOrDefault();
                    var lastAsBool = string.IsNullOrEmpty(last) || last.IsTrue();

                    switch (arg) {
                            /* options  */
                        case "min-version":
                            _minVersion = last.VersionStringToUInt64();
                            break;

                        case "max-version":
                            _maxVersion = last.VersionStringToUInt64();
                            break;

                        case "installed":
                            _installed = lastAsBool;
                            break;

                        case "active":
                            _active = lastAsBool;
                            break;

                        case "required":
                            _required = lastAsBool;
                            break;

                        case "blocked":
                            _blocked = lastAsBool;
                            break;

                        case "latest":
                            _latest = lastAsBool;
                            break;

                        case "force":
                            _force = lastAsBool;
                            break;

                        case "force-scan":
                            _forceScan = lastAsBool;
                            break;

                        case "download":
                            _download = lastAsBool;
                            break;

                        case "pretend":
                            _pretend= lastAsBool;
                            break;

                        case "auto-upgrade":
                            _autoUpgrade = lastAsBool;
                            break;

                        case "use-feed":
                            _location = last;
                            break;

                        case "pause":
                            _pause = lastAsBool;
                            break;

                        case "verbose":
                            _verbose = lastAsBool;
                            Logger.Errors = true;
                            Logger.Messages = true;
                            Logger.Warnings = true;
                            break;

                        case "dependencies":
                        case "deps":
                            _dependencies = lastAsBool;
                            break;

                            /* global switches */
                        case "load-config":
                            // all ready done, but don't get too picky.
                            break;

                        case "nologo":
                            this.Assembly().SetLogo(string.Empty);
                            break;

                        case "terse":
                            this.Assembly().SetLogo(string.Empty);
                            _terse = true;
                            _verbose = false;
                            break;

                        case "help":
                            return Help();

                        default:
                            throw new ConsoleException(Resources.UnknownParameter, arg);
                    }
                }

                Logo();

                if (parameters.Count() < 1) {
                    throw new ConsoleException(Resources.MissingCommand);
                }

                #endregion

                Task task = null;
                var command = parameters.FirstOrDefault();
                parameters = parameters.Skip(1);

                if (ConsoleExtensions.InputRedirected) {
                    // grab the contents of the input stream and use that as parameters
                    var lines = Console.In.ReadToEnd().Split(new[] {
                        '\r', '\n'
                    }, StringSplitOptions.RemoveEmptyEntries).Select(each => each.Split(new[] {
                        '#'
                    }, StringSplitOptions.RemoveEmptyEntries)[0]).Select(each => each.Trim());

                    parameters = parameters.Union(lines.Where(each => !each.StartsWith("#"))).ToArray();
                }

                if (ConsoleExtensions.OutputRedirected) {
                    this.Assembly().SetLogo(string.Empty);
                    _terse = true;
                    _verbose = false;
                }

                if (command.IsNullOrEmpty()) {
                    return Help();
                }

                Verbose("# Connecting to Service...");
                _pm.ConnectAndWait("coapp-cli-client", null, 5000);
                Verbose("# Connected to Service...");

                if( _verbose) {
                    _pm.SetLogging(true, true, true);
                }

                if (command.EndsWith(".msi") && File.Exists(command) && parameters.IsNullOrEmpty()) {
                    // assume install if the only thing given is a filename.
                    task =
                        _pm.GetPackages(command, _minVersion, _maxVersion, _dependencies , _installed, _active, _required, _blocked, _latest, _location, _forceScan, messages: _messages).
                            ContinueWith(antecedent => Install(antecedent.Result));
                    return 0;
                }

                if (!command.StartsWith("-")) {
                    command = command.ToLower();
                }

                switch (command) {
            #if FALSE
                        case "download":
                            var remoteFileUri = new Uri(parameters.First());
                            // create the remote file reference
                            var remoteFile = new RemoteFile(remoteFileUri, CancellationTokenSource.Token);
                            var previewTask = remoteFile.Preview();
                            previewTask.Wait();
                            // Tell it to download it
                            var getTask = remoteFile.Get();

                            // monitor the progress.
                            remoteFile.DownloadProgress.Notification += progress => {
                                // this executes when the download progress value changes.
                                Console.Write(progress <= 100 ? "..{0}% " : "bytes: [{0}]", progress);
                            };

                            // when it's done, do this:
                            getTask.ContinueWith(t => {
                                // this executes when the Get() operation completes.
                                Console.WriteLine("File {0} has finished downloading", remoteFile.LocalFullPath);
                            },TaskContinuationOptions.AttachedToParent);
                            break;

                        case "verify-package":
                            var r = Verifier.HasValidSignature(parameters.First());
                            Console.WriteLine("Has Valid Signature: {0}", r);
                            Console.WriteLine("Name: {0}", Verifier.GetPublisherInformation(parameters.First())["PublisherName"]);
                            break;
            #endif
                    case "-?":
                        return Help();

                    case "-l":
                    case "list":
                    case "list-package":
                    case "list-packages":
                        task =
                            _pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, _installed, _active, _required, _blocked, _latest, _location,_forceScan,  messages: _messages).ContinueWith(antecedent => ListPackages(antecedent.Result));
                        break;

                    case "-i":
                    case "install":
                    case "install-package":
                    case "install-packages":
                        if (parameters.Count() < 1) {
                            throw new ConsoleException(Resources.InstallRequiresPackageName);
                        }

                        // if you haven't specified this, we're gonna assume that you want the latest version
                        // this is overridden if the user specifies a version tho'
                        if( _latest == null ) {
                            _latest = true;
                        }

                        task =
                            _pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, _installed, _active, _required, _blocked, _latest, _location, _forceScan, messages: _messages).
                                ContinueWith(antecedent => Install(antecedent.Result));
                        break;

                    case "-r":
                    case "remove":
                    case "uninstall":
                    case "remove-package":
                    case "remove-packages":
                    case "uninstall-package":
                    case "uninstall-packages":
                        if (parameters.Count() < 1) {
                            throw new ConsoleException(Resources.RemoveRequiresPackageName);
                        }
                        task =
                            _pm.GetPackages(parameters, _minVersion, _maxVersion,_dependencies, true,  _active, _required, _blocked, _latest,_location,_forceScan,  messages: _messages).
                                ContinueWith(antecedent => Remove(antecedent.Result));

                        break;

                    case "-L":
                    case "feed":
                    case "feeds":
                    case "list-feed":
                    case "list-feeds":
                        task = ListFeeds();
                        break;

                    case "-u":
                    case "upgrade":
                    case "upgrade-package":
                    case "upgrade-packages":
                    case "update":
                    case "update-package":
                    case "update-packages":
                        if (parameters.Count() != 1) {
                            throw new ConsoleException(Resources.MissingParameterForUpgrade);
                        }

                        // if they didn't say to rescan (one way or the other), we're defaulting to yeah,
                        // because we really should force a rescan if we're updating
                        if( _forceScan == null ) {
                            _forceScan = true;
                        }

                        // should get all packages that are installed (using criteria),
                        // and then see if each one of those can be upgraded.

                        task =
                            _pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, true, _active, _required, false, _latest ,_location,_forceScan,  messages: _messages).
                                ContinueWith(antecedent => Upgrade(antecedent.Result));
                        break;

                    case "-A":
                    case "add-feed":
                    case "add-feeds":
                    case "add":
                        if (parameters.Count() < 1) {
                            throw new ConsoleException(Resources.AddFeedRequiresLocation);
                        }
                        task = AddFeed(parameters);
                        break;

                    case "-R":
                    case "remove-feed":
                    case "remove-feeds":
                        if (parameters.Count() < 1) {
                            throw new ConsoleException(Resources.DeleteFeedRequiresLocation);
                        }
                        task = DeleteFeed(parameters);
                        break;

                    case "-t":
                    case "trim-packages":
                    case "trim-package":
                    case "trim":
                        if (parameters.Count() != 0) {
                            throw new ConsoleException(Resources.TrimErrorMessage);
                        }
                        task = _pm.GetPackages("*", _minVersion, _maxVersion, _dependencies, true, false, false, _blocked, _latest, _location,
                            _forceScan, messages: _messages).ContinueWith(antecedent => Remove(antecedent.Result));
                        break;

                    case "-a":
                    case "activate":
                    case "activate-package":
                    case "activate-packages":
                        task =
                            _pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, true, _active, _required, _blocked, _latest, _location,_forceScan,  messages: _messages).
                                ContinueWith(antecedent => Activate(antecedent.Result));

                        break;

                    case "-g":
                    case "get-packageinfo":
                    case "info":
                        task = _pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, _installed, _active, _required, _blocked, _latest, _location,_forceScan,  messages: _messages).ContinueWith(antecedent => GetPackageInfo(antecedent.Result));
                        break;

                    case "-b":
                    case "block-packages":
                    case "block-package":
                    case "block":
                        task =_pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, true, _active, _required, _blocked, _latest, _location,_forceScan,  messages: _messages). ContinueWith(antecedent => Block(antecedent.Result));

                        break;

                    case "-B":
                    case "unblock-packages":
                    case "unblock-package":
                    case "unblock":
                        task = _pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, true, _active, _required, _blocked, _latest, _location,_forceScan,  messages: _messages).ContinueWith(antecedent => UnBlock(antecedent.Result));

                        break;

                    case "-m":
                    case "mark-packages":
                    case "mark-package":
                    case "mark":
                        task =
                            _pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, true, _active, _required, _blocked, _latest, _location,_forceScan,  messages: _messages).
                                ContinueWith(antecedent => Mark(antecedent.Result));
                        break;

                    case "-M":
                    case "unmark-packages":
                    case "unmark-package":
                    case "unmark":
                        task =
                            _pm.GetPackages(parameters, _minVersion, _maxVersion, _dependencies, true, _active, _required, _blocked, _latest, _location,_forceScan,  messages: _messages).
                                ContinueWith(antecedent => UnMark(antecedent.Result));
                        break;

                    case "create-symlink":
                        if (parameters.Count() != 2) {
                            throw new ConsoleException("Create-symlink requires two parameters: existing-location and new-link");
                        }
                        task = _pm.CreateSymlink(parameters.First().GetFullPath(), parameters.Last().GetFullPath(), LinkType.Symlink);
                        break;
                    case "create-hardlink":
                        if (parameters.Count() != 2) {
                            throw new ConsoleException("Create-hardlink requires two parameters: existing-location and new-link");
                        }
                        task = _pm.CreateSymlink(parameters.First().GetFullPath(), parameters.Last().GetFullPath(), LinkType.Hardlink);
                        break;
                    case "create-shortcut":
                        if (parameters.Count() != 2) {
                            throw new ConsoleException("Create-shortcut requires two parameters: existing-location and new-link");
                        }
                        task = _pm.CreateSymlink(parameters.First().GetFullPath(), parameters.Last().GetFullPath(), LinkType.Shortcut);
                        break;

                    case "-p" :
                    case "list-policies":
                    case "list-policy":
                    case "policies":
                        ListPolicies();
                        break;

                    case "add-to-policy": {
                        if (parameters.Count() != 2) {
                            throw new ConsoleException("Add-to-policy requires at two parameters (policy name and account)");
                        }

                        var policyName = parameters.First();
                        var account = parameters.Last();

                        task = _pm.AddToPolicy(policyName, account, _messages).ContinueWith(antecedent => {

                            if( antecedent.IsFaulted ) {
                                throw antecedent.Exception;
                            }

                            _pm.GetPolicy(policyName, new PackageManagerMessages {
                                PolicyInformation = (polName, description, accounts) => {
                                    Console.WriteLine("Policy: {0} -- {1} ", polName, description);
                                    foreach (var acct in accounts) {
                                        Console.WriteLine("   {0}", acct);
                                    }
                                }
                            }.Extend(_messages)).Wait();

                        });
                    }
                        break;

                    case "remove-from-policy": {
                        if (parameters.Count() != 2) {
                            throw new ConsoleException("Remove-to-policy requires at two parameters (policy name and account)");
                        }

                        var policyName = parameters.First();
                        var account = parameters.Last();

                        task = _pm.RemoveFromPolicy(policyName, account, _messages).ContinueWith(antecedent => {

                            if (antecedent.IsFaulted) {
                                throw antecedent.Exception;
                            }

                            _pm.GetPolicy(policyName, new PackageManagerMessages {
                                PolicyInformation = (polName, description, accounts) => {
                                    Console.WriteLine("Policy: {0} -- {1}", polName, description);
                                    foreach (var acct in accounts) {
                                        Console.WriteLine("   {0}", acct);
                                    }
                                }
                            }.Extend(_messages)).Wait();

                        });
                    }
                        break;

                    default:
                        throw new ConsoleException(Resources.UnknownCommand, command);
                }

                if (task != null) {
                    task.ContinueWith(antecedent => {
                        if (!(antecedent.IsFaulted || antecedent.IsCanceled)) {
                            WaitForPackageManagerToComplete();
                        }
                    }).Wait();
                }

                if( _pause == true ) {
                    Console.ReadLine();
                }
                _pm.Disconnect();
                if (_pause == true) {
                    Console.ReadLine();
                }

            }
            catch (ConsoleException failure) {
                Fail("{0}\r\n\r\n    {1}", failure.Message, Resources.ForCommandLineHelp);
                CancellationTokenSource.Cancel();
                _pm.Disconnect();
            }

            return 0;
        }
Example #44
0
        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);
        }
        /// <summary>
        /// Parse the HTML of the source page.
        /// </summary>
        /// <param name="sourceUrl">
        /// The source Url.
        /// </param>
        /// <param name="targetUrl">
        /// The target Url.
        /// </param>
        private void ExamineSourcePage(string sourceUrl, string targetUrl)
        {
            try
            {

                var remoteFile = new RemoteFile(new Uri(sourceUrl), true);
                var html = remoteFile.GetFileAsString();
                this.title = RegexTitle.Match(html).Value.Trim();
                this.containsHtml = RegexHtml.IsMatch(this.title);
                this.sourceHasLink = html.ToUpperInvariant().Contains(targetUrl.ToUpperInvariant());
            }
            catch (WebException)
            {
                this.sourceHasLink = false;
            }
        }
Example #46
0
 protected virtual Uri GetTrackbackUrl(Uri url)
 {
     // ignoreRemoteDownloadSettings should be set to true
     // for backwards compatibilty with Utils.DownloadWebPage.
     var remoteFile = new RemoteFile(url, true);
     var pageContent = remoteFile.GetFileAsString(); // ReadFromWeb(url);
     var trackbackUrl = GetTrackBackUrlFromPage(pageContent);
     return trackbackUrl;
 }
 private static string RetrieveRemoteFile(string file)
 {
     file = Utils.AbsoluteWebRoot.ToString() + file.Substring(1); 
     Uri url;
     if (Uri.TryCreate(file, UriKind.Absolute, out url))
     {
         try
         {
             var script = new RemoteFile(url, false).GetFileAsString();
             
             if (BlogSettings.Instance.CompressWebResource)
             {
                 var min = new JavascriptMinifier();
                 return min.Minify(script);
             }
             
             return script;
         }
         catch (SocketException)
         {
             // The remote site is currently down. Try again next time.
         }
     }
     return string.Empty;
 }