Ejemplo n.º 1
0
        //获取一个用户所有的设备列表

        public ActionResult GetUserTelList(GetUserTelListModels modles)
        {
            DbDataController mDbDataController = new DbDataController();
            DataTable        mDataTable;

            //是否为Ajax请求
            if (!Request.IsAjaxRequest())
            {
                return(null);
            }

            try
            {
                if (modles.Operation == "GetUserTelList")
                {
                    //身份验证-使用用户名与密码md5进行验证
                    if (mDbDataController.AuthenticationMD5(modles.UserName, modles.PasswordMD5) != null)
                    {
                        mDataTable = mDbDataController.GetUserTelName(modles.UserName); //获取指定用户的所有设备列表包含站点名称信息,[0]:站点名称;[1]:站点编号
                        return(StaticActionResult.JsonActionResult(StaticJson.DataTableToJsonWithJsonNet(mDataTable)));
                    }
                    else
                    {
                        return(StaticActionResult.JsonActionResult("用户名与密码验证失败"));
                    }
                }
            }
            catch (Exception e)
            {
                SystemLog.Write(e.StackTrace + e.Message);  //日志
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static int CreateZone(string name)
        {
            var zoneId = DbDataController.Instance().Zone.AddZone(name);

            SystemManager.PurgeZoneList();
            return(zoneId);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a simple data controller to create, update and delete entities.
 /// </summary>
 /// <param name="zoneId">Zone ID</param>
 /// <param name="appId">App ID</param>
 ///// <param name="userName">Name of user loged in</param>
 /// <param name="defaultLanguageCode">Default language of system</param>
 public SimpleDataController(int zoneId, int appId, string defaultLanguageCode)
 {
     //_zoneId = zoneId;
     _appId = appId;
     _defaultLanguageCode = defaultLanguageCode;
     _context             = DbDataController.Instance(zoneId, appId);
     _appManager          = new AppManager(zoneId, appId);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates an app and then imports the xml
        /// </summary>
        /// <returns>AppId of the new imported app</returns>
        public bool ImportApp(int zoneId, XDocument doc, out int?appId)
        {
            // Increase script timeout to prevent timeouts
            //HttpContext.Current.Server.ScriptTimeout = 300;

            appId = new int?();

            if (!IsCompatible(doc))
            {
                ImportLog.Add(new Message("The import file is not compatible with the installed version of 2sxc.", Message.MessageTypes.Error));
                return(false);
            }

            // Get root node "SexyContent"
            var xmlSource = doc.Element(XmlConstants.RootNode);
            var xApp      = xmlSource?.Element(XmlConstants.Header)?.Element(XmlConstants.App);

            var appGuid = xApp?.Attribute(XmlConstants.Guid)?.Value;

            if (appGuid == null)
            {
                ImportLog.Add(new Message("Something is wrong in the xml structure, can't get an app-guid", Message.MessageTypes.Error));
                return(false);
            }

            if (appGuid != XmlConstants.AppContentGuid)
            {
                // Build Guid (take existing, or create a new)
                if (String.IsNullOrEmpty(appGuid) || appGuid == new Guid().ToString())
                {
                    appGuid = Guid.NewGuid().ToString();
                }

                // Adding app to EAV
                var eavDc = DbDataController.Instance(zoneId);
                var app   = eavDc.App.AddApp(null, appGuid);
                eavDc.SqlDb.SaveChanges();

                appId = app.AppId;
            }
            else
            {
                appId = AppId;
            }

            if (appId <= 0)
            {
                ImportLog.Add(new Message("App was not created. Please try again or make sure the package you are importing is correct.", Message.MessageTypes.Error));
                return(false);
            }

            DataSource.GetCache(null).PurgeGlobalCache();   // must do this, to ensure that the app-id exists now
            return(ImportXml(zoneId, appId.Value, doc));
        }
Ejemplo n.º 5
0
        protected void Constructor(int zoneId, int appId, string appStaticName, bool appExport, string[] attrSetIds, string[] entityIds)
        {
            ZoneId     = zoneId;
            AppPackage = new Efc11Loader(DbDataController.Instance(zoneId, appId).SqlDb).AppPackage(appId);
            Serializer = new XmlSerializer();
            Serializer.Initialize(AppPackage);

            _appStaticName  = appStaticName;
            _isAppExport    = appExport;
            AttributeSetIDs = attrSetIds;
            EntityIDs       = entityIds;
        }
Ejemplo n.º 6
0
        //获取用户相关信息
        public ActionResult WeixinPayAttention(string json)
        {
            UniversalResponse resp = new UniversalResponse();
            DbDataController  mDbDataController = new DbDataController();
            DataTable         mDataTable;
            int status;

            resp.obj = null;
            try
            {
                WeixinUserInfo info = new WeixinUserInfo();

                info = (WeixinUserInfo)StaticJson.JsonToObject(json, info);
                if (info == null || info.openid == null)
                {
                    resp.rel = 0;
                    resp.msg = "无效的数据";
                }
                else
                {
                    mDataTable = mDbDataController.GetWeixinUser(info.openid);
                    if (mDataTable != null && mDataTable.Rows.Count > 0) //已经存在
                    {
                        status = mDbDataController.UpdateWeixinUser(info);
                    }
                    else
                    {
                        status = mDbDataController.AddWeixinUser(info);
                    }
                    if (status <= 0)
                    {
                        resp.rel = 0;
                        resp.msg = "添加数据到数据库失败";
                    }
                    else
                    {
                        resp.rel = 1;
                        resp.msg = "添加/修改成功";
                    }
                }

                return(Json(resp));
            }
            catch (Exception e)
            {
                SystemLog.Write(e.StackTrace + e.Message);  //日志

                resp.rel = 0;
                resp.msg = "发生了异常," + e.Message;
                return(Json(resp));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a xml import. The data stream passed will be imported to memory, and checked
        /// for errors. If no error could be found, the data can be persisted to the repository.
        /// </summary>
        /// <param name="zoneId">ID of 2SexyContent zone</param>
        /// <param name="appId">ID of 2SexyContent application</param>
        /// <param name="contentTypeId">ID of 2SexyContent type</param>
        /// <param name="dataStream">Xml data stream to import</param>
        /// <param name="languages">Languages that can be imported (2SexyContent languages enabled)</param>
        /// <param name="documentLanguageFallback">Fallback document language</param>
        /// <param name="deleteSetting">How to handle entities already in the repository</param>
        /// <param name="resolveReferenceMode">How value references to files and pages are handled</param>
        public ToRefactorXmlImportVTable(int zoneId, int appId, int contentTypeId, Stream dataStream, IEnumerable <string> languages, string documentLanguageFallback, ImportDeleteUnmentionedItems deleteSetting, ImportResourceReferenceMode resolveReferenceMode)
        {
            ImportEntities = new List <Entity>();
            ErrorLog       = new ImportErrorLog();

            _appId    = appId;
            _zoneId   = zoneId;
            DbContext = DbDataController.Instance(zoneId, appId);

            ContentType = DbContext.AttribSet.GetDbAttribSet(contentTypeId);
            if (ContentType == null)
            {
                ErrorLog.AppendError(ImportErrorCode.InvalidContentType);
                return;
            }

            AttributesOfType = DbContext.AttributesDefinition.GetAttributeDefinitions(contentTypeId).ToList();
            ExistingEntities = DbContext.Entities.GetEntitiesByType(ContentType).ToList();

            _languages = languages;
            if (_languages == null || !_languages.Any())
            {
                _languages = new[] { string.Empty }
            }
            ;

            _documentLanguageFallback = documentLanguageFallback;
            _deleteSetting            = deleteSetting;
            _resolveReferenceMode     = resolveReferenceMode;

            Timer.Start();
            try
            {
                if (!LoadStreamIntoDocumentElement(dataStream))
                {
                    return;
                }
                if (!RunDocumentValidityChecks())
                {
                    return;
                }
                ValidateAndImportToMemory();
            }
            catch (Exception exception)
            {
                ErrorLog.AppendError(ImportErrorCode.Unknown, exception.ToString());
            }
            Timer.Stop();
            TimeForMemorySetup = Timer.ElapsedMilliseconds;
        }
Ejemplo n.º 8
0
        // GET: /Weixin/WeixinUserInfo
        public ActionResult WeixinUserInfo(String state, String p, String id)
        {
            try
            {
                if (state == "WeiXin" && id != null && id.Length > 10 && p != null)
                {
                    DbDataController mDbDataController = new DbDataController();
                    id = id.Replace("2B%", "+");              //还原转换的+
                    String openid = StaticAES.AESDecrypt(id); //解密

                    //获取当前的时间戳
                    TimeSpan cha   = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)));
                    long     count = (long)cha.TotalSeconds;
                    p = p.Replace("2B%", "+");                   //还原转换的+
                    String time       = StaticAES.AESDecrypt(p); //解密
                    long   time_count = 0;
                    try
                    {
                        time_count = Convert.ToInt32(time);
                    }
                    catch (Exception e)
                    {
                        time_count = 0;
                    }

                    count -= time_count;
                    if (count < -7200 || count > 7200) //链接过期了
                    {
                        //去掉登录的状态
                        Session["UserName"]    = "";           //存储全局用户名称
                        Session["Password"]    = "";           //存储全局用户密码MD5
                        Session["LoginStatus"] = "";           //登录状态
                        Session["Openid"]      = openid;       //存储openid
                        return(View());
                    }

                    DataTable mDataTable = mDbDataController.GetWeixinBindUserInfo(openid); //从数据库中读取指定的微信绑定的用户信息
                    if (mDataTable != null && mDataTable.Rows.Count > 0)                    //当前微信已经绑定过用户
                    {
                        //获取

                        String UserName    = mDataTable.Rows[0]["USER"].ToString();         //获取用户名
                        String PasswordMD5 = mDataTable.Rows[0]["PASSWORD_MD5"].ToString(); //获取密码
                        //保存帐户登录名
                        //SaveCookie("UserName", UserName, DateTime.Now.AddDays(30));  //保存cookie 30天
                        //保存密码
                        //SaveCookie("PasswordMD5", PasswordMD5, DateTime.Now.AddDays(30));  //保存cookie 30天
                        //自动登录
                        Session["UserName"]    = UserName;                  //存储全局用户名称
                        Session["Password"]    = PasswordMD5;               //存储全局用户密码MD5
                        Session["LoginStatus"] = "Login Success";           //登录状态
                        Session["Openid"]      = openid;                    //存储openid
                    }
                    else //没有绑定过,则跳转到登录,登录成功后会进行绑定
                    {
                        //去掉登录的状态
                        Session["UserName"]    = "";            //存储全局用户名称
                        Session["Password"]    = "";            //存储全局用户密码MD5
                        Session["LoginStatus"] = "";            //登录状态
                        Session["Openid"]      = openid;        //存储openid
                        return(View());
                    }
                }
            }
            catch (Exception e)
            {
                SystemLog.Write(e.StackTrace + e.Message);  //日志
            }

            return(View());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Do the import
        /// </summary>
        public bool ImportXml(int zoneId, int appId, XDocument doc, bool leaveExistingValuesUntouched = true)
        {
            _eavContext = DbDataController.Instance(zoneId, appId);

            AppId  = appId;
            ZoneId = zoneId;

            if (!IsCompatible(doc))
            {
                ImportLog.Add(new Message("The import file is not compatible with the installed version of 2sxc.", Message.MessageTypes.Error));
                return(false);
            }

            // Get root node "SexyContent"
            var xmlSource = doc.Element(XmlConstants.RootNode);

            if (xmlSource == null)
            {
                ImportLog.Add(new Message("Xml doesn't have expected root node: " + XmlConstants.RootNode, Message.MessageTypes.Error));
                return(false);
            }
            PrepareFolderIdCorrectionListAndCreateMissingFolders(xmlSource);
            PrepareFileIdCorrectionList(xmlSource);

            #region Prepare dimensions (languages) based on header...
            var sourceDimensions = BuildSourceDimensionsList(xmlSource);

            var sourceDefaultLanguage = xmlSource.Element(XmlConstants.Header)?.Element(XmlConstants.Language)?.Attribute(XmlConstants.LangDefault)?.Value;
            if (sourceDimensions == null || sourceDefaultLanguage == null)
            {
                ImportLog.Add(new Message("Cant find source dimensions or source-default language.", Message.MessageTypes.Error));
                return(false);
            }

            var sourceDefaultDimensionId = sourceDimensions.Any() ?
                                           sourceDimensions.FirstOrDefault(p => p.Matches(sourceDefaultLanguage))?.DimensionId
                                : new int?();

            _targetDimensions = new ZoneRuntime(zoneId).Languages(true);

            _xmlBuilder = new XmlToEntity(AppId, sourceDimensions, sourceDefaultDimensionId, _targetDimensions, DefaultLanguage);
            #endregion

            var atsNodes = xmlSource.Element(XmlConstants.AttributeSets)?.Elements(XmlConstants.AttributeSet);
            var entNodes = xmlSource.Elements(XmlConstants.Entities).Elements(XmlConstants.Entity);

            var importAttributeSets = GetImportAttributeSets(atsNodes);
            var importEntities      = GetImportEntities(entNodes, Constants.NotMetadata);


            var import = new Import(ZoneId, AppId, leaveExistingValuesUntouched);
            import.ImportIntoDb(importAttributeSets, importEntities.Cast <Entity>());
            SystemManager.Purge(ZoneId, AppId);

            ImportLog.AddRange(GetExportImportMessagesFromImportLog(import.Storage.Log));

            if (xmlSource.Elements(XmlConstants.Templates).Any())
            {
                ImportXmlTemplates(xmlSource);
            }

            return(true);
        }