示例#1
0
        public override bool AsyncFetchContents(RemoteUrl remoteUrl, out RemoteServerException remoteException)
        {
            var chorusUrl  = (ChorusUrl)remoteUrl;
            Uri requestUri = GetContentsUri(ChorusAccount, chorusUrl);

            return(AsyncFetch(requestUri, FetchContents, out remoteException));
        }
示例#2
0
        public override void RetryFetchContents(RemoteUrl chorusUrl)
        {
            var unifiUrl = (UnifiUrl)chorusUrl;

            RetryFetch(GetRootContentsUrl(), GetFolders);
            RetryFetch(GetFileContentsUrl(unifiUrl), GetFiles);
        }
示例#3
0
 private RemoteAccount GetRemoteAccount(RemoteUrl remoteUrl)
 {
     return
         (_remoteAccounts.FirstOrDefault(
              remoteAccount =>
              Equals(remoteAccount.ServerUrl, remoteUrl.ServerUrl) &&
              Equals(remoteAccount.Username, remoteUrl.Username)));
 }
示例#4
0
        public override void RetryFetchContents(RemoteUrl chorusUrl)
        {
            Uri requestUri = GetContentsUri(ChorusAccount, (ChorusUrl)chorusUrl);

            if (null == requestUri)
            {
                return;
            }
            RetryFetch(requestUri, FetchContents);
        }
示例#5
0
        public override bool AsyncFetchContents(RemoteUrl remoteUrl, out RemoteServerException remoteException)
        {
            bool result = AsyncFetch(GetRootContentsUrl(), GetFolders, out remoteException);

            if (null == remoteException)
            {
                result = result && AsyncFetch(GetFileContentsUrl((UnifiUrl)remoteUrl), GetFiles, out remoteException);
            }
            return(result);
        }
        public SparkleFetcher(SparkleFetcherInfo info) : base(info)
        {
            if (RemoteUrl.ToString().StartsWith("ssh+"))
            {
                RemoteUrl = new Uri("ssh" + RemoteUrl.ToString().Substring(RemoteUrl.ToString().IndexOf("://")));
            }

            Uri uri = RemoteUrl;

            if (!uri.Scheme.Equals("ssh") && !uri.Scheme.Equals("https") &&
                !uri.Scheme.Equals("http") && !uri.Scheme.Equals("git"))
            {
                uri = new Uri("ssh://" + uri);
            }

            if (uri.Host.Equals("gitorious.org") && !uri.Scheme.StartsWith("http"))
            {
                if (!uri.AbsolutePath.Equals("/") &&
                    !uri.AbsolutePath.EndsWith(".git"))
                {
                    uri = new Uri("ssh://[email protected]" + uri.AbsolutePath + ".git");
                }
                else
                {
                    uri = new Uri("ssh://[email protected]" + uri.AbsolutePath);
                }
            }
            else if (uri.Host.Equals("github.com") && !uri.Scheme.StartsWith("http"))
            {
                uri = new Uri("ssh://[email protected]" + uri.AbsolutePath);
            }
            else if (uri.Host.Equals("bitbucket.org") && !uri.Scheme.StartsWith("http"))
            {
                // Nothing really
            }
            else
            {
                if (string.IsNullOrEmpty(uri.UserInfo) && !uri.Scheme.StartsWith("http"))
                {
                    if (uri.Port == -1)
                    {
                        uri = new Uri(uri.Scheme + "://storage@" + uri.Host + uri.AbsolutePath);
                    }
                    else
                    {
                        uri = new Uri(uri.Scheme + "://storage@" + uri.Host + ":" + uri.Port + uri.AbsolutePath);
                    }
                }

                this.use_git_bin = false; // TODO
            }

            RemoteUrl = uri;
        }
示例#7
0
        ///<summary>Writes this UpdateFile to an XML element for an update manifest.</summary>
        public XElement ToXml()
        {
            return(new XElement("File",
                                new XAttribute("RelativePath", RelativePath),
                                new XAttribute("Url", RemoteUrl.ToString()),
                                new XAttribute("Size", Length.ToString(CultureInfo.InvariantCulture)),
                                new XAttribute("Timestamp", DateModifiedUtc.ToString("o", CultureInfo.InvariantCulture)),

                                new XElement("Hash", Convert.ToBase64String(hash)),
                                signatures.Select(s => new XElement("Signature", Convert.ToBase64String(s)))
                                ));
        }
        private SecureStorageRequest CreateRequest()
        {
            var account = RemoteUrl?.GetLeftPart(UriPartial.Path);

            if (account == null)
            {
                throw new InvalidOperationException($"No account set for {this}");
            }

            var label = $"{RemoteUrl?.Host} OpenID Connect tokens";

            return(new SecureStorageRequest(account, OIDCServiceName, label));
        }
示例#9
0
        public string GetFileMatch(string url)
        {
            if (url.Contains(RemoteUrl.ToLower()))
            {
                url = PathHelper.GetStringAfterSubString(url, RemoteUrl.ToLower()).Split(new char[] { '?' })[0];

                var path = PathHelper.GetLocalFilePath(url, LocalDirectory, Overrides);

                return(path);
            }

            return(null);
        }
示例#10
0
        private SecureStorageRequest CreateRequest()
        {
            var service = RemoteUrl?.GetLeftPart(UriPartial.Path);

            if (service == null)
            {
                throw new InvalidOperationException($"No service set for {this}");
            }

            var label = $"{RemoteUrl?.Host} OpenID Connect tokens";

            return(new SecureStorageRequest(LocalUUID, service, label));
        }
示例#11
0
 private void tryloadUri()
 {
     try
     {
         string text = Clipboard.GetText();
         URLInfo = RemoteUrl.Parse(text) as IRemoteUrl;
         if (URLInfo != null)
         {
             DownloadUri = text;
         }
     }
     catch
     { }
 }
示例#12
0
        internal String BuildRelativeURLString(String relativePath)
        {
            // the following code is a band-aid for a system problem in the codebase
            // where it is appending "relative paths" that start with a slash, eg:
            //     http://dotcom/db/ + /relpart == http://dotcom/db/relpart
            // which is not compatible with the way the java url concatonation works.
            var remoteUrlString = RemoteUrl.ToString();

            if (remoteUrlString.EndsWith("/", StringComparison.InvariantCultureIgnoreCase) && relativePath.StartsWith("/", StringComparison.InvariantCultureIgnoreCase))
            {
                remoteUrlString = remoteUrlString.Substring(0, remoteUrlString.Length - 1);
            }
            return(remoteUrlString + relativePath);
        }
示例#13
0
		/// <summary>
		/// 根据 URL 从远程 获取Value值
		/// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String getValueFromServer(String url) throws Exception
		public virtual string getValueFromServer(string url)
		{

			// 远程地址
			RemoteUrl remoteUrl = new RemoteUrl(url, hostList);

			ValueVo confItemVo = restfulMgr.getJsonData(typeof(ValueVo), remoteUrl, retryTime, retrySleepSeconds);
			LOGGER.debug("remote server return: " + confItemVo.ToString());

			if (confItemVo.Status.Equals(Constants.NOTOK))
			{
				throw new Exception("status is not ok.");
			}

			return confItemVo.Value;
		}
示例#14
0
        public void TestRemoteUrl()
        {
            VideoInfo[] vInfos = new VideoInfo[]
            {
                new VideoInfo("video1", 2, "Name1"),
                new VideoInfo("video2", 2),
            };
            IUrl   url       = new RemoteUrl("127.0.0.1", 10000, new DateTime(2016, 1, 1), new DateTime(2016, 1, 2), vInfos, @"d:\path");
            string urlString = url.ToString();

            Console.WriteLine(urlString);
            var urlNew = RemoteUrl.Parse(urlString);

            Assert.AreEqual(url.LocalPath, urlNew.LocalPath);
            Assert.AreEqual(url.VideoInfos.Length, urlNew.VideoInfos.Length);
            (url as RemoteUrl).CheckValid();
        }
示例#15
0
        public void TestRemoteUrl_CheckValid()
        {
            VideoInfo[] vInfos = new VideoInfo[]
            {
                new VideoInfo("CCTV1_50BAD15900010301", 1, "Name1"),
                new VideoInfo("CCTV1_50BAD15900010302", 1),
            };
            new RemoteUrl("127.0.0.1", 10000, new DateTime(2016, 1, 1), new DateTime(2016, 1, 2), vInfos, @"d:\path").CheckValid();
            RemoteUrl url = new RemoteUrl("127.0.0.1", 100000, new DateTime(2016, 1, 1), new DateTime(2016, 1, 2), vInfos, @"d:\path");

            ExceptionManager.CheckInvalidOperationException(url.CheckValid);
            ExceptionManager.CheckInvalidOperationException(new RemoteUrl("127.0.0.1", 10, new DateTime(2016, 1, 1), new DateTime(2016, 1, 2), vInfos, @"d:\path").CheckValid);
            url = new RemoteUrl("192.168.257.1", 10000, new DateTime(2016, 1, 1), new DateTime(2016, 1, 2), vInfos, @"d:\path");
            ExceptionManager.CheckInvalidOperationException(url.CheckValid);
            url = new RemoteUrl("192.168.1.1", 10000, new DateTime(2016, 1, 1), new DateTime(2015, 1, 2), vInfos, @"d:\path");
            ExceptionManager.CheckInvalidOperationException(url.CheckValid);
        }
示例#16
0
        private void this_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(DownloadUri):
                URLInfo            = null;
                ErrorInfo          = null;
                IsEnabledDirectory = false;
                IsEnabledDownload  = false;
                VideoInfos         = new ObservableCollection <DownloadVideoInfo>();
                try
                {
                    URLInfo      = RemoteUrl.Parse(DownloadUri) as IRemoteUrl;
                    BeginTime    = toShowTime(URLInfo.BeginTime);
                    EndTime      = toShowTime(URLInfo.EndTime);
                    DownloadName = GlobalProcess.GetFolderName(URLInfo);

                    foreach (VideoInfo vi in URLInfo.VideoInfos)
                    {
                        VideoInfos.Add(new DownloadVideoInfo()
                        {
                            VideoId   = vi.VideoId,
                            VideoName = string.IsNullOrWhiteSpace(vi.VideoName)? "未知名称": vi.VideoName,
                            StreamId  = vi.StreamId,
                        });
                    }
                    if (!string.IsNullOrWhiteSpace(URLInfo.LocalPath))
                    {
                        DownloadDirectory = new DirectoryInfo(URLInfo.LocalPath).FullName;
                    }
                    else
                    {
                        IsEnabledDirectory = true;
                    }
                    IsEnabledDownload = true;
                }
                catch (Exception ex)
                {
                    ErrorInfo = ex.Message;
                    initData();
                }
                break;
            }
        }
示例#17
0
		/// 
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void tetGetJsonData()
		public virtual void tetGetJsonData()
		{

			try
			{
				RemoteUrl remoteUrl = new RemoteUrl(RemoteMockServer.ITEM_URL, RemoteMockServer.LOCAL_HOST_LIST);

				ValueVo valueVo = restfulMgr.getJsonData(typeof(ValueVo), remoteUrl, 3, 3);

				Assert.assertEquals(RemoteMockServer.DEFAULT_ITEM_VALUE.ToString(), valueVo.Value);

			}
			catch (Exception e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				Assert.assertTrue(false);
			}
		}
示例#18
0
        public void TestRemoteUrl_Pause()
        {
            string urlStr = @"CCTV2:REMOTE/time=63587203200-63587289600/source=127.0.0.1:10000/path=d:\path/videos=video1,2,Name1|video2,2";
            var    url    = RemoteUrl.Parse(urlStr);

            Assert.AreEqual(2, url.VideoInfos.Length);
            string invalidUrlStr0 = @"CCTV1:REMOTE/time=63587203200-63587289600/source=127.0.0.1:10000/path=d:\path/videos=video1,2,Name1|video2,2";

            ExceptionManager.CheckInvalidOperationException(() => RemoteUrl.Parse(invalidUrlStr0));
            string invalidUrlStr1 = @"CCTV2:LOCAL/time=63587203200-63587289600/source=127.0.0.1:10000/path=d:\path/videos=video1,2,Name1|video2,2";

            Assert.IsNull(RemoteUrl.Parse(invalidUrlStr1));
            string invalidUrlStr2 = @"CCTV2:REMOTE/time=63587203200-63587289600/source=127.0.0.1:10000/path=d:\path/videos=video1,2,Name1|video2";

            ExceptionManager.CheckInvalidOperationException(() => RemoteUrl.Parse(invalidUrlStr2));
            string invalidUrlStr3 = @"CCTV2:REMOTE/time=63587203200-63587289600/source=127.0.0.1:10000/";
            var    url3           = RemoteUrl.Parse(invalidUrlStr3);

            Assert.AreEqual(invalidUrlStr3, url3.ToString());
        }
示例#19
0
 private void btnOk_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         IRemoteUrl ui = RemoteUrl.Parse(txtUrl.Text.Trim()) as IRemoteUrl;
         if (ui == null)
         {
             DialogUtil.ShowWarning("不支持导入数据源格式。");
             return;
         }
         ImportUrl         = ui;
         this.DialogResult = true;
         this.Close();
     }
     catch (Exception ex)
     {
         Common.Log.Logger.Default.Error(ex);
         DialogUtil.ShowError(ex.Message);
     }
 }
示例#20
0
		/// 
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void tetDownloadFromServer()
		public virtual void tetDownloadFromServer()
		{

			try
			{
				RemoteUrl remoteUrl = new RemoteUrl(RemoteMockServer.FILE_URL, RemoteMockServer.LOCAL_HOST_LIST);

				string downloadFilePath = restfulMgr.downloadFromServer(remoteUrl, RemoteMockServer.FILE_NAME, RemoteMockServer.LOCAL_DOWNLOAD_DIR, RemoteMockServer.LOCAL_DOWNLOAD_DIR_TEMP, RemoteMockServer.LOCAL_TARGET_DOWNLOAD_DIR, true, 3, 3);

				File file = new File(downloadFilePath);
				string content = FileUtils.readFileToString(file);
				Assert.assertEquals(RemoteMockServer.FILE_CONTENT, content);

			}
			catch (Exception e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				Assert.assertTrue(false);
			}
		}
示例#21
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public bool IsRemoteAccessible()
 {
     if (string.IsNullOrWhiteSpace(RemoteUrl))
     {
         return(true);
     }
     if (RemoteUrl.StartsWith("http"))
     {
         var uri  = new Uri(RemoteUrl);
         var host = uri.Host;
         var port = uri.Port;
         var cli  = new TcpClient();
         try{
             var t = cli.ConnectAsync(host, port);
             return(t.Wait(500));
         }
         catch {
             return(false);
         }
     }
     return(Directory.Exists(RemoteUrl));
 }
示例#22
0
        /// <summary>
        /// Инициализирует и настраиват директорию
        /// </summary>
        public GitHelper Connect()
        {
            if (_connected)
            {
                return(this);
            }

            Directory.CreateDirectory(DirectoryName);
            var gitpath = Path.Combine(DirectoryName, ".git");

            if (!Directory.Exists(gitpath))
            {
                InitializeRepository();
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(RemoteUrl))
                {
                    if (RemoteUrl.Contains("https"))
                    {
                        ExecuteCommand("config", "--global http.sslVerify false");
                    }
                    RemoteSet(RemoteName, RemoteUrl);
                    if (!IsWaitMergeCommit() && 0 == GetChangedFilesList().Length&& IsRemoteAccessible())
                    {
                        EnsureBranch();
                    }
                }
            }
            if (!string.IsNullOrWhiteSpace(RemoteUrl))
            {
                if (!IsWaitMergeCommit() && IsRemoteAccessible())
                {
                    Fetch();
                }
            }
            _connected = true;
            return(this);
        }
示例#23
0
 private void initSettings(string[] args)
 {
     if (args.Length > 0)
     {
         string url = args[0];
         try
         {
             IUrl ui = null;
             try
             {
                 ui = LocalUrl.Parse(url);
             }
             catch { }
             if (ui == null)
             {
                 try
                 {
                     ui = RemoteUrl.Parse(url);
                 }
                 catch { }
             }
             if (ui != null)
             {
                 return;
             }
             if (!tryToRemote(url))
             {
                 throw new ErrorMessageException("URL未能正确解析!");
             }
         }
         catch (ErrorMessageException ae)
         {
             Common.Log.Logger.Default.Error(ae);
             Util.DialogUtil.ShowError(ae.Message);
         }
     }
 }
示例#24
0
        // Create an initial change set when the
        // user has fetched an empty remote folder
        public void CreateInitialChangeSet()
        {
            string file_path = Path.Combine(TargetFolder, "SparkleShare.txt");
            string n         = Environment.NewLine;

            UriBuilder uri_builder = new UriBuilder(RemoteUrl);

            if (RemoteUrl.Scheme.StartsWith("http"))
            {
                uri_builder.UserName = "";
                uri_builder.Password = "";
            }

            // TODO: Find better way to determine if folder should have crypto setup
            bool   repo_is_encrypted = RemoteUrl.ToString().Contains("-crypto");
            string text;

            if (repo_is_encrypted)
            {
                text = GenerateCryptoSalt() + " Secret project! " + GenerateCryptoSalt();
            }
            else
            {
                text = "Congratulations, you've successfully created a SparkleShare repository!" + n +
                       n +
                       "Any files you add or change in this folder will be automatically synced to " + n +
                       uri_builder.ToString() + " and everyone connected to it." + n +
                       n +
                       "SparkleShare is an Open Source software program that helps people " + n +
                       "collaborate and share files. If you like what we do, please consider a small " + n +
                       "donation to support the project: http://www.sparkleshare.org/" + n +
                       n +
                       "Have fun! :)" + n;
            }

            File.WriteAllText(file_path, text);
        }
示例#25
0
        private void Play()
        {
            try
            {
                IDownloadInfo dInfo  = _downloadInfo;
                IUrl          ui     = null;
                VideoInfo[]   vInfos = new VideoInfo[] { new VideoInfo(dInfo.VideoId, dInfo.StreamId, dInfo.VideoName) };

                if (!new DirectoryInfo(Path.Combine(dInfo.DownloadPath, $"{dInfo.VideoId}_{dInfo.StreamId}")).Exists)
                {
                    //throw new FileNotFoundException("未找到该视频!");
                    vInfos = null;
                }

                ui = new RemoteUrl(dInfo.SourceIp, dInfo.SourcePort, dInfo.BeginTime, dInfo.EndTime, vInfos, dInfo.DownloadPath);

                string fileName = @"D:\Workspace\CCTV\CCTVReplay\CCTVReplay\bin\Debug\CCTVReplay.exe";
                if (!new System.IO.FileInfo(fileName).Exists)
                {
                    fileName = @"F:\CCTV\CCTVReplay\CCTVReplay\bin\Debug\CCTVReplay.exe";
                }
                if (!new System.IO.FileInfo(fileName).Exists)
                {
                    fileName = @"CCTVReplay.exe";
                }
                if (!new FileInfo(fileName).Exists)
                {
                    throw new FileNotFoundException("未找到播放软件!");
                }
                Process.Start(fileName, ui.ToString());
                Console.WriteLine("\n\n" + ui.ToString() + "\n\n");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#26
0
        private void populateListViewFromDirectory(MsDataFileUri directory)
        {
            _abortPopulateList = false;
            listView.Cursor    = Cursors.Default;
            _waitingForData    = false;
            listView.Items.Clear();

            var listSourceInfo = new List <SourceInfo>();

            if (null == directory || directory is MsDataFilePath && string.IsNullOrEmpty(((MsDataFilePath)directory).FilePath))
            {
                foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
                {
                    string     label      = string.Empty;
                    string     sublabel   = driveInfo.Name;
                    ImageIndex imageIndex = ImageIndex.Folder;
                    _driveReadiness[sublabel] = false;
                    try
                    {
                        switch (driveInfo.DriveType)
                        {
                        case DriveType.Fixed:
                            imageIndex = ImageIndex.LocalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Local_Drive;
                            if (driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.CDRom:
                            imageIndex = ImageIndex.OpticalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Optical_Drive;
                            if (driveInfo.IsReady && driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.Removable:
                            imageIndex = ImageIndex.OpticalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Removable_Drive;
                            if (driveInfo.IsReady && driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.Network:
                            label = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Network_Share;
                            break;
                        }
                        _driveReadiness[sublabel] = IsDriveReady(driveInfo);
                    }
                    catch (Exception)
                    {
                        label += string.Format(@" ({0})", Resources.OpenDataSourceDialog_populateListViewFromDirectory_access_failure);
                    }

                    string name = driveInfo.Name;
                    if (label != string.Empty)
                    {
                        name = string.Format(@"{0} ({1})", label, name);
                    }

                    listSourceInfo.Add(new SourceInfo(new MsDataFilePath(driveInfo.RootDirectory.FullName))
                    {
                        type         = DataSourceUtil.FOLDER_TYPE,
                        imageIndex   = imageIndex,
                        name         = name,
                        dateModified = GetDriveModifiedTime(driveInfo)
                    });
                }
            }
            else if (directory is RemoteUrl)
            {
                RemoteUrl remoteUrl = directory as RemoteUrl;
                if (string.IsNullOrEmpty(remoteUrl.ServerUrl))
                {
                    foreach (var remoteAccount in _remoteAccounts)
                    {
                        listSourceInfo.Add(new SourceInfo(remoteAccount.GetRootUrl())
                        {
                            name       = remoteAccount.GetKey(),
                            type       = DataSourceUtil.FOLDER_TYPE,
                            imageIndex = ImageIndex.MyNetworkPlaces,
                        });
                    }
                }
                else
                {
                    RemoteAccount remoteAccount = GetRemoteAccount(remoteUrl);
                    if (RemoteSession == null || !Equals(remoteAccount, RemoteSession.Account))
                    {
                        RemoteSession = RemoteSession.CreateSession(remoteAccount);
                    }
                    RemoteServerException exception;
                    bool isComplete = _remoteSession.AsyncFetchContents(remoteUrl, out exception);
                    foreach (var item in _remoteSession.ListContents(remoteUrl))
                    {
                        var imageIndex = DataSourceUtil.IsFolderType(item.Type)
                            ? ImageIndex.Folder
                            : ImageIndex.MassSpecFile;
                        listSourceInfo.Add(new SourceInfo(item.MsDataFileUri)
                        {
                            name         = item.Label,
                            type         = item.Type,
                            imageIndex   = imageIndex,
                            dateModified = item.LastModified,
                            size         = item.FileSize
                        });
                    }
                    if (null != exception)
                    {
                        if (MultiButtonMsgDlg.Show(this, exception.Message, Resources.OpenDataSourceDialog_populateListViewFromDirectory_Retry) != DialogResult.Cancel)
                        {
                            RemoteSession.RetryFetchContents(remoteUrl);
                            isComplete = false;
                        }
                    }
                    if (!isComplete)
                    {
                        listView.Cursor = Cursors.WaitCursor;
                        _waitingForData = true;
                    }
                }
            }
            else if (directory is MsDataFilePath)
            {
                MsDataFilePath msDataFilePath = (MsDataFilePath)directory;
                DirectoryInfo  dirInfo        = new DirectoryInfo(msDataFilePath.FilePath);

                try
                {
                    // subitems: Name, Type, Spectra, Size, Date Modified
                    var arraySubDirInfo = dirInfo.GetDirectories();
                    Array.Sort(arraySubDirInfo, (d1, d2) => string.Compare(d1.Name, d2.Name, StringComparison.CurrentCultureIgnoreCase));
                    var arrayFileInfo = dirInfo.GetFiles();
                    Array.Sort(arrayFileInfo, (f1, f2) => string.Compare(f1.Name, f2.Name, StringComparison.CurrentCultureIgnoreCase));

                    // Calculate information about the files, allowing the user to cancel
                    foreach (var info in arraySubDirInfo)
                    {
                        listSourceInfo.Add(getSourceInfo(info));
                        Application.DoEvents();
                        if (_abortPopulateList)
                        {
                            //MessageBox.Show( "abort" );
                            break;
                        }
                    }

                    if (!_abortPopulateList)
                    {
                        foreach (var info in arrayFileInfo)
                        {
                            listSourceInfo.Add(getSourceInfo(info));
                            Application.DoEvents();
                            if (_abortPopulateList)
                            {
                                //MessageBox.Show( "abort" );
                                break;
                            }
                        }
                    }
                }
                catch (Exception x)
                {
                    var message = TextUtil.LineSeparate(
                        Resources.OpenDataSourceDialog_populateListViewFromDirectory_An_error_occurred_attempting_to_retrieve_the_contents_of_this_directory,
                        x.Message);
                    // Might throw access violation.
                    MessageDlg.ShowWithException(this, message, x);
                    return;
                }
            }

            // Populate the list
            var items = new List <ListViewItem>();

            foreach (var sourceInfo in listSourceInfo)
            {
                if (sourceInfo != null &&
                    (sourceTypeComboBox.SelectedIndex == 0 ||
                     sourceTypeComboBox.SelectedItem.ToString() == sourceInfo.type ||
                     // Always show folders
                     sourceInfo.isFolder))
                {
                    ListViewItem item = new ListViewItem(sourceInfo.ToArray(), (int)sourceInfo.imageIndex)
                    {
                        Tag = sourceInfo,
                    };
                    item.SubItems[2].Tag = sourceInfo.size;
                    item.SubItems[3].Tag = sourceInfo.dateModified;

                    items.Add(item);
                }
            }
            listView.Items.AddRange(items.ToArray());
        }
示例#27
0
		/// <summary>
		/// 下载配置文件, remoteUrl是 url
		/// </summary>
		/// <exception cref="Exception"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String downloadFileFromServer(String url, String fileName, String targetFileDir) throws Exception
		public virtual string downloadFileFromServer(string url, string fileName, string targetFileDir)
		{

			// 下载的路径
			string localDir = LocalDownloadDirPath;

			// 设置远程地址
			RemoteUrl remoteUrl = new RemoteUrl(url, hostList);

			// 下载
			return restfulMgr.downloadFromServer(remoteUrl, fileName, localDir, localDownloadDirTemp, targetFileDir, enableLocalDownloadDirInClassPath, retryTime, retrySleepSeconds);

		}
示例#28
0
 public override string ToString()
 {
     return($"OpenIDAuthenticator[{RemoteUrl?.GetLeftPart(UriPartial.Path)}]");
 }
示例#29
0
 private ConsoleApplicationHandler PrepareCall(string command, string args, int timeout)
 {
     if ((command == "fetch" || command == "push" || command == "clone") && !string.IsNullOrWhiteSpace(RemoteUrl) && RemoteUrl.StartsWith("http"))
     {
         if (!IsRemoteAccessible())
         {
             if (null != OnNotConnected)
             {
                 OnNotConnected.Invoke();
             }
             if (!NoErrorOnNotConnected)
             {
                 throw new Exception("Cannot perform " + command + " because remote url " + RemoteUrl + " is not accessible");
             }
             return(ConsoleApplicationHandler.Null);
         }
     }
     return(new ConsoleApplicationHandler {
         ExePath = "git",
         WorkingDirectory = DirectoryName ?? Environment.CurrentDirectory,
         Arguments = command + " " + args,
         NoWindow = true,
         Timeout = timeout
     });
 }
示例#30
0
        public void Start()
        {
            IsActive = true;
            Started();

            SparkleLogger.LogInfo("Fetcher", TargetFolder + " | Fetching folder: " + RemoteUrl);

            if (Directory.Exists(TargetFolder))
            {
                Directory.Delete(TargetFolder, true);
            }

            string host     = RemoteUrl.Host;
            string host_key = GetHostKey();

            if (string.IsNullOrEmpty(host) || host_key == null)
            {
                Failed();
                return;
            }

            bool warn = true;

            if (RequiredFingerprint != null)
            {
                string host_fingerprint = GetFingerprint(host_key);

                if (host_fingerprint == null || !RequiredFingerprint.Equals(host_fingerprint))
                {
                    SparkleLogger.LogInfo("Auth", "Fingerprint doesn't match");

                    this.errors.Add("error: Host fingerprint doesn't match");
                    Failed();

                    return;
                }

                warn = false;
                SparkleLogger.LogInfo("Auth", "Fingerprint matches");
            }
            else
            {
                SparkleLogger.LogInfo("Auth", "Skipping fingerprint check");
            }

            AcceptHostKey(host_key, warn);

            this.thread = new Thread(() => {
                if (Fetch())
                {
                    Thread.Sleep(500);
                    SparkleLogger.LogInfo("Fetcher", "Finished");

                    IsActive = false;

                    // TODO: Find better way to determine if folder should have crypto setup
                    bool repo_is_encrypted = RemoteUrl.ToString().Contains("crypto");
                    Finished(repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
                }
                else
                {
                    Thread.Sleep(500);
                    SparkleLogger.LogInfo("Fetcher", "Failed");

                    IsActive = false;
                    Failed();
                }
            });

            this.thread.Start();
        }