public void RealmInteger_HasDefaultValue(int defaultValue) { var byteValue = (byte)Math.Max(defaultValue, 0); var counter = new CounterObject { ByteProperty = byteValue, Int16Property = (short)defaultValue, Int32Property = defaultValue, Int64Property = defaultValue, }; Assert.That(counter.ByteProperty == byteValue); Assert.That(counter.Int16Property == defaultValue); Assert.That(counter.Int32Property == defaultValue); Assert.That(counter.Int64Property == defaultValue); _realm.Write(() => { _realm.Add(counter); }); Assert.That(counter.ByteProperty == byteValue); Assert.That(counter.Int16Property == defaultValue); Assert.That(counter.Int32Property == defaultValue); Assert.That(counter.Int64Property == defaultValue); }
public void NullableRealmInteger_HasDefaultValue(int?defaultValue) { var byteValue = defaultValue.HasValue ? (byte?)Math.Max(defaultValue.Value, 0) : null; var counter = new CounterObject { NullableByteProperty = byteValue, NullableInt16Property = (short?)defaultValue, NullableInt32Property = defaultValue, NullableInt64Property = defaultValue, }; Assert.That(counter.NullableByteProperty == byteValue); Assert.That(counter.NullableInt16Property == defaultValue); Assert.That(counter.NullableInt32Property == defaultValue); Assert.That(counter.NullableInt64Property == defaultValue); _realm.Write(() => { _realm.Add(counter); }); Assert.That(counter.NullableByteProperty == byteValue); Assert.That(counter.NullableInt16Property == defaultValue); Assert.That(counter.NullableInt32Property == defaultValue); Assert.That(counter.NullableInt64Property == defaultValue); }
private void AddCounterObjects(out CounterObject zeros, out CounterObject ones) { var counter0 = new CounterObject { Id = 0 }; var counter1 = new CounterObject { Id = 1, ByteProperty = 1, Int16Property = 1, Int32Property = 1, Int64Property = 1, NullableByteProperty = 1, NullableInt16Property = 1, NullableInt32Property = 1, NullableInt64Property = 1 }; _realm.Write(() => { _realm.Add(counter0); _realm.Add(counter1); }); zeros = counter0; ones = counter1; }
public ChangeCounterInteraction(SpawnCommand p_command, Int32 p_parentID, Int32 p_commandIndex) : base(p_command, p_parentID, p_commandIndex) { m_parent = Grid.FindInteractiveObject(m_parentID); InteractiveObject interactiveObject = Grid.FindInteractiveObject(m_targetSpawnID); m_interactiveObject = (interactiveObject as CounterObject); if (m_interactiveObject == null) { throw new InvalidOperationException("Tried to set counter for something that is not a CounterObject!"); } }
public CounterObject GetById(string email, string app, string sha) { CounterObject counter = new CounterObject(); string hash = Security.SHA1(email + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd") + SYNCCOUNTERCODE).ToLower(); if (hash.Equals(sha)) { //string username = Membership.GetUserNameByEmail(email); //if (!string.IsNullOrEmpty(username)) { //using (SQL.ExecuteQuery("INSERT INTO test(code) VALUES(@1)", code)) { } counter.success = "OK"; counter.message = "Success"; //if (Membership.ValidateUser(username, pw)) { // System.Web.Security.MembershipUser user = Membership.GetUser(username); // counter.success = "OK"; // counter.message = "Success"; // using (SqlDataReader reader = SQL.ExecuteQuery("SELECT token FROM logintokens WHERE dateexpires > GETDATE() AND userid=@1", user.ProviderUserKey)) { // if (reader.Read()) { // counter.data = reader.GetGuid(0).ToString(); // } else { // Guid guid = Guid.NewGuid(); // using (SQL.ExecuteQuery("DELETE FROM logintokens WHERE userid=@1; INSERT INTO logintokens(userid,datecreated,dateexpires,token) VALUES(@1,GETDATE(),(GETDATE() + 365),@2)", user.ProviderUserKey, guid)) { } // counter.data = guid.ToString(); // } // } //} else { // counter.success = "FAIL"; // counter.message = "fel pw..."; //} //} else { // counter.success = "FAIL"; // counter.message = "fel email..."; //} // } catch (Exception ex) { // counter.success = "FAIL"; // counter.message = ex.Message; // } } else { counter.success = "FAIL"; counter.message = "fel hash..."; } return counter; //FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text.Trim(), "SHA1"); //var counter = counters.FirstOrDefault((p) => p.caseid == caseid); //if (counter == null) { // throw new HttpResponseException(HttpStatusCode.NotFound); //} //return counter; }
// GET api/<controller>/5 public CounterObject GetById(string id) { CounterObject counter = new CounterObject(); //int synccount = 0; //bool update = false; //FormsAuthentication.HashPasswordForStoringInConfigFile((email+caseid+"datum"+SYNCCOUNTERCODE), "SHA1"); //FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text.Trim(), "SHA1"); //var counter = counters.FirstOrDefault((p) => p.caseid == caseid); //if (counter == null) { // throw new HttpResponseException(HttpStatusCode.NotFound); //} return counter; }
public static void Start(object obj, Action <object> onTimerWithArgCallback, float time) { if (onTimerWithArgCallback == null) { Debug.LogError("定时回调不能为空"); return; } if (Instance.m_CounterWithArgDic.ContainsKey(obj)) { Stop(onTimerWithArgCallback); } CounterObject counterObject = Instance.m_CounterPool.Get() as CounterObject; Instance.m_CounterWithArgDic[obj] = counterObject; counterObject.StartCounter(obj, onTimerWithArgCallback, time); }
public static void Stop(object obj) { if (obj == null) { Debug.LogError("object不能为空"); return; } CounterObject counterObject = null; if (!Instance.m_CounterWithArgDic.TryGetValue(obj, out counterObject)) { return; } counterObject.StopCounter(); Instance.m_CounterWithArgDic.Remove(obj); Instance.m_CounterPool.Remove(counterObject); }
// GET api/<controller>/5 public CounterObject GetById(string caseid,string sysid, string email,string sha,int reportid) { CounterObject counter = new CounterObject(); int synccount = 0; bool update = false; string hash = Security.SHA1(email + caseid + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd") + SYNCCOUNTERCODE).ToLower(); //FormsAuthentication.HashPasswordForStoringInConfigFile((email+caseid+"datum"+SYNCCOUNTERCODE), "SHA1"); if (hash.Equals(sha)) { try { using (SqlDataReader reader = SQL.ExecuteQuery("SELECT * FROM ocabpayment WHERE caseid LIKE @1 AND sysid=@2 AND ocabreportid=@3", caseid, sysid, reportid)) { if (reader.Read()) { synccount = reader.GetInt32(reader.GetOrdinal("synccounter")) + 1; update = true; } } if (update) { using (SQL.ExecuteQuery("UPDATE ocabpayment SET synccounter=@1 WHERE caseid LIKE @2 AND sysid=@3 AND ocabreportid=@4", synccount, caseid, sysid, reportid)) { } } else { using (SQL.ExecuteQuery("INSERT INTO ocabpayment (caseid,sysid,email,datecreated,datelastsync,synccounter,ocabreportid) VALUES(@1,@2,@3,GETDATE(),GETDATE(),1,@4)", caseid, sysid, email, reportid)) { } } counter.success = "OK"; counter.message = "Success"; } catch (Exception ex) { counter.success = "FAIL"; counter.message = ex.Message; } } else { counter.success = "FAIL"; counter.message = "fel hash..."; } return counter; //FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text.Trim(), "SHA1"); //var counter = counters.FirstOrDefault((p) => p.caseid == caseid); //if (counter == null) { // throw new HttpResponseException(HttpStatusCode.NotFound); //} //return counter; }
public CounterObject PostGCM(string email, string pw, string sha) { CounterObject counter = new CounterObject(); string hash = Security.SHA1(email + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd") + SYNCCOUNTERCODE).ToLower(); if (hash.Equals(sha)) { //string username = Membership.GetUserNameByEmail(email); //if (!string.IsNullOrEmpty(username)) { try { var jsonSerializer = new JsonSerializer(); long id = 0; string data = Request.Content.ReadAsStringAsync().Result; JObject gcm = JObject.Parse(data); string code = gcm["code"].ToString(); using (SqlDataReader reader = SQL.ExecuteQuery("SELECT * FROM gcm_codes WHERE email LIKE @1 AND app LIKE @2", email, pw)) { if (reader.HasRows) { using (SQL.ExecuteQuery("UPDATE gcm_codes SET code=@1 WHERE email LIKE @2 AND app LIKE @3", code, email, pw)) { } } else { using (SQL.ExecuteQuery("INSERT INTO gcm_codes(code,email,app) VALUES(@1,@2,@3)", code, email, pw)) { } } } counter.success = "OK"; counter.message = "Success"; } catch (Exception ex) { counter.success = "FAIL"; counter.message = ex.Message; } //} else { // counter.success = "FAIL"; // counter.message = "Email finns ej"; //} } else { counter.success = "FAIL"; counter.message = "Ogiltig hash"; } return counter; }
public void RealmInteger_WhenByte_IncrementTests(byte original, byte value, bool managed) { var counter = new CounterObject { ByteProperty = original, }; var sum = (byte)(original + value); if (managed) { _realm.Write(() => _realm.Add(counter)); _realm.Write(() => counter.ByteProperty.Increment(value)); Assert.That((byte)counter.ByteProperty, Is.EqualTo(sum)); } else { Assert.That(() => counter.ByteProperty.Increment(value), Throws.TypeOf <NotSupportedException>()); } }
public void RealmInteger_WhenLong_IncrementTests(long original, long value, bool managed) { var counter = new CounterObject { Int64Property = original, }; var sum = original + value; if (managed) { _realm.Write(() => _realm.Add(counter)); _realm.Write(() => counter.Int64Property.Increment(value)); Assert.That((long)counter.Int64Property, Is.EqualTo(sum)); } else { Assert.That(() => counter.Int64Property.Increment(value), Throws.TypeOf <NotSupportedException>()); } }
public CounterObject Post(string caseid, string sysid, string email, string sha) { CounterObject counter = new CounterObject(); string hash = Security.SHA1(email + caseid + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd") + SYNCCOUNTERCODE).ToLower(); if (hash.Equals(sha)) { //string username = Membership.GetUserNameByEmail(email); //if (!string.IsNullOrEmpty(username)) { try { var jsonSerializer = new JsonSerializer(); long id = 0; string data = Request.Content.ReadAsStringAsync().Result; JObject maillist = JObject.Parse(data); JArray recipients = (JArray)maillist["recipients"]; //string recipients = .ToString(); //Common.Mail(email,email,) counter.success = "OK"; counter.message = "Success"; } catch (Exception ex) { counter.success = "FAIL"; counter.message = ex.Message; } //} else { // counter.success = "FAIL"; // counter.message = "Email finns ej"; //} } else { counter.success = "FAIL"; counter.message = "Ogiltig hash"; } return counter; }
// POST api/<controller> public CounterObject Post(string caseid, string sysid, string email, string sha) { string hash = Security.SHA1(email + caseid + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd") + SYNCCODE).ToLower(); CounterObject counter = new CounterObject(); if (hash.Equals(sha)) { try { var jsonSerializer = new JsonSerializer(); long id = 0; string data = Request.Content.ReadAsStringAsync().Result; JObject jour = JObject.Parse(data); string journo = jour["caseid"].ToString(); string pw = jour["password"].ToString(); string username = Membership.GetUserNameByEmail(email); MembershipUser user = Membership.GetUser(username); using (SqlDataReader reader = SQL.ExecuteQuery("SELECT token FROM logintokens WHERE dateexpires > GETDATE() AND userid=@1", user.ProviderUserKey)) { if (reader.Read()) { //counter.data = reader.GetGuid(0).ToString(); hash = Security.SHA1(email + reader.GetGuid(0).ToString() + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd") + caseid).ToLower(); if (!hash.Equals(pw)) { counter.success = "Error"; counter.message = "Wrong hash"; return counter; } //ccase.email+settings.getString("token", null)+EaztimateSecurity.GetUTCdatetimeAsString()+ccase.caseid } else { counter.success = "Expired"; counter.message = "Token Expired"; return counter; } } //--------------------------------------------------------------------- int customerid = 1; //fix later //--------------------------------------------------------------------- string lccaseid = jour["lc_caseno"].ToString(); string contactname = jour["contactname"].ToString(); string contactaddress = jour["contactaddress1"].ToString(); string contactaddress2 = jour["contactaddress2"].ToString(); string contactpersonalnumber = jour["contactpersonalnumber"].ToString(); string contactphone1 = jour["contactphone1"].ToString(); string contactphone2 = jour["contactphone2"].ToString(); string contactzipcode = jour["contactzipcode"].ToString(); string contactcity = jour["city"].ToString(); string damagedescription = jour["damagedescription"].ToString(); string damagetype = jour["damagetype"].ToString(); string insurancetype = jour["insurancetype"].ToString(); string insurancenumber = jour["insurancenumber"].ToString(); string actiondescription = jour["actiondescription"].ToString(); string externalentrepeneur = jour["externalentrepeneur"].ToString(); int action = 0; int.TryParse(jour["contact_action"].ToString(), out action); bool contactinformed = (jour["contactinformed"] != null ? (bool)jour["contactinformed"] : false); bool building_power = (jour["buildingpower"] != null ? (bool)jour["buildingpower"] : false); bool building_lockable = (jour["buildinglockable"] != null ? (bool)jour["buildinglockable"] : false); bool building_function = (jour["buildingfunction"] != null ? (bool)jour["buildingfunction"] : false); bool building_climatesafe = (jour["buildingclimatesafe"] != null ? (bool)jour["buildingclimatesafe"] : false); bool action_transport = (jour["action_transport"] != null ? (bool)jour["action_transport"] : false); bool action_otherliving = (jour["action_otherliving"] != null ? (bool)jour["action_otherliving"] : false); bool action_helpcontact = (jour["buildingpower"] != null ? (bool)jour["action_helpcontact"] : false); bool action_cash = (jour["action_cash"] != null ? (bool)jour["action_cash"] : false); //INSERT INTO jour bool jourexists = false; using (SqlDataReader reader = SQL.ExecuteQuery("SELECT jourid FROM jour WHERE journo LIKE @1", journo)) { if (reader.Read()) { jourexists = true; id = reader.GetInt64(0); } } if (!jourexists) { using (SqlConnection con = SQL.CreateConnection()) { using (SqlTransaction trans = con.BeginTransaction(IsolationLevel.ReadCommitted)) { try { using (SqlDataReader reader = SQL.ExecuteTransQuery(con, trans, "INSERT INTO jour(journo,syncemail,datecreated,dateupdated,contactname,contactaddress,contactaddress2,contactzipcode,contactcity,contactpersonalnumber,insurancenumber,insurancetype,damagetype,actiondescription,externalentrepeneur,damagedescription,contactinformed,contactaction,action_otherliving,action_cash,action_transport,action_helpcontact,building_power,building_lockable,building_climatesafe,building_function,customerid,contactphone1,contactphone2,lccaseid)" + " VALUES(@1,@2,GETDATE(),GETDATE(),@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17,@18,@19,@20,@21,@22,@23,@24,@25,@26,@27,@28);SELECT CAST(@@IDENTITY AS BIGINT)", journo, email, contactname, contactaddress, contactaddress2, contactzipcode, contactcity, contactpersonalnumber, insurancenumber, insurancetype, damagetype, actiondescription, externalentrepeneur, damagedescription, contactinformed, action, action_otherliving, action_cash, action_transport, action_helpcontact, building_power, building_lockable, building_climatesafe, building_function, customerid, contactphone1, contactphone2, lccaseid)) { if (reader.Read()) { id = reader.GetInt64(0); } } JArray images = (JArray)jour["images"]; foreach (String image in images) { using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO jourimage (jourid,image) SELECT jourid ,@2 FROM jour WHERE journo LIKE @1", journo, new FileInfo(image).Name)) { } } JArray rooms = (JArray)jour["rooms"]; foreach (JObject room in rooms) { string desc = room["description"].ToString(); string roomid = room["roomid"].ToString(); string title = room["title"].ToString(); bool humidity = (room["roomhumidity"] != null ? (bool)room["roomhumidity"] : false); bool odor = (room["roomodor"] != null ? (bool)room["roomodor"] : false); bool water = (room["roomwater"] != null ? (bool)room["roomwater"] : false); bool contamination = (room["roomcontamination"] != null ? (bool)room["roomcontamination"] : false); JArray actions = (JArray)room["roomactions"]; StringBuilder actionsb = new StringBuilder(); foreach (String roomaction in actions) { actionsb.Append(roomaction + "|"); } using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO jour_room (jourid,uuid,datecreated,dateupdated,title,description,problem_water,problem_humidity,problem_odor,problem_contamination,roomaction)" + " SELECT jourid, @2, GETDATE(), GETDATE(), @3,@4,@5,@6,@7,@8,@9 FROM jour WHERE journo LIKE @1", journo, roomid, title, desc, water, humidity, odor, contamination, actionsb.ToString())) { } JArray roomimages = (JArray)room["images"]; foreach (String image in roomimages) { using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO jour_roomimage (roomid,image) SELECT roomid ,@2 FROM jour_room WHERE uuid LIKE @1", roomid, new FileInfo(image).Name)) { } } } DateTime timestamp; JArray logs = (JArray)jour["loglist"]; foreach (JObject log in logs) { DateTime.TryParse((log["timestamp"] != null ? log["timestamp"].ToString() : ""), out timestamp); if (timestamp < (DateTime)SqlDateTime.MinValue) { timestamp = DateTime.Now; } string activity = log["activity"].ToString(); string comment = log["comment"].ToString(); using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO jour_log (jourid,timestamp,dateupdated,activity,comment) SELECT jourid ,@2, GETDATE(),@3,@4 FROM jour WHERE journo LIKE @1", journo, timestamp, activity, comment)) { } } trans.Commit(); } catch (Exception ex) { trans.Rollback(); counter.success = "FAIL"; counter.message = ex.Message; } } } } bool success = false; if (id > 0) { success = createPdf(id, journo, email); } if (success) { counter.success = "OK"; counter.message = "Success"; } else { counter.success = "FAIL"; counter.message = "Couldn't crreate PDF"; } //string success = string.Empty; //if (id > 0) { // success = createPdf(id, journo, email); //} //if (success.Length == 0) { // counter.success = "OK"; // counter.message = "Success"; //} else { // counter.success = "FAIL"; // counter.message = success; //} } catch (Exception ex) { counter.success = "FAIL"; counter.message = ex.Message; } } else { counter.success = "FAIL"; counter.message = "fel hash..."; } return counter; }
public static void OnTimerDisable(CounterObject counterObject) { Destroy(counterObject); }
public static void OnTimerEnable(CounterObject counterObject) { counterObject.enabled = true; }
public static CounterObject OnTimerConstruct() { CounterObject counterObject = Instance.gameObject.AddComponent <CounterObject>(); return(counterObject); }
protected void Page_Load(object sender, EventArgs e) { String data; if (Request.RequestType == "POST") { using (StreamReader sr = new StreamReader(Request.InputStream)) { data = sr.ReadToEnd(); JObject constructioncase = JObject.Parse(data); string invid = constructioncase["caseid"].ToString(); File.WriteAllText(Server.MapPath("~/files/" + invid + ".txt"), constructioncase.ToString()); Response.StatusCode = (int)HttpStatusCode.OK; CounterObject counter = new CounterObject(); counter.success = "OK"; counter.message = "Success"; JObject jobject = JObject.FromObject(counter); Response.ContentType = "application/json"; Response.Write(jobject.ToString()); Response.End(); } } // do some with the requestStream if (Request.Form["data"] != null) { bool error= false; var jsonSerializer = new JsonSerializer(); JObject constructioncase = JObject.Parse(Request.Form["data"]); string invid = constructioncase["inventoryid"].ToString(); /* //UPDATE OR INSERT INVENTORY try { string damagetype = constructioncase["damagetype"].ToString(); string description = constructioncase["description"].ToString(); string address = constructioncase["customeradress"].ToString(); string zip = constructioncase["customerzip"].ToString(); DateTime datedamage; DateTime.TryParse((constructioncase["datedamage"] != null ? constructioncase["datedamage"].ToString() : ""), out datedamage); if (datedamage < (DateTime)SqlDateTime.MinValue) { datedamage = DateTime.Now; } string terms = constructioncase["terms"].ToString(); string city = constructioncase["customercity"].ToString(); string tel = constructioncase["customertel"].ToString(); string areatype = constructioncase["areatype"].ToString(); string icompany = constructioncase["insurancecompany"].ToString(); string icontact = constructioncase["insurancecontact"].ToString(); string iemail = constructioncase["insuranceemail"].ToString(); string itel = constructioncase["insurancetel"].ToString(); int area1 = 0, area2 = 0, adults = 0, teens = 0, kids = 0; int.TryParse(constructioncase["area1"].ToString(), out area1); int.TryParse(constructioncase["area2"].ToString(), out area2); int.TryParse(constructioncase["adults"].ToString(), out adults); int.TryParse(constructioncase["teens"].ToString(), out teens); int.TryParse(constructioncase["kids"].ToString(), out kids); Eaztimate.SQL.ExecuteProcedureNoReader("inventorycontrol", "@Damagetype", damagetype, "@InspectionNo", invid, "@Description", description, "@Address", address, "@Zip", zip, "@Damagedate", datedamage, "@City", city, "@Tel", tel, "@Areatype", areatype, "@ICompany", icompany, "@IContact", icontact, "@IEmail", iemail, "@ITel", itel, "@Area1", area1, "@Area2", area2, "@Adults", adults, "@Teens", teens, "@Kids", kids, "@Terms", terms); } catch (Exception ex) { throw; } Dictionary<string,int> cats = new Dictionary<string,int>(); Dictionary<int, Dictionary<String,int>> groups = new Dictionary<int, Dictionary<string,int>>(); Dictionary<int, Dictionary<String, int>> types = new Dictionary<int, Dictionary<string, int>>(); using (SqlDataReader reader = Eaztimate.SQL.ExecuteQuery("SELECT categoryid,title FROM category")) { while (reader.Read()) { cats.Add(reader.GetString(1),reader.GetInt32(0)); groups.Add(reader.GetInt32(0), new Dictionary<string,int>()); } } using (SqlDataReader reader = Eaztimate.SQL.ExecuteQuery("SELECT groupid,categoryid,title FROM grupp")) { while (reader.Read()) { groups[reader.GetInt32(1)].Add(reader.GetString(2),reader.GetInt32(0)); types.Add(reader.GetInt32(0), new Dictionary<string,int>()); } } using (SqlDataReader reader = Eaztimate.SQL.ExecuteQuery("SELECT typeid,groupid,title FROM type")) { while (reader.Read()) { types[reader.GetInt32(1)].Add(reader.GetString(2),reader.GetInt32(0)); } } //LOOP TROUGH ROOM JArray rooms = (JArray)constructioncase["rooms"]; foreach (JObject room in rooms) { int roomtype = int.Parse(room["roomtype"].ToString()); int floor = int.Parse(room["floor"].ToString()); int size = 0; int.TryParse(room["size"].ToString(),out size); string title = (room["title"] != null ? room["title"].ToString() : ""); string desc = (room["description"] != null ? room["description"].ToString() : ""); string opinion = (room["opinion"] != null ? room["opinion"].ToString() : ""); string damage = (room["damage"] != null ? room["damage"].ToString() : ""); string uuid = (room["roomid"] != null ? room["roomid"].ToString() : ""); Eaztimate.SQL.ExecuteProcedureNoReader("roomcontrol", "@Title", title, "@InspectionNo", invid, "@Description", desc, "@Floor", floor, "@UUID", uuid, "@Opinion", opinion, "@RoomTypeId", roomtype, "@Damage", damage, "@Size", size); //ROOM IMAGES JArray images = (JArray)room["images"]; foreach (String image in images) { Eaztimate.SQL.ExecuteProcedureNoReader("roomimagecontrol", "@Title", new FileInfo(image).Name, "@RoomUUID", uuid); } //ITEMS JObject jo = (JObject)room["items"]; IList<JToken> results = jo.Children().ToList(); try { foreach (JToken j in results) { string itemtitle = (((JObject)j.Children().ToList()[0])["title"] != null ? ((JObject)j.Children().ToList()[0])["title"].ToString() : ""); string itemid = ((JObject)j.Children().ToList()[0])["itemid"].ToString(); int price = (int)((JObject)j.Children().ToList()[0])["omd_price"]; int age = (int)((JObject)j.Children().ToList()[0])["omd_age"]; int usage = (int)((JObject)j.Children().ToList()[0])["omd_usage"]; int other = (int)((JObject)j.Children().ToList()[0])["omd_other"]; bool salvable = (((JObject)j.Children().ToList()[0])["salvable"] != null ? (bool)((JObject)j.Children().ToList()[0])["salvable"] : false); string catname = ((JObject)j.Children().ToList()[0])["heritage"]["categoryname"].ToString(); string groupname = ((JObject)j.Children().ToList()[0])["heritage"]["groupname"].ToString(); string typename = ((JObject)j.Children().ToList()[0])["heritage"]["typename"].ToString(); //NEW CATEGORY if (!cats.ContainsKey(catname) && !error) { using (SqlDataReader reader2 = Eaztimate.SQL.ExecuteQuery("INSERT INTO category (title, datecreated, dateupdated) VALUES(@1,GETDATE(),GETDATE());SELECT CAST(@@IDENTITY AS INT)", catname)) { if (reader2.Read()) { cats.Add(catname, reader2.GetInt32(0)); groups.Add(reader2.GetInt32(0), new Dictionary<string, int>()); } else { error = true; } } } //NEW GROUP if (!groups[cats[catname]].ContainsKey(groupname) && !error) { using (SqlDataReader reader2 = Eaztimate.SQL.ExecuteQuery("INSERT INTO grupp (title, categoryid, datecreated, dateupdated) VALUES(@1,@2,GETDATE(),GETDATE());SELECT CAST(@@IDENTITY AS INT)", groupname, cats[catname])) { if (reader2.Read()) { groups[cats[catname]].Add(groupname, reader2.GetInt32(0)); types.Add(reader2.GetInt32(0), new Dictionary<string, int>()); } else { error = true; } } } //NEW TYPE int groupid= 0; groups[cats[catname]].TryGetValue(groupname, out groupid); if (!types[groupid].ContainsKey(typename) && !error) { using (SqlDataReader reader2 = Eaztimate.SQL.ExecuteQuery("INSERT INTO type (title, groupid, datecreated, dateupdated) VALUES(@1,@2,GETDATE(),GETDATE());SELECT CAST(@@IDENTITY AS INT)", typename, groupid)) { if (reader2.Read()) { types[groupid].Add(typename, reader2.GetInt32(0)); } else { error = true; } } } int typeid = 0; types[groupid].TryGetValue(typename, out typeid); //insert item Eaztimate.SQL.ExecuteProcedureNoReader("itemcontrol", "@Title", itemtitle, "@InspectionNo", invid, "@RoomUUID", uuid, "@TypeId", typeid, "@UUID", itemid, "@Price", price, "@Age", age, "@Usage", usage, "@Other", other, "@Salvable", (salvable ? 1 : 0)); //ITEM IMAGES JArray itemimages = (JArray)((JObject)j.Children().ToList()[0])["images"]; foreach (String image in itemimages) { Eaztimate.SQL.ExecuteProcedureNoReader("itemimagecontrol", "@Title", new FileInfo(image).Name, "@ItemUUID", itemid); } } } catch (Exception ex) { error = true; } } */ if (!error) { Response.StatusCode = (int)HttpStatusCode.OK; Response.End(); } } Response.StatusCode = (int)HttpStatusCode.BadRequest; Response.End(); }
// POST api/<controller> public CounterObject Post(string caseid, string sysid, string email, string sha) { string hash = Security.SHA1(email + caseid + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd") + SYNCCODE).ToLower(); CounterObject counter = new CounterObject(); if (hash.Equals(sha)) { try { var jsonSerializer = new JsonSerializer(); long id = 0; string data = Request.Content.ReadAsStringAsync().Result; JObject klotter = JObject.Parse(data); string klotterno = klotter["caseid"].ToString(); string pw = klotter["password"].ToString(); string username = Membership.GetUserNameByEmail(email); MembershipUser user = Membership.GetUser(username); using (SqlDataReader reader = SQL.ExecuteQuery("SELECT token FROM logintokens WHERE dateexpires > GETDATE() AND userid=@1", user.ProviderUserKey)) { if (reader.Read()) { //counter.data = reader.GetGuid(0).ToString(); hash = Security.SHA1(email + reader.GetGuid(0).ToString() + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd") + caseid).ToLower(); if (!hash.Equals(pw)) { counter.success = "Error"; counter.message = "Wrong hash"; return counter; } //ccase.email+settings.getString("token", null)+EaztimateSecurity.GetUTCdatetimeAsString()+ccase.caseid } else { counter.success = "Expired"; counter.message = "Token Expired"; return counter; } } //--------------------------------------------------------------------- int customerid = 1; //fix later //--------------------------------------------------------------------- //string lccaseid = klotter["lc_caseno"].ToString(); //string contactname = klotter["contactname"].ToString(); string title = klotter["title"] != null ? klotter["title"].ToString() : ""; string caseno = klotter["caseno"] != null ? klotter["caseno"].ToString() : ""; string buildingno = klotter["buildingno"] != null ? klotter["buildingno"].ToString() : ""; string address = klotter["address"] != null ? klotter["address"].ToString() : ""; string contactzipcode = klotter["zipcode"] != null ? klotter["zipcode"].ToString() : ""; string contactcity = klotter["city"] != null ? klotter["city"].ToString() : ""; double latitude = 0, longitude = 0, accuracy = 0; double.TryParse(klotter["latitude"] != null ? klotter["latitude"].ToString() : "", out latitude); double.TryParse(klotter["longitude"] != null ? klotter["longitude"].ToString() : "", out longitude); double.TryParse(klotter["locaccuracy"] != null ? klotter["locaccuracy"].ToString() : "", out accuracy); string desc = klotter["workdescription"] != null ? klotter["workdescription"].ToString() : ""; string client = klotter["client"] != null ? klotter["client"].ToString() : ""; string clientno = klotter["clientno"] != null ? klotter["clientno"].ToString() : ""; string clientaddress = klotter["clientaddress"] != null ? klotter["clientaddress"].ToString() : ""; string clientaddress2 = klotter["clientaddress2"] != null ? klotter["clientaddress2"].ToString() : ""; string clientzip = klotter["clientzipcode"] != null ? klotter["clientzipcode"].ToString() : ""; string clientcity = klotter["clientcity"] != null ? klotter["clientcity"].ToString() : ""; bool policereport = (klotter["policereport"] != null ? (bool)klotter["policereport"] : false); string policereporttext = klotter["policereporttext"] != null ? klotter["policereporttext"].ToString() : ""; int hours = 0, minutes = 0; int.TryParse(klotter["hours"] != null ? klotter["hours"].ToString() : "", out hours); int.TryParse(klotter["minutes"] != null ? klotter["minutes"].ToString() : "", out minutes); bool pressurewasher = (klotter["pressurewasher"] != null ? (bool)klotter["pressurewasher"] : false); bool pressurewasherRecycle = (klotter["pressurewasherRecycle"] != null ? (bool)klotter["pressurewasherRecycle"] : false); bool handwash = (klotter["handwashing"] != null ? (bool)klotter["handwashing"] : false); JObject chem = (JObject)klotter["chem"]; string chemname = string.Empty; int amount = 0; if (chem != null) { chemname = chem["name"] != null ? chem["name"].ToString() : ""; int.TryParse(chem["amount"] != null ? chem["amount"].ToString() : "", out amount); } bool klotterexists = false; using (SqlDataReader reader = SQL.ExecuteQuery("SELECT klotterid FROM klotter WHERE klotterno LIKE @1", klotterno)) { if (reader.Read()) { klotterexists = true; id = reader.GetInt64(0); } } if (klotterexists) { using (SQL.ExecuteQuery("DELETE FROM klotter WHERE klotterno LIKE @1", klotterno)) { } } //if (!klotterexists) { using (SqlConnection con = SQL.CreateConnection()) { using (SqlTransaction trans = con.BeginTransaction(IsolationLevel.ReadCommitted)) { try { using (SqlDataReader reader = SQL.ExecuteTransQuery(con, trans, "INSERT INTO klotter(klotterno,syncemail,datecreated,dateupdated,title,address1,zipcode,city,latitude,longitude,accuracy,buildingno,description," + "client,clientno,clientaddress,clientaddress2,clientzipcode,clientcity,policereport,policereporttext,hours,minutes,pressurewasher,pwrecycle,handwashing,customerid,orderno)" + " VALUES(@1,@2,GETDATE(),GETDATE(),@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17,@18,@19,@20,@21,@22,@23,@24,@25,@26);SELECT CAST(@@IDENTITY AS BIGINT)", klotterno, email, title, address, contactzipcode, contactcity, latitude, longitude, accuracy, buildingno, desc, client, clientno, clientaddress, clientaddress2, clientzip, clientcity, policereport, policereporttext, hours, minutes, pressurewasher, pressurewasherRecycle, handwash, customerid, caseno)) { if (reader.Read()) { id = reader.GetInt64(0); } } using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO klotter_chem (klotterid,title,amount) SELECT klotterid, @2,@3 FROM klotter WHERE klotterno LIKE @1", klotterno, chemname, amount)) { } JArray images = (JArray)klotter["beforeimages"]; if (images != null) { foreach (String image in images) { using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO klotter_image (klotterid,image,type) SELECT klotterid ,@2,@3 FROM klotter WHERE klotterno LIKE @1", klotterno, new FileInfo(image).Name, 0)) { } } } images = (JArray)klotter["afterimages"]; if (images != null) { foreach (String image in images) { using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO klotter_image (klotterid,image,type) SELECT klotterid ,@2,@3 FROM klotter WHERE klotterno LIKE @1", klotterno, new FileInfo(image).Name, 1)) { } } } JArray tags = (JArray)klotter["tags"]; if (tags != null) { foreach (String tag in tags) { using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO klotter_tag (klotterid,tag) SELECT klotterid ,@2 FROM klotter WHERE klotterno LIKE @1", klotterno, tag)) { } } } DateTime timestamp; JArray logs = (JArray)klotter["loglist"]; if (logs != null) { foreach (JObject log in logs) { DateTime.TryParse((log["timestamp"] != null ? log["timestamp"].ToString() : ""), out timestamp); if (timestamp < (DateTime)SqlDateTime.MinValue) { timestamp = DateTime.Now; } string activity = log["activity"] != null ? log["activity"].ToString() : ""; string comment = log["comment"] != null ? log["comment"].ToString() : ""; using (SQL.ExecuteTransQuery(con, trans, "INSERT INTO klotter_log (klotterid,timestamp,dateupdated,activity,comment) SELECT klotterid ,@2, GETDATE(),@3,@4 FROM klotter WHERE klotterno LIKE @1", klotterno, timestamp, activity, comment)) { } } } trans.Commit(); } catch (Exception ex) { trans.Rollback(); //throw ex; counter.success = "FAIL"; counter.message = ex.Message; } } } // } bool success = false; if (id > 0) { success = createPdf(id, klotterno, email); if (policereport && success) { success = createpolicereportPdf(id, klotterno, email); } //success = true; } if (success) { counter.success = "OK"; counter.message = "Success"; } else { counter.success = "FAIL"; counter.message = "Couldn't crreate PDF"; } //string success = string.Empty; //if (id > 0) { // success = createPdf(id, journo, email); //} //if (success.Length == 0) { // counter.success = "OK"; // counter.message = "Success"; //} else { // counter.success = "FAIL"; // counter.message = success; //} } catch (Exception ex) { //if (!System.Diagnostics.EventLog.SourceExists("Eaztimate")) { // System.Diagnostics.EventLog.CreateEventSource("Eaztimate", "Application"); //} counter.success = "FAIL"; //System.Diagnostics.EventLog log = new System.Diagnostics.EventLog(); //log.Source = "Eaztimate"; //log.WriteEntry(String.Format("\r\n\r\nApplication Error\r\n\r\n" + // "MESSAGE: {0}\r\n" + // "SOURCE: {1}\r\n" + // "TARGETSITE: {4}\r\n" + // "STACKTRACE: {5}\r\n", // ex.Message, // ex.Source, // ex.TargetSite, // ex.StackTrace), // System.Diagnostics.EventLogEntryType.Error); counter.message = ex.Message; //throw ex; } } else { counter.success = "FAIL"; counter.message = "fel hash..."; } return counter; }