Home
OpenProjects API v3 Create Bug in c#
- Details
The approach here is to pass javascript object to a json call on your local website domain then the web services relays the request to the open projects server
change out:
project_to_add_to -- to you project
10.10.1.3 -- to your OpenProjects Web Server
basically you should be able to go to the baseAddress URL and see a json of all the work packages
Client Side Javascript
var userOpRequest = {username : '',userId : 0, subject :'', content : '', requestType : 7 };
//bind the form
userOpRequest.subject = $("#opSubject").val();
//etc..
var s = encodeURIComponent(JSON.stringify(userOpRequest ));
$.getJSON("OPWebService.asmx/fileBug?s=" + s, function (data) {
});
C# Web Service Code
using System.Text; using System.Net; using System.Web.Script.Services; using System.Web.Services; using System; using System.Collections.Generic; public class OPWebService : System.Web.Services.WebService { [WebMethod(EnableSession = false)] [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)] public void fileBug(string s) { user_openproject_request openprojectsRequest = JsonConvert.DeserializeObject(s); string WorkPackageSubject = openprojectsRequest.subject; string WorkPackageDetails = openprojectsRequest.content; string TypeId = openprojectsRequest.requestType.ToString() ; string TypeName = openprojectsRequest.getTypeName() ; string ParentId = "9999"; string ParentTitle = "Tile of parent";
//this next line is one line if your copying from web
string bugJson = "{ \"subject\": \""+ WorkPackageSubject + "\",\"description\": {\"format\": \"textile\",\"raw\": \""+ WorkPackageDetails + "\" }, \"_links\": {\"type\": { \"href\": \"/api/v3/types/" + TypeId + "\",\"title\": \"" + TypeName + "\" },\"status\": { \"href\": \"/api/v3/statuses/1\"}, \"priority\": {\"href\": \"/api/v3/priorities/8\",\"title\": \"Normal\" }, \"parent\":{\"href\":\"/api/v3/work_packages/"+ParentId+ "\",\"title\":\"" + ParentTitle + "\"} }}";//,\"assignee\": {\"href\": \"/api/v3/users/3\"}
//start web connection var baseAddress = "http://10.10.1.5/api/v3/projects/project_to_add_to/work_packages/"; var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress)); string userName = "apikey"; string apiKey = "YOUR KEY"; // YourOpenProjectServer/my/access_token var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(userName + ":" + apiKey); string userCreds = System.Convert.ToBase64String(plainTextBytes); http.Headers.Add("Authorization: Basic " + userCreds); http.Accept = "application/json"; http.ContentType = "application/json"; http.Method = "POST"; string parsedContent = bugJson; ASCIIEncoding encoding = new ASCIIEncoding(); Byte[] bytes = encoding.GetBytes(parsedContent); Stream newStream = http.GetRequestStream(); newStream.Write(bytes, 0, bytes.Length); newStream.Close(); System.Net.WebResponse response; var content = ""; try { response = http.GetResponse(); var stream = response.GetResponseStream(); var sr = new StreamReader(stream); content = sr.ReadToEnd(); }catch { } Context.Response.Clear(); Context.Response.ContentType = "application/json"; Context.Response.Write(content); } }//end web serverice class public class user_openproject_request { public string username = ""; public int userId = 0; public string subject = ""; public string content = ""; public int requestType = 7; public string urlOn = ""; public string userURL = ""; public string getTypeName() { string retVal = "Bug"; if(requestType == 4) { retVal = "Feature"; } if (requestType == 1) { retVal = "Task"; } return retVal; } }
ArcGis - How to export a lot of pdf from layer and data source combos
- Details
First we have in ArcGIS client a bunch of layers that are called District_1, District_2,District_x,etc. These are File Geodatabase feature classes with geometry type Polygon.
Basically it's the poly that defines a border for a Congressional District.
We have a database table called Health Center Clinics, which has longitude, latitude, the district in which they fall in, name, parent Health Center Name, and misc information.
We want to: show the district poly, all the health center clinics within that district, change the text label in the pdf, and set the name of the pdf.
Desired Outcome: show poly for district 1, include all health centers clinics, change the name to show the Congress persons name, Make a legend show the Health Center parent.
import arcpy def PDFIt(dist): tname = "Unrepresented" tdis = dist fname = "Congressional District " + dist + " - Unrepresented"; rows = arcpy.SearchCursor("Health Center Clinics",fields="us_house_rep;us_house_number") for row in rows: if row.getValue("us_house_number") == tdis: tname = "The Honorable " + row.getValue("us_house_rep") + '\n' + "Congressional District " + row.getValue("us_house_number") tempname = row.getValue("us_house_rep").replace(" ","_") tempname = tempname.replace(".","") tempname = tempname.replace(".","") tempname = tempname.replace("(D)","") tempname = tempname.replace("(R)","") tempname = str(tempname.encode("utf-8").replace("é","e").replace("í","i").replace("á","a")) tempname = str(tempname.encode("utf-8").replace("'","")) tempname = tempname.replace("__","_") fname = row.getValue("us_house_number") + "_mapc_" + tempname + ".pdf" print tname print fname mxd = arcpy.mapping.MapDocument("CURRENT") titleItem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "*")[0] titleItem.text = tname df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, 'District_' + tdis, df)[0] ext = lyr.getExtent() df.extent = ext lyr.visible = True lyrm = arcpy.mapping.ListLayers(mxd, 'Health Center Clinics', df)[0] lyrm.visible = True lyrm.definitionQuery= "[is_advocacy]='1' and [status] in ('Active','Reportable') and [us_house_number]='" + dist + "'" arcpy.mapping.ExportToPDF(mxd, "D:\\dlfs\\us_congress_clinic_sitename\\" + fname) lyr.visible = False lyrm.definitionQuery= "[is_advocacy]='1'and [status] in ('Active','Reportable')" for x in range(1, 37): PDFIt(str(x))
MS SQL Management Studio Intellisense Pro Tip
- Details
One of my new favorite shortcuts is to reload the intellisense with in the query window. If you make a change to the schema of a database your intellisense won't pick it up and you will have red lines under things you know exists. Hit the keys Ctrl + Shift + R to fix it.
If you have a bunch of Query windows open and you have been disconnected from the server you can reconnect those query windows just by going to the left pane top item right click and reconnect
SIP Station SMS forward as email
- Details
I like sip stations ability to receive SMS straight to the PBX (FreePBX and Asterisk). However I almost never use their web interface to get and send messages. I wanted them forwarded to my gmail account so this is what I did.
First you must have some experience using shell and have access to your asterisk server.
You will have also had to setup email on your asterisk server for this to work. I set mine up so I could get voice mails emailed to me.
What you'll do in this tutorial:
You will login to your asterisk server via SSH
Open MySQL and alter a table.
Create a PHP script
Create a cron job.
So lets starts:
First log in to mysql on your asterisk server using the database asterisk.
ssh to your asterisk server and login and type the following (or copy paste if using putty):
mysql
use asterisk;
alter table sms_messages add forwarded int(11) default '0';
exit;
now create a new file for your php script:
don't forget to swap out your email address with youremail@someaddress in the script:
new file location /var/www/html/sendsms.php
paste the following from <?php thru ?> into your nano editor. (please understand that I wrote this script on my cell phone in nano so well, this is it)
nano /var/www/html/sendsms.php
<?php $conn = mysql_connect("localhost", "root", ""); if (!$conn) { die("Connection failed: " . mysql_error()); } echo "Connected successfully"; mysql_select_db('asterisk'); $sql="select * from sms_messages where forwarded='0' limit 1"; $reader = mysql_query($sql); echo "<table><tr><th>id</th><th>from</th><th>to</th><th>message</th><th></tr>”; $id=""; $to=""; $from=""; $body=""; $body=""; $dt="";
while($row = mysql_fetch_assoc($reader)){ $mys = "<tr> <td>".$row['id']."</td> <td>".$row['from']."</td> <td>".$row['to']."</td> <td>".$row['body']."</td> <td>".$row['tx_rx_datetime']."</td>
</tr>"; echo $mys; $id=$row['id']; $to=$row['to']; $from=$row['from']; $body=$row['body']; $dt=$row['tx_rx_datetime']; } echo "</table>"; if($id != ""){ $mys = "to: ".$to . "\r\nfrom: ".$from."\r\ntime: ".$dt."\r\nmessage: ".$body; mail("youremail@someaddress","sms:".$to . " " . $from ,$mys); mysql_query("update sms_messages set forwarded='1' where id='".$id."'"); } mysql_close($conn); ?>
Add cron job using your server ip address. Swap out the 192.168.1.9 with yours:
crontab -e
* * * * * wget -O /dev/null -o /dev/null 192.168.1.9/sendsms.php
Now if you go to your asterisk server and go to the page sendsms.php you should see 1 message (assuming you have received SMS messages).
If you see a message you will get an email shortly with the SMS message.
Page 3 of 40