Ejemplo n.º 1
0
 public override void Execute(Guid targetInstanceId)
 {
     using (SPSite site = new SPSite(new Guid(SiteCollectionGuid)))
     {
         string _connectionString = site.RootWeb.Properties[eCaseConstants.PropertyBagKeys.ECASE_DB_CONNECTION_STRING];
         using (DbAdapter dbAdapter = new DbAdapter())
         {
             dbAdapter.Connect(_connectionString);
             try
             {
                 GetCaseWebsSProc sProc = new GetCaseWebsSProc(new Guid(SiteCollectionGuid));
                 dbAdapter.ExecuteReaderStoredProcedure(sProc);
                 while (dbAdapter.DataReader.Read())
                 {
                     string caseWebGuid = dbAdapter.DataReader["CaseWebGuid"].ToString();
                     try
                     {
                         using (SPWeb caseWeb = site.OpenWeb(new Guid(caseWebGuid)))
                         { CasesNextDueDate.UpdateNextDueDate(caseWeb); /* This method logs errors and consumes them */ }
                     }
                     catch (Exception x)
                     { Logger.Instance.Error(string.Format("UpdateNextDueDate Timer Job Failed to Locate Case Web {0}", caseWebGuid), x, DiagnosticsCategories.eCaseCommon); }
                 }
             }
             catch (Exception x)
             { Logger.Instance.Error(string.Format("UpdateNextDueDate Timer Job Failed for Site Collection {0}", site.Url), x, DiagnosticsCategories.eCaseCommon); }
         }
     }
 }
Ejemplo n.º 2
0
        private string GetDocumentIdForPrefix(SPListItem listItem, string prefix, bool forceUpdate)
        {
            string connectionString = GetConnectionString(listItem);

            GetCreateDocIdSProc sProc = new GetCreateDocIdSProc(listItem.ParentList.ParentWeb.Site.ID, listItem.ParentList.ParentWeb.ID, listItem.UniqueId, forceUpdate, prefix, 0, listItem.ID);

            using (DbAdapter dbAdapter = new DbAdapter())
            {
                dbAdapter.Connect(connectionString);
                dbAdapter.ExecuteNonQueryStoredProcedure(sProc);
            }
            return(string.Format("{0}-{1}", sProc.Parameters[4].Value, sProc.Parameters[5].Value.ToString().PadLeft(9, '0')));
        }
Ejemplo n.º 3
0
        public static void Sample_ReadOracle_WriteCsv()
        {
            string sampleDataPath = @"..\..\Samples\";
            var    watch          = new Stopwatch();

            using (var reader = new DbAdapter())
            {
                reader.ConnectionInfo = new OracleNativeDbConnectionInfo()
                {
                    Database = "TESTDB01",
                    UserName = "******",
                    Password = "******",
                    Host     = "COMPUTER01"
                };
                reader.TableName = "TB_DATA";
                reader.Connect();

                using (var writer = new CsvAdapter())
                {
                    writer.FileName = Path.Combine(sampleDataPath, "TB_DATA.csv");

                    watch.Start();
                    int lineCount = 0;

                    reader.ReadData(30)
                    .ForEach(x =>
                    {
                        Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count);
                        lineCount += x.Rows.Count;
                    })
                    .Do(x => writer.WriteData(x, false));

                    watch.Stop();
                    Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed);
                    Console.ReadLine();
                }

                reader.Disconnect();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// An item has been added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            this.EventFiringEnabled = false; // FINALLY CLAUSE AT END WILL ENSURE IT IS IN PROPER STATE
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(properties.SiteId))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            string uniqueUrl = string.Empty;

                            try
                            {
                                SPList casesList = web.Lists[properties.ListId];
                                SPListItem item  = casesList.GetItemById(properties.ListItemId);

                                #region Get LockCase Value
                                bool lockCase;
                                SPListItem caseStatusItem = item.GetFieldLookupAsSPListItem("CaseStatusLookup");
                                bool.TryParse(caseStatusItem[eCaseConstants.FieldGuids.ECASE_STATUSES_LOCK_SITE].ToString(), out lockCase);
                                #endregion

                                #region Get Users
                                SPUser assignedTo, supervisor;
                                GetAssignedToAndSupervisor(item, out assignedTo, out supervisor);
                                #endregion

                                #region Get Other Properties
                                string title        = item[eCaseConstants.FieldGuids.OOTB_TITLE].ToString();
                                string description  = (string)item[eCaseConstants.FieldGuids.ECASES_LIST_DESCRIPTION] ?? string.Empty;
                                string uniqueCaseId = item[eCaseConstants.FieldGuids.ECASES_LIST_UNIQUECASEID].ToString();
                                #endregion

                                // Get a unique URL that doesn't currently exist
                                uniqueUrl = web.GetValidNewWebUrl(uniqueCaseId);

                                SPWeb caseWeb;
                                string caseWebUrl = string.Empty;
                                try
                                {
                                    using (caseWeb = CreateCaseWeb(web, uniqueUrl, title, description))
                                    {
                                        #region Configure Proxy Group Lists Permissions
                                        SPGroup ownersGroup          = eCaseGroups.GetOwners(caseWeb);
                                        SPGroup participantsGroup    = eCaseGroups.GetParticipants(caseWeb);
                                        SPGroup externalSharingGroup = eCaseGroups.GetExternalUsers(caseWeb);

                                        SPRoleDefinition fullControl;
                                        caseWeb.TryGetRoleDefinition("Full Control", out fullControl);
                                        SPRoleDefinition reader;
                                        caseWeb.TryGetRoleDefinition("Read", out reader);
                                        SPRoleDefinition contributor;
                                        caseWeb.TryGetRoleDefinition("Contribute", out contributor);

                                        SPList ownersList = caseWeb.GetListByInternalName("Bureau");
                                        ownersList.BreakRoleInheritance(false);
                                        ownersList.TryGrantPermission(ownersGroup, fullControl);
                                        ownersList.TryGrantPermission(participantsGroup, reader);

                                        SPList participantsList = caseWeb.GetListByInternalName("Investigator");
                                        participantsList.BreakRoleInheritance(false);
                                        participantsList.TryGrantPermission(ownersGroup, fullControl);
                                        participantsList.TryGrantPermission(participantsGroup, reader);
                                        #endregion

                                        #region Configure Group Memberships via Proxy
                                        this.EventFiringEnabled = true; // TURN ON EVENT FIRING SO THAT PROXY GROUP EVENT RECEIVER FIRES
                                        UpdateProxyGroups(caseWeb, assignedTo, supervisor, null, null);
                                        if (assignedTo.LoginName != properties.UserLoginName && (supervisor == null || supervisor.LoginName != properties.UserLoginName))
                                        {
                                            SPList ownersProxyList = eCaseGroups.OwnersList(caseWeb);
                                            eCaseGroups.AddGroupProxyItem(ownersProxyList, web.EnsureUserProperly(properties.UserLoginName));
                                        }
                                        this.EventFiringEnabled = false; // FINALLY CLAUSE AT END WILL ENSURE IT IS IN PROPER STATE
                                        #endregion

                                        #region Configure Sharing With External Party
                                        SPList shareWithExternalUsersList = caseWeb.GetListByInternalName("ShareWithExternalUsers");
                                        shareWithExternalUsersList.BreakRoleInheritance(false);
                                        shareWithExternalUsersList.TryGrantPermission(ownersGroup, fullControl);
                                        shareWithExternalUsersList.TryGrantPermission(participantsGroup, contributor);
                                        shareWithExternalUsersList.TryGrantPermission(externalSharingGroup, reader);
                                        #endregion

                                        ConfigureItemPermissions(item, caseWeb, assignedTo, supervisor);

                                        #region Configure Group Permissions on Root Web
                                        //bool allowunsafeupdate = web.AllowUnsafeUpdates;
                                        //web.AllowUnsafeUpdates = true;
                                        //SPRoleDefinition topreader;
                                        //web.TryGetRoleDefinition("Read", out topreader);
                                        //web.TryGrantPermission(ownersGroup, topreader);
                                        //web.TryGrantPermission(participantsGroup, topreader);
                                        //web.TryGrantPermission(reviewersGroup, topreader);
                                        //web.Update();
                                        //web.AllowUnsafeUpdates = allowunsafeupdate;
                                        #endregion

                                        #region Configure eCase Statuses List Permissions
                                        //SPList statusList = web.GetListByInternalName("eCaseStatuses");
                                        //if (!statusList.HasUniqueRoleAssignments)
                                        //{
                                        //    statusList.BreakRoleInheritance(true);
                                        //    statusList.Update();
                                        //}
                                        //statusList.TryGrantPermission(ownersGroup, topreader);
                                        //statusList.TryGrantPermission(participantsGroup, topreader);
                                        //statusList.TryGrantPermission(reviewersGroup, topreader);
                                        //statusList.Update();
                                        #endregion

                                        UpdateDefaultAspx(item, caseWeb);

                                        // Record item guid in caseweb's property bag so methods can find the parent item easily
                                        caseWeb.AddProperty(eCaseConstants.PropertyBagKeys.ECASE_CASE_LIST_ITEM_GUID, item.UniqueId.ToString());
                                        caseWeb.Update();

                                        try
                                        {
                                            _connectionString = web.Properties[eCaseConstants.PropertyBagKeys.ECASE_DB_CONNECTION_STRING];
                                            using (DbAdapter dbAdapter = new DbAdapter())
                                            {
                                                dbAdapter.Connect(_connectionString);

                                                try
                                                {
                                                    #region Add Case Site Info to eCaseManagement Database
                                                    Guid siteGuid             = caseWeb.Site.ID;
                                                    Guid caseWebGuid          = caseWeb.ID;
                                                    Guid activitiesTasksGuid  = caseWeb.GetListByInternalName(eCaseConstants.ListInternalNames.ACTIVITIES_AND_TASKS).ID;
                                                    Guid caseRelatedDatesGuid = caseWeb.GetListByInternalName(eCaseConstants.ListInternalNames.CASE_RELATED_DATES).ID;

                                                    CreateCaseWebSProc sProc = new CreateCaseWebSProc(siteGuid, item.UniqueId, caseWebGuid, activitiesTasksGuid, caseRelatedDatesGuid);
                                                    dbAdapter.ExecuteNonQueryStoredProcedure(sProc);
                                                    #endregion
                                                }
                                                catch (Exception x)
                                                { Logger.Instance.Error(string.Format("Failed while recording new CaseWeb at {0} in database", caseWeb.Url), x, DiagnosticsCategories.eCaseSite); }

                                                if (lockCase)
                                                {
                                                    LockCaseSite(item, caseWeb, dbAdapter);
                                                }
                                            }
                                        }
                                        catch (Exception x)
                                        { Logger.Instance.Error(string.Format("Failed while accessing database at {0} with connection string {1}", caseWeb.Url, _connectionString), x, DiagnosticsCategories.eCaseSite); }

                                        caseWebUrl = string.Format("{0}, {1}", caseWeb.Url, "View Case");
                                    }
                                }
                                catch (Exception x)
                                {
                                    caseWebUrl = string.Format("{0}/_layouts/1033/error.htm, {1}", web.Url, "ERROR!");
                                    Logger.Instance.Error(string.Format("Failed to create Case Web for {0}", uniqueCaseId), x, DiagnosticsCategories.eCaseSite);
                                    if (web.Webs[uniqueUrl].Exists)
                                    {
                                        RemoveCaseWeb(properties, uniqueUrl);
                                    }

                                    throw x;
                                }
                                finally
                                {
                                    item[eCaseConstants.FieldGuids.ECASES_LIST_CASEURL] = caseWebUrl;
                                    item.SystemUpdate(); // Update the change in the DB using the system account
                                }
                            }
                            catch (Exception x)
                            {
                                Logger.Instance.Error(string.Format("Failed to create Case Web for {0}", uniqueUrl), x, DiagnosticsCategories.eCaseSite);
                                throw x;
                            }
                        }
                    }
                });
            }
            catch (Exception x)
            { throw x; }
            finally
            { this.EventFiringEnabled = true; }
        }
Ejemplo n.º 5
0
        public override void ItemUpdating(SPItemEventProperties properties)
        {
            try
            {
                // This represents the item as it WAS, not as it WILL BE
                SPListItem item = properties.ListItem;
                SPUser     prevAssignedToUser = null;
                SPUser     prevSupervisorUser = null;

                #region Determine Locking Behavior
                bool       newLockCase, oldLockCase, lockCase, unlockCase;
                SPListItem oldCaseStatusItem = properties.ListItem.GetFieldLookupAsSPListItem("CaseStatusLookup");
                SPListItem newCaseStatusItem = properties.AfterProperties.GetFieldLookupAsSPListItem("CaseStatusLookup", properties.List);

                if (bool.TryParse(newCaseStatusItem[eCaseConstants.FieldGuids.ECASE_STATUSES_LOCK_SITE].ToString(), out newLockCase) &&
                    bool.TryParse(oldCaseStatusItem[eCaseConstants.FieldGuids.ECASE_STATUSES_LOCK_SITE].ToString(), out oldLockCase))
                {
                    if (string.Compare(newCaseStatusItem[eCaseConstants.FieldGuids.OOTB_TITLE].ToString(), oldCaseStatusItem[eCaseConstants.FieldGuids.OOTB_TITLE].ToString()) != 0)
                    {
                        if (oldLockCase && !newLockCase) // If the status was locked, and now not, lets unlock
                        {
                            unlockCase = true;
                            lockCase   = false;
                        }
                        else if (oldLockCase && newLockCase) // If the status was locked, and still locked, do nothing
                        {
                            lockCase = unlockCase = false;
                        }
                        else if (!oldLockCase && newLockCase) // If the status was not locked, and now is locked, need to lock
                        {
                            unlockCase = false;
                            lockCase   = true;
                        }
                        else // !oldLockCase && !lockCase -- do nothing
                        {
                            lockCase = unlockCase = false;
                        }
                    }
                    else // the status didn't change
                    {
                        lockCase = unlockCase = false;
                    }
                }
                else // Something's wrong if we cannot parse one
                {
                    throw new InvalidOperationException("Cannot parse Case Status Values");
                }
                #endregion

                string caseWebUrl = item[eCaseConstants.FieldGuids.ECASES_LIST_CASEURL].ToString().Split(',')[0];

                SPSite site;
                SPWeb  caseWeb;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (site = new SPSite(caseWebUrl))
                    {
                        using (caseWeb = site.OpenWeb())
                        {
                            SPUser assignedToUser = null;
                            SPUser supervisorUser = null;
                            GetAssignedToAndSupervisor(item, properties.AfterProperties, caseWeb, ref assignedToUser, ref prevAssignedToUser, ref supervisorUser, ref prevSupervisorUser);
                            if (assignedToUser != null || supervisorUser != null)
                            {
                                UpdateProxyGroups(caseWeb, assignedToUser, supervisorUser, prevAssignedToUser, prevSupervisorUser);
                            }
                        }
                    }
                });

                if (prevAssignedToUser == null)
                {
                    prevAssignedToUser = item.GetFieldAsSPUser(eCaseConstants.FieldGuids.OOTB_ASSIGNEDTO);
                }
                if (prevSupervisorUser == null)
                {
                    prevSupervisorUser = item.GetFieldAsSPUser(eCaseConstants.FieldGuids.ECASES_LIST_ASSIGNEDTOSUPERVISOR);
                }

                if (item.DoesUserHavePermissions(SPBasePermissions.ManagePermissions))
                {
                    item.TryRemovePermissions(prevAssignedToUser);
                    item.TryRemovePermissions(prevSupervisorUser);
                }
                else // We need to elevate to do this
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (site = new SPSite(properties.SiteId))
                        {
                            using (SPWeb rootWeb = site.OpenWeb())
                            {
                                SPList list  = rootWeb.GetListByInternalName(properties.List.RootFolder.Name);
                                SPListItem i = list.GetItemById(item.ID);
                                i.TryRemovePermissions(prevAssignedToUser);
                                i.TryRemovePermissions(prevSupervisorUser);
                            }
                        }
                    });
                }

                if (lockCase || unlockCase)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (site = new SPSite(caseWebUrl))
                        {
                            using (caseWeb = site.OpenWeb())
                            {
                                using (DbAdapter dbAdapter = new DbAdapter())
                                {
                                    SPList list  = site.RootWeb.GetListByInternalName(properties.List.RootFolder.Name);
                                    SPListItem i = list.GetItemById(item.ID);

                                    _connectionString = site.RootWeb.Properties[eCaseConstants.PropertyBagKeys.ECASE_DB_CONNECTION_STRING];
                                    dbAdapter.Connect(_connectionString);
                                    if (lockCase)
                                    {
                                        LockCaseSite(i, caseWeb, dbAdapter);
                                    }
                                    else
                                    {
                                        UnlockCaseSite(i, caseWeb, dbAdapter);
                                    }
                                }
                            }
                        }
                    });
                }
            }
            catch (Exception x) { Logger.Instance.Error("Error in Cases list ItemUpdating", x, DiagnosticsCategories.eCaseSite); }
        }