public static void Set(Uri uri, Style style) { System.IO.Stream s = new System.Net.WebClient().OpenRead(uri.ToString()); System.Drawing.Image img = System.Drawing.Image.FromStream(s); string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp"); img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp); RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); if (style == Style.Stretched) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == Style.Centered) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == Style.Tiled) { key.SetValue(@"WallpaperStyle", 1.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); s.Close(); }
public WebServiceHelper(string Url, string classname) { if ((classname == null) || (classname == string.Empty)) { this.classname = this.GetWsClassName(Url); } else { this.classname = classname; } try { Stream stream = new WebClient().OpenRead(Url + "?WSDL"); ServiceDescription serviceDescription = ServiceDescription.Read(stream); ServiceDescriptionImporter importer = new ServiceDescriptionImporter(); importer.AddServiceDescription(serviceDescription, "", ""); CodeNamespace namespace2 = new CodeNamespace(this.@namespace); stream.Close(); CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); codeCompileUnit.Namespaces.Add(namespace2); importer.Import(namespace2, codeCompileUnit); ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler(); CompilerParameters options = new CompilerParameters(); options.GenerateExecutable = false; options.GenerateInMemory = true; options.ReferencedAssemblies.Add("System.dll"); options.ReferencedAssemblies.Add("System.XML.dll"); options.ReferencedAssemblies.Add("System.Web.Services.dll"); options.ReferencedAssemblies.Add("System.Data.dll"); CompilerResults results = compiler.CompileAssemblyFromDom(options, codeCompileUnit); if (results.Errors.HasErrors) { StringBuilder builder = new StringBuilder(); foreach (CompilerError error in results.Errors) { builder.Append(error.ToString()); builder.Append(Environment.NewLine); } throw new Exception(builder.ToString()); } this.assembly = results.CompiledAssembly; } catch (Exception exception) { throw new Exception(exception.InnerException.Message, new Exception(exception.InnerException.StackTrace)); } }
private void UploadRecordToS3(string callId, string parentCallId, string recordUrl) { try { Thread.Sleep(10000); CoreContext.TenantManager.SetCurrentTenant(Tenant); var stream = new WebClient().OpenRead(recordUrl); var storage = StorageFactory.GetStorage(Tenant.TenantId.ToString(CultureInfo.InvariantCulture), "crm"); var newRecordUri = storage.Save(recordUrl.Split('/').Last() + ".wav", stream.GetBuffered()); if (stream != null) stream.Close(); SaveOrUpdateCallHistory(callId, parentCallId, recordUrl: newRecordUri.AbsoluteUri); } catch (Exception e) { Log.ErrorFormat("UploadRecord: StackTrace:{0}, Message: {1}", e.StackTrace, e.Message); } }
public void SaveComplaint() { try { WebClient client = new WebClient(); client.Headers["Content-type"] = "application/json"; ConsoleTest.Models.complaintItem temp = new ConsoleTest.Models.complaintItem(); //temp.complaintId = complaint.complaintId; temp.userId = 1; temp.title = "Rubbish Test"; temp.details = "Test Rubbish"; temp.numLikes = 2; temp.numComments = 1; temp.picture = "zascac"; temp.complaintDate = DateTime.Now; temp.location = "dasdas"; temp.latitude = (float)0.323; temp.longitude = (float)32.44; temp.category = "pothole"; temp.complaintStatus = "Solved"; temp.date = DateTime.Now; temp.isAnonymous = 1; string path = @"C:\Users\Banka\Desktop\images.jpg"; FileStream fs=new FileStream(path,FileMode.Open); byte[] PhotoBytes = new byte[fs.Length]; fs.Read(PhotoBytes, 0, PhotoBytes.Length); temp.ImageByte = PhotoBytes; MemoryStream stream = new MemoryStream(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ConsoleTest.Models.complaintItem)); serializer.WriteObject(stream, temp); byte[] data = client.UploadData("http://127.0.0.1/Core.svc/SaveComplaint", "POST", stream.ToArray()); stream = new MemoryStream(data); serializer = new DataContractJsonSerializer(typeof(int)); int result = (int)serializer.ReadObject(stream); Console.WriteLine("Save User Result : " + result); logger.warning("Exit TestConnection Method"); Console.ReadLine(); } catch (FaultException<ConsoleTest.CoreService.Bug> Fex) { logger.error("ErrorMessage::" + Fex.Detail.ErrorMessage + Environment.NewLine); logger.error("ErrorDetails::" + Environment.NewLine + Fex.Detail.ErrorDetails); Console.ReadLine(); } finally { if (null != client) { client.Close(); } } }
//public void TestConnection() //{ // logger.warning("Enter TestConnection Method"); // try // { // client = new CoreClient(); // TestConnectionRequest request = new TestConnectionRequest(); // TestConnectionResponse response; // response = client.TestConnection(request); // Console.WriteLine("Testing Connection Result : " + response.TestConnectionResult); // logger.warning("Exit TestConnection Method"); // Console.ReadLine(); // } // catch (FaultException<ConsoleTest.CoreService.Bug> Fex) // { // logger.error("ErrorMessage::" + Fex.Detail.ErrorMessage + Environment.NewLine); // logger.error("ErrorDetails::" + Environment.NewLine + Fex.Detail.ErrorDetails); // Console.ReadLine(); // } // finally // { // if (null != client) // { // client.Close(); // } // } //} public void SaveUser() { logger.warning("Enter TestConnection Method"); try { WebClient client = new WebClient(); client.Headers["Content-type"] = "application/json"; ConsoleTest.Models.userItem item = new ConsoleTest.Models.userItem(); item.userName = "******"; item.userAddress = "scdscscsdac"; item.email = "*****@*****.**"; item.date = DateTime.Now; MemoryStream stream = new MemoryStream(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ConsoleTest.Models.userItem)); serializer.WriteObject(stream, item); byte[] data = client.UploadData("http://127.0.0.1/Core.svc/SaveUser", "POST", stream.ToArray()); stream = new MemoryStream(data); serializer = new DataContractJsonSerializer(typeof(int)); int result = (int)serializer.ReadObject(stream); Console.WriteLine("Save User Result : " + result); logger.warning("Exit TestConnection Method"); Console.ReadLine(); } catch (FaultException<ConsoleTest.CoreService.Bug> Fex) { logger.error("ErrorMessage::" + Fex.Detail.ErrorMessage + Environment.NewLine); logger.error("ErrorDetails::" + Environment.NewLine + Fex.Detail.ErrorDetails); Console.ReadLine(); } finally { if (null != client) { client.Close(); } } }
/// <summary> /// Gets the region map. /// </summary> /// <param name="url">URL.</param> /// <returns></returns> private Image GetRegionMap(Uri url) { Image map = Cache.Instance.Get(url) as Image; if (map == null) try { Stream ImageStream = new WebClient().OpenRead(url.AbsoluteUri); map = Image.FromStream(ImageStream); ImageStream.Close(); Cache.Instance.Insert(url, map, CacheItemLifetime.Permanent); } catch { map = GetWeatherIcon("NOCONNECTION"); } return map; }