示例#1
0
        void IInscriptionService.ResetPassword(string email)
        {
            IDataManager dm = EntityManager.FromDataBaseService(ServiceName.MyDataService);

            List <User> users = dm.GetEntities <User>(new QueryCriteria(User.Fields.Email, ComparisonOperator.Equal, email.ToLower().Trim()));

            if (users.Count == 1)
            {
                User user = users[0];

                if (user.Status != EnumUserStatus.Blocked)
                {
                    user.Status           = EnumUserStatus.Pending;
                    user.VerificationCode = Guid.NewGuid();

                    var mailService = ExecutingContext.GetService <IAspectizeSMTPService>(ServiceName.MyMailService);

                    string subject = "Reset your password";

                    string applicationLink = string.Format(@"{0}{1}/[email protected]&code={2}", ExecutingContext.CurrentHostUrl, ExecutingContext.CurrentApplicationName, user.VerificationCode);

                    string body = string.Format(@"Click on the following link to fill a new password: <a href='{0}' target='_blank'>New password</a>", applicationLink);

                    mailService.SendMailSimple(false, email, subject, body);

                    dm.SaveTransactional();
                }
            }
        }
示例#2
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);
        }
示例#3
0
        object IAutoIdentityService.GetAutoIdentityValue(string fullTableName)
        {
            IDataBaseService dataBaseService = ExecutingContext.GetService <IDataBaseService>(ServiceName.ADWDB);

            IDataManager dataManager = EntityManager.FromDataBaseService(ServiceName.ADWDB);

            if (DataBaseType == DBMS.AzureStorage)
            {
                TableId tableId = dataManager.GetEntity <TableId>(fullTableName);

                if (tableId != null)
                {
                    tableId.NextId++;
                }
                else
                {
                    IEntityManager em = dataManager as IEntityManager;

                    tableId = em.CreateInstance <TableId>();

                    tableId.TableName = fullTableName;
                    tableId.NextId    = 1;
                }

                dataManager.SaveTransactional();

                return(tableId.NextId);
            }
            else
            {
                return(dataManager.GetNextId(fullTableName));
            }
        }
示例#4
0
        byte[] IOffice.ExportExcel(string fileName)
        {
            var svc = ExecutingContext.GetService <IProductionService>("ProductionService");

            var ds = svc.LoadAllProducts();

            byte[] bytes = null;

            //if (fileName.EndsWith(".xls")) {

            var tempFileName = Context.MapPath(@"~\" + fileName);

            Aspectize.ExcelHelper.SaveToFile(tempFileName, ds);

            bytes = File.ReadAllBytes(tempFileName);

            File.Delete(tempFileName);

            //} else {

            //    var xlSvc = ExecutingContext.GetService<IAspectizeExcel>("AspectizeExcel");

            //    bytes = xlSvc.ToExcel(ds, null);
            //}

            ExecutingContext.SetHttpDownloadFileName(fileName);

            return(bytes);
        }
示例#5
0
        Guid IAdminService.UploadLogoFile(Stream data, Dictionary <string, object> info)
        {
            IFileService fileService = ExecutingContext.GetService <IFileService>(AdventureWorksFileService);

            fileService.Write("Logo", data);

            return(Guid.NewGuid());
        }
示例#6
0
        void ILoadDataService.BuildDataDemo()
        {
            //string adwCnxString = @"Data Source=NICOW8\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True";

            //IDataManager dmSQL = EntityManager.FromConnectionString(adwCnxString, DBMS.SQLServer2005);

            //IEntityManager emSql = dmSQL as IEntityManager;

            //dmSQL.LoadAssociated<SalesReason, SalesOrderHeaderSalesReason>();

            //foreach (SalesReason salesReason in emSql.GetAllInstances<SalesReason>())
            //{
            //    //salesReason.data.SetAdded();

            //    foreach (SalesOrderHeaderSalesReason sohsr in salesReason.GetRelationsInstances<SalesOrderHeader, SalesOrderHeaderSalesReason>())
            //    {
            //        sohsr.data.SetAdded();
            //    }
            //}

            //IDataManager dm = EntityManager.FromDataSetAndBaseService(emSql.Data, ServiceName.ADWDB);

            //dm.SaveTransactional();


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

            var relations = new List <IRoleRelationQuery>();

            relations.Add(new RoleRelationQuery <Category, CategorySubcategory>());
            relations.Add(new RoleRelationQuery <Subcategory, ProductSubcategory>());
            relations.Add(new RoleRelationQuery <Product, ProductProductPhoto>());

            dm.LoadEntitiesGraph <Category>(relations);

            relations = new List <IRoleRelationQuery>();

            relations.Add(new RoleRelationQuery <Employee, EmployeeManager>());
            relations.Add(new RoleRelationQuery <Employee, EmployeeContact>());

            dm.LoadEntitiesGraph <Employee>(relations);

            relations = new List <IRoleRelationQuery>();

            relations.Add(new RoleRelationQuery <SalesPerson, ContactSalesPerson>());
            //relations.Add(new RoleRelationQuery<SalesPerson, SalesOrderHeaderSalesPerson>());
            //relations.Add(new RoleRelationQuery<SalesOrderHeader, SalesOrderHeaderSalesReason>());

            dm.LoadEntitiesGraphFields <SalesPerson>(EntityLoadOption.AllFields, relations);

            dm.LoadEntities <Department>();

            IFileService fs = ExecutingContext.GetService <IFileService>(ServiceName.ADWFileService);

            var data = DataSetHelper.BinarySave(dm.Data);

            fs.Write("DataDemo2", data);
        }
示例#7
0
        //-------------------------------------------------------------------------------------------------------------------------------
        public bool GetDataSetExport(string keyExport)
        {
            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
                {
                    result = serviceClientAspectize.GetDataSetExport(nTimosSessionId, keyExport);
                    if (!result)
                    {
                        throw new SmartException(1010, "Erreur GetDataSetExport(nTimosSessionId = " + nTimosSessionId + ", keyExport = " + keyExport + ")" +
                                                 Environment.NewLine +
                                                 result.MessageErreur);
                    }

                    if (result && result.Data != null)
                    {
                        DataSet ds = result.Data as DataSet;
                        if (ds != null && ds.Tables.Count > 0)
                        {
                            var fs = ExecutingContext.GetService <IFileService>("TimosFileService");

                            string       relativePath = keyExport + ".json";
                            string       json         = JsonConvert.SerializeObject(ds, Formatting.None);
                            MemoryStream stream       = new MemoryStream(Encoding.ASCII.GetBytes(json));
                            fs.Write(relativePath, stream);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new SmartException(1010,
                                             "Erreur GetExportsForUser(nTimosSessionId = " + nTimosSessionId + ", keyExport = " + keyExport + ")" +
                                             Environment.NewLine +
                                             ex.Message);
                }
            }
            else
            {
                throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
            }
            return(true);
        }
示例#8
0
        void IInitializable.Initialize(Dictionary <string, object> parameters)
        {
            if (dsDemo == null)
            {
                IFileService fs = ExecutingContext.GetService <IFileService>(ServiceName.ADWFileService);

                var dataDemo = fs.Read("DataDemo2");

                dsDemo = DataSetHelper.BinaryLoad(dataDemo);
            }
        }
示例#9
0
        DataSet ILoadDataService.LoadDataDemo()
        {
            if (dsDemo == null)
            {
                IFileService fs = ExecutingContext.GetService <IFileService>(ServiceName.ADWFileService);

                var dataDemo = fs.Read("DataDemo2");

                dsDemo = DataSetHelper.BinaryLoad(dataDemo);
            }

            return(dsDemo);
        }
示例#10
0
        //-------------------------------------------------------------------------------------------------------------------------------
        public byte[] GetExportForExcel(string keyExport, string strLibelle)
        {
            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)
                        {
                            IAspectizeExcel aspectizeExcel = ExecutingContext.GetService <IAspectizeExcel>("AspectizeExcel");
                            var             bytes          = aspectizeExcel.ToExcel(dsExport, null);
                            ExecutingContext.SetHttpDownloadFileName(string.Format(strLibelle + " {0:yyyyMMddHHmm}.xlsx", File.GetLastWriteTime(fullPath)));
                            return(bytes);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new SmartException(1010,
                                             "Erreur GetExportForExcel(nTimosSessionId = " + nTimosSessionId + ", keyExport = " + keyExport + ")" +
                                             Environment.NewLine +
                                             ex.Message);
                }
            }
            else
            {
                throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
            }
            return(new byte[] { });
        }
示例#11
0
        byte[] ILoadDataService.DownloadAttachment(Guid workItemId, Guid attachmentId)
        {
            IDataManager dm = EntityManager.FromDataBaseService("MyDataService");

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

            var attachment = dm.GetEntity <Attachment>(attachmentId);

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

            ExecutingContext.SetHttpDownloadFileName(attachment.FileName);

            return(fileService.ReadBytes(pathFile));
        }
示例#12
0
        void ILoadDataService.DeleteAttachment(Guid workItemId, Guid attachmentId)
        {
            IDataManager dm = EntityManager.FromDataBaseService("MyDataService");

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

            var attachment = dm.GetEntity <Attachment>(attachmentId);

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

            fileService.DeleteFile(pathFile);

            attachment.Delete();

            dm.SaveTransactional();
        }
示例#13
0
        void ITrace.WriteTrace(TraceInfo traceInfo)
        {
            IDataManager dm = EntityManager.FromDataBaseService(DataServiceName);

            IEntityManager em = dm as IEntityManager;

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

            trace.ApplicationName = traceInfo.ApplicationName;
            trace.CommandName     = traceInfo.CommandName;
            trace.InfoType        = traceInfo.InfoType.ToString();
            trace.InfoTypeName    = traceInfo.InfoTypeName;
            //trace.Message = traceInfo.Message.Length > 10000 ? traceInfo.Message.Substring(0, 10000) : traceInfo.Message;
            trace.Received    = traceInfo.Received;
            trace.ServiceName = traceInfo.ServiceName;
            trace.UserHost    = traceInfo.UserHost;
            trace.UserAgent   = (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null) ? System.Web.HttpContext.Current.Request.UserAgent : "";

            bool messageTooLong = traceInfo.Message.Length > 32000;

            if (messageTooLong)
            {
                IFileService fs = ExecutingContext.GetService <IFileService>(FileServiceName);

                Guid fileId = Guid.NewGuid();

                string fileName = string.Format("Trace/{0}.txt", fileId);

                trace.Message = fileName;

                using (Stream s = GenerateStreamFromString(traceInfo.Message))
                {
                    fs.Write(fileName, s);
                }
            }
            else
            {
                trace.Message = traceInfo.Message;
            }

            dm.SaveTransactional();
        }
示例#14
0
        public DataSet UploadFiles(UploadedFile[] uploadedFiles)
        {
            AspectizeUser  aspectizeUser = ExecutingContext.CurrentUser;
            IEntityManager em            = EntityManager.FromDataSet(DataSetHelper.Create());

            if (aspectizeUser.IsAuthenticated)
            {
                var fs = ExecutingContext.GetService <IFileService>("TimosFileService");

                foreach (UploadedFile file in uploadedFiles)
                {
                    fs.Write(file.Name, file.Stream);
                }
            }
            else
            {
                throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
            }
            return(em.Data);
        }
示例#15
0
        bool IInscriptionService.SignUp(string firstName, string lastName, string email)
        {
            IDataManager dm = EntityManager.FromDataBaseService(ServiceName.MyDataService);

            List <User> users = dm.GetEntities <User>(new QueryCriteria(User.Fields.Email, ComparisonOperator.Equal, email.ToLower().Trim()));

            User user;

            if (users.Count == 0)
            {
                IEntityManager em = dm as IEntityManager;

                user = em.CreateInstance <User>();

                user.FirstName = firstName;
                user.LastName  = lastName;

                user.Email            = email;
                user.Status           = EnumUserStatus.Pending;
                user.VerificationCode = Guid.NewGuid();

                dm.SaveTransactional();
            }
            else
            {
                return(false);
            }

            var mailService = ExecutingContext.GetService <IAspectizeSMTPService>(ServiceName.MyMailService);

            string applicationLink = string.Format(@"{0}{1}/[email protected]&code={2}", ExecutingContext.CurrentHostUrl, ExecutingContext.CurrentApplicationName, user.VerificationCode);

            string subject = "Welcome to Application LeanKaban";

            string body = string.Format(@"To confirm your subscription, click on thr following link: <a href='{0}' target='_blank'>Application</a>", applicationLink);

            mailService.SendMailSimple(false, email, subject, body);

            return(true);
        }
示例#16
0
        byte[] IAdminService.GetLogo(Guid logoId)
        {
            IFileService fileService = ExecutingContext.GetService <IFileService>(AdventureWorksFileService);

            return(fileService.ReadBytes("Logo"));
        }
示例#17
0
        DataSet IDataService.SaveData(DataSet dataSet, string sessionId, string circulatingId, bool updateVersion)
        {
            IDataManager dm = EntityManager.FromDataSetAndBaseService(dataSet, "MyDataService");

            IEntityManager em = dm as IEntityManager;

            var log = new AspectizeTaskLoggingHelper();

            var currentSessionId = circulatingId;

            var appName = "PlayGroundRT";

            Session session = null;

            var sessions = em.GetAllInstances <Session>();

            if (sessions.Count > 0)
            {
                session = sessions[0];
            }
            else
            {
                session = dm.GetEntity <Session>(circulatingId);
            }

            if (updateVersion)
            {
                NextId nextId        = null;
                var    nextIdSession = "";

                if (currentSessionId.Contains("-"))
                {
                    var parts = currentSessionId.Split('-');

                    nextIdSession = parts[0];
                }
                else
                {
                    nextIdSession = currentSessionId;
                }

                nextId = dm.GetEntity <NextId>(nextIdSession);

                if (nextId != null)
                {
                    nextId.Version++;
                }
                else
                {
                    nextId = em.CreateInstance <NextId>();

                    nextId.Id      = session.Id;
                    nextId.Version = 1;
                }

                currentSessionId = string.Format("{0}-{1}", nextId.Id, nextId.Version);

                session.Id      = currentSessionId;
                session.Persist = true;

                session.data.AcceptChanges();
                session.data.SetAdded();
            }

            var controlInfos = WebBuilder.BuildHtml(appName, session.Html, session.JSLibrary, log);

            string jsonControlInfos = JsonSerializer.Serialize(controlInfos);

            session.HtmlControlInfoJSON = jsonControlInfos;

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

            var typeInfo = fs.Read("PlayGroundRT.Types.Intellisense.txt");

            System.IO.StreamReader reader = new System.IO.StreamReader(typeInfo);
            string allTypesInfo           = reader.ReadToEnd();

            //var typeInfoString = System.Text.Encoding.UTF8.GetString(text);

            var ctrinfos = WebBuilder.BuildTypeDefinitionControl(appName, controlInfos);

            var indexControls = allTypesInfo.IndexOf("aas:'Controls'") + "aas:'Controls'".Length;

            allTypesInfo = allTypesInfo.Substring(0, indexControls) + ctrinfos + allTypesInfo.Substring(indexControls);

            var javaScriptCommandInfos = WebTypeInfo.BuildJavascriptCommandInfo(session.js);

            var serviceInfos = WebBuilder.BuildTypeDefinitionBrowserServices(javaScriptCommandInfos);

            var indexBrowserServices = allTypesInfo.IndexOf("aas:'BrowserServices'") + "aas:'BrowserServices'".Length;

            allTypesInfo = allTypesInfo.Substring(0, indexBrowserServices) + serviceInfos + allTypesInfo.Substring(indexBrowserServices);

            var clientSchema = JavascriptEntityDeclaration.Translate(session.MainJS);

            var indexContextData = allTypesInfo.IndexOf("aas:'ContextData'") + "aas:'ContextData'".Length;

            allTypesInfo = allTypesInfo.Substring(0, indexContextData) + "," + clientSchema + allTypesInfo.Substring(indexContextData);

            var jsView = WebBuilder.BuildViews(appName, session.Bindings, allTypesInfo, log);

            session.JSView = jsView;

            var jsLibrary = WebBuilder.BuildJSLibrary(appName, session.js, log);

            session.JSLibrary     = jsLibrary;
            session.Log           = log.ToString();
            session.CirculatingId = currentSessionId;

            dm.SaveTransactional();

            //Create new Entity with same id for result

            IEntityManager emResult = EntityManager.FromDataSet(DataSetHelper.Create());

            Session sessionResult = emResult.CreateInstance <Session>();

            sessionResult.Id = sessionId;

            foreach (DataColumn dc in session.data.Table.Columns)
            {
                if (dc.ColumnName != PlayGround.Session.Fields.Id)
                {
                    sessionResult.data[dc.ColumnName] = session.data[dc.ColumnName];
                }
            }

            emResult.Data.AcceptChanges();

            return(emResult.Data);
        }
示例#18
0
        //-------------------------------------------------------------------------------------------------------------------------------
        public void UpdateAllExports()
        {
            try
            {
                ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize));
                CResultAErreur            result = serviceClientAspectize.GetExportsForUser(0, "");

                if (result && result.Data != null)
                {
                    DataSet ds = result.Data as DataSet;

                    if (ds != null && ds.Tables.Contains(CExportWeb.c_nomTable))
                    {
                        DataTable dt = ds.Tables[CExportWeb.c_nomTable];
                        foreach (DataRow row in dt.Rows)
                        {
                            string keyExport        = (string)row[CExportWeb.c_champId];
                            string strLibelleExport = (string)row[CExportWeb.c_champLibelle];
                            int    nUpdatePeriod    = (int)row[CExportWeb.c_champPeriode];

                            try
                            {
                                // On vérifie la période de rafraichissement (en heures)
                                var    fs           = ExecutingContext.GetService <IFileService>("TimosFileService");
                                string relativePath = keyExport + ".json";
                                string fullPath     = fs.GetFileUrl(relativePath);
                                fullPath = fullPath.Substring(16);
                                if (File.Exists(fullPath))
                                {
                                    DateTime lastDataDate = File.GetLastWriteTime(fullPath);
                                    TimeSpan span         = DateTime.Now - lastDataDate;
                                    if (span.TotalHours < nUpdatePeriod)
                                    {
                                        continue;
                                    }
                                }

                                result = serviceClientAspectize.GetDataSetExport(0, keyExport);
                                if (!result)
                                {
                                    Context.Log(InfoType.Warning, "Erreur GetDataSetExport(" + keyExport + ")" + Environment.NewLine + "Export label : " + strLibelleExport + Environment.NewLine + result.MessageErreur);
                                }

                                if (result && result.Data != null)
                                {
                                    DataSet dsExport = result.Data as DataSet;
                                    if (dsExport != null && dsExport.Tables.Count > 0)
                                    {
                                        DataTable    dtExport = dsExport.Tables[0];
                                        string       json     = JsonConvert.SerializeObject(dsExport, Formatting.None);
                                        MemoryStream stream   = new MemoryStream(Encoding.ASCII.GetBytes(json));
                                        fs.Write(relativePath, stream);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Context.Log(InfoType.Warning, "Erreur GetDataSetExport(" + keyExport + ")" + Environment.NewLine + "Export label : " + strLibelleExport + Environment.NewLine + ex.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Context.Log(InfoType.Warning, ex.Message);
            }
        }
示例#19
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);
        }
示例#20
0
        public AppInitService()
        {
            svc = ExecutingContext.GetService <IWebInitService>("WebInitService");

            version = 1 - version;
        }
示例#21
0
        //-------------------------------------------------------------------------------------------------------------------------------
        public DataSet GetListeExportsForCurrentUser()
        {
            AspectizeUser  aspectizeUser = ExecutingContext.CurrentUser;
            IEntityManager em            = EntityManager.FromDataSet(DataSetHelper.Create());

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

                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
                {
                    result = serviceClientAspectize.GetExportsForUser(nTimosSessionId, keyUser);
                    if (!result)
                    {
                        throw new SmartException(1010, "Erreur GetExportsForUser(nTimosSessionId = " + nTimosSessionId + ", keyUser = "******")" +
                                                 Environment.NewLine +
                                                 result.MessageErreur);
                    }

                    if (result && result.Data != null)
                    {
                        DataSet ds = result.Data as DataSet;

                        if (ds != null && ds.Tables.Contains(CExportWeb.c_nomTable))
                        {
                            DataTable dt = ds.Tables[CExportWeb.c_nomTable];

                            foreach (DataRow row in dt.Rows)
                            {
                                var export = em.CreateInstance <Export>();
                                export.Id           = (string)row[CExportWeb.c_champId];
                                export.Libelle      = (string)row[CExportWeb.c_champLibelle];
                                export.Description  = (string)row[CExportWeb.c_champDescription];
                                export.UpdatePeriod = (int)row[CExportWeb.c_champPeriode];

                                var    fs           = ExecutingContext.GetService <IFileService>("TimosFileService");
                                string relativePath = export.Id + ".json";
                                string fullPath     = fs.GetFileUrl(relativePath);
                                fullPath = fullPath.Substring(16);
                                if (File.Exists(fullPath))
                                {
                                    export.DataDate = File.GetLastWriteTime(fullPath);
                                }
                                else
                                {
                                    export.DataDate = null;
                                }
                            }
                        }


                        em.Data.AcceptChanges();
                        return(em.Data);
                    }
                }
                catch (Exception ex)
                {
                    throw new SmartException(1010,
                                             "Erreur GetExportsForUser(nTimosSessionId = " + nTimosSessionId + ", keyUser = "******")" +
                                             Environment.NewLine +
                                             ex.Message);
                }
            }
            else
            {
                throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
            }
            return(null);
        }
示例#22
0
        void ILog.WriteLog(TraceInfo traceInfo)
        {
            if (traceInfo.Level < 0)
            {
                if (!ExecutingContext.CurrentHostUrl.ToLower().StartsWith(@"http://localhost"))
                {
                    bool messageTooLong = traceInfo.Message.Length > 32000;

                    IDataManager dm = null;

                    IEntityManager em = null;

                    if (!string.IsNullOrEmpty(DataServiceName))
                    {
                        dm = EntityManager.FromDataBaseService(DataServiceName);

                        em = dm as IEntityManager;
                    }
                    else
                    {
                        em = EntityManager.FromDataSet(DataSetHelper.Create());
                    }

                    LogException logException = em.CreateInstance <LogException>();

                    logException.ApplicationName = traceInfo.ApplicationName;
                    logException.CommandName     = traceInfo.CommandName;
                    logException.InfoTypeName    = traceInfo.InfoTypeName;
                    logException.Message         = (messageTooLong) ? "" : traceInfo.Message;
                    logException.ServiceName     = traceInfo.ServiceName;
                    logException.DateException   = traceInfo.Received;
                    logException.UserAgent       = (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null && (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.UserAgent))) ? System.Web.HttpContext.Current.Request.UserAgent : "";

                    AspectizeUser aspectizeUser = ExecutingContext.CurrentUser;

                    if (aspectizeUser.IsAuthenticated && aspectizeUser["Email"] != null)
                    {
                        logException.UserName = aspectizeUser["Email"].ToString();
                    }
                    else
                    {
                        logException.UserName = "******";
                    }

                    if (messageTooLong && !string.IsNullOrEmpty(FileServiceName))
                    {
                        IFileService fs = ExecutingContext.GetService <IFileService>(FileServiceName);

                        Guid fileId = Guid.NewGuid();

                        string fileName = string.Format("Trace/{0}.txt", fileId);

                        logException.Message = string.Format("Message Exception is too long to be saved in entity, and is saved in file {0}", fileName);

                        MemoryStream stream = new MemoryStream();
                        StreamWriter writer = new StreamWriter(stream);
                        writer.Write(traceInfo.Message);
                        writer.Flush();
                        stream.Position = 0;

                        fs.Write(fileName, stream);
                    }

                    if (!string.IsNullOrEmpty(DataServiceName))
                    {
                        dm.SaveTransactional();
                    }

                    if (!string.IsNullOrEmpty(MailTo) && !string.IsNullOrEmpty(MailServiceName))
                    {
                        IAspectizeSMTPService smtpService = ExecutingContext.GetService <IAspectizeSMTPService>(MailServiceName);

                        string subject = string.Format("Bug : {0} {1}", traceInfo.ApplicationName, logException.UserName);

                        StringBuilder sb = new StringBuilder();

                        sb.AppendLine();
                        sb.AppendFormat("Date: {0}", traceInfo.Received);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Application: {0}", traceInfo.ApplicationName);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Host: {0}", ExecutingContext.CurrentHostUrl);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null)
                        {
                            sb.AppendFormat("Url: {0}", System.Web.HttpContext.Current.Request.Url.AbsoluteUri);
                            sb.AppendLine("<br />");
                            sb.AppendLine();
                        }
                        sb.AppendFormat("UserAgent: {0}", logException.UserAgent);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Service: {0}", traceInfo.ServiceName);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Command: {0}", traceInfo.CommandName);
                        sb.AppendLine("<br />");
                        sb.AppendLine();
                        sb.AppendFormat("Message: {0}", (messageTooLong) ? logException.Message : traceInfo.Message.Replace("\r\n", "<br />"));
                        sb.AppendLine("<br />");

                        string emailContent = sb.ToString();

                        smtpService.SendMail(false, MailTo.Split(','), subject, emailContent, null);
                    }
                }
            }
        }