public static IResource File(string name) { var uri = new CustomUri(FilePath(name)); var resource = new FileResource(uri); return(resource); }
public void Test_Custormer_uri() { var name = "assembly://" + typeof(Xml).Assembly.FullName + "/XmlFiles/" + "hasResourceIncludes.xml"; Assert.AreEqual(name, "assembly://Castle.Windsor.Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc/XmlFiles/hasResourceIncludes.xml"); var uri = new CustomUri(name); Assert.AreEqual(uri.Path, "/XmlFiles/hasResourceIncludes.xml"); var resource = new AssemblyResource(uri); var assemblyName = uri.Host; Assert.AreEqual(assemblyName, "Castle.Windsor.Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc"); var indexOfComma = assemblyName.IndexOf(','); assemblyName = indexOfComma < 0 ? assemblyName : assemblyName.Substring(0, indexOfComma); Assert.AreEqual(assemblyName, "Castle.Windsor.Tests"); var resourcePath = string.Format(CultureInfo.CurrentCulture, "{0}{1}", assemblyName, uri.Path.Replace('/', '.')); Assert.AreEqual(resourcePath, "Castle.Windsor.Tests.XmlFiles.hasResourceIncludes.xml"); var assembly = Assembly.Load(assemblyName); Assert.IsNotNull(assembly); var names = assembly.GetManifestResourceNames(); Assert.AreEqual(names.Length, 60); foreach (var s in names) { Console.WriteLine(s); } var nameFound = names.FirstOrDefault(x => string.Compare(resourcePath, x, StringComparison.OrdinalIgnoreCase) == 0); Assert.IsNotNull(nameFound); }
public static AbstractConfigurationRunner Read( IWindsorContainer container, CustomUri uri, GenerationOptions generationOptions, string name, string environment, params string[] namespaces) { try { using (AbstractConfigurationRunner.UseLocalContainer(container)) { AbstractConfigurationRunner conf = GetConfigurationInstanceFromResource( name, environment, container, uri, generationOptions, namespaces); using (AbstractConfigurationRunner.CaptureRegistrations()) { conf.Run(); } foreach (INeedSecondPassRegistration needSecondPassRegistration in NeedSecondPassRegistrations) { needSecondPassRegistration.RegisterSecondPass(); } return(conf); } } finally { NeedSecondPassRegistrations = null; } }
public static IResource Embedded(string name) { var uri = new CustomUri(EmbeddedPath(name)); var resource = new AssemblyResource(uri); return(resource); }
private void OnDownloadTempCommand() { String FileUrl = CustomUri.GetAbsoluteUrl("ProductmanagerFileTemp/产品导入模版.xls"); try { saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "All Files|*.*"; saveFileDialog.GetType().GetMethod("set_DefaultFileName").Invoke(saveFileDialog, new object[] { "产品导入模版.xls" }); bool?dialogResult = saveFileDialog.ShowDialog(); if (dialogResult != true) { return; } WebClient client = new WebClient(); Uri uri = new Uri(FileUrl, UriKind.RelativeOrAbsolute); client.OpenReadCompleted += new OpenReadCompletedEventHandler(OpenReadCompleted); client.OpenReadAsync(uri); } catch (System.Exception ex) { NotifyWindow notifyWindow = new NotifyWindow("下载错误", ex.Message); notifyWindow.Show(); } }
private void loadOperationProjectFiles_Completed(object sender, EventArgs e) { ProjectFilesEntityList.Clear(); LoadOperation <ProductManager.Web.Model.project_files> loadOperation = sender as LoadOperation <ProductManager.Web.Model.project_files>; foreach (ProductManager.Web.Model.project_files project_files in loadOperation.Entities) { ProjectFilesEntity projectFilesEntity = new ProjectFilesEntity(); projectFilesEntity.ProjectFiles = project_files; projectFilesEntity.Update(); projectFilesEntity.FileUrl = CustomUri.GetAbsoluteUrl(projectFilesEntity.ManufactureNumber + "/" + projectFilesEntity.FileName); DepartmentEntity lDepartmentEntity; if (DepartmentEntityDictionary.TryGetValue(projectFilesEntity.DepartmentID, out lDepartmentEntity)) { projectFilesEntity.DepartmentName = lDepartmentEntity.DepartmentName; } UserEntity lUserEntity; if (UserEntityDictionary.TryGetValue(projectFilesEntity.UserID, out lUserEntity)) { projectFilesEntity.UserName = lUserEntity.CUserName; } FileTypeEntity lFileTypeEntity; if (FileTypeEntityDictionary.TryGetValue(projectFilesEntity.FileTypeID, out lFileTypeEntity)) { projectFilesEntity.FileTypeName = lFileTypeEntity.FileTypeName; } ProjectFilesEntityList.Add(projectFilesEntity); } IsBusy = false; }
public void Update() { this.fileName = PlanFiles.file_name; this.userID = PlanFiles.user_id.GetValueOrDefault(0); this.fileUploadTime = PlanFiles.file_uploadtime.GetValueOrDefault(); this.fileBytes = PlanFiles.file_bytes.GetValueOrDefault(0); this.fileUrl = CustomUri.GetAbsoluteUrl("PlanOutline/" + fileName); }
protected override AbstractConfigurationRunner InstallInto(IWindsorContainer container) { var system = (IResourceSubSystem)container.Kernel.GetSubSystem(SubSystemConstants.ResourceKey); var resource = system.CreateResource(uri); var Uri = new CustomUri(uri); return(BooReader.Read(container, Uri, GenerationOptions, GetName(), EnvironmentName)); }
private bool canView(object aObject) { if (fileUrl == null) { if (TaxPayerIsLink.GetValueOrDefault(false)) { fileUrl = (CustomUri.GetAbsoluteUrl("upload/" + TaxPayerLinkId.Value) + "/" + TaxPayerDocumentName); } else { fileUrl = (CustomUri.GetAbsoluteUrl("upload/" + TaxPayerId.Value) + "/" + TaxPayerDocumentName); } } if (fileUrl != null) { int lastDot = fileUrl.LastIndexOf("."); if (lastDot <= 0) { return(false); } String lExt = fileUrl.Substring(lastDot, fileUrl.Length - lastDot).ToLower(); if (lExt == ".pdf" || lExt == ".doc" || lExt == ".docx" || lExt == ".xls" || lExt == ".xlsx" || lExt == ".jpeg" || lExt == ".jpg" || lExt == ".png" || lExt == ".bmp" || lExt == ".tiff" || lExt == ".tif" || lExt == ".gif") { if (!TaxPayerUpdateTime.HasValue) { return(false); } DateTime lToday = DateTime.Now; if (lToday.Year == TaxPayerUpdateTime.Value.Year && lToday.Month == TaxPayerUpdateTime.Value.Month && lToday.Day == TaxPayerUpdateTime.Value.Day) { return(false); } return(true); } else { return(false); } } else { return(false); } }
public void AssemblyUri2() { CustomUri uri1 = new CustomUri("assembly://Assembly.Name/Some/Namespace/properties.config"); Assert.AreEqual("/Some/Namespace/properties.config", uri1.Path); Assert.AreEqual("Assembly.Name", uri1.Host); Assert.AreEqual("assembly", uri1.Scheme); Assert.AreEqual(false, uri1.IsFile); Assert.AreEqual(false, uri1.IsUnc); }
public void FileUris2() { CustomUri uri1 = new CustomUri("file://Config/properties.config"); Assert.AreEqual("Config/properties.config", uri1.Path); Assert.AreEqual(null, uri1.Host); Assert.AreEqual("file", uri1.Scheme); Assert.AreEqual(true, uri1.IsFile); Assert.AreEqual(false, uri1.IsUnc); }
public void FileUris3() { CustomUri uri1 = new CustomUri("e:\\somedir\\somefile.extension"); Assert.AreEqual("e:/somedir/somefile.extension", uri1.Path); Assert.AreEqual(null, uri1.Host); Assert.AreEqual("file", uri1.Scheme); Assert.AreEqual(true, uri1.IsFile); Assert.AreEqual(false, uri1.IsUnc); }
public void CreateWithAbsolutePath() { CustomUri uri = new CustomUri(@"\\hammet\C$\file.txt"); IResource resource = resFactory.Create(uri, null); Assert.IsNotNull(resource); String line = resource.GetStreamReader().ReadLine(); Assert.AreEqual("The long and winding road", line); }
public void CreateWithRelativePathAndContext() { CustomUri uri = new CustomUri("file://file1.txt"); IResource resource = resFactory.Create(uri, basePath); Assert.IsNotNull(resource); string line = resource.GetStreamReader().ReadLine(); Assert.AreEqual("Something", line); }
public static AbstractConfigurationRunner Read( IWindsorContainer container, CustomUri uri, GenerationOptions generationOptions, string name, string environment, params string[] namespaces) { using (AbstractConfigurationRunner.UseLocalContainer(container)) { var conf = GetConfigurationInstanceFromResource(name, environment, container, uri, generationOptions, namespaces); conf.Run(); return(conf); } }
public HttpFileUploader(UserFile file, string httpHandlerName) { _file = file; _dataLength = _file.FileStream.Length; _dataSent = 0; if(string.IsNullOrEmpty(httpHandlerName)) httpHandlerName = "HttpUploadHandler.ashx"; UploadUrl = new CustomUri(httpHandlerName).ToString(); }
public void CreateRelative() { CustomUri uri = new CustomUri(@"\\hammet\C$\file.txt"); IResource resource = resFactory.Create(uri, null); resource = resource.CreateRelative("file2.txt"); Assert.IsNotNull(resource); String line = resource.GetStreamReader().ReadLine(); Assert.AreEqual("Something", line); }
public void With_config_section() { var sectionName = "config://castle/"; //trailing slash is required var uri = new CustomUri(sectionName); Assert.AreEqual("config", uri.Scheme); Assert.AreEqual("castle", uri.Host); var container = new WindsorContainer(sectionName); container.Resolve <ICalcService>("calcservice"); }
private bool CanViewCommand(object aObject) { if (FileUrl == null) { string manufactureNumberTemp = manufactureNumber.TrimEnd(); string rmanufactureNumberTemp = ""; if (!String.IsNullOrEmpty(rmanufactureNumber)) { rmanufactureNumberTemp = rmanufactureNumber.TrimEnd(); } FileUrl = (CustomUri.GetAbsoluteUrl(String.IsNullOrEmpty(rmanufactureNumber) ? manufactureNumberTemp : rmanufactureNumberTemp) + "/" + fileName); } if (FileUrl != null) { int lastDot = FileUrl.LastIndexOf("."); if (lastDot <= 0) { return(false); } String lExt = FileUrl.Substring(lastDot, FileUrl.Length - lastDot).ToLower(); if (lExt == ".pdf" || lExt == ".doc" || lExt == ".docx" || lExt == ".xls" || lExt == ".xlsx" || lExt == ".jpeg" || lExt == ".jpg" || lExt == ".png" || lExt == ".bmp" || lExt == ".tiff" || lExt == ".tif" || lExt == ".gif") { DateTime lToday = DateTime.Now; if (lToday.Year == fileUpdateTime.Value.Year && lToday.Month == fileUpdateTime.Value.Month && lToday.Day == fileUpdateTime.Value.Day) { return(false); } return(true); } else { return(false); } } else { return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyResourceEx"/> class. /// </summary> /// <param name="resource">The resource.</param> /// <param name="basePath">The base path.</param> public AssemblyResourceEx(CustomUri resource, string basePath) { AbstractStreamResource.StreamFactory factory = null; if (factory == null) { factory = delegate { return(CreateResourceFromUri(resource, basePath)); }; } base.CreateStream = factory; }
public void UriWithEnvironmentVariable() { string path = Environment.GetEnvironmentVariable("PATH"); Assert.IsNotEmpty(path); CustomUri uri1 = new CustomUri("file://%PATH%"); Assert.AreEqual(path, uri1.Path); Assert.AreEqual(null, uri1.Host); Assert.AreEqual("file", uri1.Scheme); Assert.AreEqual(true, uri1.IsFile); Assert.AreEqual(false, uri1.IsUnc); }
public static AbstractConfigurationRunner GetConfigurationInstanceFromResource( string name, string environment, IWindsorContainer container, CustomUri uri, GenerationOptions generationOptions, params string[] namespaces) { var system = (IResourceSubSystem)container.Kernel.GetSubSystem(SubSystemConstants.ResourceKey); var resource = system.CreateResource(uri); string baseDirectory = Path.GetDirectoryName(uri.Path); var urlResolver = CreateWindorUrlResolver(container); return(GetConfigurationInstance( name, environment, new ReaderInput(name, resource.GetStreamReader()), generationOptions, new AutoReferenceFilesCompilerStep(baseDirectory, urlResolver), namespaces)); }
public void CreateWithAbsolutePath() { string file = Path.Combine(basePath, "file1.txt"); FileInfo fileInfo = new FileInfo(file); CustomUri uri = new CustomUri(fileInfo.FullName); IResource resource = resFactory.Create(uri, null); Assert.IsNotNull(resource); string line = resource.GetStreamReader().ReadLine(); Assert.AreEqual("Something", line); }
public RhinoContainer(CustomUri uri, IEnvironmentInfo env) : base(new DefaultKernel(), CreateInterpreter(uri, env)) { IResourceSubSystem system = (IResourceSubSystem)Kernel.GetSubSystem(SubSystemConstants.ResourceKey); IResource resource = system.CreateResource(uri); if (IsBoo(uri)) { RunInstaller(); } else { InitalizeFromConfigurationSource( new XmlInterpreter(resource), env); } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyResourceEx"/> class. /// </summary> /// <param name="resource">The resource.</param> /// <param name="cultureInfo">The culture info.</param> public AssemblyResourceEx(CustomUri resource, CultureInfo cultureInfo) { _ResourceUri = resource; _CultureInfo = cultureInfo; AbstractStreamResource.StreamFactory factory = null; if (factory == null) { factory = delegate { return(CreateResourceFromUri(resource, null)); }; } base.CreateStream = factory; }
private void onView() { if (fileUrl == null) { if (TaxPayerIsLink.GetValueOrDefault(false)) { fileUrl = (CustomUri.GetAbsoluteUrl("upload/" + TaxPayerLinkId.Value) + "/" + TaxPayerDocumentName); } else { fileUrl = (CustomUri.GetAbsoluteUrl("upload/" + TaxPayerId.Value) + "/" + TaxPayerDocumentName); } } ReviewWindow review = new ReviewWindow(fileUrl + ".xod"); review.Show(); }
public IResource CreateResource(CustomUri uri) { if (uri == null) { throw new ArgumentNullException("uri"); } foreach (IResourceFactory resFactory in resourceFactories) { if (resFactory.Accept(uri)) { return(resFactory.Create(uri)); } } throw new KernelException("No Resource factory was able to " + "deal with Uri " + uri.ToString()); }
private void OnDownloadCommand() { //MessageBox.Show(FileUrl); if (FileUrl == null) { string manufactureNumberTemp = manufactureNumber.TrimEnd(); string rmanufactureNumberTemp = ""; if (!String.IsNullOrEmpty(rmanufactureNumber)) { rmanufactureNumberTemp = rmanufactureNumber.TrimEnd(); } FileUrl = (CustomUri.GetAbsoluteUrl(String.IsNullOrEmpty(rmanufactureNumber) ? manufactureNumberTemp : rmanufactureNumberTemp) + "/" + fileName); //FileUrl = (CustomUri.GetAbsoluteUrl(String.IsNullOrEmpty(rmanufactureNumber) ? manufactureNumber.TrimEnd() : rmanufactureNumber.TrimEnd()) + "/" + fileName); } //MessageBox.Show(FileUrl); try { saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "All Files|*.*"; saveFileDialog.GetType().GetMethod("set_DefaultFileName").Invoke(saveFileDialog, new object[] { this.FileName }); //MessageBox.Show("3"); bool?dialogResult = saveFileDialog.ShowDialog(); if (dialogResult != true) { return; } //MessageBox.Show("4"); WebClient client = new WebClient(); Uri uri = new Uri(FileUrl, UriKind.RelativeOrAbsolute); client.OpenReadCompleted += new OpenReadCompletedEventHandler(OpenReadCompleted); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged); client.OpenReadAsync(uri); DownLoading = Visibility.Visible; } catch (System.Exception ex) { //MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }
private bool CanViewCommand(object aObject) { if (FileUrl == null) { FileUrl = CustomUri.GetAbsoluteUrl("PlanOutline/" + fileName); } if (FileUrl != null) { int lastDot = FileUrl.LastIndexOf("."); String lExt = FileUrl.Substring(lastDot, FileUrl.Length - lastDot).ToLower(); if (lExt == ".pdf" || lExt == ".doc" || lExt == ".docx" || lExt == ".xls" || lExt == ".xlsx" || lExt == ".jpeg" || lExt == ".png" || lExt == ".bmp" || lExt == ".tiff" || lExt == ".gif") { DateTime lToday = DateTime.Now; if (lToday.Year == fileUploadTime.Year && lToday.Month == fileUploadTime.Month && lToday.Day == fileUploadTime.Day) { return(false); } return(true); } else { return(false); } } else { return(false); } }
public IResource CreateResource(CustomUri uri, String basePath) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (basePath == null) { throw new ArgumentNullException(nameof(basePath)); } foreach (var resFactory in resourceFactories) { if (resFactory.Accept(uri)) { return(resFactory.Create(uri, basePath)); } } throw new KernelException("No Resource factory was able to " + "deal with Uri " + uri); }
private void onDownload() { if (fileUrl == null) { if (TaxPayerIsLink.GetValueOrDefault(false)) { fileUrl = (CustomUri.GetAbsoluteUrl("upload/" + TaxPayerLinkId.Value) + "/" + TaxPayerDocumentName); } else { fileUrl = (CustomUri.GetAbsoluteUrl("upload/" + TaxPayerId.Value) + "/" + TaxPayerDocumentName); } } try { saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "All Files|*.*"; saveFileDialog.GetType().GetMethod("set_DefaultFileName").Invoke(saveFileDialog, new object[] { TaxPayerDocumentName }); bool?dialogResult = saveFileDialog.ShowDialog(); if (dialogResult != true) { return; } WebClient client = new WebClient(); Uri uri = new Uri(fileUrl, UriKind.RelativeOrAbsolute); client.OpenReadCompleted += new OpenReadCompletedEventHandler(OpenReadCompleted); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged); client.OpenReadAsync(uri); DownLoading = Visibility.Visible; } catch (System.Exception ex) { MessageBox.Show(ex.StackTrace); } }