public static string AbsolutoParaRelativo(string de, string para, string inicio) { string path = new Uri(para).MakeRelativeUri(new Uri(de)).ToString(); path = path.Substring(path.LastIndexOf(inicio), path.Length - path.LastIndexOf(inicio)); return "~" + path; }
public Compiler() { configFileName = "config.cpp"; stdLibPath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath; stdLibPath = stdLibPath.Substring(0, stdLibPath.LastIndexOf('\\')) + "\\stdLibrary\\"; addFunctionsClass = true; outputFolderCleanup = true; printOutMode = 0; flagDefines = new List<PPDefine>(); SqfCall.readSupportInfoList(); includedFiles = new List<string>(); }
private string generateLocalEpisodeFileName(PodcastEpisodeModel podcastEpisode) { // Parse the filename of the logo from the remote URL. string localPath = new Uri(podcastEpisode.EpisodeDownloadUri).LocalPath; string podcastEpisodeFilename = localPath.Substring(localPath.LastIndexOf('/') + 1); podcastEpisodeFilename = PodcastSubscriptionsManager.sanitizeFilename(podcastEpisodeFilename); podcastEpisodeFilename = String.Format("{0}_{1}", DateTime.Now.Millisecond, podcastEpisodeFilename); string localPodcastEpisodeFilename = App.PODCAST_DL_DIR + "/" + podcastEpisodeFilename; Debug.WriteLine("Found episode filename: " + localPodcastEpisodeFilename); return localPodcastEpisodeFilename; }
private MimeType[] GetAcceptedTypes(MimeTypes registeredMimes) { var mimeTypes = new List<MimeType>(); var originalUrl = Request.Uri.GetLeftPart(UriPartial.Authority) + Request.Url; var lastSegment = new Uri(originalUrl).Segments.Last(); if (lastSegment.Contains(".") && (lastSegment.LastIndexOf(".") < lastSegment.Length - 1)) { var extension = lastSegment.Substring(lastSegment.LastIndexOf(".") + 1); var mimeType = registeredMimes.GetMimeTypeForExtension(extension); if (mimeType != null) mimeTypes.Add(mimeType); } mimeTypes.AddRange(AcceptType.Parse(AcceptHeader, registeredMimes)); return mimeTypes.Distinct().ToArray(); }
public ActionResult MetaGenerator(string domain, string page) { domain = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port).ToLower(); var host = new System.Uri(domain).Host; int index = host.LastIndexOf('.'), last = 3; while (index > 0 && index >= last - 3) { last = index; index = host.LastIndexOf('.', last - 1); } var res = host.Substring(index + 1); res = "~/Views/Shared/" + (res == "localhost" ? "gestionestampa.com" : res); try { TempData["MetaTitle"] = HttpContext.GetLocalResourceObject(res, page.ToLower() + "Title") + " - PapiroStar "; TempData["MetaDescription"] = HttpContext.GetLocalResourceObject(res, page.ToLower() + "Description"); TempData["MetaKeyword"] = HttpContext.GetLocalResourceObject(res, page.ToLower() + "Keyword"); TempData["MetaRobots"] = HttpContext.GetLocalResourceObject(res, page.ToLower() + "Robots") == null ? "index,follow" : HttpContext.GetLocalResourceObject(res, page.ToLower() + "Robots"); } catch (Exception) { TempData["MetaTitle"] = "PapiroStar"; TempData["MetaDescription"] = ""; TempData["MetaKeyword"] = ""; TempData["MetaRobots"] = "noindex, nofollow"; } return null; }
private async Task AddFromUrl(string url) { var uriDrag = new Uri(url).AbsolutePath; var jiraRef = uriDrag.Substring(uriDrag.LastIndexOf("/") + 1); var todaysDate = DateTime.Now.Date; var dayTimers = ModelHelpers.Gallifrey.JiraTimerCollection.GetTimersForADate(todaysDate).ToList(); if (dayTimers.Any(x => x.JiraReference == jiraRef)) { ModelHelpers.Gallifrey.JiraTimerCollection.StartTimer(dayTimers.First(x => x.JiraReference == jiraRef).UniqueId); ModelHelpers.RefreshModel(); ModelHelpers.SelectRunningTimer(); } else { //Validate jira is real try { ModelHelpers.Gallifrey.JiraConnection.GetJiraIssue(jiraRef); } catch (NoResultsFoundException) { await DialogCoordinator.Instance.ShowMessageAsync(ModelHelpers.DialogContext, "Invalid Jira", $"Unable To Locate That Jira.\n\nJira Ref Dropped: '{jiraRef}'"); return; } //show add form, we know it's a real jira & valid var addTimer = new AddTimer(ModelHelpers, startDate: todaysDate, jiraRef: jiraRef, startNow: true); await ModelHelpers.OpenFlyout(addTimer); if (addTimer.AddedTimer) { ModelHelpers.SetSelectedTimer(addTimer.NewTimerId); } } }
public ActionResult LostPassword(UserLostPasswordForm input) { var status = ModelState.IsValid ? LostPassworsStatus.Send : LostPassworsStatus.Error; if (status == LostPassworsStatus.Error) { var error = new { Status = status }; return Json(error, JsonRequestBehavior.AllowGet); } var user = _repositoryCommerce.GetUserByEmail(input.Email); if (user == null) { ModelState.AddModelError("email", "E-mail não cadastrado"); status = LostPassworsStatus.InvalidEmail; } if (ModelState.IsValid) { var guid = Guid.NewGuid().ToString("N"); var dateLimit = DateTime.Now.AddDays(2); var originalPath = new Uri(System.Web.HttpContext.Current.Request.Url.AbsoluteUri).OriginalString; var parentDirectory = originalPath.Substring(0, originalPath.LastIndexOf("/", StringComparison.Ordinal)); var guidLink = string.Concat(parentDirectory, "/RecoveryPassword?guid=", guid); try { if (!_mailProvider.SendEmailLostPassword(user, guidLink)) throw new Exception("Error to sent email"); user.LostPasswordGuid = guid; user.LostPasswordDateLimit = dateLimit; _repositoryCommerce.CommitChanges(); } catch (Exception) { status = LostPassworsStatus.ErrorSendEmail; } } var returnValue = new { Status = status }; return Json(returnValue, JsonRequestBehavior.AllowGet); }
private void LoadDesignerAssembly() { if (this.assembly != null && ! this.IsFrameworkAssembly()) { var file = new Uri(assembly.CodeBase).AbsolutePath; var designerName = file.Insert(file.LastIndexOf('.'), ".design"); try { this.DesignerAssembly = Assembly.LoadFile(designerName); // TODO: This is a hack to see if copying the assemblies to the bin folder fixes the problem of the designer failing to load an assembly. this.CopyAssemblies(Assembly); this.CopyAssemblies(DesignerAssembly); RegisterDesigner(); } catch (FileLoadException) { } catch (FileNotFoundException) { } } }
private void tabTimerDays_DragDrop(object sender, DragEventArgs e) { var url = GetUrl(e); if (!string.IsNullOrWhiteSpace(url)) { var uriDrag = new Uri(url).AbsolutePath; var jiraRef = uriDrag.Substring(uriDrag.LastIndexOf("/") + 1); var selectedTabDate = GetSelectedTabDate(); //Check if already added & if so start timer. if (selectedTabDate.HasValue) { var dayTimers = gallifrey.JiraTimerCollection.GetTimersForADate(selectedTabDate.Value); if (dayTimers.Any(x => x.JiraReference == jiraRef)) { gallifrey.JiraTimerCollection.StartTimer(dayTimers.First(x => x.JiraReference == jiraRef).UniqueId); RefreshInternalTimerList(); if (gallifrey.JiraTimerCollection.GetRunningTimerId().HasValue) { SelectTimer(gallifrey.JiraTimerCollection.GetRunningTimerId().Value); } return; } } //Validate jira is real try { gallifrey.JiraConnection.GetJiraIssue(jiraRef); } catch (Exception) { MessageBox.Show(string.Format("Unable To Locate That Jira.\n\nJira Ref Dropped: '{0}'", jiraRef), "Cannot Find Jira", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //show add form, we know it's a real jira & valid var addForm = new AddTimerWindow(gallifrey); addForm.PreLoadJira(jiraRef); if (selectedTabDate.HasValue) { addForm.PreLoadDate(selectedTabDate.Value, true); if (selectedTabDate.Value.Date == DateTime.Now.Date) { addForm.PreLoadStartNow(); } } else { addForm.PreLoadStartNow(); } if (addForm.DisplayForm) { addForm.ShowDialog(); RefreshInternalTimerList(); if (addForm.NewTimerId.HasValue) SelectTimer(addForm.NewTimerId.Value); } } }
private string localEpisodeFileName(PodcastEpisodeModel podcastEpisode) { // Parse the filename of the logo from the remote URL. string localPath = new Uri(podcastEpisode.EpisodeDownloadUri).LocalPath; string podcastEpisodeFilename = localPath.Substring(localPath.LastIndexOf('/') + 1); string localPodcastEpisodeFilename = App.PODCAST_DL_DIR + "/" + podcastEpisodeFilename; Debug.WriteLine("Found episode filename: " + localPodcastEpisodeFilename); return localPodcastEpisodeFilename; }
public List <double> PhishingIndexes(string URL) { List <double> indexes = new List <double>(); string newURL = ""; Uri uriURL; if (Uri.IsWellFormedUriString(URL, UriKind.Absolute) == false) // Prideda https:// jei jo nėra { newURL = "https://" + URL; uriURL = new Uri(newURL); } else { newURL = URL; uriURL = new Uri(URL); } string[] parts = uriURL.Authority.Split('.'); // Domena sudalina dalimis int digitCount = 0; if (parts.Length >= 4) { for (int i = 0; i < 4; i++) { if (System.Text.RegularExpressions.Regex.IsMatch(parts[i], @"^\d+$")) // Tikrina ar domeno dalis yra skaičius { digitCount++; } } } if (digitCount == 4) // Ar naudojamas IP adresas { indexes.Add(1); } else { indexes.Add(-1); } if (newURL.Length >= 75) // Ar adresas ilgesnis nei 75 simboliai { indexes.Add(1); } else { indexes.Add(-1); } if (newURL.Contains('@')) // Ar adresas turi @ simbolį { indexes.Add(1); } else { indexes.Add(-1); } string path = uriURL.AbsolutePath; // Ar naudojamas peradresavimas su // string str = ""; if (path.Length >= 2) { str = path.Substring(0, 2); } if (str == "//") { indexes.Add(1); } else { indexes.Add(-1); } if (uriURL.Authority.Contains('-')) // Ar domene naudojamas – { indexes.Add(1); } else { indexes.Add(-1); } var host = new System.Uri(newURL).Host; int index = host.LastIndexOf('.'), last = 3; while (index > 0 && index >= last - 3) // Randa subdomena { last = index; index = host.LastIndexOf('.', last - 1); } var domain = host.Substring(index + 1); int dotCount = 0; for (int i = 0; i < domain.Length; i++) { if (domain[i] == '.') { dotCount++; } } if (dotCount > 2) // Ar taškų skaičius subdomene yra didesnis nei 2 { indexes.Add(1); } else { indexes.Add(-1); } if (uriURL.Authority == "bit.ly") // Ar adresas yra sutrumpintas naudojant „TinyURL“ { indexes.Add(1); } else { indexes.Add(-1); } int[] goodPorts = { 21, 22, 23, 80, 443, 445, 1433, 1521, 3306, 3389 }; // Standartiški portai if (goodPorts.Contains(uriURL.Port) == false) // Ar naudojamas nestandartiškas portas { indexes.Add(1); } else { indexes.Add(-1); } if (newURL.Contains("mail()") || newURL.Contains("mailto:")) // Ar naudojamas duomenų persiuntimas į paštą (ar yra „mail()“ arba „mailto:“) { indexes.Add(1); } else { indexes.Add(-1); } if (uriURL.Authority.Contains("https")) // Ar domene yra „https“ { indexes.Add(1); } else { indexes.Add(-1); } indexes.Add(-1); return(indexes); }
static int Main(string[] args) { var exitCode = -1; if (args.Length == 0) { Logger.Instance.log(Logger.LogLevel.ERROR, "No Parameter provided, use \"<programm> -help\" for help"); Logger.Instance.close(); return exitCode; } string path = ""; bool anyKey = true; bool createEmptyProject = false; string checkSyntaxFile = ""; string dllPath = ""; bool exitAfterParamReading = false; List<string> compilerFlags = new List<string>(); foreach (string s in args) { if (s.StartsWith("-")) { int count = s.IndexOf('='); if (count == -1) count = s.Length; string switchstring = s.Substring(1, count - 1); switch (switchstring) { case "help": Logger.Instance.log(Logger.LogLevel.INFO, "Usage: <EXECUTABLE> [<PARAMS>] <PATH>"); Logger.Instance.log(Logger.LogLevel.CONTINUE, " -help Outputs this help page"); Logger.Instance.log(Logger.LogLevel.CONTINUE, " -v Enables VERBOSE logging mode"); Logger.Instance.log(Logger.LogLevel.CONTINUE, " -d Enables DEBUG logging mode"); Logger.Instance.log(Logger.LogLevel.CONTINUE, " -a Automation mode (no ANY key message)"); Logger.Instance.log(Logger.LogLevel.CONTINUE, " -gen Generates empty project at path"); Logger.Instance.log(Logger.LogLevel.CONTINUE, " -sc=<FILE> checks the syntax of the file"); Logger.Instance.log(Logger.LogLevel.CONTINUE, " -dll=<FILE> forces given dll for project"); Logger.Instance.log(Logger.LogLevel.CONTINUE, " -log[=<FILE>] writes log output to file"); exitAfterParamReading = true; exitCode = 0; break; case "v": if (Logger.Instance.LoggingLevel > Logger.LogLevel.VERBOSE) Logger.Instance.LoggingLevel = Logger.LogLevel.VERBOSE; break; case "d": if (Logger.Instance.LoggingLevel > Logger.LogLevel.DEBUG) Logger.Instance.LoggingLevel = Logger.LogLevel.DEBUG; break; case "a": anyKey = false; break; case "gen": createEmptyProject = true; break; case "dll": if (count == -1) { Logger.Instance.log(Logger.LogLevel.ERROR, "No path to DLL provided"); exitAfterParamReading = true; break; } dllPath = s.Substring(count + 1); break; case "log": string logfile = ""; if (count != -1) logfile = s.Substring(count + 1); Logger.Instance.setLogFile(logfile); break; case "sc": if (count == -1) { Logger.Instance.log(Logger.LogLevel.ERROR, "No file provided for syntax checking"); Logger.Instance.close(); exitAfterParamReading = true; break; } checkSyntaxFile = s.Substring(count + 1); break; } } else if(s.StartsWith("/")) { compilerFlags.Add(s); } else { path = s; } } if(exitAfterParamReading) { Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; } Logger.Instance.log(Logger.LogLevel.VERBOSE, "extended output is enabled"); Logger.Instance.log(Logger.LogLevel.DEBUG, "Debug output is enabled"); if (createEmptyProject) { try { if (!Directory.Exists(path)) { Logger.Instance.log(Logger.LogLevel.INFO, "Creating directory"); Directory.CreateDirectory(path); } if (!path.EndsWith("\\")) path += '\\'; Logger.Instance.log(Logger.LogLevel.VERBOSE, "Creating project file at '" + path + "project.oosproj" + "'"); StreamWriter writer = new StreamWriter(path + "project.oosproj"); writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); writer.WriteLine("<root>"); writer.WriteLine(" <project>"); writer.WriteLine(" <title>testProject</title>"); writer.WriteLine(" <author>NA</author>"); writer.WriteLine(" <mainfile>./main.oos</mainfile>"); writer.WriteLine(" <outputfolder>./output/</outputfolder>"); writer.WriteLine(" <buildfolder>./build/</buildfolder>"); writer.WriteLine(" </project>"); writer.WriteLine(" <compiler version=\"0.6.0-ALPHA\" />"); writer.WriteLine("</root>"); writer.Close(); if (!File.Exists(path + "Main.oos")) { Logger.Instance.log(Logger.LogLevel.VERBOSE, "Creating main file at '" + path + "Main.oos" + "'"); File.Create(path + "Main.oos").Close(); } if (!Directory.Exists(path + "output")) { Logger.Instance.log(Logger.LogLevel.VERBOSE, "Creating output directory at '" + path + "output" + "'"); Directory.CreateDirectory(path + "output"); } if (!Directory.Exists(path + "build")) { Logger.Instance.log(Logger.LogLevel.VERBOSE, "Creating build directory at '" + path + "build" + "'"); Directory.CreateDirectory(path + "build"); } Logger.Instance.log(Logger.LogLevel.INFO, "Created empty project for 0.5.3-ALPHA compiler"); } catch (Exception ex) { Logger.Instance.log(Logger.LogLevel.ERROR, ex.Message); } Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; } if (!File.Exists(path)) { Logger.Instance.log(Logger.LogLevel.ERROR, "Cannot open project file as it does not exists (typo?)."); Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; } if (checkSyntaxFile != "" && !File.Exists(checkSyntaxFile)) { Logger.Instance.log(Logger.LogLevel.ERROR, "Cannot open checkSyntax as it does not exists (typo?)."); Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; } Project proj; ICompiler_1 compiler; try { proj = Project.openProject(path); } catch (Exception ex) { Logger.Instance.log(Logger.LogLevel.ERROR, "Failed to open Project file:"); Logger.Instance.log(Logger.LogLevel.CONTINUE, ex.Message); Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; } try { //ToDo: Dont pick "default" compiler and instead pick by version number (need to scan filesystem for this + have a compiler rdy for usage ...) string compilerPath = ""; string compilerVersion = proj.CompilerVersion.ToString(); if (compilerVersion == "") { Logger.Instance.log(Logger.LogLevel.ERROR, "Compiler version of given project is either not set or empty"); Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; } if (dllPath == "") { var executablePath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath; executablePath = executablePath.Substring(0, executablePath.LastIndexOf('\\')); foreach (var f in Directory.EnumerateFiles(executablePath)) { if (f.Contains(compilerVersion)) { compilerPath = f; break; } } } else { compilerPath = dllPath; } if (compilerPath == "") { Logger.Instance.log(Logger.LogLevel.ERROR, "Coult not locate compiler dll with version number " + proj.CompilerVersion); Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; } Assembly assembly = Assembly.LoadFrom(compilerPath); Type type = assembly.GetType("Wrapper.Compiler", true); compiler = (ICompiler_1)Activator.CreateInstance(type); } catch (Exception ex) { Logger.Instance.log(Logger.LogLevel.ERROR, "Failed to load compiler:"); Logger.Instance.log(Logger.LogLevel.CONTINUE, ex.Message); Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; } if (checkSyntaxFile != "") { compiler.CheckSyntax(checkSyntaxFile); } else { #if DEBUG #else try { #endif compiler.setFlags(compilerFlags.ToArray()); compiler.Compile(proj); exitCode = 0; #if DEBUG #else } catch (Exception ex) { Logger.Instance.log(Logger.LogLevel.ERROR, "Failed to generate project:"); Logger.Instance.log(Logger.LogLevel.CONTINUE, ex.Message); } #endif } Logger.Instance.close(); if (anyKey) { Console.WriteLine("\nPress ANY key to continue"); Console.ReadKey(); } return exitCode; }