public static bool UploadTextFileContents(string filePhysicalPath, string fileContents, out FaultContract Fault) { Fault = null; if (!File.Exists(filePhysicalPath)) { Fault = new FaultContract { FaultType = "Error", Message = "File doesn't exist" + filePhysicalPath }; return(false); } try { using (FileStream stream = new FileStream(filePhysicalPath, FileMode.Truncate)) { using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(fileContents); writer.Flush(); writer.Close(); } } return(true); } catch (Exception ex) { Fault = new FaultContract { FaultType = "Error", Message = "Error writing file:- " + ex.Message }; } return(true); }
public Form1() { InitializeComponent(); try { FaultContract serviceData = client.Connection(); if (serviceData.Result) { csatlLabel.Text = "Csatlakozva az adatbázishoz"; loginpassTxtbox.PasswordChar = '*'; logoutBtn.Visible = false; fajtaTxtbox.Enabled = false; alkoholNumeric.Enabled = false; edessegTxtbox.Enabled = false; felvitelBtn.Enabled = false; modositBtn.Enabled = false; borGrid.Enabled = false; modositBtn.Visible = false; LoadGrid(); FillGrid(); } } catch (FaultException <FaultContract> fault) { MessageBox.Show("ErrorMessage:" + fault.Detail.Message, "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("ErrorDetails::" + fault.Detail.Description, "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Error); } csatlLabel.Text = ""; }
/// <summary> /// Processes the current request /// </summary> protected override void HandleRequest() { // Get site and template info from the request string siteId = Request["siteId"]; string templateId = Request["templateId"]; FaultContract fault = null; // Perform the upgrade Site site = UpgradeSite(siteId, templateId, out fault); if (site != null) { // Return the upgraded site's metadata as the response XmlSerializer serializer = new XmlSerializer(typeof(Site)); serializer.Serialize(Response.OutputStream, site); Response.OutputStream.Flush(); } else { // Return error message string errorMessage = fault != null && !string.IsNullOrEmpty(fault.Message) ? fault.Message : "Upgrade failed"; Response.StatusCode = (int)HttpStatusCode.InternalServerError; Response.Write(errorMessage); Response.OutputStream.Flush(); } }
public override FileDescriptor UploadFile(string siteId, bool isTemplate, string relativePath, string fileName, byte[] fileContents) { FaultContract Fault = null; string physicalPath = FileUtils.GetPhysicalPathForId(siteId, isTemplate, relativePath, out Fault); if (Fault != null) { throw new Exception(Fault.Message); } if (!System.IO.Directory.Exists((physicalPath))) { throw new Exception("Unable to upload file"); } string filePath = string.Format("{0}\\{1}", physicalPath, fileName); FileExplorerUtility.UploadFile(filePath, fileContents, out Fault); FileDescriptor newFile = new FileDescriptor(); newFile.FileName = fileName; if (relativePath != null) { newFile.RelativePath = string.Format("{0}/{1}", relativePath, fileName); } else { newFile.RelativePath = fileName; } return(newFile); }
protected override void DoValidate(IEnumerable <Fault> objectToValidate, object currentTarget, string key, ValidationResults validationResults) { Operation operation = currentTarget as Operation; if (operation == null) { return; } // Validation Application block doesn't recreate validators every time. // Reset fc counter before validating the collection faultContracts.Clear(); foreach (Fault item in objectToValidate) { DataContractFault fault = item as DataContractFault; if (fault == null || fault.Type == null) { continue; } if (!fault.Type.IsValidReference()) { validationResults.AddResult( new ValidationResult( String.Format(CultureInfo.CurrentUICulture, Resources.CannotResolveReference, currentTarget.GetType().Name, fault.Name, fault.Type.GetDisplayName()), fault, key, String.Empty, this)); return; } ModelElement mel = ModelBusReferenceResolver.ResolveAndDispose(fault.Type); if (mel == null) { return; } FaultContract dcFault = mel as FaultContract; if (dcFault == null) { return; } if (faultContracts.Contains(dcFault)) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, fault.Name, operation.Name), objectToValidate, key, String.Empty, this) ); } else { faultContracts.Add(dcFault); } } }
public IIsVirtualDirectoryInfo CreateNewSite(Site site, string webSiteId, out FaultContract Fault) { string status = string.Empty; Fault = null; if (!string.IsNullOrEmpty(site.IISPath) && !string.IsNullOrEmpty(site.IISHost)) { string iisLocation = string.Empty; // Check if we can query IIS string pathToQuery = string.Format("IIS://{0}/W3SVC", site.IISHost); // Get the location of the the website running at this host and that port .. as Active Directory entry iisLocation = IISHelper.GetIISLocation(site.IISHost, string.Format(":{0}:", site.IISPort), out status); string websitePhysicalPath = GetPhysicalPathForSite(site, false, out Fault); if (!string.IsNullOrEmpty(status)) { Fault = new FaultContract { FaultType = "Error", Message = "Error retrieving physical path for site.Server:- " + site.IISHost + " Port:- " + site.IISPort + " Status:- " + status }; return(null); } // When doing File I/O .. we need UNC paths .. but for IIS Helper .. we need a normal path string websiteUNCPath = GetPhysicalPathForSite(site, true, out Fault); if (!Directory.Exists(websiteUNCPath)) { Directory.CreateDirectory(websiteUNCPath); } if (IISHelper.VirtualDirectoryExists(iisLocation, site.IISPath, out status)) { Fault = new FaultContract { FaultType = "Error", Message = "Virtual Directory already exists" + status }; return(null); } if (IISHelper.CreateVirtualDirectory(iisLocation + "/Root", site.IISPath, websitePhysicalPath, out status)) { IIsVirtualDirectoryInfo vDir = new IIsVirtualDirectoryInfo { ADSIPath = pathToQuery + "/" + site.IISPath, Name = site.Name, PhysicalPath = websiteUNCPath, VirtualPath = site.IISPath }; return(vDir); } } return(null); }
protected override void DoValidateCollectionItem(DataMember objectToValidate, object currentTarget, string key, ValidationResults validationResults) { FaultContract faultContract = currentTarget as FaultContract; if (faultContract != null) { if (String.Compare(faultContract.Name, objectToValidate.Name, StringComparison.Ordinal) == 0) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, this.GetObjectName(currentTarget)), objectToValidate, key, String.Empty, this)); } } base.DoValidateCollectionItem(objectToValidate, currentTarget, key, validationResults); }
protected ModelElement ResolveFaultElement(string instanceNamespace) { using (Transaction transaction = DataContractStore.TransactionManager.BeginTransaction()) { FaultContract fc = new FaultContract(DataContractStore); fc.DataContractModel = new DataContractModel(DataContractStore); fc.DataContractModel.ProjectMappingTable = "WCF"; fc.Name = instanceNamespace; WCFFaultContract extender = new WCFFaultContract(); fc.ObjectExtender = extender; extender.ModelElement = fc; transaction.Commit(); return(fc); } }
protected override Site CreateSite(string targetSiteName, string targetTitle, string targetSiteDescription, string targetSiteTemplateId, SitePublishInfo targetSitePublishInfo) { // Make sure target site directory does not already exist string physicalPath = string.Format("{0}\\{1}", AppSettings.AppsPhysicalDir, targetSiteName); if (System.IO.Directory.Exists(physicalPath)) { throw new Exception("Site with name '" + targetSiteName + "' is in use already. Please try an alternate name."); } // Create a new site Site targetSite = new Site() { ID = Guid.NewGuid().ToString("N"), IsHostedOnIIS = true, Name = targetSiteName, Title = targetTitle, Description = targetSiteDescription, PhysicalPath = physicalPath, Url = string.Format("{0}/{1}", AppSettings.AppsBaseUrl.TrimEnd('/'), targetSiteName.TrimStart('/')) }; Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; targetSite.ProductVersion = string.Format("{0}.{1}.{2}.0", currentVersion.Major, currentVersion.Minor, currentVersion.Build); // Create the viewer application ApplicationBuilderHelper appBuilderHelper = new ApplicationBuilderHelper(); FaultContract Fault = null; if (!appBuilderHelper.CreateSiteFromTemplate(targetSiteTemplateId, targetSite, true, out Fault)) { throw new Exception(Fault != null ? Fault.Message : "Unable to create site"); } // Save the configuration files if (!appBuilderHelper.SaveConfigurationForSite(targetSite, targetSitePublishInfo, out Fault)) { return(null); } // Add entry to Sites.xml SiteConfiguration.AddSite(targetSite); // Return target site object return(targetSite); }
public string GetIISLocation(string server, int port, out FaultContract Fault) { Fault = null; string status; string iisLocation = IISHelper.GetIISLocation(server, string.Format(":{0}:", port), out status); if (!string.IsNullOrEmpty(status)) { Fault = new FaultContract() { FaultType = "Error", Message = "Unable to retrieve IIS location", }; return(null); } return(iisLocation); }
public IIsWebsiteInfo[] GetWebSitesOnIIsWebServer(string server, out FaultContract fault) { fault = null; try { return(IISHelper.GetWebsitesOnIISServer(server).ToArray()); } catch (Exception ex) { fault = new FaultContract { Message = ex.ToString(), FaultType = "Error retrieving websites on " + server }; return(null); } }
public static string GetPhysicalPathForId(string siteId, bool isTemplate, string relativePath, out FaultContract Fault) { Fault = null; string physicalPath = null; if (isTemplate) { Template template = TemplateConfiguration.FindTemplateById(siteId); if (template == null) { Fault = new FaultContract(); Fault.FaultType = "Error"; Fault.Message = "Unable to find template with ID = " + siteId; return(null); } else { physicalPath = ServerUtility.MapPath(TemplateFolderPath) + "\\" + template.ID; if (!string.IsNullOrEmpty(relativePath)) { physicalPath += "\\" + relativePath.Replace("/", "\\"); } } } else { Site site = SiteConfiguration.FindExistingSiteByID(siteId); if (site == null) { Fault = new FaultContract(); Fault.FaultType = "Error"; Fault.Message = "Unable to find Site with ID = " + siteId; return(null); } else { physicalPath = site.PhysicalPath; if (!string.IsNullOrEmpty(relativePath)) { physicalPath += "\\" + relativePath.Replace("/", "\\"); } } } return(physicalPath); }
/// <summary> /// this will be called for all request that decorated with CustomFilter. /// </summary> /// <param name="context"></param> public void OnAuthorization(AuthorizationFilterContext context) { string authorization = context.HttpContext.Request.Headers["Authorization"]; IConfiguration configuration = context.HttpContext.RequestServices.GetService <IConfiguration>(); IUserRepository _userRepository = context.HttpContext.RequestServices.GetService <IUserRepository>(); if (authorization == null) { context.Result = new UnauthorizedResult(); return; } else { if (authorization.Split(" ")[0] == "Bearer") { string token = authorization.Split(" ")[1]; FaultContract faultContract = null; TokenInfo info = JwtTokenManager.ValidateToken(token, configuration, out faultContract); if (faultContract != null && faultContract.faultcode == EfaultCode.TokenExpire) { //here token is expired. info.Token = token; string userGuid = _userRepository.GetUserGuId(info); if (!string.IsNullOrEmpty(userGuid)) { string Newtoken = JwtTokenManager.GenerateToken(info.username, userGuid, configuration); context.HttpContext.Response.Headers["Token"] = Newtoken; //context.Result } else { // New token Already Assigned someone tried to use old token. context.Result = new UnauthorizedResult(); return; } } } else { context.Result = new UnauthorizedResult(); return; } } }
public void TestInitialize() { serviceProvider = new MockMappingServiceProvider(); attributes = new NameValueCollection(); attributes.Add("elementNameProperty", "Name"); #region Data Contract dcStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(DataContractDslDomainModel)); dcDomainModel = dcStore.GetDomainModel <DataContractDslDomainModel>(); dcTransaction = dcStore.TransactionManager.BeginTransaction(); dcModel = (DataContractModel)dcDomainModel.CreateElement(new Partition(dcStore), typeof(DataContractModel), null); dcModel.ProjectMappingTable = projectMappingTableName; fc = dcStore.ElementFactory.CreateElement(FaultContract.DomainClassId) as FaultContract; fc.Name = faultContractName; dcModel.Contracts.Add(fc); #endregion #region Service Contract scStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(ServiceContractDslDomainModel)); scDomainModel = scStore.GetDomainModel <ServiceContractDslDomainModel>(); scTransaction = scStore.TransactionManager.BeginTransaction(); scModel = (ServiceContractModel)scDomainModel.CreateElement(new Partition(scStore), typeof(ServiceContractModel), null); scModel.ProjectMappingTable = projectMappingTableName; operation = scStore.ElementFactory.CreateElement(Operation.DomainClassId) as Operation; operation.Name = operationName; //Create the moniker //mel://[DSLNAMESPACE]\[MODELELEMENTTYPE]\[MODELELEMENT.GUID]@[PROJECT]\[MODELFILE] string requestMoniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}", fc.GetType().Namespace, fc.GetType().Name, fc.Id.ToString(), dataContractModelProjectName, dataContractModelFileName); dcfault = scStore.ElementFactory.CreateElement(DataContractFault.DomainClassId) as DataContractFault; dcfault.Name = dcfaultName; dcfault.Type = new MockModelBusReference(fc); operation.Faults.Add(dcfault); scModel.Operations.Add(operation); #endregion }
public T ExecuteScaler <T>(string procedureName, List <SqlParameter> parameters, out FaultContract fault) { T result = default(T); fault = null; using (SqlConnection con = getDBConnection()) { using (SqlCommand sqlCommand = new SqlCommand(procedureName, con)) { sqlCommand.CommandType = CommandType.StoredProcedure; if (parameters != null) { sqlCommand.Parameters.AddRange(parameters.ToArray()); } if (con.State != ConnectionState.Open) { con.Open(); } try { result = (T)sqlCommand.ExecuteScalar(); } catch (Exception ex) { LogMessages.PrintException(ex); fault = new FaultContract() { FaultType = ex.Message, Message = ex.Message }; } finally { if (con.State != ConnectionState.Closed) { con.Close(); } } } } return(result); }
public void ExecureNonQuery(string procedureName, List <SqlParameter> parameters, out FaultContract fault, int?timeOut = null) { fault = null; using (SqlConnection con = getDBConnection()) { using (SqlCommand sqlCommand = new SqlCommand(procedureName, con)) { sqlCommand.CommandType = CommandType.StoredProcedure; if (timeOut != null) { sqlCommand.CommandTimeout = Convert.ToInt32(timeOut); } if (parameters != null) { sqlCommand.Parameters.AddRange(parameters.ToArray()); } if (con.State != ConnectionState.Open) { con.Open(); } try { sqlCommand.ExecuteNonQuery(); } catch (Exception ex) { LogMessages.PrintException(ex); fault = new FaultContract() { FaultType = ex.Message, Message = ex.Message }; } finally { if (con.State != ConnectionState.Closed) { con.Close(); } } } } }
protected override Site CopySite(string sourceSiteId, string targetSiteName, string targetSiteDescription) { // Resolve source site id into its corresponding site object Site sourceSite = SiteConfiguration.FindExistingSiteByID(sourceSiteId); if (sourceSite == null) { throw new Exception("Unable to find site with siteId = " + sourceSiteId); } // Make sure target site directory does not already exist string physicalPath = string.Format("{0}\\{1}", AppSettings.AppsPhysicalDir, targetSiteName); if (System.IO.Directory.Exists(physicalPath)) { throw new Exception("Site with name '" + targetSiteName + "' is in use already. Please try an alternate name."); } // Create a new site Site targetSite = new Site(); targetSite.ID = Guid.NewGuid().ToString("N"); targetSite.IsHostedOnIIS = true; targetSite.Name = targetSiteName; targetSite.Description = targetSiteDescription; targetSite.PhysicalPath = physicalPath; targetSite.Url = string.Format("{0}/{1}", AppSettings.AppsBaseUrl.TrimEnd('/'), targetSiteName.TrimStart('/')); targetSite.ProductVersion = sourceSite.ProductVersion; // Copy files from source site directory to target site directory FaultContract Fault = null; if (!(new ApplicationBuilderHelper()).CopySite(sourceSite.PhysicalPath, targetSite, true, out Fault)) { throw new Exception(Fault != null ? Fault.Message : "Unable to copy site"); } // Update site database (XML file) SiteConfiguration.AddSite(targetSite); // Return target site object return(targetSite); }
public string RenameSite(Site site, string oldSiteName, string newSiteName, out FaultContract Fault) { Fault = null; string status = string.Empty; string newSitePhysPath = string.Empty; if (CopyWebApplication(site, oldSiteName, newSiteName, out newSitePhysPath, out status, true)) { return(newSitePhysPath); } else { Fault = new FaultContract { FaultType = "Error", Message = "Error renaming site " + status }; return(null); } }
protected override void SaveSite(string siteId, string newTitle, SitePublishInfo info) { Site site = SiteConfiguration.FindExistingSiteByID(siteId); if (site == null) { throw new Exception("Unable to find site with siteId = " + siteId); } FaultContract Fault = null; if (!(new ApplicationBuilderHelper()).SaveConfigurationForSite(site, info, out Fault, newTitle)) { throw new Exception(Fault != null ? Fault.Message : "Unable to save site"); } if (!string.IsNullOrEmpty(newTitle) && site.Title != newTitle) // Update site's title in site configuration list { site.Title = newTitle; SiteConfiguration.SaveSite(site); } }
/// <summary> /// Return principal. /// </summary> /// <param name="token">Based on JWT Token it returns Principal.</param> /// <returns></returns> private static ClaimsPrincipal GetPrincipal(string token, IConfiguration configuration, bool IsRequiredExpiration, ref FaultContract faultContract) { try { JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler(); JwtSecurityToken jwtToken = (JwtSecurityToken)tokenHandler.ReadToken(token); if (jwtToken == null) { return(null); } string Secret = configuration["Jwt:Secretekey"].ToString(); byte[] key = Convert.FromBase64String(Secret); TokenValidationParameters parameters = new TokenValidationParameters() { RequireExpirationTime = IsRequiredExpiration, ValidateIssuer = false, ValidateAudience = false, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateLifetime = IsRequiredExpiration }; SecurityToken securityToken; ClaimsPrincipal principal = tokenHandler.ValidateToken(token, parameters, out securityToken); return(principal); } catch (Exception ex) { if (ex.Message.Contains("The token is expired.")) { string str = ex.Message.ToString(); faultContract = new FaultContract(); faultContract.faultmessage = "The token is expired."; faultContract.faultcode = EfaultCode.TokenExpire; return(GetPrincipal(token, configuration, false, ref faultContract)); } } return(null); }
/// <summary> /// Upgrades the site with the specified ID to the current version of the product /// </summary> /// <param name="siteId"></param> /// <param name="templateId"></param> /// <returns></returns> protected override Site UpgradeSite(string siteId, string templateId, out FaultContract fault) { // Get the site Site site = SiteConfiguration.FindExistingSiteByID(siteId); if (site == null) { throw new Exception("Unable to find site with siteId = " + siteId); } // Do upgrade fault = null; bool upgraded = ApplicationBuilderHelper.UpgradeSite(site, templateId, out fault); if (upgraded) { // Upgrade successful - update the version on the site and save it to disk Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; site.ProductVersion = string.Format("{0}.{1}.{2}.0", currentVersion.Major, currentVersion.Minor, currentVersion.Build); SiteConfiguration.SaveSite(site); return(site); } else { if (fault == null) { fault = new FaultContract() { Message = "Upgrade failed" } } ; return(null); } } }
public static void UploadFile(string filePath, byte[] bytes, out FaultContract Fault) { Fault = null; if (string.IsNullOrEmpty(filePath)) { Fault = new FaultContract { FaultType = "Error", Message = "Must enter a valid file path" }; return; } try { if (bytes == null || bytes.Length > 0) { using (System.IO.FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { fs.Write(bytes, 0, bytes.Length); fs.Close(); } } else { Fault = new FaultContract { FaultType = "Warning", Message = "Empty bytes for file" }; } } catch (Exception ex) { Fault = new FaultContract { FaultType = "Error", Message = ex.Message }; } }
/// <summary> /// Method used to ValidateToken based on token. /// </summary> /// <param name="token"></param> /// <param name="configuration"></param> /// <param name="faultContract"></param> /// <returns></returns> public static TokenInfo ValidateToken(string token, IConfiguration configuration, out FaultContract faultContract) { string username = null; TokenInfo info = new TokenInfo(); faultContract = null; ClaimsPrincipal principal = GetPrincipal(token, configuration, true, ref faultContract); if (principal == null) { return(null); } ClaimsIdentity identity = null; try { identity = (ClaimsIdentity)principal.Identity; } catch (NullReferenceException) { return(null); } Claim usernameClaim = identity.FindFirst(ClaimTypes.Name); Claim userdataClaim = identity.FindFirst(ClaimTypes.UserData); Claim creationtime = identity.FindFirst("CreationTime"); username = usernameClaim.Value; info.username = username; info.Uniquekey = userdataClaim.Value; info.Issuetime = creationtime.Value; return(info); }
public bool DeleteSite(Site site, out FaultContract Fault) { Fault = null; string iisLocation = ""; string innerStatus = ""; try { iisLocation = IISHelper.GetIISLocation(site.IISHost, String.Format(":{0}:", site.IISPort), out innerStatus); if (!string.IsNullOrEmpty(iisLocation)) { string siteName = site.IISPath; //of the format Root/Folder/SubFolder if (IISHelper.DeleteVirtualDirectory(iisLocation + "/Root", siteName, out innerStatus)) { string iisPhysicalPath = ""; string websitePhysPath = ""; siteName = siteName.Replace("/", "\\"); if (IISHelper.GetPhysicalPath(iisLocation + "/Root", out iisPhysicalPath, out innerStatus)) { websitePhysPath = iisPhysicalPath + "\\" + siteName; websitePhysPath = ConvertToUNCPath(site.IISHost, websitePhysPath); try { if (Directory.Exists(websitePhysPath)) { Directory.Delete(websitePhysPath, true); } } catch (IOException) { // Sometimes the delete operations fail on first attempt on IIS 7 machines // So retry once more try { if (Directory.Exists(websitePhysPath)) { Directory.Delete(websitePhysPath, true); } } catch (IOException ioe) { Fault = new FaultContract { FaultType = "Error", Message = "Error deleting directory " + ioe.ToString() }; return(false); } } } } else { return(false); } } else { return(false); } } catch (Exception) { return(false); } return(true); }
protected override void DoValidate(IEnumerable <Fault> objectToValidate, object currentTarget, string key, ValidationResults validationResults) { Operation operation = currentTarget as Operation; if (operation == null) { return; } string serviceContractImplementationTech = String.Empty; if (operation.ServiceContractModel.ImplementationTechnology == null) { return; } else { serviceContractImplementationTech = operation.ServiceContractModel.ImplementationTechnology.Name; } SerializerType serviceContractSerializer = operation.ServiceContractModel.SerializerType; foreach (Fault item in objectToValidate) { bool isValid = true; DataContractFault fault = item as DataContractFault; if (fault == null || fault.Type == null) { continue; } if (!fault.Type.IsValidReference()) { validationResults.AddResult( new ValidationResult( String.Format(CultureInfo.CurrentUICulture, Resources.CannotResolveReference, currentTarget.GetType().Name, fault.Name, fault.Type.GetDisplayName()), fault, key, String.Empty, this)); return; } ModelElement mel = ModelBusReferenceResolver.ResolveAndDispose(fault.Type); if (mel == null) { return; } FaultContract dcFault = mel as FaultContract; if (dcFault == null || dcFault.DataContractModel == null || dcFault.DataContractModel.ImplementationTechnology == null) { return; } if (serviceContractImplementationTech.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase)) { if (serviceContractSerializer.Equals(SerializerType.XmlSerializer)) { isValid = !(dcFault.DataContractModel.ImplementationTechnology.Name.Equals(WCFExtension, StringComparison.OrdinalIgnoreCase)); } else { // Asmx Extension only supports XmlSerializer validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, asmxExtensionInvalidSerializerMessage, fault.Name, operation.Name), objectToValidate, key, String.Empty, this) ); return; } } else if (serviceContractImplementationTech.Equals(WCFExtension, StringComparison.OrdinalIgnoreCase)) { if (serviceContractSerializer.Equals(SerializerType.DataContractSerializer)) { isValid = !(dcFault.DataContractModel.ImplementationTechnology.Name.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase)); } else { if (dcFault.DataContractModel.ImplementationTechnology.Name.Equals(ASMXExtension, StringComparison.OrdinalIgnoreCase)) { // Faults cannot be XMLSerializable validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, faultInvalidSerializerMessage, operation.Name, fault.Name), objectToValidate, key, String.Empty, this) ); return; } } } if (!isValid) { validationResults.AddResult( new ValidationResult(String.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, fault.Name, operation.Name), objectToValidate, key, String.Empty, this) ); } } }
public string GetPhysicalPathForSite(Site site, bool makeUNCPath, out FaultContract Fault) { Fault = null; string status = string.Empty; string iisLocation = string.Empty; // Get the location of the the website running at this host and that port .. as Active Directory entry iisLocation = IISHelper.GetIISLocation(site.IISHost, String.Format(":{0}:", site.IISPort), out status); if (!string.IsNullOrEmpty(status)) { Fault = new FaultContract { FaultType = "Error", Message = "Unable to retrieve IIS location for " + site.IISHost + " Port " + site.IISPort }; return(null); } string iisPhysicalPath = string.Empty; if (!string.IsNullOrEmpty(iisLocation)) { string websitePhysicalPath = string.Empty; // Check if we can query IIS string pathToQuery = iisLocation + "/Root"; // get the physical location of IIS on the server IISHelper.GetPhysicalPath(iisLocation + "/Root", out iisPhysicalPath, out status); if (string.IsNullOrEmpty(iisPhysicalPath)) { Fault = new FaultContract { FaultType = "Error", Message = "Unable to retrieve IIS location for " + site.IISHost + " Port " + site.IISPort }; return(null); } if (!iisPhysicalPath.EndsWith("\\", StringComparison.Ordinal)) { iisPhysicalPath = iisPhysicalPath + "\\"; } string virtualDir = site.IISPath; virtualDir = virtualDir.Replace("/", "\\"); // replace forward slashes to backward slashes for path if (isRemoteServer(site.IISHost) && makeUNCPath) { // We need a UNC path ... eg:- \\maestro\C$\Inetput\wwwroot iisPhysicalPath = "\\\\" + site.IISHost + "\\" + iisPhysicalPath.Replace(':', '$'); websitePhysicalPath = iisPhysicalPath + virtualDir; } else { websitePhysicalPath = Path.Combine(iisPhysicalPath, virtualDir); } return(websitePhysicalPath); } else { Fault = new FaultContract { FaultType = "Error", Message = "Unable to retrieve IIS location for " + site.IISHost + " Port " + site.IISPort }; return(null); } }
protected abstract Site UpgradeSite(string siteId, string templateId, out FaultContract fault);
protected override FileDescriptor[] GetFiles(string siteId, bool isTemplate, string relativePath, string[] fileExts) { FaultContract Fault = null; string physicalPath = FileUtils.GetPhysicalPathForId(siteId, isTemplate, relativePath, out Fault); if (Fault != null) { throw new Exception(Fault.Message); } if (!System.IO.Directory.Exists((physicalPath))) { throw new Exception("Unable to find files"); } List <FileDescriptor> allFiles = new List <FileDescriptor>(); string[] dirs = FileExplorerUtility.GetDirectories(physicalPath); if (dirs != null && dirs.Length > 0) { foreach (string dir in dirs) { if (string.IsNullOrEmpty(dir)) { continue; } FileDescriptor fileInfo = new FileDescriptor(); string fileName = dir; int pos = fileName.LastIndexOf('\\'); if (pos > -1) { fileName = fileName.Substring(pos + 1); } fileInfo.FileName = fileName; fileInfo.IsFolder = true; if (!string.IsNullOrEmpty(relativePath)) { fileInfo.RelativePath = string.Format("{0}/{1}", relativePath, fileName); } else { fileInfo.RelativePath = fileName; } allFiles.Add(fileInfo); } } string[] files = FileExplorerUtility.GetFiles(physicalPath, fileExts); if (files != null && files.Length > 0) { foreach (string file in files) { FileDescriptor fileInfo = new FileDescriptor(); string fileName = file; int pos = fileName.LastIndexOf('\\'); if (pos > -1) { fileName = fileName.Substring(pos + 1); } fileInfo.FileName = fileName; if (!string.IsNullOrEmpty(relativePath)) { fileInfo.RelativePath = string.Format("{0}/{1}", relativePath, fileName); } else { fileInfo.RelativePath = fileName; } allFiles.Add(fileInfo); } } return(allFiles.ToArray()); }