Exemple #1
0
        public void execute(SPSite site, SPWeb web, string data)
        {
            try
            {
                Guid intlistid = new Guid(base.key);

                API.Integration.IntegrationCore core = new API.Integration.IntegrationCore(site.ID, web.ID);
                Hashtable hshParms = new Hashtable();
                hshParms.Add("intlistid", intlistid);
                DateTime dtStarted = DateTime.Now;

                DataSet   DS            = core.GetDataSet("SELECT * FROM INT_LISTS where INT_LIST_ID=@intlistid", hshParms);
                DataRow   drIntegration = DS.Tables[0].Rows[0];
                Hashtable hshProperties = null;
                DataSet   dsColumns     = null;
                DataTable dtCols        = null;
                DataTable dtItem        = null;
                DataSet   dsUserFields  = null;
                DataTable dtUserFields  = null;
                Hashtable hshUserMap    = null;
                DataTable dtRet         = null;
                DataSet   dsItem        = null;
                try
                {
                    hshProperties = core.GetProperties(intlistid);

                    dsColumns = core.GetDataSet("SELECT * FROM INT_COLUMNS where INT_LIST_ID=@intlistid", hshParms);
                    dtCols    = dsColumns.Tables[0];

                    dtItem = new DataTable();
                    dtItem.Columns.Add("ID");
                    foreach (DataRow drCol in dtCols.Rows)
                    {
                        dtItem.Columns.Add(drCol["IntegrationColumn"].ToString());
                    }

                    DateTime dtLastSynch = new DateTime(1900, 1, 1);

                    try
                    {
                        dtLastSynch = DateTime.Parse(drIntegration["LASTSYNCH"].ToString());
                    }
                    catch { }

                    if (drIntegration["TIMEINCOMING"].ToString() == "True")
                    {
                        dtItem = core.PullData(dtItem, intlistid, new Guid(drIntegration["LIST_ID"].ToString()), dtLastSynch);

                        base.totalCount = dtItem.Rows.Count + 1;

                        int count = 0;

                        bool allowAdd = false;

                        try
                        {
                            allowAdd = bool.Parse(hshProperties["AllowAddList"].ToString());
                        }
                        catch { }

                        SPList list = web.Lists[new Guid(drIntegration["LIST_ID"].ToString())];

                        GridGanttSettings settings = new GridGanttSettings(list);

                        bool bBuildTeamSec = settings.BuildTeamSecurity;

                        dsUserFields = core.GetDataSet(list, "", intlistid);
                        dtUserFields = dsUserFields.Tables[1];
                        if (dtUserFields.Select("Type='1'").Length > 0 || bBuildTeamSec)
                        {
                            hshUserMap = core.GetUserMap(drIntegration["INT_LIST_ID"].ToString(), true);
                        }

                        bool bSPCol = false;
                        try
                        {
                            if (hshProperties["SPColumn"].ToString() != "")
                            {
                                bSPCol = true;
                            }
                        }
                        catch { }

                        dtRet = new DataTable();
                        dtRet.Columns.Add("ID");

                        if (bSPCol)
                        {
                            dtRet.Columns.Add(hshProperties["SPColumn"].ToString());
                        }

                        foreach (DataRow dr in dtItem.Rows)
                        {
                            int spid = core.iProcessItemRow(dr, list, dtCols, hshProperties, drIntegration["INT_COLID"].ToString(), intlistid, new Guid(drIntegration["MODULE_ID"].ToString()), allowAdd, dtUserFields, hshUserMap);

                            try
                            {
                                if (spid != 0 && bSPCol)
                                {
                                    dtRet.Rows.Add(new string[] { dr["ID"].ToString(), spid.ToString() });
                                }
                            }
                            catch { }

                            base.updateProgress(count++);
                        }

                        if (bSPCol)
                        {
                            core.PostIntegrationUpdateToExternal(dtRet, intlistid, list.ID);
                        }

                        core.LogMessage(intlistid.ToString(), drIntegration["LIST_ID"].ToString(), "Timer: Imported " + dtItem.Rows.Count + " Items", 1);
                    }
                    else if (drIntegration["TIMEOUTGOING"].ToString() == "True")
                    {
                        SPList list = web.Lists[new Guid(drIntegration["LIST_ID"].ToString())];
                        core.OpenConnection();
                        dsItem = core.GetDataSet(list, "", intlistid);

                        SPQuery query = new SPQuery();
                        query.Query = "<Where><Gt><FieldRef Name=\"Modified\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">" + Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(dtLastSynch) + "</Value></Gt></Where>";
                        SPListItemCollection lic = list.GetItems(query);

                        base.totalCount = lic.Count * 2;
                        int count = 0;
                        foreach (SPListItem li in lic)
                        {
                            core.ProcessItem(dsItem, li, list);
                            updateProgress(count++);
                        }

                        core.PostIntegration(dsItem.Tables[0].Copy(), dsItem.Tables[1], dsItem.Tables[2], list);

                        core.LogMessage(intlistid.ToString(), drIntegration["LIST_ID"].ToString(), "Timer: Exported " + lic.Count + " Items", 1);
                    }

                    hshParms.Add("lastsynch", dtStarted.ToString());
                    core.ExecuteQuery("UPDATE INT_LISTS set lastsynch=@lastsynch where INT_LIST_ID=@intlistid", hshParms, true);

                    core.CloseConnection(true);
                }
                catch (Exception ex)
                {
                    core.LogMessage(intlistid.ToString(), drIntegration["LIST_ID"].ToString(), "Timer: " + ex.Message, 3);
                    sErrors += "General Error: " + ex.Message;
                    bErrors  = true;
                }
                finally
                {
                    hshParms      = null;
                    hshUserMap    = null;
                    hshProperties = null;
                    if (DS != null)
                    {
                        DS.Dispose();
                    }
                    if (dsColumns != null)
                    {
                        dsColumns.Dispose();
                    }
                    if (dtCols != null)
                    {
                        dtCols.Dispose();
                    }
                    if (dtItem != null)
                    {
                        dtItem.Dispose();
                    }
                    if (dsUserFields != null)
                    {
                        dsUserFields.Dispose();
                    }
                    if (dtUserFields != null)
                    {
                        dtUserFields.Dispose();
                    }
                    if (dtRet != null)
                    {
                        dtRet.Dispose();
                    }
                    if (dsItem != null)
                    {
                        dsItem.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                sErrors += "General Error: " + ex.Message;
                bErrors  = true;
            }
            finally
            {
                if (web != null)
                {
                    web.Dispose();
                }
                if (site != null)
                {
                    site.Dispose();
                }
                data = null;
            }
        }
        internal bool DeleteIntegration(Guid intlistid, out string message)
        {
            message = "";
            if (_core.RemoveIntegration(intlistid, ListId, out message))
            {
                Hashtable hshProps = new Hashtable();
                hshProps.Add("intlistid", intlistid);


                string sql = "SELECT SITE_ID,WEB_ID,LIST_ID, INT_COLID from INT_LISTS where INT_LIST_ID=@intlistid";

                DataSet ds     = _core.GetDataSet(sql, hshProps);
                DataRow dr     = ds.Tables[0].Rows[0];
                Guid    listid = new Guid(dr["LIST_ID"].ToString());
                string  colid  = "INTUID" + dr["INT_COLID"].ToString();
                Guid    SiteId = new Guid(dr["SITE_ID"].ToString());
                Guid    WebId  = new Guid(dr["WEB_ID"].ToString());

                sql = "DELETE FROM INT_LISTS where INT_LIST_ID=@intlistid";

                _core.ExecuteQuery(sql, hshProps, false);


                sql = "DELETE FROM INT_LOG where INT_LIST_ID=@intlistid";
                _core.ExecuteQuery(sql, hshProps, false);

                sql = "DELETE FROM INT_COLUMNS where INT_LIST_ID=@intlistid";
                _core.ExecuteQuery(sql, hshProps, false);

                sql = "DELETE FROM INT_PROPS where INT_LIST_ID=@intlistid";
                _core.ExecuteQuery(sql, hshProps, true);

                using (SPSite site = new SPSite(SiteId))
                {
                    using (SPWeb web = site.OpenWeb(WebId))
                    {
                        web.AllowUnsafeUpdates = true;
                        SPList  list  = web.Lists[listid];
                        SPField field = null;
                        try
                        {
                            field = list.Fields.GetFieldByInternalName(colid);
                        }
                        catch { }

                        if (field != null)
                        {
                            field.Hidden = false;
                            field.Update();
                            list.Fields.Delete(field.InternalName);
                        }
                        list.Update();

                        RemoveEventHandlers(list);
                    }
                }

                _core.UpdatePriorityNumbers(listid);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            bool success = true;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                Hashtable hshProps = new Hashtable();
                hshProps.Add("IDColumn", ddlIDColumn.SelectedValue);
                hshProps.Add("SPColumn", ddlSPColumn.SelectedValue);
                if (ddlSharePointMatch.SelectedValue == "")
                {
                    hshProps.Add("ItemMatch", "");
                }
                else
                {
                    hshProps.Add("ItemMatch", ddlSharePointMatch.SelectedValue + "|" + ddlIntegrationMatch.SelectedValue);
                }

                hshProps.Add("SecMatch", ddlSecMatch.SelectedValue);

                intcore.SaveProperties(intlistid, hshProps);

                hshProps = new Hashtable();
                hshProps.Add("intlistid", intlistid);
                intcore.ExecuteQuery("Delete from INT_COLUMNS where INT_LIST_ID=@intlistid", hshProps, false);

                foreach (DropDownList ddl in ArrControls)
                {
                    if (ddl.SelectedValue != "")
                    {
                        hshProps = new Hashtable();
                        hshProps.Add("intlistid", intlistid);
                        hshProps.Add("SharePointColumn", ddl.ID);
                        hshProps.Add("IntegrationColumn", ddl.SelectedValue);

                        intcore.ExecuteQuery("INSERT INTO INT_COLUMNS (INT_LIST_ID, SharePointColumn, IntegrationColumn) VALUES (@intlistid, @SharePointColumn, @IntegrationColumn)", hshProps, false);
                    }
                }



                if (Request["wizard"] == "1")
                {
                    hshProps = new Hashtable();
                    hshProps.Add("intlistid", intlistid);

                    string message = "";


                    if (intcore.InstallIntegration(intlistid, new Guid(Request["List"]), out message))
                    {
                        intcore.ExecuteQuery("UPDATE INT_LISTS set active=1 where INT_LIST_ID=@intlistid", hshProps, true);
                    }
                    else
                    {
                        success          = false;
                        lblError.Text    = message + "<br>";
                        lblError.Visible = true;
                    }
                }

                if (chkCleanup.Checked)
                {
                    intcore.ExecuteQuery("UPDATE INT_LISTS set lastsynch=null where INT_LIST_ID=@intlistid", hshProps, true);
                }

                intcore.CloseConnection(true);
            });
            if (success)
            {
                if (Request["ret"] == "Manage")
                {
                    SPUtility.Redirect("epmlive/integration/manage.aspx", SPRedirectFlags.RelativeToLayoutsPage, System.Web.HttpContext.Current);
                }
                else
                {
                    SPUtility.Redirect("epmlive/integration/integrationlist.aspx?LIST=" + Request["List"], SPRedirectFlags.RelativeToLayoutsPage, System.Web.HttpContext.Current);
                }
            }
        }