コード例 #1
0
        private ComponentData ValidateCore(Component comp, string logPath, ComponentCustomAction caction)
        {
            ComponentData cd = new ComponentData(this.Context.ClientID, (Component)comp);

            cd.ImportFields = this.Context.ImportFields.Where(x => x.ComponentID == comp.ID).ToList();
            cd.lookupPath   = logPath + "/" + this.Context.ID + "_lookup.json";
            if (comp.TableName.ToLower() == "position")
            {
                cd.ExtractDataFromSource(dt, true);
            }
            else
            {
                cd.ExtractDataFromSource(dt);
            }
            cd.LoadTargetData(this.Context.Connection);
            cd.SetLookupList(dtLk);
            if (caction != null)
            {
                cd.Validation = caction.CustomAction;
                cd.Validation.Init();
            }
            cd.ValidateData(this.Context.EnableUpdateDuplicate, this.Context.Connection, logPath, this.Context.ID);
            cd.Errors = cd.Errors.Where(x => x.Type == ErrorType.ERROR).ToList();
            if (cd.Logs.Where(x => x.Type == ErrorType.ERROR).ToList().Count > 0 || cd.Errors.Where(x => x.Type == ErrorType.ERROR).ToList().Count > 0)
            {
                cd.IsValid = false;
            }
            cd.Validation = null;
            cd.lookupPath = "";
            cd.GetProcessedData(logPath, this.Context.ID);

            CacheData(logPath + "/" + "cd" + "_" + comp.ID + "_" + this.Context.ID + ".json", Newtonsoft.Json.JsonConvert.SerializeObject(cd));
            return(cd);
        }
コード例 #2
0
        private ComponentData Validatepsedo(string logPath, List <ComponentCustomAction> caction)
        {
            var pseudo = Context.View.Components.Where(x => x.Type == ComponentType.pseudocore).FirstOrDefault();

            if (pseudo != null)
            {
                ComponentData cd = new ComponentData(this.Context.ClientID, (Component)pseudo);
                cd.ImportFields = this.Context.ImportFields.Where(x => x.ComponentID == pseudo.ID).ToList();
                cd.lookupPath   = logPath + "/" + this.Context.ID + "_lookup.json";


                // pseudo component base template modified template field due to privot so we cannot use template field from context template. that is why i init again to get template & field
                var currentTemplate = new CompExtention.ImportTemplate.Template(this.Context.Template.TemplateID, this.Context.ClientID, this.Context.Connection);
                cd.SetLookupList(dtLk);
                var action = caction.Where(x => x.ComponentName == pseudo.TableName).FirstOrDefault();
                if (action != null)
                {
                    cd.Validation = action.CustomAction;
                    cd.Validation.Init();
                }
                if (this.Context.Template.Type == CompExtention.ImportTemplate.Template.TemplateType.PIVOT)
                {
                    List <string> com = new List <string>();
                    com.Add(pseudo.ID);
                    var ViewAttributes = CompExtention.ComponentManager.GetComponentAttributes(string.Join(",", com.ToArray()), this.Context.ClientID, new CompExtention.DataAccess.ComponentDataHandler(this.Context.Connection));

                    cd.ExtractDataFromSource(dt);
                    cd.LoadTargetPivotData(this.Context.Connection, currentTemplate.TemplateFields, ViewAttributes);

                    cd.ValidatePivotData(false, this.Context.Connection, logPath, this.Context.ID, currentTemplate.TemplateFields, ViewAttributes);
                    cd.Errors     = cd.Errors.Where(x => x.Type == ErrorType.ERROR).ToList();
                    cd.Validation = null;
                    cd.lookupPath = "";
                    cd.GetProcessedData(logPath, this.Context.ID);
                    CacheData(logPath + "/" + "cd" + "_" + pseudo.ID + "_" + this.Context.ID + ".json", Newtonsoft.Json.JsonConvert.SerializeObject(cd));
                    return(cd);
                }
                else
                {
                    cd.ExtractDataFromSource(dt);
                    cd.LoadTargetData(this.Context.Connection);
                    cd.ValidateData(this.Context.EnableUpdateDuplicate, this.Context.Connection, logPath, this.Context.ID);
                    cd.Errors = cd.Errors.Where(x => x.Type == ErrorType.ERROR).ToList();
                    if (cd.Logs.Where(x => x.Type == ErrorType.ERROR).ToList().Count > 0 || cd.Errors.Where(x => x.Type == ErrorType.ERROR).ToList().Count > 0)
                    {
                        cd.IsValid = false;
                    }
                    cd.Validation = null;
                    cd.lookupPath = "";
                    cd.GetProcessedData(logPath, this.Context.ID);
                    CacheData(logPath + "/" + "cd" + "_" + pseudo.ID + "_" + this.Context.ID + ".json", Newtonsoft.Json.JsonConvert.SerializeObject(cd));
                    return(cd);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        ///  get data of component before validate like show data
        /// </summary>
        /// <param name="compID"></param>
        /// <param name="logPath"></param>
        /// <returns></returns>
        public DataTable GetComponentData(string compID, string logPath)
        {
            List <ImportError> ie      = new List <ImportError>();
            string             strjson = File.ReadAllText(logPath + "/" + this.Context.ID + ".json");

            dt = Newtonsoft.Json.JsonConvert.DeserializeObject <DataTable>(strjson);
            this.Context.LoadComponentView();
            var CoreComponent = Context.View.Components.Where(x => x.Type == ComponentType.core).ToList();
            var comp          = Context.View.Components.Where(x => x.ID == compID).FirstOrDefault();

            if (comp.Type == ComponentType.core)
            {
                ComponentData cd = new ComponentData(this.Context.ClientID, (Component)comp);
                cd.ClientID  = this.Context.ClientID;
                cd.Component = (Component)comp;
                List <ImportFieldMap> compIFM = this.Context.ImportFields.Where(x => x.ComponentID == comp.ID).ToList();
                cd.ImportFields = compIFM;
                cd.ExtractDataFromSource(dt);
                return(cd.GetProcessedData(logPath, this.Context.ID, false));
            }
            else
            {
                ComponentData cd = new ComponentData(this.Context.ClientID, (Component)comp);
                cd.ClientID  = this.Context.ClientID;
                cd.Component = (Component)comp;
                List <ImportFieldMap> compIFM = this.Context.ImportFields.Where(x => x.ComponentID == comp.ID).ToList();
                cd.ImportFields = compIFM;
                foreach (Component c in CoreComponent)
                {
                    var cRelation = Context.View.ComponentRelations.Where(x => (x.ComponentID == c.ID || x.ChildComponentID == c.ID) &&
                                                                          (x.ComponentID == comp.ID || x.ChildComponentID == comp.ID)).ToList();
                    if (cRelation.Count > 0)
                    {
                        var keyFields = this.Context.ImportFields.Where(x => x.ComponentID == c.ID && x.IsKey == true).ToList();
                        cd.ImportFields.AddRange(keyFields);
                    }
                }
                List <string> cols = new List <string>();
                foreach (ImportFieldMap ifm in compIFM)
                {
                    ifm.FileFields = ifm.FileFields.Replace(" ", "_");
                    cols.Add(ifm.FileFields);
                }
                foreach (DataColumn dc in dt.Columns)
                {
                    dc.ColumnName = dc.ColumnName.Replace(" ", "_");
                }
                cd.SourceData = dt.DefaultView.ToTable(true, cols.ToArray());
                return(cd.GetProcessedData(logPath, this.Context.ID, false));
            }
        }
コード例 #4
0
        private ComponentData ValidateAttribute(string logPath, List <ComponentCustomAction> customAction)
        {
            var comp = this.Context.View.Components.Where(x => x.Type == ComponentType.attribute).FirstOrDefault();

            //foreach (Component comp in MetaComponent)
            //{
            if (comp != null)
            {
                var           caction = customAction.Where(x => x.ComponentName == comp.TableName).FirstOrDefault();
                ComponentData cd      = new ComponentData(this.Context.ClientID, (Component)comp);
                cd.ImportFields = this.Context.ImportFields.Where(x => x.ComponentID == comp.ID).ToList();
                cd.lookupPath   = logPath + "/" + this.Context.ID + "_lookup.json";
                cd.ExtractDataFromSource(dt);
                cd.LoadTargetData(this.Context.Connection);
                cd.SetLookupList(dtLk);
                if (caction != null)
                {
                    cd.Validation = caction.CustomAction;
                    cd.Validation.Init();
                }
                cd.ValidateData(this.Context.EnableUpdateDuplicate, this.Context.Connection, logPath, this.Context.ID);
                cd.Validation = null;
                cd.Errors     = cd.Errors.Where(x => x.Type == ErrorType.ERROR).ToList();
                if (cd.Logs.Where(x => x.Type == ErrorType.ERROR).ToList().Count > 0 || cd.Errors.Where(x => x.Type == ErrorType.ERROR).ToList().Count > 0)
                {
                    cd.IsValid = false;
                }

                cd.GetProcessedData(logPath, this.Context.ID);
                cd.lookupPath = "";
                //cd.Logs.Clear();
                CacheData(logPath + "/" + "cd" + "_" + comp.ID + "_" + this.Context.ID + ".json", Newtonsoft.Json.JsonConvert.SerializeObject(cd));
                return(cd);
            }
            else
            {
                return(null);
            }

            ///  }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logPath"></param>
        /// <returns></returns>
        public override ImportError HandleRequest(string logPath)
        {
            var lok = Global.GetLookup(this.Context.ClientID, GetLookup(), this.Context.Connection);

            File.WriteAllText(logPath + "/" + this.Context.ID + "_lookup.json", Newtonsoft.Json.JsonConvert.SerializeObject(lok));
            string strjson = File.ReadAllText(logPath + "/" + this.Context.ID + ".json");

            dt = Newtonsoft.Json.JsonConvert.DeserializeObject <DataTable>(strjson);
            this.Context.LoadComponentView();
            List <ImportError> ie = new List <ImportError>();
            var CoreComponent     = Context.View.Components.Where(x => x.Type == ComponentType.core).ToList();

            foreach (IComponent comp in CoreComponent)
            {
                ComponentData cd = new ComponentData(this.Context.ClientID, (Component)comp);

                List <ImportFieldMap> compIFM = this.Context.ImportFields.Where(x => x.ComponentID == comp.ID).ToList();
                cd.ImportFields = compIFM;
                cd.ExtractDataFromSource(dt);
                cd.LoadTargetData(this.Context.Connection);
                cd.lookupPath = logPath + "/" + this.Context.ID + "_lookup.json";
                this.Context.ComponentData.Add(cd);
                CacheData(logPath + "/" + "cd" + "_" + comp.ID + "_" + this.Context.ID + ".json", Newtonsoft.Json.JsonConvert.SerializeObject(cd));
                //  ie.Add( cd.Validate(this.Context.EnableUpdateDuplicate,this.Context.Connection));
            }

            var linkComp = Context.View.Components.Where(x => x.Type == ComponentType.link).ToList();

            foreach (IComponent comp in linkComp)
            {
                ComponentData cd = new ComponentData(this.Context.ClientID, (Component)comp);
                cd.ClientID  = this.Context.ClientID;
                cd.Component = (Component)comp;
                List <ImportFieldMap> compIFM = this.Context.ImportFields.Where(x => x.ComponentID == comp.ID).ToList();
                cd.ImportFields = compIFM;
                foreach (Component c in CoreComponent)
                {
                    var cRelation = Context.View.ComponentRelations.Where(x => (x.ComponentID == c.ID || x.ChildComponentID == c.ID) &&
                                                                          (x.ComponentID == comp.ID || x.ChildComponentID == comp.ID)).ToList();
                    if (cRelation.Count > 0)
                    {
                        var keyFields = this.Context.ImportFields.Where(x => x.ComponentID == c.ID && x.IsKey == true).ToList();
                        cd.ImportFields.AddRange(keyFields);
                    }
                }
                List <string> cols = new List <string>();
                foreach (ImportFieldMap ifm in compIFM)
                {
                    ifm.FileFields = ifm.FileFields.Replace(" ", "_");
                    cols.Add(ifm.FileFields);
                }
                foreach (DataColumn dc in dt.Columns)
                {
                    dc.ColumnName = dc.ColumnName.Replace(" ", "_");
                }
                cd.SourceData = dt.DefaultView.ToTable(true, cols.ToArray());
                cd.LoadTargetData(this.Context.Connection);
                cd.lookupPath = logPath + "/" + this.Context.ID + "_lookup.json";
                this.Context.ComponentData.Add(cd);
                CacheData(logPath + "/" + "cd" + "_" + comp.ID + "_" + this.Context.ID + ".json", Newtonsoft.Json.JsonConvert.SerializeObject(cd));
                //     ie.Add(cd.Validate(this.Context.EnableUpdateDuplicate));
            }

            this.Context.View     = null;
            this.Context.Template = null;
            Global.SaveImportContext(this.Context.ID, Newtonsoft.Json.JsonConvert.SerializeObject(this.Context), 4,
                                     this.Context.ActionBy,
                                     this.Context.Connection, this.Context.ClientID
                                     );
            return(ie.Where(x => x.Type != ErrorType.NOERROR).FirstOrDefault());
            // update data in the request;
        }