public DefinitionObject(DatabaseCore.Core core, BaseItem item)
        {
            this.Core   = core;
            this.Values = new Dictionary <string, object>();
            this.Source = item.Owner.TableName.Replace("[", "").Replace("]", "");
            this.Path   = "Id=" + item.Id;
            this.Values.Add("Id", item.Id);

            if (this.Source.Contains("dbo."))
            {
                this.Source = this.Source.Replace("dbo.", "");
            }

            this.TypeName = item.GetType().Name;
        }
        public DefinitionObject(DatabaseCore.Core core, string source)
        {
            this.Core   = core;
            this.Values = new Dictionary <string, object>();
            this.Source = source;

            if (this.Source.Contains("dbo."))
            {
                this.Source = this.Source.Replace("dbo.", "");
            }

            if (File.Exists(source))
            {
                this.StorageType = StorageMethodType.Xml;
            }
        }
        public DefinitionObject(DatabaseCore.Core core, string fileName, XmlNode xmlNode)
            : this(core, fileName)
        {
            this.XmlNode = xmlNode;
            this.Path    = xmlNode.GetXPath();

            this.TypeName   = xmlNode.Name;
            this.ParentPath = xmlNode.ParentNode.GetXPath(true);

            if (this.TypeName.StartsWith("IsTaxonomy") == false &&
                xmlNode.Attributes["IsTaxonomy"] != null &&
                bool.Parse(xmlNode.Attributes["IsTaxonomy"].Value) == true)
            {
                this.TypeName = "Taxonomy" + this.TypeName;
            }
        }
        public DefinitionObject(DatabaseCore.Core core, string source, string path)
            : this(core, source)
        {
            this.Path = path;

            if (this.Path.StartsWith("Id="))
            {
                Guid id = Guid.Parse(this.Path.Remove(0, 3).Split('&')[0]);
                this.Values.Add("Id", id);
            }

            if (this.StorageType == StorageMethodType.Xml)
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(this.Source);
                /*XmlDocument xmlDocument = ApplicationUtilities.FileSystem.LoadXml(this.Source, true);*/

                XmlNode xmlNode = xmlDocument.SelectSingleNode(this.Path);

                if (xmlNode != null)
                {
                    this.TypeName = xmlNode.Name;

                    if (this.TypeName == "Variable" && xmlNode.Attributes["IsTaxonomy"] != null && bool.Parse(xmlNode.Attributes["IsTaxonomy"].Value) == true)
                    {
                        this.TypeName = "TaxonomyVariable";
                    }

                    if (xmlNode.ParentNode.NodeType != XmlNodeType.Document)
                    {
                        this.ParentPath = xmlNode.ParentNode.GetXPath(true);
                    }

                    this.XmlNode = xmlNode;
                }
            }
        }
示例#5
0
        private void DeleteStudyAsynch(object _params)
        {
            object[] parameters = (object[])_params;

            List <Guid> studies = (List <Guid>)parameters[0];

            DatabaseCore.Core core            = (DatabaseCore.Core)parameters[1];
            string            applicationPath = (string)parameters[2];

            foreach (Guid idStudy in studies)
            {
                try
                {
                    core.Respondents.ExecuteQuery(string.Format(
                                                      "Delete FROM [QALogs] WHERE IdStudy='{0}'",
                                                      idStudy
                                                      ));

                    core.Respondents.ExecuteQuery(string.Format(
                                                      "Delete FROM [CategoryLabels] WHERE IdCategory IN (SELECT Id FROM Categories WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}'))",
                                                      idStudy
                                                      ));

                    core.Respondents.ExecuteQuery(string.Format(
                                                      "Delete FROM [CategoryLinks] WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}')",
                                                      idStudy
                                                      ));

                    core.Respondents.ExecuteQuery(string.Format(
                                                      "Delete FROM [Categories] WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}')",
                                                      idStudy
                                                      ));


                    core.Respondents.ExecuteQuery(string.Format(
                                                      "Delete FROM [VariableLinks] WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}')",
                                                      idStudy
                                                      ));

                    core.Respondents.ExecuteQuery(string.Format(
                                                      "Delete FROM [VariableLabels] WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}')",
                                                      idStudy
                                                      ));

                    foreach (object[] variable in core.Variables.GetValues(new string[] { "Id" }, new string[] { "IdStudy" }, new object[] { idStudy }))
                    {
                        try
                        {
                            core.Variables.ExecuteQuery("DROP TABLE resp.[Var_" + variable[0].ToString() + "]");
                        }
                        catch { }
                    }
                    core.Respondents.ExecuteQuery(string.Format(
                                                      "Delete FROM [Respondents] WHERE IdStudy='{0}'",
                                                      idStudy
                                                      ));

                    core.Respondents.ExecuteQuery(string.Format(
                                                      "Delete FROM Variables WHERE IdStudy='{0}'",
                                                      idStudy
                                                      ));

                    core.Studies.Delete(idStudy);
                }
                catch (Exception ex)
                {
                    Study study = core.Studies.GetSingle(idStudy);

                    if (study != null)
                    {
                        study.Status = StudyStatus.DeletionFailed;
                        study.Save();
                    }

                    string fileName = Path.Combine(
                        applicationPath,
                        "Fileadmin",
                        "StudyDeletionErrors"
                        );

                    if (!Directory.Exists(fileName))
                    {
                        Directory.CreateDirectory(fileName);
                    }

                    fileName = Path.Combine(
                        fileName,
                        idStudy + ".log"
                        );

                    File.WriteAllText(fileName, ex.ToString());
                }
            }

            Global.ClearCaches();
            Global.ClientManager.IncreaseCaseDataVersion(Global.Core.ClientName);
        }
        private void DeleteStudyAsynch(object _params)
        {
            object[] parameters = (object[])_params;

            Guid idStudy = (Guid)parameters[0];

            DatabaseCore.Core core            = (DatabaseCore.Core)parameters[1];
            string            applicationPath = (string)parameters[2];

            try
            {
                core.Respondents.ExecuteQuery(string.Format(
                                                  "Delete FROM [QALogs] WHERE IdStudy='{0}'",
                                                  idStudy
                                                  ));

                core.Respondents.ExecuteQuery(string.Format(
                                                  "DELETE FROM [CATEGORYLABELS] WHERE IDCATEGORY IN (SELECT CATEGORIES.ID FROM CATEGORIES,VARIABLES WHERE CATEGORIES.IDVARIABLE=VARIABLES.ID AND VARIABLES.IDSTUDY='{0}')",
                                                  idStudy
                                                  ));

                core.Respondents.ExecuteQuery(string.Format(
                                                  "Delete FROM [CategoryLinks] WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}')",
                                                  idStudy
                                                  ));

                core.Respondents.ExecuteQuery(string.Format(
                                                  "Delete FROM [Categories] WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}')",
                                                  idStudy
                                                  ));


                core.Respondents.ExecuteQuery(string.Format(
                                                  "Delete FROM [VariableLinks] WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}')",
                                                  idStudy
                                                  ));

                core.Respondents.ExecuteQuery(string.Format(
                                                  "Delete FROM [VariableLabels] WHERE IdVariable IN (SELECT Id FROM Variables WHERE IdStudy='{0}')",
                                                  idStudy
                                                  ));

                StringBuilder dropRespData = new StringBuilder();
                dropRespData.Append("drop table ");

                foreach (object[] variable in core.Variables.GetValues(new string[] { "Id" }, new string[] { "IdStudy" }, new object[] { idStudy }))
                {
                    try
                    {
                        dropRespData.Append("resp.[Var_" + variable[0].ToString() + "],");
                        // core.Variables.ExecuteQuery("DROP TABLE resp.[Var_" + variable[0].ToString() + "]");
                    }
                    catch { }
                }

                core.Variables.ExecuteQuery(dropRespData.ToString().Remove(dropRespData.ToString().Length - 1));

                core.Respondents.ExecuteQuery(string.Format(
                                                  "Delete FROM [Respondents] WHERE IdStudy='{0}'",
                                                  idStudy
                                                  ));

                core.Respondents.ExecuteQuery(string.Format(
                                                  "Delete FROM Variables WHERE IdStudy='{0}'",
                                                  idStudy
                                                  ));

                core.Studies.Delete(idStudy);

                Global.ClearCaches(core);
            }
            catch (Exception ex)
            {
                Study study = core.Studies.GetSingle(idStudy);

                if (study != null)
                {
                    study.Status = StudyStatus.DeletionFailed;
                    study.Save();
                }

                string fileName = Path.Combine(
                    applicationPath,
                    "Fileadmin",
                    "StudyDeletionErrors"
                    );

                if (!Directory.Exists(fileName))
                {
                    Directory.CreateDirectory(fileName);
                }

                fileName = Path.Combine(
                    fileName,
                    idStudy + ".log"
                    );

                File.WriteAllText(fileName, ex.ToString());
            }
        }