Exemplo n.º 1
0
        private static void ScanSubWeb(ClientContext context, string webUrl, Microsoft.SharePoint.Client.TimeZone rootTimeZone, List <ListInfo> listsInfo)
        {
            var web = context.Site.OpenWeb(webUrl);

            context.Load(web, w => w.Url, w => w.RegionalSettings.TimeZone);
            context.ExecuteQuery();

            logger.InfoFormat("Start scan {0}", web.Url);
            if (web.RegionalSettings.TimeZone.Id != rootTimeZone.Id)
            {
                context.Load(web.Lists, lists => lists.Include(
                                 l => l.BaseType,
                                 l => l.Id,
                                 l => l.RootFolder.ServerRelativeUrl,
                                 l => l.Title,
                                 l => l.Hidden,
                                 l => l.MajorVersionLimit,
                                 l => l.EnableVersioning,
                                 l => l.EnableMinorVersions,
                                 l => l.MajorWithMinorVersionsLimit,
                                 l => l.EnableModeration,
                                 l => l.ItemCount));
                context.ExecuteQuery();
                foreach (var list in web.Lists)
                {
                    if (list.BaseType == BaseType.DocumentLibrary && list.Hidden == false && list.ItemCount > 0)
                    {
                        var listInfo = new ListInfo
                        {
                            WebUrl = web.Url,
                            listId = list.Id,
                            EnableMinorVersions         = list.EnableMinorVersions,
                            EnableModeration            = list.EnableModeration,
                            EnableVersioning            = list.EnableVersioning,
                            ItemCount                   = list.ItemCount,
                            ListTitle                   = list.Title,
                            MajorVersionLimit           = list.MajorVersionLimit,
                            MajorWithMinorVersionsLimit = list.MajorWithMinorVersionsLimit,
                            BigList = list.ItemCount >= 5000
                        };
                        listsInfo.Add(listInfo);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static List <Complaint> GetAllComplaintsData(UserInfo userInfo)
 {
     try
     {
         using (var clientContext = new ClientContext("http://cmlbi.za.omlac.net/sites/gladius"))
         {
             List <Complaint> compdata = new List <Complaint>();
             var complaintListNames    = userInfo.userMasters.Select(x => x.ClListName).Distinct();
             foreach (var complaintListName in complaintListNames)
             {
                 List      announcementsList = clientContext.Web.Lists.GetByTitle(complaintListName);
                 CamlQuery query             = new CamlQuery();
                 query.ViewXml = CamlQueryConstants.GetAllComplaintsDataQuery;
                 ListItemCollection items = announcementsList.GetItems(query);
                 clientContext.Load(items);
                 clientContext.ExecuteQuery();
                 foreach (ListItem listItem in items)
                 {
                     Microsoft.SharePoint.Client.TimeZone timeZoneSP = clientContext.Web.RegionalSettings.TimeZone;
                     clientContext.Load(timeZoneSP);
                     clientContext.ExecuteQuery();
                     var       fixedTimeZoneName = timeZoneSP.Description.Replace("and", "&");
                     var       timeZoneInfo      = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(tz => tz.DisplayName == fixedTimeZoneName);
                     var       row              = userInfo?.userMasters?.FirstOrDefault(x => x.ClListName == complaintListName);
                     string    rcaListName      = row?.RcaListName;
                     string    seg              = row?.Segment;
                     bool      pemissiontoWrite = CheckPermission(clientContext, complaintListName, userInfo.Groups);
                     Complaint result           = MapComplaint(complaintListName, listItem, timeZoneInfo, rcaListName, pemissiontoWrite, seg);
                     compdata.Add(result);
                 }
             }
             if (compdata.Count > 0)
             {
                 compdata = compdata.OrderByDescending(x => x.DateReceived).ToList();
             }
             return(compdata);
         }
     }
     catch (Exception ex)
     {
         //log to list
         throw new ArgumentException("Something went wrong: " + ex.Message);
     }
 }
Exemplo n.º 3
0
 public static Complaint GetComplaint(int id, string cllistName, string seg)
 {
     try
     {
         using (var clientContext = new ClientContext("http://cmlbi.za.omlac.net/sites/gladius"))
         {
             List   complaints = clientContext.Web.Lists.GetByTitle(cllistName);
             string query      = string.Format(CamlQueryConstants.GetComplaintQuery, id);
             var    q          = new CamlQuery()
             {
                 ViewXml = query
             };
             ListItemCollection items = complaints.GetItems(q);
             Microsoft.SharePoint.Client.TimeZone timeZoneSP = clientContext.Web.RegionalSettings.TimeZone;
             clientContext.Load(timeZoneSP);
             clientContext.Load(items);
             clientContext.ExecuteQuery();
             ListItem listItem          = items.FirstOrDefault(x => x.Id == id);
             var      fixedTimeZoneName = timeZoneSP.Description.Replace("and", "&");
             var      timeZoneInfo      = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(tz => tz.DisplayName == fixedTimeZoneName);
             var      result            = new Complaint()
             {
                 Reference              = Convert.ToString(listItem[ListColumnConstants.CompRef]),
                 EmsCaseReference       = Convert.ToString(listItem[ListColumnConstants.EMSCaseRef]),
                 MailboxName            = Convert.ToString(listItem[ListColumnConstants.MailboxName]),
                 MemberCode             = Convert.ToString(listItem[ListColumnConstants.MemCode]),
                 Surname                = Convert.ToString(listItem[ListColumnConstants.Surname]),
                 SchemePolicyContractNo = Convert.ToString(listItem[ListColumnConstants.SchmePlcyContractNo]),
                 Source                    = Convert.ToString(listItem[ListColumnConstants.Source]),
                 SourceType                = Convert.ToString(listItem[ListColumnConstants.CompSourceType]),
                 DepartmentInvolved        = Convert.ToString(listItem[ListColumnConstants.DeptInvolved]),
                 RelatedProcess            = Convert.ToString(listItem[ListColumnConstants.ReltdProcess]),
                 Levels                    = Convert.ToString(listItem[ListColumnConstants.Levels]),
                 PreviousLevelComp         = Convert.ToString(listItem[ListColumnConstants.PrevLevel1Comp]),
                 DateReceived              = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(listItem[ListColumnConstants.DateTimeReceived]), timeZoneInfo),
                 ExtensionRequested        = Convert.ToString(listItem[ListColumnConstants.ExtnRequested]),
                 ExtensionRequestedComment = Convert.ToString(listItem[ListColumnConstants.ExtnReqComment]),
                 ProductType               = Convert.ToString(listItem[ListColumnConstants.ProductType]),
                 BenefitType               = Convert.ToString(listItem[ListColumnConstants.BenefitType]),
                 BenefitDetail             = Convert.ToString(listItem[ListColumnConstants.BenefitDetail]),
                 Category                  = Convert.ToString(listItem[ListColumnConstants.CompCategory]),
                 TcfComplaintOutcome       = Convert.ToString(listItem[ListColumnConstants.TCFCompOutcome]),
                 TcfComplaintRelatedTo     = Convert.ToString(listItem[ListColumnConstants.TCFCompReltdTo]),
                 DepartmentAtFault         = Convert.ToString(listItem[ListColumnConstants.DeptAtFault]),
                 RelatedToFund             = Convert.ToString(listItem[ListColumnConstants.ReltdToFund]),
                 Outcome                   = Convert.ToString(listItem[ListColumnConstants.Outcome]),
                 Status                    = Convert.ToString(listItem[ListColumnConstants.Status]),
                 WriteOffAmount            = Convert.ToString(listItem[ListColumnConstants.WriteOffAmtInRands]),
                 RootCauseAnalysis         = Convert.ToString(listItem[ListColumnConstants.RCAnalysis]),
                 ComplaintResponder        = Convert.ToString(listItem[ListColumnConstants.CompRespUser]),
                 ClosedwithinSLA           = Convert.ToString(listItem[ListColumnConstants.ClosedwithinSLA]),
                 RCAFindings               = Convert.ToString(listItem[ListColumnConstants.RCAFindings]),
                 TlComplaintOwner          = Convert.ToString(listItem[ListColumnConstants.TLComplaintOwner]),
                 ComplaintTheme            = Convert.ToString(listItem[ListColumnConstants.ComplaintTheme]),
                 LitigationAction          = Convert.ToString(listItem[ListColumnConstants.RefForLitignLegalAct]),
                 FinancialImpact           = Convert.ToString(listItem[ListColumnConstants.TypeOfFinImpact]),
                 ReasonForSlaBreach        = Convert.ToString(listItem[ListColumnConstants.ReasonSLABreach]),
                 IdNumber                  = Convert.ToString(listItem[ListColumnConstants.CompIDNumber])
             };
             if (listItem[ListColumnConstants.RCACompletionDate] != null)
             {
                 result.RcTargetCompletionDate = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(listItem[ListColumnConstants.RCACompletionDate]), timeZoneInfo);
             }
             if (listItem[ListColumnConstants.QryClosedDateRspnd] != null)
             {
                 result.QueryClosedDate = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(listItem[ListColumnConstants.QryClosedDateRspnd]), timeZoneInfo);
             }
             if (listItem[ListColumnConstants.RenegoDueDate] != null)
             {
                 result.RenegotiatedDueDate = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(listItem[ListColumnConstants.RenegoDueDate]), timeZoneInfo);
             }
             result.SegmentName = seg;
             if (listItem[seg + ListColumnConstants.RCAID] != null)
             {
                 FieldLookupValue lookuprca = listItem[seg + ListColumnConstants.RCAID] as FieldLookupValue;
                 result.RcId = lookuprca.LookupId.ToString();
             }
             if (listItem[ListColumnConstants.TLComplaintOwner] != null)
             {
                 FieldLookupValue lookup = listItem[ListColumnConstants.TLComplaintOwner] as FieldLookupValue;
                 result.TlComplaintOwner = lookup.LookupValue;
             }
             return(result);
         }
     }
     catch (Exception ex)
     {
         throw new ArgumentException("Something went wrong: " + ex.Message);
     }
 }
Exemplo n.º 4
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // parse query parameter
            string siteURL = req.GetQueryNameValuePairs()
                             .FirstOrDefault(q => string.Compare(q.Key, "siteURL", true) == 0)
                             .Value;

            string timeZoneToSet = req.GetQueryNameValuePairs()
                                   .FirstOrDefault(q => string.Compare(q.Key, "timeZone", true) == 0)
                                   .Value;

            // Get request body
            dynamic data = await req.Content.ReadAsAsync <object>();

            if (siteURL == null)
            {
                siteURL = data?.siteURL;
                if (siteURL == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass the siteURL in the request body"));
                }
            }
            if (timeZoneToSet == null)
            {
                timeZoneToSet = data?.timeZone;
                if (timeZoneToSet == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass the timeZone in the request body"));
                }
            }

            // Get access to source site
            using (var ctx = new ClientContext(siteURL))
            {
                var User = Environment.GetEnvironmentVariable("spAdminUser");
                var Psw  = Environment.GetEnvironmentVariable("password");
                //Provide count and pwd for connecting to the source
                var passWord = new SecureString();
                foreach (char c in Psw.ToCharArray())
                {
                    passWord.AppendChar(c);
                }
                ctx.Credentials = new SharePointOnlineCredentials(User, passWord);

                // Actual code for operations
                Web web = ctx.Web;
                Microsoft.SharePoint.Client.TimeZone tz = ctx.Web.RegionalSettings.TimeZone;
                TimeZoneCollection tzc = ctx.Web.RegionalSettings.TimeZones;
                ctx.Load(tz);
                ctx.Load(tzc);
                //ctx.Load(web);
                ctx.ExecuteQuery();

                var timeZone  = tz;
                var timeZones = tzc.Where(x => x.Description == timeZoneToSet).FirstOrDefault();

                ctx.Web.RegionalSettings.TimeZone = timeZones;
                ctx.Web.Update();
                ctx.ExecuteQuery();
                log.Info("New regional settings set {0}", ctx.Web.RegionalSettings.TimeZone.Description);
            }

            return(req.CreateResponse(HttpStatusCode.OK, "The Time Zone is correctly configured"));
        }
        public ProjectOnlineAccessService(string projectOnlineUrl, string projectOnlineUserName,
                                          string projectOnlinePassword, bool isOnline, Guid winServiceIterationUid)
        {
            logger.LogAndSendMessage(null, "ProjectOnlineAccessService START",
                                     null, winServiceIterationUid,
                                     $"ProjectOnlineAccessService START ProjectOnlineUrl: {ProjectOnlineUrl}; " +
                                     $"projectOnlineUserName: {projectOnlineUserName}; projectOnlinePassword: {projectOnlinePassword}; " +
                                     $"isOnline: {isOnline};",
                                     false, null);

            ProjectOnlineUrl            = projectOnlineUrl;
            this.isOnline               = isOnline;
            this.winServiceIterationUid = winServiceIterationUid;
            var securePassword = new SecureString();

            foreach (char c in projectOnlinePassword)
            {
                securePassword.AppendChar(c);
            }
            if (isOnline)
            {
                ProjectContext = new ProjectContext(ProjectOnlineUrl)
                {
                    Credentials = new SharePointOnlineCredentials(projectOnlineUserName, securePassword)
                };
            }
            else
            {
                ProjectContext = new ProjectContext(ProjectOnlineUrl)
                {
                    Credentials = new NetworkCredential(projectOnlineUserName, projectOnlinePassword)
                };
            }
            ProjectContext.RequestTimeout = RequestTimeout;
            ProjectContext.PendingRequest.RequestExecutor.WebRequest.Timeout          = RequestTimeout;
            ProjectContext.PendingRequest.RequestExecutor.WebRequest.ReadWriteTimeout = RequestTimeout;

            //SPClientCallableSettings

            //TODO:!!!!!!!!!!!!!
            //The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." >>
            //"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
            //In my case, this solved the problem: **System.Net.ServicePointManager.Expect100Continue = false; **
            ServicePointManager.Expect100Continue = false;

            //One more solution. Add into Register
            //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ DWORD SynAttackProtect 00000000

            Web web = ProjectContext.Web;
            RegionalSettings regSettings = web.RegionalSettings;

            ProjectContext.Load(web);
            ProjectContext.Load(regSettings); //To get regional settings properties
            Microsoft.SharePoint.Client.TimeZone projectOnlineTimeZone = regSettings.TimeZone;
            ProjectContext.Load(projectOnlineTimeZone);
            //To get the TimeZone propeties for the current web region settings
            ExecuteQuery();
            TimeSpan projectOnlineUtcOffset =
                TimeSpan.Parse(projectOnlineTimeZone.Description.Substring(4,
                                                                           projectOnlineTimeZone.Description.IndexOf(")", StringComparison.Ordinal) - 4));
            ReadOnlyCollection <TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();

            ProjectOnlineTimeZoneInfo =
                timeZones.FirstOrDefault(x => x.BaseUtcOffset == projectOnlineUtcOffset);
            CurrentDateForCompare = ProjectOnlineTimeZoneInfo != null
                ? TimeZoneInfo.ConvertTime(DateTime.Now, ProjectOnlineTimeZoneInfo)
                : DateTime.Now;

            logger.LogAndSendMessage(null, "ProjectOnlineAccessService END",
                                     null, winServiceIterationUid, "ProjectOnlineAccessService END", false, null);
        }