Пример #1
0
        DataSet IUserProfile.GetUserProfile()
        {
            AspectizeUser aspectizeUser = ExecutingContext.CurrentUser;

            IDataManager dm = EntityManager.FromDataBaseService(ServiceName.MyDataService);

            IEntityManager em = dm as IEntityManager;

            if (aspectizeUser.IsAuthenticated)
            {
                var userId = new Guid(aspectizeUser.UserId.ToString());

                User user = dm.GetEntity <User>(userId);

                var roleRelations = new List <IRoleRelationQuery>();

                roleRelations.Add(new RoleRelationQuery <User, BoardUser>());

                dm.LoadEntitiesGraph <User>(roleRelations, userId);

                CurrentUser currentUser = em.CreateInstance <CurrentUser>();

                currentUser.Id = userId;

                em.AssociateInstance <IsUser>(currentUser, user);

                dm.Data.AcceptChanges();
            }

            return(dm.Data);
        }
Пример #2
0
        internal static void BuildStat <T, R>(IDataManager dm, Guid rootId, Events events, Stat stat, DateTime dateTime, string datePeriodFormat)
            where T : Entity, IEntity, IDataWrapper, new()
            where R : DataWrapper, IDataWrapper, IRelation, new()
        {
            IEntityManager em = dm as IEntityManager;

            string periodId = TraceService.GetTimeIdFromDate(rootId, events.Id, dateTime, datePeriodFormat);

            T t = dm.GetEntity <T>(periodId);

            if (t != null)
            {
                em.AssociateInstance <R>(t, events);

                string periodName = typeof(T).Name;

                string columnName       = string.Format("Last{0}Count", periodName);
                string periodColumnName = string.Format("Count{0}", periodName);
                stat.data[columnName] = t.data[periodColumnName];

                columnName            = string.Format("Last{0}Sum", periodName);
                periodColumnName      = string.Format("Sum{0}", periodName);
                stat.data[columnName] = t.data[periodColumnName];
            }
        }
Пример #3
0
        internal static void BuildPeriod <T, R>(IDataManager dm, Guid rootId, Guid eventsId, Trace trace, DateTime datePeriod, string datePeriodFormat)
            where T : Entity, IEntity, IDataWrapper, new()
            where R : DataWrapper, IDataWrapper, IRelation, new()
        {
            IEntityManager em = dm as IEntityManager;

            string timeId = GetTimeIdFromDate(rootId, eventsId, datePeriod, datePeriodFormat);

            T t = em.GetInstance <T>(timeId);

            if (t == null)
            {
                t = dm.GetEntity <T>(timeId);

                if (t == null)
                {
                    t = em.CreateInstance <T>();

                    t.data["Id"]         = timeId;
                    t.data["TimeKey"]    = timeId.Split('|')[2];
                    t.data["DatePeriod"] = datePeriod;
                }
            }

            em.AssociateInstance <R>(trace, t);

            if (trace.Value != null)
            {
                t.data["Sum" + typeof(T).Name] = (decimal)t.data["Sum" + typeof(T).Name] + trace.Value;
            }
        }
Пример #4
0
        DataSet ILoadDataService.UploadAttachment(UploadedFile[] uploadedFiles, Guid workItemId)
        {
            IDataManager dm = EntityManager.FromDataBaseService("MyDataService");

            IEntityManager em = dm as IEntityManager;

            var fileService = ExecutingContext.GetService <IFileService>("MyFileService");

            var workItem = dm.GetEntity <WorkItem>(workItemId);

            foreach (UploadedFile uploadedFile in uploadedFiles)
            {
                var attachment = em.CreateInstance <Attachment>();

                string pathFile = string.Format(@"{0:N}/{1:N}", workItemId, attachment.Id);

                attachment.FileName   = uploadedFile.Name;
                attachment.FileLength = uploadedFile.ContentLength;

                em.AssociateInstance <WorkItemAttachment>(workItem, attachment);

                fileService.Write(pathFile, uploadedFile.Stream);
            }

            dm.SaveTransactional();

            return(dm.Data);
        }
Пример #5
0
        DataSet IUserProfile.GetUserProfile()
        {
            AspectizeUser aspectizeUser = ExecutingContext.CurrentUser;

            if (aspectizeUser.IsAuthenticated)
            {
                Guid userId = new Guid(aspectizeUser.UserId);

                IDataManager dm = EntityManager.FromDataBaseService(DataBaseService);

                IEntityManager em = dm as IEntityManager;

                User user = dm.GetEntity <User>(userId);

                if (user != null)
                {
                    CurrentUser currentUser = em.CreateInstance <CurrentUser>();

                    em.AssociateInstance <IsUser>(currentUser, user);

                    em.Data.AcceptChanges();

                    return(dm.Data);
                }
            }

            return(null);
        }
Пример #6
0
        static void handleMessage(string dsn, DateTime dt, string eventName, string eventValue, string userId, string info, string userAgent)
        {
            var DataServiceName = dsn;

            IDataManager dm = EntityManager.FromDataBaseService(DataServiceName);

            IEntityManager em = dm as IEntityManager;

            DateTime traceDate = dt;

            decimal?decimalValue = null;

            if (!string.IsNullOrEmpty(eventValue))
            {
                decimal decimalValueNonNull;
                if (decimal.TryParse(eventValue, out decimalValueNonNull))
                {
                    decimalValue = decimalValueNonNull;
                }
            }

            Root root = GetRoot(dm, true);

            Who who = null;

            if (string.IsNullOrEmpty(userId))
            {
                userId = Guid.Empty.ToString("N");
            }

            who = dm.GetEntity <Who>(userId);

            if (who == null)
            {
                who = em.CreateInstance <Who>();

                who.Id = userId;

                em.AssociateInstance <RootWho>(who, root);
            }

            who.DateLastTrace = dt;

            string[] eventslist = eventName.Split('|');

            foreach (string name in eventslist)
            {
                BuildTrace(root, decimalValue, who, null, null, info, dm, traceDate, name.Trim());
            }

            dm.SaveTransactional();
        }
Пример #7
0
        internal static void BuildStat(IDataManager dm, Guid rootId, Events events, DateTime dateTime)
        {
            IEntityManager em = dm as IEntityManager;

            Stat stat = em.CreateInstance <Stat>();

            stat.Id = events.Id;

            em.AssociateInstance <EventsStat>(events, stat);

            BuildStat <Year, EventsYear>(dm, rootId, events, stat, dateTime, TraceService.ExtractFormatDateYear);
            BuildStat <Quarter, EventsQuarter>(dm, rootId, events, stat, dateTime, TraceService.ExtractFormatDateQuarter);
            BuildStat <Month, EventsMonth>(dm, rootId, events, stat, dateTime, TraceService.ExtractFormatDateMonth);
            BuildStat <Week, EventsWeek>(dm, rootId, events, stat, dateTime, TraceService.ExtractFormatDateWeek);
            BuildStat <Day, EventsDay>(dm, rootId, events, stat, dateTime, TraceService.ExtractFormatDateDay);
            BuildStat <Hour, EventsHour>(dm, rootId, events, stat, dateTime, TraceService.ExtractFormatDateHour);
            //BuildTagStat<Minute, TagMinute>(dm, rootId, events, stat, dateTime, TraceService.ExtractFormatDateMinute);
        }
Пример #8
0
        //-------------------------------------------------------------------------------------------------------------------------------
        public DataSet GetExportForDisplay(string keyExport, string strLibelle, string strDescription)
        {
            AspectizeUser  aspectizeUser = ExecutingContext.CurrentUser;
            IEntityManager em            = EntityManager.FromDataSet(DataSetHelper.Create());

            if (aspectizeUser.IsAuthenticated)
            {
                int nTimosSessionId = (int)aspectizeUser[CUserTimosWebApp.c_champSessionId];

                ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize));
                CResultAErreur            result = serviceClientAspectize.GetSession(nTimosSessionId);
                if (!result)
                {
                    throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
                }
                try
                {
                    IFileService fs           = ExecutingContext.GetService <IFileService>("TimosFileService");
                    string       relativePath = keyExport + ".json";
                    string       fullPath     = fs.GetFileUrl(relativePath);
                    fullPath = fullPath.Substring(16);
                    if (File.Exists(fullPath))
                    {
                        byte[]  buffer      = fs.ReadBytes(relativePath);
                        string  jsonLecture = Encoding.ASCII.GetString(buffer);
                        DataSet dsExport    = JsonConvert.DeserializeObject <DataSet>(jsonLecture);

                        if (dsExport != null && dsExport.Tables.Count > 0)
                        {
                            Export export = em.CreateInstance <Export>();
                            export.Id          = keyExport;
                            export.Libelle     = strLibelle;
                            export.Description = strDescription;
                            export.DataDate    = File.GetLastWriteTime(fullPath);

                            // Extraction des données du DataSet
                            DataTable tableExport = dsExport.Tables[0]; // On traite uniquement la première table
                            int       nIndexCol   = 1;                  // Les 10 premières colonnes uniquement
                            foreach (DataColumn col in tableExport.Columns)
                            {
                                export.data["COL" + nIndexCol] = col.ColumnName;
                                nIndexCol++;
                                if (nIndexCol > 10)
                                {
                                    break;
                                }
                            }
                            // Traitement des données (lignes)
                            int nIndexRow = 0;
                            foreach (DataRow row in tableExport.Rows)
                            {
                                string      strIdCompose = keyExport + "#" + nIndexRow++;
                                ExportDatas expData      = em.GetInstance <ExportDatas>(strIdCompose);
                                if (expData == null)
                                {
                                    expData    = em.CreateInstance <ExportDatas>();
                                    expData.Id = strIdCompose;
                                    em.AssociateInstance <RelationExportDatas>(export, expData);
                                }
                                for (int i = 0; i < tableExport.Columns.Count && i < 10; i++)
                                {
                                    if (row[i] == DBNull.Value)
                                    {
                                        expData.data[i + 1] = "";
                                    }
                                    else
                                    {
                                        expData.data[i + 1] = row[i];
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new SmartException(1010,
                                             "Erreur GetExportForDisplay(nTimosSessionId = " + nTimosSessionId + ", keyExport = " + keyExport + ")" +
                                             Environment.NewLine +
                                             ex.Message);
                }
            }
            else
            {
                throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
            }
            em.Data.AcceptChanges();
            return(em.Data);
        }
Пример #9
0
        internal static void BuildTrace(Root root, decimal?value, Who who, double?longitude, double?latitude, string info, IDataManager dm, DateTime traceDate, string tagName)
        {
            IEntityManager em = dm as IEntityManager;

            Events existingEvents = root.Events.Find(item => item.Name == tagName);

            if (existingEvents == null)
            {
                existingEvents = em.CreateInstance <Events>();

                existingEvents.Name = tagName;

                if (value.HasValue)
                {
                    existingEvents.ValueType = EnumTagValueType.Summarize;
                }

                em.AssociateInstance <RootEvents>(root, existingEvents);
            }

            Trace trace = em.CreateInstance <Trace>();

            trace.DateTrace = traceDate;
            trace.Value     = value;
            trace.Who       = (who != null) ? who.Id : "";
            trace.Longitude = longitude;
            trace.Latitude  = latitude;
            trace.Info      = info;

            if (HttpContext.Current != null && HttpContext.Current.Request != null)
            {
                trace.UserAgent = HttpContext.Current.Request.UserAgent;
            }

            trace.IndexKey = string.Format("{0:N}|{1:N}|{2}", root.Id, existingEvents.Id, GetTimeKey(traceDate)); //GetTimeTagKey(root.Id, existingEvents.Id, traceDate);

            if (value.HasValue)
            {
                existingEvents.SumEvents += value.Value;
            }

            int quarter = GetNumQuarter(traceDate);

            //BuildPeriod<Minute, TraceMinute>(dm, trace, new DateTime(traceDate.Year, traceDate.Month, traceDate.Day, traceDate.Hour, traceDate.Minute, 0), ExtractFormatDateMinute);
            BuildPeriod <Hour, TraceHour>(dm, root.Id, existingEvents.Id, trace, new DateTime(traceDate.Year, traceDate.Month, traceDate.Day, traceDate.Hour, 0, 0), ExtractFormatDateHour);
            BuildPeriod <Day, TraceDay>(dm, root.Id, existingEvents.Id, trace, new DateTime(traceDate.Year, traceDate.Month, traceDate.Day, 12, 0, 0), ExtractFormatDateDay);

            DayOfWeek dayOfWeek     = traceDate.DayOfWeek;
            int       dayFromMonday = ((int)dayOfWeek - 1) % 7;

            if (dayFromMonday < 0)
            {
                dayFromMonday += 7;
            }
            DateTime weekDate = traceDate.AddDays(-dayFromMonday);

            weekDate = weekDate.AddTicks(-(traceDate.Ticks % TimeSpan.TicksPerDay));
            weekDate = weekDate.AddHours(12);

            BuildPeriod <Week, TraceWeek>(dm, root.Id, existingEvents.Id, trace, weekDate, ExtractFormatDateWeek);
            BuildPeriod <Month, TraceMonth>(dm, root.Id, existingEvents.Id, trace, new DateTime(traceDate.Year, traceDate.Month, 1, 12, 0, 0), ExtractFormatDateMonth);
            BuildPeriod <Quarter, TraceQuarter>(dm, root.Id, existingEvents.Id, trace, new DateTime(traceDate.Year, 3 * (quarter - 1) + 1, 1, 12, 0, 0), ExtractFormatDateQuarter);
            BuildPeriod <Year, TraceYear>(dm, root.Id, existingEvents.Id, trace, new DateTime(traceDate.Year, 1, 1, 12, 0, 0), ExtractFormatDateYear);

            em.AssociateInstance <EventsTrace>(trace, existingEvents);
            em.AssociateInstance <RootTrace>(root, trace);
            if (who != null)
            {
                em.AssociateInstance <WhoTrace>(who, trace);
            }
        }
Пример #10
0
        //[PrincipalPermission(SecurityAction.Demand, Authenticated = true)]
        //DataSet ITrace.GetTrace(Date dateStart, Date dateEnd)
        //{
        //    IDataManager dm = EntityManager.FromDataBaseService(DataServiceName);

        //    var root = GetRoot(dm, true);

        //    IEntityManager em = dm as IEntityManager;

        //    TimeSpan timeSpan = dateEnd - dateStart;

        //    foreach (Events events in em.GetAllInstances<Events>())
        //    {
        //        string dayStart = TraceService.GetTimeTagKey(root.Id, events.Id, dateStart);//.Substring(0, 11).PadRight(6, '0');
        //        string dayEnd = TraceService.GetTimeTagKey(root.Id, events.Id, dateEnd.DateTime.AddDays(1)); //.Substring(0, 11).PadRight(6, '0');
        //        QueryCriteria qcDay = new QueryCriteria(Day.Fields.Id, ComparisonOperator.GreaterOrEquals, dayStart);
        //        qcDay = qcDay.AND(new QueryCriteria(Day.Fields.Id, ComparisonOperator.LessOrEquals, dayEnd));

        //        List<Day> tagDays = dm.GetEntities<Day>(qcDay);

        //        foreach (Day d in tagDays)
        //        {
        //            em.AssociateInstance<EventsDay>(events, d);
        //        }
        //    }

        //    dm.Data.AcceptChanges();

        //    return dm.Data;
        //}

        DataSet ITrace.GetEventsHistory(Guid eventsId, Date dateStart, Date dateEnd, EnumFrequency frequency)
        {
            IDataManager dm = EntityManager.FromDataBaseService(DataServiceName);

            var root = GetRoot(dm, false);

            IEntityManager em = dm as IEntityManager;

            DateTime dateEndTomorrow = dateEnd.DateTime.AddDays(1);

            Events events = dm.GetEntity <Events>(eventsId);

            string dayStart = TraceService.GetTimeIdFromDate(root.Id, events.Id, dateStart, TraceService.ExtractFormatDateDay);
            string dayEnd   = TraceService.GetTimeIdFromDate(root.Id, events.Id, dateEndTomorrow, TraceService.ExtractFormatDateDay);

            string weekStart = TraceService.GetTimeIdFromDate(root.Id, events.Id, dateStart, TraceService.ExtractFormatDateWeek);
            string weekEnd   = TraceService.GetTimeIdFromDate(root.Id, events.Id, dateEndTomorrow, TraceService.ExtractFormatDateWeek);

            string monthStart = TraceService.GetTimeIdFromDate(root.Id, events.Id, dateStart, TraceService.ExtractFormatDateMonth);
            string monthEnd   = TraceService.GetTimeIdFromDate(root.Id, events.Id, dateEndTomorrow, TraceService.ExtractFormatDateMonth);

            QueryCriteria qcMonth = new QueryCriteria(Month.Fields.Id, ComparisonOperator.GreaterOrEquals, monthStart);

            qcMonth = qcMonth.AND(new QueryCriteria(Month.Fields.Id, ComparisonOperator.LessOrEquals, monthEnd));

            List <Month> tagMonths = dm.GetEntities <Month>(qcMonth);

            foreach (Month m in tagMonths)
            {
                em.AssociateInstance <EventsMonth>(events, m);
            }

            QueryCriteria qcWeek = new QueryCriteria(Month.Fields.Id, ComparisonOperator.GreaterOrEquals, weekStart);

            qcWeek = qcWeek.AND(new QueryCriteria(Month.Fields.Id, ComparisonOperator.LessOrEquals, weekEnd));

            List <Week> tagWeeks = dm.GetEntities <Week>(qcWeek);

            foreach (Week w in tagWeeks)
            {
                em.AssociateInstance <EventsWeek>(events, w);
            }

            QueryCriteria qcDay = new QueryCriteria(Day.Fields.Id, ComparisonOperator.GreaterOrEquals, dayStart);

            qcDay = qcDay.AND(new QueryCriteria(Day.Fields.Id, ComparisonOperator.LessOrEquals, dayEnd));

            List <Day> days = dm.GetEntities <Day>(qcDay);

            foreach (Day d in days)
            {
                em.AssociateInstance <EventsDay>(events, d);
            }

            DateTime temp = dateStart.DateTime;

            TimeSpan ts = new Date(dateEndTomorrow) - dateStart;

            for (var i = 0; i < ts.Days; i++)
            {
                string tempDayId = TraceService.GetTimeIdFromDate(root.Id, events.Id, temp, TraceService.ExtractFormatDateDay);

                if (!events.Day.Exists(item => item.Id == tempDayId))
                {
                    Day tempTagDay = em.CreateInstance <Day>();
                    tempTagDay.Id         = tempDayId;
                    tempTagDay.TimeKey    = tempDayId.Split('|')[2]; //TraceService.GetTimeKey(temp);
                    tempTagDay.DatePeriod = temp.AddHours(12);
                    em.AssociateInstance <EventsDay>(events, tempTagDay);
                }

                string tempWeekId = TraceService.GetTimeIdFromDate(root.Id, events.Id, temp, TraceService.ExtractFormatDateWeek);

                if (!events.Week.Exists(item => item.Id == tempWeekId))
                {
                    Week tempTagWeek = em.CreateInstance <Week>();
                    tempTagWeek.Id         = tempWeekId;
                    tempTagWeek.TimeKey    = tempWeekId.Split('|')[2]; //TraceService.GetTimeKey(temp);
                    tempTagWeek.DatePeriod = temp.AddHours(12);
                    em.AssociateInstance <EventsWeek>(events, tempTagWeek);
                }

                string tempMonthId = TraceService.GetTimeIdFromDate(root.Id, events.Id, temp, TraceService.ExtractFormatDateMonth);

                if (!events.Month.Exists(item => item.Id == tempMonthId))
                {
                    Month tempTagMonth = em.CreateInstance <Month>();
                    tempTagMonth.Id         = tempMonthId;
                    tempTagMonth.TimeKey    = tempMonthId.Split('|')[2]; //TraceService.GetTimeKey(temp);
                    tempTagMonth.DatePeriod = temp.AddHours(12);
                    em.AssociateInstance <EventsMonth>(events, tempTagMonth);
                }

                temp = temp.AddDays(1);
            }

            dm.Data.AcceptChanges();

            return(dm.Data);
        }