Пример #1
0
 private static void TraceObject(object value, string category)
 {
     if (value is Exception)
     {
         log.Error(ERRINFO + FormatException((Exception)value));
         TR.TraceError(typeof(Trace).ToString());
         TR.WriteLine(ERRINFO + FormatException((Exception)value));
     }
     else
     {
         string strValue = (new StringBuilder().Append(indentation).Append(value.ToString())).ToString();
         TR.WriteLine(category + " " + strValue);
         log.Info(category + " " + strValue);
     }
 }
Пример #2
0
        private void CreateUser(string username, SqlConnection sqlConnection)
        {
            var createUserCommand = default(SqlCommand);

            try
            {
                createUserCommand = new SqlCommand($"create user [{username}] from login [{username}]", sqlConnection);
                createUserCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                SysTrace.TraceError($"Error while creating new user. Details: {ex}");
            }
            finally
            {
                createUserCommand?.Dispose();
            }
        }
        private void ProcessSites(SqlConnection connection, string siteGuidValue, string username, Guid timerJobGuid)
        {
            var outputBuilder = new StringBuilder();

            try
            {
                var siteCount  = 1;
                var sitesArray = GetSitesArray(connection);

                if (sitesArray?.Length > 0)
                {
                    siteCount += sitesArray.Length;
                }

                using (var site = new SPSite(new Guid(siteGuidValue)))
                {
                    var result = ProcessSite(site, siteCount, connection, timerJobGuid, siteGuidValue, username, 0);
                    outputBuilder.Append(result);
                }

                if (sitesArray != null)
                {
                    var siteCounter = 1;

                    foreach (var siteUrl in sitesArray)
                    {
                        using (SPSite site = new SPSite(siteUrl))
                        {
                            var pctFactor = (double)siteCounter / siteCount;
                            var result    = ProcessSite(site, siteCount, connection, timerJobGuid, siteGuidValue, username, pctFactor);
                            outputBuilder.Append(result);
                        }
                        siteCounter++;
                    }
                }

                SaveLog(connection, true, timerJobGuid, outputBuilder.ToString());
            }
            catch (Exception ex)
            {
                SysTrace.TraceError(ex.ToString());
                SaveLog(connection, false, timerJobGuid, $"{outputBuilder}<br><br>Error: {ex.Message}");
            }
        }
Пример #4
0
        /// <summary>
        /// Retrives a value with given key. If key can not be found, defaultValue is returned.
        /// </summary>
        /// <param name="key">The key to retrieve data for.</param>
        /// <param name="defaultValue">The default value of the key-value pair, used if the supplied key isn't found.</param>
        /// <returns>Deserialzed complex value.</returns>
        public T Get <T>(string key, T defaultValue = default(T))
        {
            var data = Get(key);

            if (data == null)
            {
                return(defaultValue);
            }

            try
            {
                return(AniListJsonSerializer.Default.Deserialize <T>(data));
            }
            catch (Exception)
            {
                Trace.TraceError($"Error occurred while deserializing object with key {key} from SharedPreferences.");
                return(defaultValue);
            }
        }
Пример #5
0
        private void AddRoles(string username, SqlConnection sqlConnection)
        {
            var command = default(SqlCommand);

            try
            {
                command             = new SqlCommand("sp_addrolemember", sqlConnection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@rolename", "db_owner");
                command.Parameters.AddWithValue("@membername", username);
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                SysTrace.TraceError($"Error while adding roles to the user. Details: {ex}");
            }
            finally
            {
                command?.Dispose();
            }
        }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string action = Request["action"];

                MenuTemplate propertyNameListMenu = new MenuTemplate();
                propertyNameListMenu.ID = "PropertyNameListMenu";

                MenuItemTemplate testMenu = new MenuItemTemplate("Remove From Database", "/_layouts/images/delete.gif");
                testMenu.ClientOnClickScript = "javascript:if(confirm('Are you sure you want to remove this project from the EPM Live Database?')){location.href='epubstatus.aspx?action=delete&projectid=%NAME%';}";
                propertyNameListMenu.Controls.Add(testMenu);

                testMenu = new MenuItemTemplate("Link Workspace", "/_layouts/epmlive/images/linkworkspace.gif");
                testMenu.ClientOnClickScript = "javascript:linkworkspace('%NAME%');";
                propertyNameListMenu.Controls.Add(testMenu);

                testMenu = new MenuItemTemplate("Unlink Workspace", "/_layouts/epmlive/images/unlinkworkspace.gif");
                testMenu.ClientOnClickScript = "javascript:if(confirm('Are you sure you want to unlink that workspace?')){location.href='epubstatus.aspx?action=unlink&projectid=%NAME%';}";
                propertyNameListMenu.Controls.Add(testMenu);

                testMenu = new MenuItemTemplate("View Publish Log", "/_layouts/images/txt16.gif");
                testMenu.ClientOnClickNavigateUrl = "eviewlog.aspx?projectid=%NAME%";
                propertyNameListMenu.Controls.Add(testMenu);

                this.Controls.Add(propertyNameListMenu);

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (var connection =
                               new SqlConnection(CoreFunctions.getConnectionString(SPContext.Current.Site.WebApplication.Id)))
                    {
                        connection.Open();
                        if (!string.IsNullOrWhiteSpace(action))
                        {
                            switch (action)
                            {
                            case "delete":
                                using (var command = new SqlCommand(
                                           "DELETE FROM publishercheck where projectguid=@projectguid",
                                           connection))
                                {
                                    command.Parameters.AddWithValue("@projectguid", Request["projectid"]);
                                    command.ExecuteNonQuery();
                                }
                                break;

                            case "unlink":
                                using (var command = new SqlCommand(
                                           "UPDATE publishercheck set weburl='',webguid=NULL where projectguid=@projectguid",
                                           connection))
                                {
                                    command.Parameters.AddWithValue("@projectguid", Request["projectid"]);
                                    command.ExecuteNonQuery();
                                }
                                break;

                            default:
                                DiagTrace.TraceError($"Unexpected action '{action}'.");
                                break;
                            }

                            Response.Redirect($"{SPContext.Current.Web.Url}/_layouts/epmlive/epubstatus.aspx");
                        }

                        var dataSet = new DataSet();
                        using (var command =
                                   new SqlCommand("select * from vwGetProjectStatus order by projectname", connection))
                        {
                            using (var adapter = new SqlDataAdapter(command))
                            {
                                adapter.Fill(dataSet);
                            }
                        }

                        GvItems.DataSource = dataSet;
                        GvItems.DataBind();
                    }
                });
            }
            catch (Exception exception)
            {
                DiagTrace.TraceError(exception.ToString());
                Response.Write($"Error: {exception.Message}");
            }
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Server.ScriptTimeout = 300;

            var webapp = SPWebService.ContentService.WebApplications[new Guid(Request[KeyWebApp])];

            var server   = Request[KeyServer];
            var database = Request[KeyDatabase];
            var username = Request[KeyUsername];
            var password = Request[KeyPassword];

            var credentials = string.IsNullOrWhiteSpace(username)
                ? "Trusted_Connection=True"
                : $"User Id={username};Password={password}";

            string connectionString;

            SqlConnection sqlConnection = null;

            try
            {
                connectionString = $"Server={server};Database=master;{credentials}";
                CreateDatabase(database, connectionString);

                connectionString = $"Server={server};Database={database};{credentials}";
                sqlConnection    = new SqlConnection(connectionString);

                sqlConnection.Open();

                CreateUser(webapp.ApplicationPool.Username, sqlConnection);
                AddRoles(webapp.ApplicationPool.Username, sqlConnection);

                ExecuteCommand(Properties.Resources._0Tables01, sqlConnection);
                ExecuteCommand(Properties.Resources._0Tables02, sqlConnection);
                ExecuteCommand(Properties.Resources._1Views01, sqlConnection);
                ExecuteCommand(Properties.Resources._2SPs01, sqlConnection);
                ExecuteCommand(Properties.Resources._9Data01, sqlConnection);
                ExecuteCommand(Properties.Resources._9Data02, sqlConnection);
                InsertVersions(sqlConnection);

                string error;
                SPContext.Current.Web.AllowUnsafeUpdates  = true;
                SPContext.Current.Site.AllowUnsafeUpdates = true;
                CoreFunctions.setConnectionString(webapp.Id, connectionString, out error);

                if (!string.IsNullOrWhiteSpace(error))
                {
                    output = $"Error Setting String: {error}";
                    return;
                }
            }
            catch (Exception ex)
            {
                SysTrace.TraceError(ex.ToString());
                output = $"Failed: {ex.Message}";
                return;
            }
            finally
            {
                sqlConnection?.Dispose();
            }

            output = "Success";
        }
        private void AddWebs(SPWeb web, XmlNode parentNode)
        {
            var newNode    = doc.CreateNode(XmlNodeType.Element, "row", doc.NamespaceURI);
            var canPublish = false;

            try
            {
                if (web.DoesUserHavePermissions(SPBasePermissions.ViewPages))
                {
                    var attributeLocked = doc.CreateAttribute("locked");
                    attributeLocked.Value = "1";
                    var attributeExpand = doc.CreateAttribute("open");
                    attributeExpand.Value = "1";
                    var attributeId = doc.CreateAttribute("id");
                    attributeId.Value = web.ServerRelativeUrl;

                    newNode.Attributes.Append(attributeLocked);
                    newNode.Attributes.Append(attributeExpand);
                    newNode.Attributes.Append(attributeId);

                    if (Request["List"] == null)
                    {
                        ProcessUserData(newNode, web);
                        canPublish = true;
                    }
                    else
                    {
                        canPublish = ProcessDataList(web, newNode);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugTrace.TraceError("Exception swallowed: {0}", ex);
            }

            try
            {
                foreach (SPWeb additionalWeb in web.Webs)
                {
                    try
                    {
                        AddWebs(additionalWeb, newNode);
                    }
                    catch (Exception ex)
                    {
                        WriteTrace(Area.EPMLiveCore,
                                   Categories.EPMLiveCore.Event,
                                   TraceSeverity.Medium,
                                   ex.ToString());
                    }
                    finally
                    {
                        additionalWeb?.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                DebugTrace.TraceError("Exception swallowed: {0}", ex);
            }

            if (newNode.SelectSingleNode("row") != null || canPublish)
            {
                parentNode.AppendChild(newNode);
            }
        }
        private bool ProcessDataList(SPWeb web, XmlNode newNode)
        {
            var    canPublish = false;
            SPList list       = null;

            try
            {
                list = web.Lists[HttpUtility.UrlDecode(Request["List"])];
            }
            catch (Exception ex)
            {
                DebugTrace.TraceError("Exception swallowed: {0}", ex);
            }

            if (list != null)
            {
                if (!list.Hidden)
                {
                    var gSettings = new GridGanttSettings(list);

                    if (gSettings.HideNewButton)
                    {
                        list = null;
                    }
                }
                else
                {
                    list = null;
                }
            }

            var newCell = doc.CreateNode(XmlNodeType.Element, "userdata", doc.NamespaceURI);

            if (list != null)
            {
                newCell.InnerText = list.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl;
                var attrName = doc.CreateAttribute("name");
                attrName.Value = "NewItemURL";
                newCell.Attributes.Append(attrName);
                newNode.AppendChild(newCell);

                newCell           = doc.CreateNode(XmlNodeType.Element, "userdata", doc.NamespaceURI);
                newCell.InnerText = "No";
                attrName          = doc.CreateAttribute("name");
                attrName.Value    = "CanPublish";
                newCell.Attributes.Append(attrName);

                if (list.DoesUserHavePermissions(SPBasePermissions.AddListItems))
                {
                    newCell.InnerText = "Yes";
                    canPublish        = true;
                }
            }

            newNode.AppendChild(newCell);
            newCell           = doc.CreateNode(XmlNodeType.Element, "cell", doc.NamespaceURI);
            newCell.InnerText = web.Title;
            newNode.AppendChild(newCell);
            newCell           = doc.CreateNode(XmlNodeType.Element, "cell", doc.NamespaceURI);
            newCell.InnerText = web.ServerRelativeUrl;
            newNode.AppendChild(newCell);
            newCell           = doc.CreateNode(XmlNodeType.Element, "userdata", doc.NamespaceURI);
            newCell.InnerText = web.ID.ToString();

            var attributeName = doc.CreateAttribute("name");

            attributeName.Value = "webid";
            newCell.Attributes.Append(attributeName);
            newNode.AppendChild(newCell);

            return(canPublish);
        }