Exemple #1
0
        private SurveyRequestResultBO PublishRelatedFormSurvey(SurveyInfoBO pRequestMessage)
        {
            string _Xml = pRequestMessage.XML;
            SurveyRequestResultBO SurveyRequestResultBO = new Web.Common.BusinessObject.SurveyRequestResultBO();
            // Dictionary<int, int> ViewIds = new Dictionary<int, int>();
            Dictionary <int, string> SurveyIds = new Dictionary <int, string>();
            string ParentId = "";

            // 1- breck down the xml to n views
            List <string> XmlList = new List <string>();

            XmlList = XmlChunking(pRequestMessage.XML);

            // 2- call publish() with each of the views
            foreach (string Xml in XmlList) //Pain Point
            {
                XDocument    xdoc         = XDocument.Parse(Xml);
                SurveyInfoBO SurveyInfoBO = new SurveyInfoBO();
                XElement     ViewElement  = xdoc.XPathSelectElement("Template/Project/View");
                int          _ViewId;
                int.TryParse(ViewElement.Attribute("ViewId").Value.ToString(), out _ViewId);

                GetRelateViewIds(ViewElement, _ViewId);

                SurveyInfoBO     = pRequestMessage;
                SurveyInfoBO.XML = Xml;
                if (_ViewId == 1)
                {
                    SurveyInfoBO.SurveyName = pRequestMessage.SurveyName;
                }
                else
                {
                    SurveyInfoBO.SurveyName = ViewElement.Attribute("Name").Value.ToString();
                }
                SurveyInfoBO.ViewId   = _ViewId;
                SurveyInfoBO.ParentId = ParentId;
                // SurveyInfoBO.OwnerId = pRequestMessage.OwnerId ;
                SurveyInfoBO.IsSqlProject = pRequestMessage.IsSqlProject;
                // SurveyInfoBO.IsShareable = pRequestMessage.IsShareable;
                SurveyInfoBO.DBConnectionString = pRequestMessage.DBConnectionString;
                SurveyRequestResultBO           = Publish(SurveyInfoBO); //temp
                                                                         // ParentId = SurveyRequestResultBO.URL.Split('/').Last();

                if (SurveyRequestResultBO.ViewIdAndFormIdList != null)
                {
                    ParentId = SurveyRequestResultBO.ViewIdAndFormIdList[_ViewId];
                }
                SurveyIds.Add(_ViewId, ParentId);
            }


            foreach (var ViewId in this.ViewIds)
            {
                try
                {
                    string PId = SurveyIds[ViewId.Value].ToString();
                    string SId = SurveyIds[ViewId.Key].ToString();
                    this.SurveyInfoDao.UpdateParentId(SId, ViewId.Key, PId);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            SetSourceTable(_Xml, SurveyIds[1].ToString());
            SurveyRequestResultBO.ViewIdAndFormIdList = SurveyIds;
            // SurveyRequestResultBO.URL = SurveyRequestResultBO.URL.Remove(SurveyRequestResultBO.URL.LastIndexOf('/'));
            SurveyRequestResultBO.URL = GetURL(pRequestMessage, new Guid(SurveyIds[1].ToString()));
            return(SurveyRequestResultBO);
        }
Exemple #2
0
        //private SurveyRequestResultBO RePublish(SurveyInfoBO pRequestMessage)
        //    {

        //    SurveyRequestResultBO result = new SurveyRequestResultBO();
        //    string _Xml = pRequestMessage.XML;
        //        var SurveyId = new Guid(pRequestMessage.SurveyId);

        //        if (pRequestMessage != null)
        //            {

        //            if (! string.IsNullOrEmpty(pRequestMessage.SurveyNumber)  &&  ValidateOrganizationKey(pRequestMessage.OrganizationKey))
        //               // if (ValidateOrganizationKeyByUser(pRequestMessage.OrganizationKey,pRequestMessage.OwnerId))//EW-96
        //                {

        //                if (ValidateSurveyFields(pRequestMessage))
        //                    {
        //                    try
        //                        {

        //                            if (pRequestMessage.IsSqlProject)
        //                                this.SurveyInfoDao.ValidateServername(pRequestMessage);
        //                            XDocument xdoc = XDocument.Parse(pRequestMessage.XML);
        //                           xdoc.Descendants().Where(e => e.Name == "SourceTable").Remove();
        //                           pRequestMessage.XML = xdoc.ToString();
        //                            this.SurveyInfoDao.UpdateSurveyInfo(ToBusinessObject(pRequestMessage, SurveyId));
        //                        ////Insert Connection string..
        //                        //DbConnectionStringBO DbConnectionStringBO = new DbConnectionStringBO();
        //                        //DbConnectionStringBO = GetConnection(pRequestMessage.DBConnectionString);
        //                        //DbConnectionStringBO.SurveyId = SurveyId;
        //                        //this.SurveyInfoDao.InsertConnectionString(DbConnectionStringBO);
        //                        var BO = ToBusinessObject(pRequestMessage, SurveyId);
        //                        this.SurveyInfoDao.InsertFormdefaultSettings(SurveyId.ToString(), pRequestMessage.IsSqlProject, GetSurveyControls(BO));
        //                        Dictionary<int, string> SurveyIdsList = new Dictionary<int, string>();
        //                        SurveyIdsList.Add(GetViewId(pRequestMessage.XML), SurveyId.ToString());
        //                        result.ViewIdAndFormIdList = SurveyIdsList;
        //                        result.URL = GetURL(pRequestMessage, SurveyId);
        //                        result.IsPulished = true;
        //                        ReSetSourceTable(_Xml, SurveyId.ToString());
        //                        }
        //                    catch (Exception ex)
        //                        {
        //                        System.Console.Write(ex.ToString());
        //                        //Entities.ObjectStateManager.GetObjectStateEntry(SurveyMetaData).Delete();
        //                        result.URL = "";
        //                        result.IsPulished = false;
        //                        result.StatusText = "An Error has occurred while publishing your survey.";
        //                        }



        //                    }
        //                else
        //                    {

        //                    result.URL = "";
        //                    result.IsPulished = false;
        //                    result.StatusText = "One or more survey required fields are missing values.";
        //                    }

        //                }
        //            else
        //                {

        //                result.URL = "";
        //                result.IsPulished = false;
        //                result.StatusText = "Organization Key is invalid.";

        //                }
        //            }

        //    return result;
        //    }
        private SurveyRequestResultBO RePublishRelatedFormSurvey(SurveyInfoBO pRequestMessage)
        {
            SurveyRequestResultBO    SurveyRequestResultBO = new Web.Common.BusinessObject.SurveyRequestResultBO();
            Dictionary <int, int>    ViewIds   = new Dictionary <int, int>();
            Dictionary <int, string> SurveyIds = new Dictionary <int, string>();
            string _Xml = pRequestMessage.XML;
            List <SurveyInfoBO> FormsHierarchyIds = this.GetFormsHierarchyIdsByRootId(pRequestMessage.SurveyId.ToString());
            // 1- breck down the xml to n views
            List <string> XmlList = new List <string>();

            XmlList = XmlChunking(pRequestMessage.XML);
            string ParentId = "";

            // 2- call publish() with each of the views
            foreach (string Xml in XmlList)
            {
                XDocument    xdoc         = XDocument.Parse(Xml);
                SurveyInfoBO SurveyInfoBO = new SurveyInfoBO();
                XElement     ViewElement  = xdoc.XPathSelectElement("Template/Project/View");
                int          ViewId;
                int.TryParse(ViewElement.Attribute("ViewId").Value.ToString(), out ViewId);

                GetRelateViewIds(ViewElement, ViewId);

                SurveyInfoBO     = pRequestMessage;
                SurveyInfoBO.XML = Xml;
                if (ViewId == 1)
                {
                    SurveyInfoBO.SurveyName = pRequestMessage.SurveyName;
                }
                else
                {
                    SurveyInfoBO.SurveyName = ViewElement.Attribute("Name").Value.ToString();
                }
                SurveyInfoBO.ViewId = ViewId;
                var ViewExists = FormsHierarchyIds.Where(x => x.ViewId == ViewId);
                if (ViewExists.Count() > 0)
                {
                    SurveyInfoBO pBO = FormsHierarchyIds.Single(x => x.ViewId == ViewId);
                    SurveyInfoBO.SurveyId       = pBO.SurveyId;
                    SurveyInfoBO.ParentId       = pBO.ParentId;
                    SurveyInfoBO.UserPublishKey = pBO.UserPublishKey;
                    //SurveyInfoBO.OwnerId = pRequestMessage.OwnerId;
                    SurveyInfoBO.IsSqlProject = pRequestMessage.IsSqlProject;
                    // SurveyInfoBO.IsShareable = pRequestMessage.IsShareable;
                    SurveyInfoBO.DBConnectionString = pRequestMessage.DBConnectionString;
                    SurveyRequestResultBO           = RePublish(SurveyInfoBO);
                }
                else
                {
                    SurveyInfoBO.XML        = Xml;
                    SurveyInfoBO.SurveyName = ViewElement.Attribute("Name").Value.ToString();
                    SurveyInfoBO.ViewId     = ViewId;
                    SurveyInfoBO.ParentId   = ParentId;
                    //SurveyInfoBO.OwnerId = pRequestMessage.OwnerId;
                    SurveyInfoBO.IsSqlProject = pRequestMessage.IsSqlProject;
                    //  SurveyInfoBO.IsShareable = pRequestMessage.IsShareable;
                    SurveyInfoBO.DBConnectionString = pRequestMessage.DBConnectionString;
                    SurveyRequestResultBO           = Publish(SurveyInfoBO);
                }
                ParentId = SurveyRequestResultBO.ViewIdAndFormIdList[ViewId];
                SurveyIds.Add(ViewId, ParentId);
            }
            foreach (var _ViewId in this.ViewIds)
            {
                string PId = SurveyIds[_ViewId.Value].ToString();
                string SId = SurveyIds[_ViewId.Key].ToString();
                this.SurveyInfoDao.UpdateParentId(SId, _ViewId.Key, PId);
            }
            var _SId = SurveyIds.Keys.ElementAt(0);

            ReSetSourceTable(_Xml, FormsHierarchyIds[0].SurveyId);
            SurveyRequestResultBO.URL = GetURL(pRequestMessage, new Guid(FormsHierarchyIds[0].SurveyId));
            return(SurveyRequestResultBO);
        }