Exemplo n.º 1
0
        public static Info FindByUniqueCode(string uniqueCode)
        {
            if (string.IsNullOrEmpty(uniqueCode))
            {
                return(null);
            }

            Info result = null;

            if (m_infosCache.TryGetValue(uniqueCode, out result))
            {
                return(result);
            }

            List <Info> allInfos = GenericDbHelper.Get <Info>();

            foreach (Info info in allInfos)
            {
                if (info.UniqueCode.Equals(uniqueCode))
                {
                    result = info;
                    break;
                }
            }

            if (result != null)
            {
                m_infosCache.Add(uniqueCode, result);
            }

            return(result);
        }
Exemplo n.º 2
0
        private List <TaskSync> LoadAllTasksByUserId(string userId, DateTime lastSyncDate)
        {
            List <TaskSync> result = new List <TaskSync>();

            if (string.IsNullOrEmpty(userId))
            {
                return(result);
            }
            result = GenericDbHelper.Get <TaskSync>(string.Format("LAST_MODIFY_DATE >= '{0}' and USER_ID = '{1}'",
                                                                  lastSyncDate.ToString("yyyy.MM.dd hh:mm:ss"), userId));
            return(result);
        }
Exemplo n.º 3
0
        public string GetUserTasks(string json)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(Soap));
            new ConfigHelper().Load();

            try
            {
                if (string.IsNullOrEmpty(json))
                {
                    return(string.Empty);
                }

                AdminObject adminObject = JsonHelper.OnlyJsonToObject <AdminObject>(json);
                if (adminObject == null)
                {
                    return(string.Empty);
                }

                string userId   = adminObject.UserId;
                string password = adminObject.Password;
                if (ServicesConstants.DELETE_PASSWORD.Equals(password) == false ||
                    string.IsNullOrEmpty(userId))
                {
                    return(string.Empty);
                }

                List <TaskSync> tasks  = GenericDbHelper.Get <TaskSync>(string.Format("USER_ID = '{0}'", userId));
                SyncObject      result = new SyncObject();
                result.Tasks = tasks;
                return(JsonHelper.ConvertToJson <SyncObject>(result));
            }
            catch (Exception e)
            {
                log.Error(e);
                return(e.ToString());
            }
        }
Exemplo n.º 4
0
        public void Sync()
        {
            if (string.IsNullOrEmpty(Static.StaticData.Settings.Sync.Id))
            {
                return;
            }

            try
            {
                DateTime startSync    = DateTime.Now;
                DateTime lastSyncDate = Minder.Static.StaticData.Settings.Sync.LastSyncDate;
                string   dateSync     = DBTypesConverter.ToFullDateStringByCultureInfo(lastSyncDate);
//				new ErrorBox(dateSync);
                List <Task> allTasks   = GenericDbHelper.Get <Task>(string.Format("LAST_MODIFY_DATE >= '{0}'", dateSync));
                SyncObject  syncObject = new SyncObject();
                syncObject.UserId       = Static.StaticData.Settings.Sync.Id;
                syncObject.Tasks        = new List <Task>();
                syncObject.LastSyncDate = lastSyncDate.ToUniversalTime();

                foreach (Task task in allTasks)
                {
                    task.UserId = Static.StaticData.Settings.Sync.Id;
                    syncObject.Tasks.Add(task);
//					task.LastModifyDate = task.LastModifyDate.ToUniversalTime();
//					task.DateRemainder = task.DateRemainder.ToUniversalTime();
                }

                //Paruošti taskai siuntimui
                List <Task> tasksFromServer = GetSyncedTasksFromServer(syncObject);

                SetLocalDate(allTasks.ToArray());

                m_newTasks = tasksFromServer.Count;
                m_log.DebugFormat("Tasks' count retrieved from server {0}", m_newTasks);
//				using(IConnection con = new ConnectionCollector().GetConnection())
//				{
                foreach (Task task in tasksFromServer)
                {
                    task.LastModifyDate = task.LastModifyDate.ToLocalTime();
                    task.DateRemainder  = task.DateRemainder.ToLocalTime();

                    foreach (Task localTask in allTasks)
                    {
                        if (localTask.Equals(task))
                        {
                            m_newTasks--;
                        }
                    }

                    if (ExistTask(task))
                    {
                        //Negalime updatinti pagal ID, nes serveryje kitoks id.
                        GenericDbHelper.RunDirectSql(string.Format("DELETE FROM TASK WHERE SOURCE_ID = '{0}'", task.SourceId));
                        GenericDbHelper.Save(task);
                        m_log.DebugFormat("Updated existing task {0}", task);
                    }
                    else
                    {
                        GenericDbHelper.Save(task);
                        m_log.DebugFormat("Created new task {0}", task);
                    }
                }
                GenericDbHelper.Flush();
//				}

                if (m_newTasks > 0)
                {
                    if (Synced != null)
                    {
                        Synced();
                    }
                }

                Minder.Static.StaticData.Settings.Sync.LastSyncDate = DateTime.Now;
                TimeSpan span = DateTime.Now - startSync;
                m_log.InfoFormat("Synced in {0} seconds", span.TotalSeconds);
            }
            catch (Exception e)
            {
                m_log.Error(e);
            }
        }