private async Task <bool> GetFromWebAsync() { try { progressBar.IsIndeterminate = true; ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; string username = (string)localSettings.Values["username"]; if (username == null) { return(false); } else { PasswordVault vault = new PasswordVault(); string password = vault.Retrieve("ClockOutCalculator", username).Password; //Insert your own method here List <TimeSpan> times = await WebLoader.GetFromWebAsync(username, password); for (int i = 0; i < times.Count && i < 3; i++) { timePickers[i].Time = times[i]; } return(true); } } catch (Exception) { return(false); } finally { progressBar.IsIndeterminate = false; } }
private static void SetUpGitFiles() { EnvironmentVariables ev = EnvironmentVariables.Instance; string precommitPath = Path.Combine(ev["userpath"], ev["precommitPath"]); string gitAttributesPath = Path.Combine(ev["userpath"], ev["gitAttributesPath"]); string gitIgnorePath = Path.Combine(ev["userpath"], ev["gitIgnorePath"]); string emptyDirectoryRemoverPath = Path.Combine(ev["userpath"], ev["emptyDirectoryRemoverPath"]); using (var wc = new WebClient()) { WebLoader.SaveText(wc, ev["precommitHook"], precommitPath); Dialogue($"Precommit Hook has been placed @ {precommitPath}"); WebLoader.SaveText(wc, ev["gitAttributes"], gitAttributesPath); Dialogue($"Git Attributes have been placed @ {gitAttributesPath}"); WebLoader.SaveText(wc, ev["gitIgnore"], gitIgnorePath); Dialogue($"Git Ignore has been been placed @ {gitIgnorePath}"); if (!DirectoryManipulator.Find(Path.Combine(ev["userpath"], ev["assetsFolder"]))) { Dialogue("I was unable to locate an assets folder, I have created one for now."); DirectoryManipulator.CreateNew(Path.GetDirectoryName(emptyDirectoryRemoverPath)); } WebLoader.ScrapeText(wc, ev["emptyDirectoryRemover"], emptyDirectoryRemoverPath); Dialogue($"EmptyDirectoryRemover has been placed @ {emptyDirectoryRemoverPath}"); } }
// Start is called before the first frame update void Start() { try { map = GameObject.FindGameObjectWithTag("Map").GetComponent <AbstractMap>(); foreach (WebLoader wl in gameObject.GetComponents <WebLoader>()) { if (wl.enabled) { dataSource = wl; break; } } } catch (System.Exception) { } g = new Gradient(); colorKey[0].time = 0.0f; colorKey[1].color = dropColor; colorKey[1].time = 1.0f; alphaKey[1].alpha = 1.0f; alphaKey[1].time = 1.0f; }
// Update is called once per frame void Update() { if (wl == null) { try { wl = GameObject.FindGameObjectWithTag("GameController").GetComponent <WebLoader>(); } catch (System.Exception) { Debug.LogError("Did you forget to start the webloader?"); } } if (map == null) { try { map = GameObject.FindGameObjectWithTag("Map").GetComponent <AbstractMap>(); map.OnInitialized += delegate { updateMap(); }; map.OnUpdated += delegate { updateMap(); }; updateMap(); } catch (System.Exception) { } } }
// Use this for initialization void Start() { if (wl == null) { try { foreach (var webl in GameObject.FindGameObjectWithTag("GameController").GetComponents <WebLoader>()) { if (webl.isActiveAndEnabled) { wl = webl; break; } } } catch (System.Exception) { Debug.Log("Did you forget to start the webloader?"); } } if (map == null) { try { map = GameObject.FindGameObjectWithTag("Map").GetComponent <AbstractMap>(); map.OnInitialized += delegate { newMap(); }; map.OnUpdated += delegate { updateMap(); }; } catch (System.Exception) { } } }
//开始、继续、从新下载 public void CheckDownLoadList() { if (_taskList.Count == 0) { return; } WebLoader loader = GetIdleLoader(); if (loader == null) { return; } var finishedCount = 0;//已经完成的数目 for (int i = 0; i < _taskList.Count; i++) { DownloadTask task = _taskList[i]; switch (task.state) { case DownloadTaskState.Failed: Logger.Error(task.itemPath + " giveup"); _taskList.RemoveAt(i); i--; task.OnError(); break; case DownloadTaskState.Success: //Logger.Log("完成任务:" + task.itemPath); finishedCount++; _taskList.RemoveAt(i); task.OnFinished(); i--; break; case DownloadTaskState.Wait: case DownloadTaskState.Retry: if (task.retryCount >= MAX_COUNT) { Logger.Error("failed too much. give up" + task.itemPath); _taskList.RemoveAt(i); i--; task.OnError(); break; } loader.StartLoad(task); return; } } //如果全部完成,修改原来等于判断,不然最后一个或者只有一个下载任务时不会执行自己的finish if (_taskList.Count == 0) { if (AllDownloadFinished != null) { AllDownloadFinished(); AllDownloadFinished = null; } } }
private async Task RunAsync(CancellationToken cancellationToken) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse( ConfigurationManager.AppSettings["StorageConnectionString"] ); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue commandQueue = queueClient.GetQueueReference(CommandMessage.QUEUE_COMMAND); commandQueue.CreateIfNotExists(); CloudQueue urlQueue = queueClient.GetQueueReference(UrlMessage.QUEUE_URL); commandQueue.CreateIfNotExists(); while (!cancellationToken.IsCancellationRequested) { CloudQueueMessage commandMessage = commandQueue.GetMessage(TimeSpan.FromMinutes(5)); if (commandMessage != null) { if (commandMessage.AsString == CommandMessage.COMMAND_LOAD) { workerStateMachine.setState(WorkerStateMachine.STATE_LOADING); webLoader = new WebLoader(); } else if (commandMessage.AsString == CommandMessage.COMMAND_IDLE) { workerStateMachine.setState(WorkerStateMachine.STATE_IDLE); } else if (commandMessage.AsString == CommandMessage.COMMAND_CRAWL) { workerStateMachine.setState(WorkerStateMachine.STATE_CRAWLING); webCrawler = new WebCrawler(statsManager); } commandQueue.DeleteMessage(commandMessage); } if (workerStateMachine.getState() != WorkerStateMachine.STATE_IDLE) // in a loading or crawling state { CloudQueueMessage urlMessage = urlQueue.GetMessage(); if (urlMessage != null) // got url from queue of sitemap or urlset { // load or crawl with UrlEntity depending on current state UrlMessage urlEntity = UrlMessage.Parse(urlMessage.AsString); bool deleteMessage = workerStateMachine.Act(urlEntity); if (deleteMessage) { urlQueue.DeleteMessage(urlMessage); } } else { workerStateMachine.Act(null); // need to call Act(null) to finish crawling one day } } await Task.Delay(100); } }
// Use this for initialization void Start() { if (singletonScripts != null) { inputDetector = (InputDetector)singletonScripts.GetComponent("InputDetector"); webLoader = singletonScripts.GetComponent <WebLoader>(); } }
public void Setup() { var webLoader = new WebLoader(); var settings = new SettingsStub(); var repos = new SecurityRepository(webLoader, settings); var useraccessDto = repos.LoadAccessLevel().Result; _permissionManager = new PermissionManager(useraccessDto); }
public RamMalfunctionsDbInitializer() { _resourcePath = ConfigurationManager.ConnectionStrings["GithubPages"].ConnectionString; webLoader = new WebLoader(); _configFileNames = new[] { "Ram", "FixIssue", "Malfunction", "UserServiceLink" }; }
private static void WeblinkTest() { WebLoader webload = new WebLoader(); string[] lines = webload.load(); foreach (string line in lines) { Console.WriteLine(line); } }
public void CanLoadSessionMap() { var webLoader = new WebLoader(); var settings = new SettingsStub(); var repos = new SecurityRepository(webLoader, settings); var level = repos.LoadSessionMap().Result; Assert.IsNotNull(level); level.AssertNoPropertiesAreNull(); }
public void Init() { GameObject go = new GameObject(); go.name = "DownloadMgr"; for (int i = 0; i < LOADER_MAXIMUM; i++) { WebLoader loader = go.AddComponent <WebLoader>(); loader.Init(this); _loaders[i] = loader; } }
public async Task GetDecodedVin_DecodesCorrectly_WhenVinIsValid() { var webLoader = new WebLoader(); var options = Options.Create(new SiteSettingsConfiguration() { Manufacturers = new string[] { "Subaru" } }); var service = new VinDecoderService(webLoader, options); var result = await service.GetDecodedVin(_vin); Assert.IsNotNull(result); }
public static IDataLoader GetLoaderFor(string source) { IDataLoader loader; if (source.IsUrl()) { loader = new WebLoader(source); } else { loader = new LocalLoader(source); } return(loader); }
public DataParser(WebLoader webloader) { _webloader = webloader; foreach (string line in _webloader.Lines) { //try block try { string[] dataList = line.Split(','); _employee = new Employee(dataList[0], dataList[1], dataList[2], dataList[3], dataList[4], dataList[5], dataList[6], dataList[7]); _employeelistdictionary.Add(_employee, _employee); } catch (Exception exception) { Console.WriteLine(exception.Message); } } }
// Use this for initialization void Start() { if (ButtonHandler == null) { ButtonHandler = GameObject.FindGameObjectWithTag("ButtonHandler").GetComponent <vars>(); } if (ButtonHandler == null) { Debug.LogError("No Button handler found"); } if (wl == null) { try { foreach (var webl in GameObject.FindGameObjectWithTag("GameController").GetComponents <WebLoader>()) { if (webl.isActiveAndEnabled) { wl = webl; break; } } } catch (System.Exception) { Debug.LogError("Did you forget to start the webloader?"); } } if (map == null) { try { map = GameObject.FindGameObjectWithTag("Map").GetComponent <AbstractMap>(); } catch (System.Exception) { } } }
private bool LoadFromUri(string rawUri, string sourceFileDir, Action refreshAction, out string errorString) { if (string.IsNullOrWhiteSpace(rawUri)) { Source = null; errorString = "No image specified"; return(false); } var expandedUrl = _variableExpander.ProcessText(rawUri); if (!File.Exists(expandedUrl)) //TODO: Refactor this eg. post processing step { // if the file does not exists, but we have an existing "docfx.json", lets try to find file in "$(ProjectDir)\images" directory var jsonFile = _variableExpander.ProcessText("$(ProjectDir)\\docfx.json"); if (File.Exists(jsonFile)) { // Example: we replace in "..\\images\picture.png" all the ".." with "$ProjectDir" --> "$ProjectDir\\images\\picture.png" expandedUrl = rawUri.Replace("..", "$(ProjectDir)"); expandedUrl = _variableExpander.ProcessText(expandedUrl); } } var success = Uri.TryCreate(_variableExpander.ProcessText(expandedUrl), UriKind.Absolute, out var uri); var canLoadData = success && DataUriLoader.CanLoad(uri); var canLoadFromWeb = success && WebLoader.CanLoad(uri); if (canLoadData) { //TODO [!]: Currently, this loading system prevents images from being changed on disk, fix this // e.g. using http://stackoverflow.com/questions/1763608/display-an-image-in-wpf-without-holding-the-file-open Source = Load(DataUriLoader.Load(uri), uri); } else if (canLoadFromWeb) { expandedUrl = WebLoader.Load(uri); } else if (!success && !Path.IsPathRooted(expandedUrl) && sourceFileDir != null) { expandedUrl = Path.Combine(sourceFileDir, expandedUrl); expandedUrl = Path.GetFullPath((new Uri(expandedUrl)).LocalPath); } if (!canLoadData && File.Exists(expandedUrl)) { var data = new MemoryStream(File.ReadAllBytes(expandedUrl)); Source = Load(data, new Uri(expandedUrl)); // Create file system watcher to update changed image file. _watcher = new FileSystemWatcher { //NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size, Path = Path.GetDirectoryName(expandedUrl), Filter = Path.GetFileName(expandedUrl) }; var w = _watcher; void Refresh(object sender, FileSystemEventArgs e) { try { var enableRaisingEvents = w.EnableRaisingEvents; w.EnableRaisingEvents = false; if (!enableRaisingEvents) { return; } Attributes.Url = null; refreshAction(); } catch { // ignored } } _watcher.Changed += Refresh; _watcher.Renamed += Refresh; _watcher.Deleted += Refresh; _watcher.EnableRaisingEvents = true; errorString = null; return(true); } Source = null; errorString = $"Could not load image '{uri}' (resolved to '{expandedUrl}')"; return(false); }
public async Task <TablesCombinationModel> GetParticipantsAsync() { var loader = new WebLoader(); var crawler = new CompetitionsDataReader(loader); var executionRootPath = Path.GetFullPath(HostingEnvironment.ApplicationPhysicalPath); var projectRootPath = Directory.GetParent(Directory.GetParent(executionRootPath).FullName).FullName; //var competitionsDataPath = $"{projectRootPath}\\SampleData\\AllCopmetitionsPageData.txt"; //var participantsDataPath = $"{projectRootPath}\\SampleData\\UkrainianPilotsTable.txt"; var competitionsDataPath = $"http://civlrankings.fai.org/?a=327&ladder_id=3&ranking_date=2017-09-01&"; var participantsDataPath = $"http://civlrankings.fai.org/?a=326&ladder_id=3&ranking_date=2017-09-01&nation_id=230&"; var competitionsTable = await crawler.LoadUsedCompetitionsTableAsync(competitionsDataPath); var participantsTable = await crawler.LoadNationPilotsTableAsync(participantsDataPath); var competitions = new Dictionary <int, Competition>(); foreach (DataRow competitionRow in competitionsTable.Rows) { var competitionId = GetCellValue(competitionRow, "CompetitionId"); var pq = GetCellValue(competitionRow, "Pq"); var name = GetCellValue(competitionRow, "Name"); int parsedId = GeInt(competitionId); if (competitions.ContainsKey(parsedId)) { continue; } var parsedPq = GetDouble(pq); competitions.Add( parsedId, new Competition { Id = parsedId, Name = name.ToString(), Quality = parsedPq }); } var participants = new List <NationTeamParticipant>(); foreach (DataRow participantRow in participantsTable.Rows) { var rank = GetCellValue(participantRow, "Rank").ToString(); rank = rank.Substring(0, rank.IndexOf('w')); var name = GetCellValue(participantRow, "Name").ToString(); name = name.Substring(0, name.IndexOf("CIVL")); var rating = GetCellValue(participantRow, "Points"); var cr1 = GetCellValue(participantRow, "CompetitionRating1"); var cr2 = GetCellValue(participantRow, "CompetitionRating2"); var cr3 = GetCellValue(participantRow, "CompetitionRating3"); var cr4 = GetCellValue(participantRow, "CompetitionRating4"); var cid1 = GetCellValue(participantRow, "CompetitionId1"); var cid2 = GetCellValue(participantRow, "CompetitionId2"); var cid3 = GetCellValue(participantRow, "CompetitionId3"); var cid4 = GetCellValue(participantRow, "CompetitionId4"); var cid1Parsed = GeInt(cid1); var cid2Parsed = GeInt(cid2); var cid3Parsed = GeInt(cid3); var cid4Parsed = GeInt(cid4); var cq1 = GetCq(competitions, cid1Parsed); var cq2 = GetCq(competitions, cid2Parsed); var cq3 = GetCq(competitions, cid3Parsed); var cq4 = GetCq(competitions, cid4Parsed); var cr1Parsed = GetDouble(cr1); var cr2Parsed = GetDouble(cr2); var cr3Parsed = GetDouble(cr3); var cr4Parsed = GetDouble(cr4); var rankParsed = GeInt(rank); var ratingParsed = GetDouble(rating); participants.Add( new NationTeamParticipant { Rank = rankParsed, Name = name.ToString(), Rating = ratingParsed, CQ1 = cq1, CQ2 = cq2, CQ3 = cq3, CQ4 = cq4, CR1 = cr1Parsed, CR2 = cr2Parsed, CR3 = cr3Parsed, CR4 = cr4Parsed }); } CalculateQuivalentRankings(participants); var equivalentRatingOrderList = participants.OrderByDescending(part => part.EquivalentRating).ToList(); var model = new TablesCombinationModel { DirectList = participants, EquivalentList = equivalentRatingOrderList }; return(model); }
private IEnumerator RunLoadImageFromWeb() { var fileToLoad = _imageUri; // Start image download. var loader = WebLoader.LoadImage(_imageUri, size: Dimensions[ImageSize], alsoReturnBytes: CacheImage, fitMode: FitMode); yield return(loader); IsLoading = false; // Safety check to see if we didn't change files while the download was happening. if (_imageUri != fileToLoad) { // Unload the no longer needed texture. if (loader.Current is TextureAndBytes) { DestroyTexture(((TextureAndBytes)loader.Current).Texture); } else if (loader.Current is Texture2D) { DestroyTexture((Texture2D)loader.Current); } yield break; } // Retrieve texture, or texture and raw bytes if we intend to cache the image. Texture2D texture = null; byte[] bytes = null; if (CacheImage) { if (loader.Current is TextureAndBytes) { texture = ((TextureAndBytes)loader.Current).Texture; bytes = ((TextureAndBytes)loader.Current).Bytes; } } else { texture = loader.Current as Texture2D; } if (texture == null) { yield break; } _texture = texture; // Clamp the texture to prevent artifacts on raw images. _texture.wrapMode = TextureWrapMode.Clamp; // Apply the texture to the raw image. ApplyImage(_texture); // Add the texture to the dictionary if it is flagged to be kept in memory. AddToMemoryList(); // Cache the image if desired. if (CacheImage && bytes != null) { if (GetCachedImagePath() != null) { File.WriteAllBytes(GetCachedImagePath(), bytes); } } }
public static void ClipSSHKeys(string location) { Clipboard.SetText(FileManipulator.ReadFile(location)); WebLoader.Load(EnvironmentVariables.Instance["sshKeyWebsite"]); }
// Use this for initialization void Start() { if (singletonScripts != null) { inputDetector = (InputDetector) singletonScripts.GetComponent("InputDetector"); webLoader = singletonScripts.GetComponent<WebLoader>(); } }