Ejemplo n.º 1
0
 protected virtual void OnExportError(TableInfo table, Exception ex)
 {
     args.Table    = table;
     args.Duration = timer.Elapsed;
     args.Error    = ex;
     ExportError?.Invoke(this, args);
 }
        public void ExcuteWorker(IEnumerable <int> rouIdList)
        {
            //返回现场
            BackToLastExport();
            foreach (var rid in rouIdList)
            {
                try
                {
                    if (SignalConfig.IsStop)
                    {
                        Console.WriteLine("收到停止导入命令,当前导入id(当前id未导入):" + rid);
                        return;
                    }
                    //time.Marke("6.导入活动数据+用户数据", rid.ToString());
                    if (ExportAct(rid))
                    {
                        //time.Marke("7.设置redisKey", rid.ToString());
                        _redisHelper.StringSet(SUCCESSACTIDQUEUEKEY, rid.ToString(), 60 * 60 * 24 * 3);
                    }
                    else
                    {
                        //time.Marke("8.该活动导入数据失败了", rid.ToString());
                        Console.WriteLine(rid + "该活动导入数据失败了");
                        //加入日志
                        ExportError error = new ExportError()
                        {
                            RowId    = rid.ToString(),
                            ErrorMsg = "该活动导入数据失败了111"
                        };

                        //time.Marke("9.开始插入失败日志", rid.ToString());
                        _exportErrorRepository.Insert(error);
                        //time.Marke("10.失败日志插入完成", rid.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //加入错误队列
                    //_redisHelper.ListRightPush(SUCCESSACTIDQUEUEKEY, actId.ToString());
                    Console.WriteLine(rid + "该活动导入数据出错了,错误原因:" + ex.Message);
                    //加入日志
                    ExportError error = new ExportError()
                    {
                        RowId            = rid.ToString(),
                        ErrorMsg         = ex.Message,
                        OperateException = ex.ToString()
                    };
                    //time.Marke("11.开始插入异常日志", rid.ToString());
                    _exportErrorRepository.Insert(error);
                    //time.Marke("12.异常日志插入完成", rid.ToString());
                }
                //一个活动保存一次
                time.SaveData(rid);
            }
        }
        private void VerifyExportErrorString(IConversation conversation, Exception ex, string descriptionExpected)
        {
            ExportError exportError = new ExportError(conversation, ex);
            var mockDescriptionHelper = new Mock<IConversationDescriptionHelper>();

            mockDescriptionHelper.Setup(x => x.GetDescription(It.IsAny<IConversation>()))
                .Returns("<some conversation>");

            ExportErrorFormatter errorFormatter = new ExportErrorFormatter(mockDescriptionHelper.Object);
            string descriptionActual = errorFormatter.Format(exportError);
            Assert.AreEqual(descriptionExpected, descriptionActual);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Вызвать событие <see cref="ExportError"/>.
        /// </summary>
        /// <param name="exception">Ошибка соединения.</param>
        private void RaiseExportError(Exception exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            ExportState = ConnectionStates.Failed;
            ExportError.SafeInvoke(exception);

            this.AddErrorLog(exception);
        }
        private void VerifyExportErrorString(IConversation conversation, Exception ex, string descriptionExpected)
        {
            ExportError exportError           = new ExportError(conversation, ex);
            var         mockDescriptionHelper = new Mock <IConversationDescriptionHelper>();

            mockDescriptionHelper.Setup(x => x.GetDescription(It.IsAny <IConversation>()))
            .Returns("<some conversation>");

            ExportErrorFormatter errorFormatter = new ExportErrorFormatter(mockDescriptionHelper.Object);
            string descriptionActual            = errorFormatter.Format(exportError);

            Assert.AreEqual(descriptionExpected, descriptionActual);
        }
        public void ReExportErrorData()
        {
            List <ExportError> errorActList = _exportErrorRepository.GetAllList();

            if (errorActList.Any())
            {
                foreach (var act in errorActList)
                {
                    try
                    {
                        SignActivity signActEntity = _signActRepositoryMongo.FirstOrDefault(m => m.RowId == Convert.ToInt32(act.RowId));
                        DeleteActData(signActEntity.RowId, signActEntity.ActID);
                        if (ExportAct(signActEntity.RowId))
                        {
                            _exportErrorRepository.Delete(t => t.RowId == signActEntity.RowId.ToString());
                        }
                        else
                        {
                            //加入错误队列
                            Console.WriteLine(signActEntity.RowId + "该活动导入数据出错了");
                            //加入日志
                            ExportError error = new ExportError()
                            {
                                RowId    = act.RowId,
                                ErrorMsg = "该活动导入数据失败了111"
                            };
                            _exportErrorRepository.Insert(error);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(act.RowId + "该活动导入数据出错了,错误原因:" + ex.Message);
                        //加入日志
                        ExportError error = new ExportError()
                        {
                            RowId            = act.RowId,
                            ErrorMsg         = ex.Message,
                            OperateException = ex.ToString()
                        };
                        _exportErrorRepository.Insert(error);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Checks if the Glyma Export Timer Job exists in the current web pplicatio for the site.
        /// </summary>
        /// <returns>True if the site's Web Application has the Glyma Export Timer Job (i.e. the Web Application featrue is enabled that installs the timer job)</returns>
        public ExportAvailabilityResponse IsExportingAvailable()
        {
            ExportAvailabilityResponse response = new ExportAvailabilityResponse()
            {
                IsAvailable = false
            };

            try
            {
                Guid webID  = SPContext.Current.Web.ID;
                Guid siteID = SPContext.Current.Site.ID;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(siteID))
                    {
                        if (site != null)
                        {
                            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
                            {
                                if (job.Name == GlymaExportWorkItemTimerJob.JobName)
                                {
                                    response.IsAvailable = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("The SPSite was null.");
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                ExportError error = new ExportError()
                {
                    ErrorMessage = "Failed to read if exporting was available."
                };
                throw new FaultException <ExportError>(error, ex.Message);
            }
            return(response);
        }
        /// <summary>
        ///导出活动以及活动设置数据
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        public bool ExportAct(int rid)
        {
            //time.Marke("24.执行查询活动的信息 select top 1 * from SignPointActivity where  ID=@id;select  * from   SignPointSet where  ActivityID=@id ", rid.ToString());
            List <IEnumerable <object> > queryList = _signPointActivityRepository.QueryMultiple(
                "select top 1 * from SignPointActivity where  ID=@id;select  * from   SignPointSet where  ActivityID=@id",
                new { id = rid }, typeof(SignPointActivityDto), typeof(SignPointSetDto));
            //time.Marke("25.结束查询活动的信息 select top 1 * from SignPointActivity where  ID=@id;select  * from   SignPointSet where  ActivityID=@id ", rid.ToString());

            SignPointActivityDto signAct = (SignPointActivityDto)queryList[0].FirstOrDefault();
            //IEnumerable<SignPointSetDto> actSetList =(IEnumerable<SignPointSetDto>) queryList[1];
            List <SignPointSetDto> actSetList = new List <SignPointSetDto>();

            //time.Marke("26.循环更改SignPointSetDto数据结构", rid.ToString());
            foreach (var item in queryList[1])
            {
                actSetList.Add((SignPointSetDto)item);
            }
            //time.Marke("27.循环更改SignPointSetDto数据结构结束", rid.ToString());


            //time.Marke("28.SignActivity map过程开始", rid.ToString());
            SignActivity signActEntity = signAct.MapTo <SignActivity>();

            //time.Marke("29.SignActivity map过程结束", rid.ToString());

            if (signAct != null)
            {
                signActEntity.Id         = signAct.ActID.ToString();
                signActEntity.ActID      = signActEntity.Id;
                signActEntity.RowId      = rid;
                signActEntity.CreateTime = signAct.Addtime;
            }


            if (actSetList == null || !actSetList.Any())
            {
                //time.Marke("30.活动奖项不存在异常开始", rid.ToString());
                //throw new ArgumentException("活动奖项不存在。");
                //日志记录
                ExportError error = new ExportError()
                {
                    RowId            = rid.ToString(),
                    ErrorMsg         = rid + "活动没有奖项信息",
                    OperateException = ""
                };
                _exportErrorRepository.Insert(error);

                //time.Marke("31.活动奖项不存在异常结束", rid.ToString());
                return(false);
            }

            List <SignPointSetEntity> setEntityList = new List <SignPointSetEntity>();

            //time.Marke("32.循环添加对象List<SignPointSetEntity>转换开始", rid.ToString());
            foreach (var set in actSetList)
            {
                var temp = set.MapTo <SignPointSetEntity>();
                temp.ActID = signActEntity.Id;
                setEntityList.Add(temp);
            }

            //time.Marke("33.循环添加对象List<SignPointSetEntity>转换结束", rid.ToString());

            signActEntity.SignPointSet = setEntityList;

            //time.Marke("34.判断插入的数据是否重复开始", rid.ToString());

            //插入数据到mongoDB
            if (_signActRepositoryMongo.FirstOrDefault(signActEntity.Id) == null)
            {
                //time.Marke("35.判断插入的数据是否重复结束", rid.ToString());

                //time.Marke("36.插入活动信息开始", rid.ToString());
                //插入活动
                _signActRepositoryMongo.Insert(signActEntity);
                //time.Marke("37.插入活动信息结束", rid.ToString());

                //time.Marke("38.填入库存缓存数据到redis开始", rid.ToString());
                //填入库存缓存数据到redis
                //ExportCacheData(setEntityList, rid);
                //time.Marke("39.填入库存缓存数据到redis结束", rid.ToString());
                //time.Marke("40.插入用户签到,领奖记录开始", rid.ToString());
                //插入用户签到,领奖记录
                //ExportUserSign(rid, signActEntity.Id);
                //time.Marke("41.插入用户签到,领奖记录结束", rid.ToString());
                return(true);
            }
            else
            {
                Console.WriteLine(rid + "活动数据重复导入");
                //ExportError error = new ExportError()
                //{ rid = rid.ToString(), ErrorMsg = rid + "活动数据重复导入", OperateException = "" };
                //_exportErrorRepository.Insert(error);
                return(true);
            }
            return(true);
        }
Ejemplo n.º 9
0
 public string Format(ExportError exportError)
 {
     string errorHeader = CreateErrorMessagePrefix(exportError.Conversation);
     return string.Format("{0}: ({1}) {2}", errorHeader, exportError.Error.GetType().ToString(), exportError.Error.Message);
 }
Ejemplo n.º 10
0
 private void ExportErrorHandler(Exception exception)
 {
     AddGuiAction(() => ExportError.SafeInvoke(exception));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the ExportJobs for the particular map schema type for a domain and root map.
        /// </summary>
        /// <param name="mapType">OPTIONALLY: The map schema type</param>
        /// <param name="domainUid">The DomainUid for the exports</param>
        /// <param name="rootMapUid">The RootMapUid for the exports</param>
        /// <returns>A list of all the ExportJobs that match the criteria supplied as arguments</returns>
        private ExportJobsResponse GetExportJobsImp(MapType?mapType, Guid domainUid, Guid rootMapUid)
        {
            ExportJobsResponse response = new ExportJobsResponse();

            response.ExportJobs = new Dictionary <Guid, ExportJob>();

            try
            {
                Guid webID  = SPContext.Current.Web.ID;
                Guid siteID = SPContext.Current.Site.ID;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(siteID))
                    {
                        using (SPWeb web = site.OpenWeb(webID))
                        {
                            if (web != null)
                            {
                                SPList exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports"); //TODO get the name from a constant
                                if (exportsList != null)
                                {
                                    SPQuery query = new SPQuery();
                                    if (mapType.HasValue)
                                    {
                                        query.Query = "<Where><And><And>" +
                                                      "<Eq><FieldRef Name='DomainUid' /><Value Type='Text'>" + domainUid.ToString() + "</Value></Eq>" +
                                                      "<Eq><FieldRef Name='RootMapUid' /><Value Type='Text'>" + rootMapUid.ToString() + "</Value></Eq>" +
                                                      "</And><Eq><FieldRef Name='MapType' /><Value Type='Text'>" + mapType.ToString() + "</Value></Eq></And></Where>" +
                                                      "<OrderBy><FieldRef Name='Created' Ascending='TRUE'></FieldRef></OrderBy>";
                                    }
                                    else
                                    {
                                        query.Query = "<Where><And>" +
                                                      "<Eq><FieldRef Name='DomainUid' /><Value Type='Text'>" + domainUid.ToString() + "</Value></Eq>" +
                                                      "<Eq><FieldRef Name='RootMapUid' /><Value Type='Text'>" + rootMapUid.ToString() + "</Value></Eq>" +
                                                      "</And></Where>" +
                                                      "<OrderBy><FieldRef Name='Created' Ascending='TRUE'></FieldRef></OrderBy>";
                                    }
                                    //get the exports for this domain/rootmap in ascending order
                                    SPListItemCollection exports = exportsList.GetItems(query);
                                    foreach (SPListItem export in exports)
                                    {
                                        ExportJob exportJob = GetExportJob(export);
                                        response.ExportJobs.Add(exportJob.Id, exportJob);

                                        if (exportJob.Status == ExportStatus.Error)
                                        {
                                            //maintenance task if the export job had an error clear the TimerJobWorkItem if it was left behind
                                            CleanupErrorWorkItems(exportJob, site, web);
                                        }
                                    }
                                }
                                else
                                {
                                    throw new Exception("Failed to find the Glyma Exports list.");
                                }
                            }
                            else
                            {
                                throw new Exception("The SPWeb was not found.");
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                ExportError error = new ExportError()
                {
                    ErrorMessage = "Failed to get the export jobs for the site."
                };
                throw new FaultException <ExportError>(error, ex.ToString());
            }

            return(response);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Deletes an ExportJob if it's in the Scheduled, Completed, or Error ExportStates.
        /// </summary>
        /// <param name="job">The ExportJob to delete</param>
        /// <returns>The ExportJob that was deleted</returns>
        public ExportJobResponse DeleteExportJob(ExportJob job)
        {
            ExportJobResponse response = new ExportJobResponse();

            try
            {
                Guid webID  = SPContext.Current.Web.ID;
                Guid siteID = SPContext.Current.Site.ID;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPList exportsList = null;
                    using (SPSite site = new SPSite(siteID))
                    {
                        using (SPWeb web = site.OpenWeb(webID))
                        {
                            if (web != null && site != null)
                            {
                                exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports");
                                if (exportsList != null)
                                {
                                    SPQuery query = new SPQuery();
                                    query.Query   = "<Where>" +
                                                    "<Eq><FieldRef Name='Title' /><Value Type='Text'>" + job.Id.ToString() + "</Value></Eq>" +
                                                    "</Where>";
                                    SPListItemCollection exports = exportsList.GetItems(query);
                                    // There can only be one ExportJob with the job ID (unique values enforced in SP list for Title column)
                                    if (exports.Count > 0)
                                    {
                                        SPListItem exportItem = exports[0];
                                        if (exportItem != null)
                                        {
                                            string exportStatusStr    = exportItem["ExportStatus"] as string;
                                            ExportStatus exportStatus = (ExportStatus)Enum.Parse(typeof(ExportStatus), exportStatusStr, true);

                                            if (exportStatus == ExportStatus.Scheduled)
                                            {
                                                SPWorkItemCollection workItemsCollection = new SPWorkItemCollection(site, GlymaExportWorkItemTimerJob.WorkItemTypeId);
                                                uint colCount, rowCount = 0;
                                                object workItems        = null;
                                                site.GetWorkItems(workItemsCollection, out colCount, out rowCount, out workItems); //gets all work items for this site of the type GlymaExportWorkItemTimerJob
                                                if (workItemsCollection.Count > 0)
                                                {
                                                    // Delete the work item that this export job created
                                                    SPWorkItemCollection subCollection = workItemsCollection.SubCollection(site, web, 0, (uint)workItemsCollection.Count);
                                                    subCollection.DeleteWorkItem(job.Id);
                                                }
                                            }

                                            if (exportStatus == ExportStatus.Scheduled || exportStatus == ExportStatus.Completed || exportStatus == ExportStatus.Error)
                                            {
                                                exportItem.Delete(); //delete the item after it has been cancelled
                                            }
                                            else if (exportStatus == ExportStatus.Processing)
                                            {
                                                throw new Exception("The export job is currently processing and cannot be deleted.");
                                            }
                                        }
                                        response.ExportJob = job;
                                    }
                                }
                                else
                                {
                                    throw new Exception("Failed to find the Glyma Exports list.");
                                }
                            }
                            else
                            {
                                throw new Exception("The SPSite and/or the SPWeb were null.");
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                ExportError error = new ExportError()
                {
                    ErrorMessage = "Failed to cancel the Glyma map export job."
                };
                throw new FaultException <ExportError>(error, ex.ToString());
            }

            return(response);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates an ExportJob and schedules the WorkItem for the timer job that processes the exports.
        /// </summary>
        /// <param name="domainUid">The DominUid for the map being exported</param>
        /// <param name="rootMapUid">The RootMapUid for the map being exported</param>
        /// <param name="exportProperties">The export properties for the export</param>
        /// <param name="mapType">The map type (schema) for the map being exported</param>
        /// <param name="exportType">The output format for the export</param>
        /// <returns>The ExportJob that was created</returns>
        public ExportJobResponse CreateExportJob(Guid domainUid, Guid rootMapUid, IDictionary <string, string> exportProperties, MapType mapType, ExportType exportType)
        {
            ExportJobResponse response = new ExportJobResponse();

            try
            {
                Guid   webID       = SPContext.Current.Web.ID;
                Guid   siteID      = SPContext.Current.Site.ID;
                SPUser currentUser = null;
                using (SPSite site = new SPSite(siteID))
                {
                    using (SPWeb web = site.OpenWeb(webID))
                    {
                        if (web != null)
                        {
                            currentUser = web.CurrentUser;
                        }
                    }
                }
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    int userId         = -1;
                    SPList exportsList = null;
                    int listItemIdNum  = -1;

                    using (SPSite site = new SPSite(siteID))
                    {
                        using (SPWeb web = site.OpenWeb(webID))
                        {
                            if (web != null)
                            {
                                if (currentUser == null)
                                {
                                    //The current user shouldn't be null, it should have been resolved outside of this RunWithElevatedPrivileges delegate
                                    currentUser = web.CurrentUser;
                                }
                                if (currentUser != null)
                                {
                                    userId = currentUser.ID;

                                    exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports"); //TODO get the name from a constant
                                    if (exportsList != null)
                                    {
                                        //the text payload will contain the properties serialized into a simple XML format
                                        ExportPropertiesDictionary serializableDict = new ExportPropertiesDictionary(exportProperties);
                                        string textPayload = serializableDict.ConvertToXml();

                                        Guid workItemId = Guid.NewGuid(); // Create a unique id for the work item and export job
                                        listItemIdNum   = CreateExportJobListEntry(exportsList, domainUid, rootMapUid, mapType, exportType, workItemId, textPayload, userId);

                                        // if the list item was created then create the export job, if it wasn't it was because an export
                                        // for this particular root map of this type was already scheduled (changing the properties doesn't have effect)
                                        if (listItemIdNum != -1)
                                        {
                                            site.AddWorkItem(workItemId,                                            //gWorkItemId - A Guid that identifies the work item
                                                             DateTime.Now.ToUniversalTime(),                        //schdDateTime - represents a time in universal time for when the work item should take place
                                                             GlymaExportWorkItemTimerJob.WorkItemTypeId,            //gWorkItemType - this must be the GUID used in the GlymaExportWorkItemTimerJob
                                                             web.ID,                                                //gWebId - The identifier of the web containing the list
                                                             exportsList.ID,                                        //gParentId - The list ID
                                                             listItemIdNum,                                         //nItemId - The list item ID number
                                                             true,                                                  //fSetWebId - true to set the Web identifier
                                                             exportsList.Items.GetItemById(listItemIdNum).UniqueId, //gItemGuid - The unique identifier of the list item
                                                             domainUid,                                             //gBatchId - A Guid context identifier for the work item engine
                                                             userId,                                                //nUserId - SPUser ID number
                                                             null,                                                  //rgbBinaryPayload - not used
                                                             textPayload,                                           //strTextPayload
                                                             Guid.Empty);                                           //gProcessingId - needs to be Guid.Empty

                                            ExportJob scheduledJob = new ExportJob();
                                            scheduledJob.Created   = (DateTime)exportsList.Items.GetItemById(listItemIdNum)[SPBuiltInFieldId.Created];
                                            scheduledJob.CreatedBy = new GlymaUser()
                                            {
                                                Name = currentUser.Name
                                            };
                                            scheduledJob.Id                 = workItemId;
                                            scheduledJob.IsCurrent          = true;
                                            scheduledJob.Status             = ExportStatus.Scheduled;
                                            scheduledJob.Type               = exportType;
                                            scheduledJob.MapType            = mapType;
                                            scheduledJob.ExportProperties   = exportProperties;
                                            scheduledJob.PercentageComplete = 0;
                                            response.ExportJob              = scheduledJob;
                                        }
                                        else
                                        {
                                            //already scheduled so throw an exception to be handled with an error
                                            throw new Exception(string.Format("A scheduled export job already exists for the Glyma map: DomainUid: {0}, RootMapUid: {1}, Export Type: {2}, Map Type: {3}",
                                                                              domainUid.ToString(), rootMapUid.ToString(), exportType.ToString(), mapType.ToString()));
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("Failed to find the Glyma Exports list.");
                                    }
                                }
                                else
                                {
                                    throw new Exception("The current user was not able to be determined.");
                                }
                            }
                            else
                            {
                                throw new Exception("The SPSite and/or the SPWeb were null.");
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                ExportError error = new ExportError()
                {
                    ErrorMessage = "Failed to create the Glyma map export job."
                };
                throw new FaultException <ExportError>(error, ex.ToString());
            }

            return(response);
        }