/// <summary> /// for more on registering, see https://developers.google.com/cloud-print/docs/devguide#registering /// Java code for registering - https://github.com/jittagornp/GoogleCloudPrint /// PHP code for registering - /// Example of what should go in capabilites parameter? - https://stackoverflow.com/questions/12724201/google-cloud-print-how-to-submit-valid-capabilities /// </summary> /// <param name="pReg"></param> /// <returns></returns> public UnregisteredCloudPrinter RegisterPrinter(UnregisteredCloudPrinter pReg) { // call the register method and fill the parameter p above with the data // since CloudPrinter, at this time, does not have fields for a message, we'll return // debuging stuff in exiting fields // TODO consider a new class inheriting from CloudPrinter to contain messages try { var p = new PostData(); if (String.IsNullOrEmpty(pReg.capabilities)) { pReg.capabilities = "{\"capabilities\":[{}]}"; } p.Parameters.Add(new PostDataParam { Name = "name", Value = pReg.name, Type = PostDataParamType.Field }); p.Parameters.Add(new PostDataParam { Name = "default_display_name", Value = pReg.default_display_name, Type = PostDataParamType.Field }); p.Parameters.Add(new PostDataParam { Name = "tag", Value = pReg.tag, Type = PostDataParamType.Field }); p.Parameters.Add(new PostDataParam { Name = "proxy", Value = pReg.proxy, Type = PostDataParamType.Field }); //p.Parameters.Add(new PostDataParam { Name = "capabilities", Value = pReg.capabilities, Type = PostDataParamType.Field }); p.Parameters.Add(new PostDataParam { Name = "capabilities", Value = "{\"capabilities\":[{}]}", Type = PostDataParamType.Field }); pReg = GCPServiceCall <UnregisteredCloudPrinter>("register", p); } catch (Exception ex) { pReg.name = ex.Message; pReg.id = "failure"; pReg.description = ex.StackTrace; } // we could get actual response to inspect the success parameter // but it's a failure if object is null if (pReg.id == null) { pReg.id = "failure"; pReg.name = string.Empty; pReg.description = string.Empty; } return(pReg); }
public UnregisteredCloudPrinter UpdatePrinter(UnregisteredCloudPrinter pReg) { // call the update method to change name and display name of printer // since CloudPrinter, at this time, does not have fields for a message, we'll return // debuging stuff in exiting fields // TODO consider a new class inheting from (un reg)CloudPrinter to contain messages try { var p = new PostData(); //p.Parameters.Add(new PostDataParam { Name = "name", Value = pReg.name, Type = PostDataParamType.Field }); p.Parameters.Add(new PostDataParam { Name = "default_display_name", Value = pReg.default_display_name, Type = PostDataParamType.Field }); p.Parameters.Add(new PostDataParam { Name = "printerid", Value = pReg.id, Type = PostDataParamType.Field }); pReg = GCPServiceCall <UnregisteredCloudPrinter>("update", p); } catch (Exception ex) { pReg.name = ex.Message; pReg.id = "failure"; pReg.description = ex.StackTrace; } // we could get actual response to inspect the success parameter // but it's a failure if object is null if (pReg.id == null) { pReg.id = "failure"; pReg.name = string.Empty; pReg.description = string.Empty; } return(pReg); }