protected override bool checkModify(int id)
        {
            bool result = false;

            while (true)
            {
                if (!base.checkModify(id))
                {
                    break;
                }

                // check m_companyid == Row.companyid
                var pro = m_logic.Row.GetType().GetProperty(G.companyid);
                if (pro == null)
                {
                    break;
                }

                var value = pro.GetValue(m_logic.Row);
                if (m_companyid != THelper.StringToInt(value))
                {
                    m_error = G.L["no_permission"];
                    break;
                }

                result = true;
                break;
            }
            return(result);
        }
        protected int getNumber(object row, string pre, bool increase = false)
        {
            var result = 0;

            while (true)
            {
                if (row == null)
                {
                    break;
                }

                string content = m_table;
                content = content.Replace(c_pre, "");
                content = THelper.UpFirst(content);
                content = pre + content;
                var pro = row.GetType().GetProperty(content);
                if (pro == null)
                {
                    break;
                }

                var value = pro.GetValue(row);
                result = THelper.StringToInt(value);
                if (increase)
                {
                    pro.SetValue(row, ++result);
                }
                break;
            }
            return(result);
        }
        public string ModifySave(FormCollection collection)
        {
            bool result = false;

            while (true)
            {
                m_isSave = true;
                var id = THelper.StringToInt(collection.Get(c_id));
                if (!Modify(id, Request.QueryString[c_t]))
                {
                    break;
                }

                // save
                if (!m_logic.SaveRow(collection))
                {
                    m_error = m_logic.Error;
                    break;
                }

                result = true;
                break;
            }

            return(rowJson(result));
        }
Exemplo n.º 4
0
 public EnumSelect()
 {
     if (THelper.GetUnderlyingType <TEnum>().IsEnum)
     {
         DataSource = EnumHelper <TEnum> .GetValueList();
     }
 }
        public ActionResult List(string t = null, string c = null, int p = 1)
        {
            if (!initQuery(t))
            {
                return(error(m_error));
            }

            // listUI
            TListUI listUI = new TListUI();

            ViewBag.listDict = listUI.Class2UI(m_logic.FullName);
            ViewBag.t        = t;

            // page
            int pageSize = THelper.StringToInt(m_adminConfig["pageSize"]);

            m_logic.PresetDict = getPreset();
            var result = m_logic.Condition(c).GetList(p, pageSize, true);

            ViewBag.spage = m_logic.Paging;
            ViewBag.title = m_logic.GetTitle();

            // filter
            var searchFields = listUI.Class2Search(m_logic.FullName);

            ViewBag.filter = THelper.GetFilter(searchFields, m_logic.CompareDict);
            if (c != null)
            {
                ViewBag.filterString = c.Replace(G.Split1, "&").Replace(G.Split2, "=");
            }

            return(View(result));
        }
Exemplo n.º 6
0
        public string Index()
        {
            int companyid;

            if (TS.s1.Equals(Session[G.super]))
            {
                companyid = 1;
            }
            else
            {
                companyid = THelper.StringToInt(Session[G.companyid]);
            }

            HttpPostedFileBase httpFile = Request.Files[0];
            string             index    = Request.Params["index"];

            var jo   = new JObject();
            var path = m_upload.Upload(httpFile, companyid);

            if (path != null)
            {
                jo["index"]   = index;
                jo["success"] = true;
                jo["url"]     = "/Upload/Show?pic=" + path;
                jo["path"]    = path;
            }
            else
            {
                path        = m_upload.Error;
                jo["error"] = m_upload.Error;
            }

            return(JsonConvert.SerializeObject(jo));
        }
        public IFilterExpression GetFilterExpression()
        {
            if (THelper.GetUnderlyingType <T>().IsEnum)
            {
                return(_enumFilter);
            }
            if (THelper.IsNumericType <T>())
            {
                return(_numberFilter);
            }
            var underlyingType = THelper.GetUnderlyingType <T>();

            if (underlyingType == typeof(DateTime))
            {
                return(_dateFilter);
            }
            if (underlyingType == typeof(string))
            {
                return(_stringFilter);
            }
            if (underlyingType == typeof(Guid))
            {
                return(_guidFilter);
            }
            throw new NotImplementedException();
        }
Exemplo n.º 8
0
 public IFilterExpression GetFilterExpression()
 {
     if (THelper.IsNumericType <T>())
     {
         return(_numberFilter);
     }
     else
     {
         if (THelper.GetUnderlyingType <T>() == typeof(DateTime))
         {
             return(_dateFilter);
         }
         else
         {
             if (THelper.GetUnderlyingType <T>() == typeof(string))
             {
                 return(_stringFilter);
             }
             else
             {
                 throw new NotImplementedException();
             }
         }
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// 获取签名前拼接字符串
        /// </summary>
        public static string GetStringSignTemp <T>(T model, string SignKey, bool ParaAsc = true, StringComparison StrCompar = StringComparison.Ordinal, string SplitStr = "&", Func <string, string, string> KeyValueJoin = null, BindingFlags?bindingAttr = null)
        {
            StringBuilder stringSignTemp = new StringBuilder();

            if (model != null)
            {
                List <PropertyInfo> ProList;
                if (bindingAttr.HasValue)
                {
                    ProList = model.GetType().GetProperties(bindingAttr.Value).ToList();
                }
                else
                {
                    ProList = model.GetType().GetProperties().ToList();
                }
                if (ParaAsc)
                {
                    ProList.Sort((x, y) => string.Compare(x.Name, y.Name, StrCompar));
                }
                else
                {
                    ProList.Sort((x, y) => - (string.Compare(x.Name, y.Name, StrCompar)));
                }

                for (int i = 0; i < ProList.Count; i++)
                {
                    if (THelper.GetCustomAttribute <NoSignAttribute>(ProList[i]) == null)
                    {
                        object ProIValue = ProList[i].GetValue(model, null);
                        if (ProIValue != null)
                        {
                            if (!string.IsNullOrEmpty(ProIValue.ToString().Trim()))
                            {
                                if (stringSignTemp.Length > 0)
                                {
                                    stringSignTemp.Append(SplitStr);
                                }

                                if (KeyValueJoin != null)
                                {
                                    stringSignTemp.Append(KeyValueJoin(ProList[i].Name, ProIValue.ToString()));
                                }
                                else
                                {
                                    stringSignTemp.Append(ProList[i].Name + "=" + ProIValue.ToString());
                                }
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(SignKey))
            {
                stringSignTemp.Append(SignKey);
            }

            return(stringSignTemp.ToString());
        }
Exemplo n.º 10
0
    static bool RequestComponent (Guid id, TModelContext context, TEntityAction action, TModelAction modelAction)
    {
      /*
      DATA OUT
      - action.ModelAction (model)
      */

      bool res = false;

      try {
        // info
        var infoList = context.ComponentInfo.AsQueryable()
          .Where (p => p.Id.Equals (id))
          .ToList ()
        ;

        // info found
        if (infoList.Count.Equals (1)) {
          var model = infoList [0];
          modelAction.ComponentInfoModel.CopyFrom (model);

          // update category
          if (action.CategoryType.IsCategory (TCategory.None)) {
            var descList = context.ComponentDescriptor.AsQueryable()
              .Where (p => p.Id.Equals (action.Id))
              .ToList ()
            ;

            // found
            if (descList.Count.Equals (1)) {
              var desc = descList [0];
              action.SelectCategoryType (TCategoryType.Create (TCategoryType.FromValue (desc.Category)));
            }
          }
        }

        // status
        var statusList = context.ComponentStatus.AsQueryable()
          .Where (p => p.Id.Equals (id))
          .ToList ()
        ;

        // status found
        if (statusList.Count.Equals (1)) {
          var model = statusList [0];
          modelAction.ComponentStatusModel.CopyFrom (model);
        }

        res = true;
      }

      catch (Exception exception) {
        THelper.FormatException ("RequestComponent - TOperationSupport", exception, action);
      }

      return (res);
    }
Exemplo n.º 11
0
        private void WHEN_ChangeEmailAddress_With(EmailAddress emailAddress)
        {
            var command = ChangeCustomerEmailAddress.Build(customerID.Value, emailAddress.Value);

            try {
                recordedEvents = registeredCustomer.ChangeEmailAddress(command);
            } catch (NullReferenceException e) {
                throw new XunitException(THelper.propertyIsNull("emailAddress"));
            }
        }
Exemplo n.º 12
0
        private void WHEN_ConfirmEmailAddress_With(Hash confirmationHash)
        {
            var command = ConfirmCustomerEmailAddress.Build(customerID.Value, confirmationHash.Value);

            try {
                recordedEvents = registeredCustomer.ConfirmEmailAddress(command);
            } catch (NullReferenceException e) {
                throw new XunitException(THelper.propertyIsNull("confirmationHash"));
            }
        }
Exemplo n.º 13
0
        private void WHEN_ChangeEmailAddress_With(EmailAddress emailAddress)
        {
            var command = ChangeCustomerEmailAddress.Build(customerID.Value, emailAddress.Value);

            try {
                recordedEvents          = Customer5.ChangeEmailAddress(eventStream, command);
                changedConfirmationHash = command.ConfirmationHash;
            } catch (NullReferenceException e) {
                throw new XunitException(THelper.propertyIsNull("emailAddress"));
            }
        }
Exemplo n.º 14
0
    private static void Register <THelper> () where THelper : BehaviourHelper, new()
    {
        BehaviourHelper helper = new THelper() as BehaviourHelper;

        if (createdTypes.Contains(helper.GetType()))
        {
            return;
        }
        createdTypes.Add(helper.GetType());
        behaviourHelpers.Add(helper);
    }
Exemplo n.º 15
0
        private void THEN_EmailAddressConfirmed()
        {
            var method    = "confirmEmailAddress";
            var eventName = "CustomerEmailAddressConfirmed";

            Assert.Single(recordedEvents);
            Assert.NotNull(recordedEvents[0]);
            Assert.True(recordedEvents[0] is CustomerEmailAddressConfirmed, THelper.eventOfWrongTypeWasRecorded(method));
            var @event = (CustomerEmailAddressConfirmed)recordedEvents[0];

            Assert.True(Equals(customerID, @event.CustomerId), THelper.propertyIsWrong(method, "customerID"));
        }
Exemplo n.º 16
0
    internal static void RequestNode (TModelContext context, TEntityAction action)
    {
      /*
       DATA IN
      - action.Id {used as ParentId}

      DATA OUT
       - action.CollectionAction.ExtensionNodeCollection
       - action.CollectionAction.ModelCollection {id, modelAction}    // node model
      */

      if (context.NotNull () && action.NotNull ()) {
        var nodesCollection = context.ExtensionNode.AsQueryable ()
          .Where (p => p.ParentId.Equals (action.Id))
          .ToList ()
        ;

        var nodeReverse = action.ModelAction.ComponentStatusModel.NodeReverse;

        if (nodeReverse) {
          nodesCollection = context.ExtensionNode.AsQueryable ()
            .Where (p => p.ChildId.Equals (action.Id))
            .ToList ()
          ;
        }

        try {
          // node (child)
          foreach (var node in nodesCollection) {
            action.CollectionAction.ExtensionNodeCollection.Add (node);

            var id = nodeReverse ? node.ParentId : node.ChildId;
            var categoryValue = nodeReverse ? node.ParentCategory : node.ChildCategory;

            var modelAction = TModelAction.CreateDefault;

            if (RequestComponent (id, context, action, modelAction)) {
              if (RequestExtension (categoryValue, id, context, action, modelAction)) {
                action.CollectionAction.ModelCollection.Add (id, modelAction);    // add node model
              }
            }
          }
        }

        catch (Exception exception) {
          THelper.FormatException ("RequestNode - TOperationSupport", exception, action);
        }
      }
    }
Exemplo n.º 17
0
        /// <summary>
        /// 在调用操作方法前调用。
        /// </summary>
        /// <param name="filterContext">有关当前请求和操作的信息</param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //获取登录用户信息
            _model_login = GetLoginCookie();
            if (_model_login != null)
            {
                _model_login = GetLoginModel(_model_login);
            }

            //检查是否需要特殊验证
            CheckAttribute CheckAttribute = THelper.GetCustomAttribute <CheckAttribute>(filterContext.Controller.GetType().GetMethod(filterContext.ActionDescriptor.ActionName, (System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase)));

            if (CheckAttribute == null)
            {
                CheckAttribute = THelper.GetCustomAttribute <CheckAttribute>(filterContext.Controller.GetType());
            }

            //特殊验证(登录)
            if (CheckAttribute != null)
            {
                CheckLoginDefault = CheckAttribute.CheckLogin;                 //检查是否是否需要验证登录
            }
            if (CheckLoginDefault)
            {
                //检测是否已登录成功
                if (Model_Login == null)
                {
                    filterContext.Result = Redirect((string.IsNullOrEmpty(LoginFailUrl)) ? "/Home/Index" : LoginFailUrl);
                }
                {
                    //特殊验证(权限)
                    if (CheckAttribute != null)
                    {
                        CheckPermissionsDefault = CheckAttribute.CheckPermissions;                 //检查是否是否需要验证权限
                    }
                    if (CheckPermissionsDefault)
                    {
                        if (!CheckPermissions())
                        {
                            filterContext.Result = Redirect((string.IsNullOrEmpty(PermissionsFailUrl)) ? "/Home/Index" : PermissionsFailUrl);
                        }
                    }
                }
            }
            ViewBag.Model_Login = Model_Login;

            base.OnActionExecuting(filterContext);
        }
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);

            while (true)
            {
                m_companyid = THelper.StringToInt(Session[G.companyid]);
                if (m_companyid > 0)
                {
                    break;
                }

                var companyidConfig = ConfigurationManager.AppSettings[G.companyid];
                m_companyid = THelper.StringToInt(companyidConfig);
                break;
            }
            m_pageList = "/AdminCompany/List";
        }
Exemplo n.º 19
0
        dynamic convertValue(string content, int?type)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(null);
            }

            dynamic result = null;

            if (type == 1)
            {
                result = new Dictionary <dynamic, string>();
                string[] lines = content.Split('\n');
                for (int i = 0; i < lines.Length; ++i)
                {
                    string line  = lines[i];
                    var    index = line.IndexOf(':');
                    if (index != -1)
                    {
                        string t1  = line.Substring(0, index);
                        string t2  = line.Substring(index + 1);
                        int    key = THelper.StringToInt(t1, -1);
                        if (key != -1)
                        {
                            result[key] = t2;
                        }
                        else
                        {
                            result[t1] = t2;
                        }
                    }
                    else
                    {
                        result[i + 1] = line;
                    }
                }
            }
            else
            {
                result = content;
            }
            return(result);
        }
Exemplo n.º 20
0
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            while (true)
            {
                if (HttpContext.Current.Session[G.companyid] != null)
                {
                    break;
                }

                var companyidConfig = ConfigurationManager.AppSettings[G.companyid];
                if (!string.IsNullOrEmpty(companyidConfig))
                {
                    HttpContext.Current.Session[G.companyid] = THelper.StringToInt(companyidConfig);
                    break;
                }

                filterContext.Result = new RedirectResult(AdminBaseController.c_pageLogin);
                break;
            }
        }
Exemplo n.º 21
0
        //  1: ok
        //  0: code error
        // -1: password error
        // -2: too many time
        //
        int tryLogin(string password, string code)
        {
            var result = 0;

            while (true)
            {
                if (string.IsNullOrEmpty(password))
                {
                    break;
                }

                if (Session[c_code] == null)
                {
                    break;
                }

                if (string.IsNullOrEmpty(code))
                {
                    if (ConfigurationManager.AppSettings[c_uname] == password)
                    {
                        Session[G.super] = TS.s1;
                        result           = 1;
                    }
                    break;
                }

                if (code != Session[c_code].ToString())
                {
                    break;
                }

                int tryLimit = THelper.StringToInt(ConfigurationManager.AppSettings[c_try]);
                if (Session[c_try] != null && (int)Session[c_try] >= tryLimit)
                {
                    result = -2;
                    break;
                }

                var model = new CompanyModel();
                var row   = model.GetCompany(password);
                if (row != null)
                {
                    Session[G.companyid] = row.id.Value;
                    Session[G.super]     = TS.s2;
                    Session.Remove(c_try);
                    result = 1;
                }
                else
                {
                    result = -1;
                    if (Session[c_try] == null)
                    {
                        Session[c_try] = 1;
                    }
                    else
                    {
                        Session[c_try] = (int)Session[c_try] + 1;
                    }
                }

                Session.Remove(c_code);
                break;
            }

            return(result);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 模拟http/post请求(multipart/form-data)
        /// </summary>
        public static string HttpRequest_Post_FormData(out HttpStatusCode OpStatusCode, out string OpStatusDescription, string url, NameValueCollection values, List <PostUploadFile> files = null, NameValueCollection headers = null, string encodingType = "UTF-8", int timeout = 10000, string boundary = null)
        {
            try
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                Encoding       encoding       = Encoding.GetEncoding(encodingType);
                if (headers != null)
                {
                    foreach (string text in headers.Keys)
                    {
                        httpWebRequest.Headers.Add(text, headers[text]);
                    }
                }
                httpWebRequest.Method           = "POST";
                httpWebRequest.Accept           = "*/*";
                httpWebRequest.Timeout          = timeout;
                httpWebRequest.CachePolicy      = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
                httpWebRequest.ReadWriteTimeout = timeout;

                if (string.IsNullOrEmpty(boundary))
                {
                    boundary = string.Format("----WebKitFormBoundary{0}", THelper.GetRandomString(15));
                }
                httpWebRequest.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);

                Stream requestStream = httpWebRequest.GetRequestStream();
                string Enter         = "\r\n";
                string Str;
                byte[] bytes;
                if (values.Count > 0)
                {
                    foreach (string key in values.Keys)
                    {
                        Str = string.Format("--{0}{1}Content-Disposition: form-data; name=\"{2}\"{1}{1}{3}{1}", boundary, Enter, key, values[key]);

                        bytes = encoding.GetBytes(Str);
                        requestStream.Write(bytes, 0, bytes.Length);
                    }
                }

                if (files != null)
                {
                    foreach (PostUploadFile file in files)
                    {
                        Str = string.Format("--{0}{1}Content-Disposition: form-data; name=\"{2}\"; filename=\"{3}\"{1}", boundary, Enter, file.FieldName, file.FileName);

                        if (!string.IsNullOrEmpty(file.ContentType))
                        {
                            Str += string.Format("Content-Type:{0}{1}{1}", file.ContentType, Enter);
                        }

                        bytes = encoding.GetBytes(Str);
                        requestStream.Write(bytes, 0, bytes.Length);
                        requestStream.Write(file.Content, 0, file.ContentLength);
                        bytes = encoding.GetBytes(Enter);
                        requestStream.Write(bytes, 0, bytes.Length);
                    }
                }

                Str   = string.Format("--{0}--", boundary);
                bytes = encoding.GetBytes(Str);
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();

                HttpWebResponse httpWebResponse = null;
                OpStatusCode        = HttpStatusCode.NotFound;
                OpStatusDescription = null;
                try
                {
                    httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                }
                catch (WebException e)
                {
                    if (e.Response != null)
                    {
                        httpWebResponse = (HttpWebResponse)e.Response;
                    }
                    else
                    {
                        OpStatusCode        = HttpStatusCode.RequestTimeout;
                        OpStatusDescription = e.Message;
                    }
                }

                if (httpWebResponse != null)
                {
                    OpStatusCode        = httpWebResponse.StatusCode;
                    OpStatusDescription = httpWebResponse.StatusDescription;
                    using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), encoding))
                    {
                        string result = streamReader.ReadToEnd();
                        streamReader.Close();
                        httpWebResponse.Close();
                        return(result);
                    }
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                OpStatusCode        = HttpStatusCode.ExpectationFailed;
                OpStatusDescription = ex.Message;
                return(string.Empty);
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// 类实例化
 /// </summary>
 protected T R <T>(ref T RClass, object[] Params = null)
 {
     return(THelper.R(ref RClass, Params));
 }
Exemplo n.º 24
0
 public void OnSettingsCommadClicked ()
 {
   THelper.DispatcherLater (StartSettingsProcessDispatcher);
 }
Exemplo n.º 25
0
    void OnCommunicationHandle (object sender, TMessagingEventArgs<TDataComm> e)
    {
      TProcess.TName module = (TProcess.TName) Enum.Parse (typeof (TProcess.TName), e.Data.ClientName);

      switch (module) {
        case TProcess.TName.ModuleSettings: {
            switch (e.Data.Command) {
              case TCommandComm.Shutdown: {
                  RemoveProcess (module);
                }
                break;

              case TCommandComm.Closed: {
                  RemoveProcess (module);
                  Model.EnableAll ();
                  ApplyChanges ();
                }
                break;

              case TCommandComm.Success: {
                  Model.SettingsValidated ();
                  ApplyChanges ();
                }
                break;

              case TCommandComm.Error: {
                  Model.SettingsHasError ();
                  ApplyChanges ();

                  THelper.DispatcherLater (RemoveProcessPartialDispatcher);
                }
                break;
            }
          }
          break;

        case TProcess.TName.GadgetMaterial: {
            switch (e.Data.Command) {
              case TCommandComm.Closed: {
                  RemoveProcess (module);
                }
                break;
            }
          }
          break;

        case TProcess.TName.GadgetTarget: {
            switch (e.Data.Command) {
              case TCommandComm.Closed: {
                  RemoveProcess (module);
                }
                break;
            }
          }
          break;

        case TProcess.TName.GadgetTest: {
            switch (e.Data.Command) {
              case TCommandComm.Closed: {
                  RemoveProcess (module);
                }
                break;
            }
          }
          break;

        case TProcess.TName.GadgetRegistration: {
            switch (e.Data.Command) {
              case TCommandComm.Closed: {
                  RemoveProcess (module);
                }
                break;
            }
          }
          break;

        case TProcess.TName.GadgetResult: {
            switch (e.Data.Command) {
              case TCommandComm.Closed: {
                  RemoveProcess (module);
                }
                break;
            }
          }
          break;

        case TProcess.TName.GadgetReport: {
            switch (e.Data.Command) {
              case TCommandComm.Closed: {
                  RemoveProcess (module);
                }
                break;
            }
          }
          break;
      }
    }
Exemplo n.º 26
0
 public static object GetValue(JsonElement jsonElement)
 {
     if (_columnDataType == typeof(DateTime))
     {
         return(jsonElement.GetDateTime());
     }
     else if (_columnDataType.IsEnum)
     {
         if (jsonElement.ValueKind == JsonValueKind.Number)
         {
             return(Enum.Parse(THelper.GetUnderlyingType <TValue>(), jsonElement.GetInt32().ToString()));
         }
         else
         {
             return(Enum.Parse(THelper.GetUnderlyingType <TValue>(), jsonElement.GetString()));
         }
     }
     else if (_columnDataType == typeof(byte))
     {
         return(jsonElement.GetByte());
     }
     else if (_columnDataType == typeof(decimal))
     {
         return(jsonElement.GetDecimal());
     }
     else if (_columnDataType == typeof(double))
     {
         return(jsonElement.GetDouble());
     }
     else if (_columnDataType == typeof(short))
     {
         return(jsonElement.GetInt16());
     }
     else if (_columnDataType == typeof(int))
     {
         return(jsonElement.GetInt32());
     }
     else if (_columnDataType == typeof(long))
     {
         return(jsonElement.GetInt64());
     }
     else if (_columnDataType == typeof(sbyte))
     {
         return(jsonElement.GetSByte());
     }
     else if (_columnDataType == typeof(float))
     {
         return(jsonElement.GetSingle());
     }
     else if (_columnDataType == typeof(ushort))
     {
         return(jsonElement.GetUInt16());
     }
     else if (_columnDataType == typeof(uint))
     {
         return(jsonElement.GetUInt32());
     }
     else if (_columnDataType == typeof(ulong))
     {
         return(jsonElement.GetUInt64());
     }
     else if (_columnDataType == typeof(Guid))
     {
         return(jsonElement.GetGuid());
     }
     else if (_columnDataType == typeof(bool))
     {
         if (jsonElement.ValueKind == JsonValueKind.True)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(jsonElement.GetString());
     }
 }
Exemplo n.º 27
0
    static bool RequestExtension (int categoryValue, Guid id, TModelContext context, TEntityAction action, TModelAction modelAction)
    {
      /*
      DATA OUT
      - action.ModelAction (model)
      - action.CollectionAction.ExtensionNodeCollection
      - action.ComponentModel.NodeModelCollection
      */

      var res = false;

      // Extension (CategoryRelationCollection)
      var categoryRelationList = action.CollectionAction.CategoryRelationCollection
        .Where (p => p.Category.Equals (categoryValue))
        .ToList ()
      ;

      // found
      if (categoryRelationList.Count.Equals (1)) {
        var categoryRelation = categoryRelationList [0]; // get extension using TComponentExtension

        var extension = TComponentExtension.Create (categoryRelation.Extension);
        extension.Request ();

        try {
          foreach (var extensionName in extension.ExtensionList) {
            switch (extensionName) {
              //case TComponentExtensionNames.Document: {
              //    var list = context.ExtensionDocument
              //      .Where (p => p.Id.Equals (id))
              //      .ToList ()
              //    ;

              //    if (list.Count.Equals (1)) {
              //      modelAction.ExtensionDocumentModel.CopyFrom (list [0]);
              //    }
              //  }
              //  break;

              case TComponentExtensionNames.Geometry: {
                  var list = context.ExtensionGeometry.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionGeometryModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Image: {
                  var list = context.ExtensionImage.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionImageModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Layout: {
                  var list = context.ExtensionLayout.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionLayoutModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Node: {
                  // child first
                  var childList = context.ExtensionNode.AsQueryable()
                    .Where (p => p.ChildId.Equals (id))
                    .ToList ()
                  ;

                  if (childList.Count.Equals (1)) {
                    var node = childList [0];
                    modelAction.ExtensionNodeModel.CopyFrom (node);

                    //  check duplicated
                    //var list = action.CollectionAction.ExtensionNodeCollection
                    //  .Where (p => p.ChildId.Equals (id))
                    //  .ToList ()
                    //;

                    //if (list.Count.Equals (0)) {
                    //  action.CollectionAction.ExtensionNodeCollection.Add (node);
                    //  action.ComponentModel.NodeModelCollection.Add (node);
                    //}
                  }

                  //else {
                  //  // parent next
                  //  //var parentList = context.ExtensionNode.AsQueryable()
                  //  //  .Where (p => p.ParentId.Equals (id))
                  //  //  .ToList ()
                  //  //;

                  //  //foreach (var node in parentList) {
                  //  //  //  check duplicated
                  //  //  var list = action.CollectionAction.ExtensionNodeCollection
                  //  //    .Where (p => p.ChildId.Equals (node.ChildId))
                  //  //    .ToList ()
                  //  //  ;

                  //  //  if (list.Count.Equals (0)) {
                  //  //    action.CollectionAction.ExtensionNodeCollection.Add (node);
                  //  //    action.ComponentModel.NodeModelCollection.Add (node);
                  //  //  }
                  //  //}
                  //}
                }
                break;

              case TComponentExtensionNames.Text: {
                  var list = context.ExtensionText.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionTextModel.CopyFrom (list [0]);
                  }
                }
                break;

              case TComponentExtensionNames.Content: {
                  var list = context.ExtensionContent.AsQueryable()
                    .Where (p => p.Id.Equals (id))
                    .ToList ()
                  ;

                  if (list.Count.Equals (1)) {
                    modelAction.ExtensionContentModel.CopyFrom (list [0]);
                  }
                }
                break;
            }
          }

          res = true;
        }

        catch (Exception exception) {
          THelper.FormatException ("RequestExtension - TOperationSupport", exception, action);
        }
      }

      return (res);
    }
Exemplo n.º 28
0
 static JsonElementHelper()
 {
     _columnDataType = THelper.GetUnderlyingType <TValue>();
 }
Exemplo n.º 29
0
 /// <summary>
 /// 类型转换
 /// </summary>
 protected T C <T>(object ChangeValue, T DefaultValue)
 {
     return(THelper.C(ChangeValue, DefaultValue));
 }