Esempio n. 1
0
        public void WriteUsageLogToFile(string usageLogFilePath)
        {
            // Read existing json data
            string jsonData = "[]";

            if (File.Exists(usageLogFilePath))
            {
                jsonData = System.IO.File.ReadAllText(usageLogFilePath);
            }
            else
            {
                System.IO.File.WriteAllText(usageLogFilePath, jsonData);
            }

            // De-serialize to object or create new list
            var logData = new JavaScriptSerializer().Deserialize <List <LogEntry> >(jsonData);

            // Add any new employees
            logEntry.TimeStamp();
            logData.Add(logEntry);

            // Update json data string
            jsonData = new JavaScriptSerializer().Serialize(logData);
            System.IO.File.WriteAllText(usageLogFilePath, jsonData);
        }
Esempio n. 2
0
        private static void AddToDictionary(string accountNumber)
        {
            var accountDictionary = new JavaScriptSerializer().Deserialize <Dictionary <string, string> >(File.ReadAllText(Constants.UrlCrawlerTrackerFile));

            accountDictionary.Add(accountNumber, "0");
            File.WriteAllText(Constants.UrlCrawlerTrackerFile, new JavaScriptSerializer().Serialize(accountDictionary));
        }
Esempio n. 3
0
        public static void WriteTelemetryRecord <T>(string telemetryFilePath, T telemetryRecord)
        {
            string existingTelemetryData = "[]";

            if (File.Exists(telemetryFilePath))
            {
                existingTelemetryData = File.ReadAllText(telemetryFilePath);
            }
            else
            {
                File.WriteAllText(telemetryFilePath, existingTelemetryData);
            }

            var telemetryData = new JavaScriptSerializer().Deserialize <List <T> >(existingTelemetryData);

            telemetryData.Add(telemetryRecord);

            existingTelemetryData = new JavaScriptSerializer().Serialize(telemetryData);
            File.WriteAllText(telemetryFilePath, existingTelemetryData);
        }
Esempio n. 4
0
        /// <summary>
        /// Заменяет в теле запроса представление навигационных свойств с Имя_Связи@odata.bind:null на представление Имя_Связи:null.
        /// </summary>
        /// <returns>Возвращается EdmEntityObject преобразованный из JSON-строки.</returns>
        private EdmEntityObject ReplaceOdataBindNull()
        {
            if (!Request.Properties.ContainsKey(ExtendedODataEntityDeserializer.OdataBindNull))
            {
                if (Request.Properties.ContainsKey(ExtendedODataEntityDeserializer.ReadException))
                {
                    throw (Exception)Request.Properties[ExtendedODataEntityDeserializer.ReadException];
                }
                throw new Exception("ReplaceOdataBindNull: edmEntity is null.");
            }

            Stream stream;

            string json = (string)Request.Properties[PostPatchHandler.RequestContent];

            Dictionary <string, object> props = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(json);
            var keys = props.Keys.ToArray();
            var odataBindNullList = new List <string>();

            foreach (var key in keys)
            {
                var p = key.IndexOf("@odata.bind");
                if (p != -1 && props[key] == null)
                {
                    props.Remove(key);
                    var newKey = key.Substring(0, p);
                    if (props.ContainsKey(newKey))
                    {
                        props.Remove(newKey);
                    }

                    var type = (EdmEntityTypeReference)Request.Properties[ExtendedODataEntityDeserializer.OdataBindNull];

                    var prop = type.FindNavigationProperty(newKey);
                    if (prop.Type.IsCollection())
                    {
                        odataBindNullList.Add(newKey);
                    }
                    else
                    {
                        props.Add(newKey, null);
                    }
                }
            }

            json            = new JavaScriptSerializer().Serialize(props);
            Request.Content = new StringContent(json, Encoding.UTF8, "application/json");

            IContentNegotiator negotiator = (IContentNegotiator)Configuration.Services.GetService(typeof(IContentNegotiator));
            var resultNegotiate           = negotiator.Negotiate(typeof(EdmEntityObject), Request, Configuration.Formatters);

            stream = Request.Content.ReadAsStreamAsync().Result;
            var formatter = resultNegotiate.Formatter;

            /*
             * // Другой вариант получения форматтера.
             *  var formatter = ((ODataMediaTypeFormatter)Configuration.Formatters[0]).GetPerRequestFormatterInstance(
             *      typeof(EdmEntityObject), Request, Request.Content.Headers.ContentType);
             *
             */

            var edmEntity = (EdmEntityObject)formatter.ReadFromStreamAsync(
                typeof(EdmEntityObject),
                stream,
                Request.Content,
                new ModelStateFormatterLogger(ModelState, "edmEntity")).Result;

            if (edmEntity == null && Request.Properties.ContainsKey(ExtendedODataEntityDeserializer.ReadException))
            {
                throw (Exception)Request.Properties[ExtendedODataEntityDeserializer.ReadException];
            }

            foreach (var prop in odataBindNullList)
            {
                edmEntity.TrySetPropertyValue(prop, null);
            }

            return(edmEntity);
        }
Esempio n. 5
0
    public static Hashtable modify(String data, String executor)
    {
        Hashtable t_return = new Hashtable();
        SQLiteConnection conn = tools.getSqliteConn();
        SQLiteCommand comd = new SQLiteCommand();
        comd.Connection = conn;
        SQLiteDataReader rd = null;
        String sql = "";

        Hashtable t_data = new JavaScriptSerializer().Deserialize<Hashtable>(data);
        String username = (String)t_data["username"];
        t_data.Remove("username");
        String group_code = (String)t_data["group_code"];

        sql = "delete from basic_group_2_user where user_code = '" + username + "' ;";
        comd.CommandText = sql;
        comd.ExecuteNonQuery();
        sql = "insert into basic_group_2_user (user_code,group_code) values ('" + username + "','" + group_code + "');";
        comd.CommandText = sql;
        comd.ExecuteNonQuery();

        IDictionaryEnumerator en = t_data.GetEnumerator();
        Hashtable t_data2 = new Hashtable();
        while (en.MoveNext())
        {
            String value = en.Value.ToString();
            String key = en.Key.ToString();

            t_data2.Add(key, "'" + value + "'");
        }
        t_data = t_data2;
        t_data.Add("time_lastupdated", "now()");
        t_data.Add("count_updated", "count_updated+1");

        en = t_data.GetEnumerator();
        sql = "update basic_user set ";
        int columns = 0;
        while (en.MoveNext())
        {
            columns++;
            String value = en.Value.ToString();
            String key = en.Key.ToString();

            sql += key+ " = "+value+" ,";
        }
        sql = sql.Substring(0, sql.Length - 1);
        sql += " where username = '******'";
        comd.CommandText = sql;
        comd.ExecuteNonQuery();

        conn.Close();
        t_return.Add("status","1");
        t_return.Add("columns",columns);
        return t_return;
    }
Esempio n. 6
0
    public static Hashtable add(String data,String executor)
    {
        Hashtable t_return = new Hashtable();
        SQLiteConnection conn = tools.getSqliteConn();
        SQLiteCommand comd = new SQLiteCommand();
        comd.Connection = conn;
        SQLiteDataReader rd = null;
        String sql = "";

        Hashtable t_data = new JavaScriptSerializer().Deserialize<Hashtable>(data);

        sql = "select * from basic_user where username = '******'";
        comd.CommandText = sql;
        rd = comd.ExecuteReader();
        if(rd.Read())
        {
            t_return.Add("status","2");
            t_return.Add("msg","username used already");
            rd.Close();
            conn.Close();
            return t_return;
        }
        rd.Close();

        IDictionaryEnumerator en = t_data.GetEnumerator();
        Hashtable t_data2 = new Hashtable();
        while (en.MoveNext())
        {
            String value = en.Value.ToString();
            String key = en.Key.ToString();

            t_data2.Add(key , "'" + value + "'");
        }
        t_data = t_data2;
        int id = tools.getTableId("basic_user")+1;
        t_data.Add("id", id);
        t_data.Add("creater_code", "'" + executor + "'");
        t_data.Add("creater_group_code", "(select group_code from basic_group_2_user where user_code = '" + executor + "' order by group_code limit 1 )");

        en = t_data.GetEnumerator();
        sql = "insert into basic_user ";
        String keys = "";
        String values = "";
        while (en.MoveNext())
        {
            String value = en.Value.ToString();
            String key = en.Key.ToString();

            keys += key + ",";
            values += value + ",";
        }

        sql = sql + "(" + keys.Substring(0, keys.Length - 1) + ") values (" + values.Substring(0,values.Length-1) + ");";
        comd.CommandText = sql;
        comd.ExecuteNonQuery();

        String user_code = (String) t_data["username"];
        String group_code = (String) t_data["group_code"];

        sql = "insert into basic_group_2_user (user_code,group_code) values ("+user_code+","+group_code+");";
        comd.CommandText = sql;
        comd.ExecuteNonQuery();

        conn.Close();
        t_return.Add("status","1");
        t_return.Add("id",id);
        return t_return;
    }
Esempio n. 7
0
        public ActionResult Addtocart(int productId, int quantity, int shopId, int sizeId = 0)
        {
            var msg = new JsonMessage {
                Erros = false, Message = "Bạn đã thêm sản phẩm vào giỏ hàng"
            };

            if (quantity <= 0)
            {
                msg = new JsonMessage
                {
                    Erros   = true,
                    Message = "Số lượng phải >= 1.",
                };
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
            if (shopId == 0)
            {
                msg = new JsonMessage
                {
                    Erros   = true,
                    Message = "Không thể đặt sản phẩm này.",
                };
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
            var obj        = new List <ShopProductDetailCartItem>();
            var codeCookie = HttpContext.Request.Cookies["addtocart"];

            if (codeCookie == null)
            {
                var item = new ShopProductDetailCartItem
                {
                    ProductId = productId,
                    SizeID    = sizeId,
                    Quantity  = quantity,
                    ShopID    = shopId,
                };
                obj.Add(item);
                var val = new JavaScriptSerializer().Serialize(obj);
                codeCookie = new HttpCookie("addtocart")
                {
                    Value = val, Expires = DateTime.Now.AddHours(6)
                };
                Response.Cookies.Add(codeCookie);
            }
            else
            {
                var temp  = codeCookie.Value;
                var lst   = new JavaScriptSerializer().Deserialize <List <ShopProductDetailCartItem> >(temp);
                var check = lst.Any(c => c.ProductId == productId && c.SizeID == sizeId);
                if (check)
                {
                    foreach (var item in lst.Where(item => item.ProductId == productId && item.SizeID == sizeId))
                    {
                        item.Quantity = (item.Quantity ?? 0) + quantity;
                        item.ShopID   = shopId;
                        break;
                    }
                    var val = new JavaScriptSerializer().Serialize(lst);
                    codeCookie = new HttpCookie("addtocart")
                    {
                        Value = val, Expires = DateTime.Now.AddHours(6)
                    };
                    Response.Cookies.Add(codeCookie);
                }
                else
                {
                    var item = new ShopProductDetailCartItem
                    {
                        ProductId = productId,
                        SizeID    = sizeId,
                        Quantity  = quantity,
                        ShopID    = shopId,
                    };
                    lst.Add(item);
                    var val = new JavaScriptSerializer().Serialize(lst);
                    codeCookie = new HttpCookie("addtocart")
                    {
                        Value = val, Expires = DateTime.Now.AddHours(6)
                    };
                    Response.Cookies.Add(codeCookie);
                }
                //codeCookie.Value = val;
                codeCookie.Expires = DateTime.Now.AddHours(6);
                Response.Cookies.Add(codeCookie);
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }