public void CONVERT_TO_BOOLEAN_FROM_STRING()
        {
            string test = "true";
            bool   val  = ConverterUtil.GetTFromString <bool>(test);

            Assert.IsTrue(val);
        }
Ejemplo n.º 2
0
        public MyStatusCode PlayActivity(Activity activity)
        {
            MyStatusCode state = MyStatusCode.Validated;

            long[] idDogs   = ConverterUtil.ConvertIds(activity.dogs);
            long[] idLovers = ConverterUtil.ConvertIds(activity.lovers);

            using (var dbTransaction = activityDao.db.Database.BeginTransaction())
            {
                try
                {
                    activityDao.Add(activity);
                    foreach (long idLover in idLovers)
                    {
                        loverDao.IncLoves(idLover, DefaultUtil.PlayActivityLoversPoint);
                    }
                    foreach (long idDog in idDogs)
                    {
                        dogDao.IncLoves(idDog, DefaultUtil.PlayActivityLoversPoint);
                    }
                    dbTransaction.Commit();
                }
                catch (Exception)
                {
                    state = MyStatusCode.InternalServerError;
                    dbTransaction.Rollback();
                }
            }

            return(state);
        }
Ejemplo n.º 3
0
 public FileNamePattern(string pattern, IContext context)
 {
     Pattern = FileFilterUtil.slashify(pattern);
     Context = context;
     Parse();
     ConverterUtil.startConverters(_headTokenConverter);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Highlightes completed test.
        /// </summary>
        public virtual void HighlightCompletedTest(TestResult testResult)
        {
            BeginInvoke(new Action(() =>
            {
                if (!mTestNodes.ContainsKey(testResult.TestInfo))
                {
                    return;
                }

                TreeView.BeginUpdate();

                foreach (var node in mTestNodes[testResult.TestInfo])
                {
                    node.BackColor   = TreeView.BackColor;
                    node.NodeFont    = mCompletedTestFont;
                    node.Text        = node.Text;
                    node.ToolTipText = TooltipHelper.CreateTestTooltip(testResult.TestInfo, testResult);
                    node.ForeColor   = ConverterUtil.GetStatusColor(testResult.TestStatus);

                    mColouredNodes.Add(node);
                }

                TreeView.EndUpdate();
            }));
        }
Ejemplo n.º 5
0
        private void BtnStart_OnClick(object sender, RoutedEventArgs e)
        {
            if (IsRunning)
            {
                return;
            }

            //если пресс был зажат вручную - не стоит пробовать зажимать его ещё раз
            ClampParameters.SkipClamping = Cache.Clamp.ManualClamping;

            var commPar = new Types.Commutation.TestParameters()
            {
                BlockIndex      = (!Cache.Clamp.UseTmax) ? Types.Commutation.HWBlockIndex.Block1 : Types.Commutation.HWBlockIndex.Block2,
                CommutationType = ConverterUtil.MapCommutationType(CommType),
                Position        = ConverterUtil.MapModulePosition(ModPosition)
            };

            var parameters = new List <BaseTestParametersAndNormatives>(1);

            parameters.Add(Parameters);

            if (!Cache.Net.Start(commPar, ClampParameters, parameters))
            {
                return;
            }
            IsRunning = true;
        }
        public static int GetNumberOfSplits(TASK task)
        {
            var listParam = new PARAM_LENGTH_Service().GetAll().OrderByDescending(q => q.PK_ID_PARAM_LENGTH);

            try
            {
                double megabytes = ConverterUtil.ConvertBytesToMegabytes((double)task.LENGTH);
                foreach (var param in listParam)
                {
                    if (megabytes >= param.LENGTH)
                    {
                        return((int)param.NB_OF_SPLITS);
                    }
                }
                return(1);
            }
            catch (Exception e)
            {
                task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.ERREUR;
                new TASK_Service().UpdateTask(task);

                TRACE trace = new TRACE()
                {
                    FK_ID_TASK   = task.PK_ID_TASK,
                    FK_ID_SERVER = 1,
                    METHOD       = "GetNumberOfSplits problème lors de la recupération de la length",
                    TYPE         = "ERROR",
                    DESCRIPTION  = e.Message + " " + e.InnerException,
                    DATE_TRACE   = DateTime.Now,
                    NOM_SERVER   = System.Environment.MachineName
                };
                new TRACE_Service().AddTrace(trace);
                return(0);
            }
        }
        // Resolves a user-friendly value for a given input value, field, and layer
        private void resolveValue()
        {
            if (!string.IsNullOrEmpty(FieldName) && Value != null && Layer != null && MapApplication.Current != null)
            {
                // Create a dummy graphic with the value to resolve and the field the value belongs to
                Graphic g = new Graphic();
                g.Attributes.Add(FieldName, Value);

                // Get the popup info for the graphic and the layer to which the input value belongs.  This will initialize
                // and give access to field metadata for the layer
                OnClickPopupInfo info = MapApplication.Current.GetPopup(g, Layer);

                // Resolve the value into its user-friendly equivalent
                if (info != null)
                {
                    ResolvedValue = ConverterUtil.GetValue(info.PopupItem, FieldName);
                }
                else
                {
                    ResolvedValue = null;
                }
            }
            else
            {
                ResolvedValue = null;
            }
        }
Ejemplo n.º 8
0
 private void SetupProfileNode(Profile profile, TreeNode node, TestStatus status)
 {
     node.ToolTipText      = TooltipHelper.CreateProfileTooltip(profile);
     node.ForeColor        = ConverterUtil.GetStatusColor(status);
     node.ImageKey         = GetImageKey(status.ToFeatureStatus());
     node.SelectedImageKey = node.ImageKey;
 }
Ejemplo n.º 9
0
 protected void RefreshFeatureNode(FeatureInfo feature, TreeNode node, FeatureStatus status)
 {
     node.ToolTipText      = TooltipHelper.CreateFeatureTooltip(feature);
     node.ForeColor        = ConverterUtil.GetStatusColor(status);
     node.ImageKey         = GetImageKey(status);
     node.SelectedImageKey = node.ImageKey;
 }
Ejemplo n.º 10
0
 public List <Dictionary <string, object> > SeeDonations(long userId)
 {
     if (userId == 0)
     {
         return(null);
     }
     return(ConverterUtil.ConvertDonations(donateDao.GetDonations(userId)));
 }
Ejemplo n.º 11
0
 public Dictionary <string, object> SeeLoverBasic(long userId)
 {
     if (userId == 0)
     {
         return(null);
     }
     return(ConverterUtil.ConvertDogLover(loverDao.Get(userId)));
 }
Ejemplo n.º 12
0
 public List <Dictionary <String, Object> > GetSentDogs(long userId)
 {
     if (userId == 0)
     {
         return(null);
     }
     return(ConverterUtil.ConvertDogs(userId, dogDao.GetSentDogs(userId), ConverterUtil.ConvertInfo.SenderOnly));
 }
Ejemplo n.º 13
0
 public List <Dictionary <String, Object> > GetFollowDogs(long userId)
 {
     if (userId == 0)
     {
         return(null);
     }
     return(ConverterUtil.ConvertDogs(0, followDao.GetFollowDogs(userId), ConverterUtil.ConvertInfo.SenderAdopter));
 }
Ejemplo n.º 14
0
        private void BtnStart_OnClick(object sender, RoutedEventArgs e)
        {
            if (VM.IsRunning)
            {
                return;
            }

            VM.IsRunning = true;

            var paramGate = new Types.Gate.TestParameters {
                IsEnabled = false
            };
            var paramVtm = new Types.VTM.TestParameters {
                IsEnabled = false
            };
            var paramBvt = new Types.BVT.TestParameters {
                IsEnabled = false
            };
            var paramATU = new Types.ATU.TestParameters {
                IsEnabled = false
            };
            var paramQrrTq = new Types.QrrTq.TestParameters {
                IsEnabled = false
            };
            var paramIH = new Types.IH.TestParameters {
                IsEnabled = false
            };
            var paramRCC = new Types.RCC.TestParameters {
                IsEnabled = false
            };

            //если пресс был зажат вручную - не стоит пробовать зажимать его ещё раз
            VM.Clamping.SkipClamping = Cache.Clamp.ManualClamping;

            Types.Commutation.TestParameters commutation = new Types.Commutation.TestParameters()
            {
                BlockIndex      = (!Cache.Clamp.UseTmax) ? Types.Commutation.HWBlockIndex.Block1 : Types.Commutation.HWBlockIndex.Block2,
                CommutationType = ConverterUtil.MapCommutationType(VM.CommutationType),
                Position        = ConverterUtil.MapModulePosition(VM.Position)
            };



            if (!Cache.Net.Start(paramGate, paramVtm, paramBvt, paramATU, paramQrrTq, paramIH, paramRCC, commutation, VM.Clamping, VM.TOU))
            {
                return;
            }

            ClearStatus();
        }
Ejemplo n.º 15
0
        internal void Start()
        {
            if (IsRunning)
            {
                return;
            }

            var paramGate = new Types.Gate.TestParameters {
                IsEnabled = false
            };
            var paramVtm = new Types.SL.TestParameters {
                IsEnabled = false
            };
            var paramAtu = new Types.ATU.TestParameters {
                IsEnabled = false
            };
            var paramQrrTq = new Types.QrrTq.TestParameters {
                IsEnabled = false
            };
            var paramRAC = new Types.RAC.TestParameters {
                IsEnabled = false
            };
            var paramIH = new Types.IH.TestParameters {
                IsEnabled = false
            };
            var paramRCC = new Types.RCC.TestParameters {
                IsEnabled = false
            };

            ClampParameters.SkipClamping = Cache.Clamp.ManualClamping;

            Parameters.VoltageFrequency = (ushort)Settings.Default.BVTVoltageFrequency;
            Parameters.MeasurementMode  = Types.BVT.BVTMeasurementMode.ModeV;

            if (!Cache.Net.Start(paramGate, paramVtm, Parameters, paramAtu, paramQrrTq, paramRAC, paramIH, paramRCC,
                                 new Types.Commutation.TestParameters
            {
                BlockIndex = (!Cache.Clamp.clampPage.UseTmax) ? Types.Commutation.HWBlockIndex.Block1 : Types.Commutation.HWBlockIndex.Block2,
                CommutationType = ConverterUtil.MapCommutationType(CommType),
                Position = ConverterUtil.MapModulePosition(ModPosition)
            }, ClampParameters))
            {
                return;
            }

            ClearStatus();
            IsRunning = true;
        }
Ejemplo n.º 16
0
        internal void Start()
        {
            if (IsRunning)
            {
                return;
            }

            var paramGate = new Types.Gate.TestParameters {
                IsEnabled = false
            };
            var paramVtm = new Types.VTM.TestParameters {
                IsEnabled = false
            };
            var paramBvt = new Types.BVT.TestParameters {
                IsEnabled = false
            };
            var paramATU = new Types.ATU.TestParameters {
                IsEnabled = false
            };
            var paramIH = new Types.IH.TestParameters {
                IsEnabled = false
            };
            var paramRCC = new Types.RCC.TestParameters {
                IsEnabled = false
            };
            var paramTOU = new Types.TOU.TestParameters {
                IsEnabled = false
            };

            //если пресс был зажат вручную - не стоит пробовать зажимать его ещё раз
            ClampParameters.SkipClamping = Cache.Clamp.ManualClamping;

            if (!Cache.Net.Start(paramGate, paramVtm, paramBvt, paramATU, Parameters, paramIH, paramRCC,
                                 new Types.Commutation.TestParameters
            {
                BlockIndex = (!Cache.Clamp.clampPage.UseTmax) ? Types.Commutation.HWBlockIndex.Block1 : Types.Commutation.HWBlockIndex.Block2,
                CommutationType = ConverterUtil.MapCommutationType(CommType),
                Position = ConverterUtil.MapModulePosition(ModPosition)
            }, ClampParameters, paramTOU))
            {
                return;
            }

            ClearStatus();
            IsRunning = true;
        }
        private void PriceItClick(object sender, RoutedEventArgs e)
        {
            ButtonCopyNote.Content = "Copy";

            var pastedStationLines = StationCode.Split(Environment.NewLine);

            // Entry 5 (index 4) will hold the information how many crafts there are in this station.

            if (pastedStationLines.Length > 10 && Regex.IsMatch(pastedStationLines[4], "Crafts: (1|2|3)/3")) //a valid export of a stationcode
            {
                var craftCount = int.Parse(pastedStationLines[4].Replace("Crafts: ", "").Replace("/3", ""));

                // Entry 8 (Index 7) will hold the first craft.
                FirstCraft = new SavedCraft(SeedCraft.Find(MasterList, pastedStationLines[7]));
                //FirstCraft = new SavedCraft(pastedStationLines[7]);

                if (craftCount >= 2)
                {
                    SecondCraft = new SavedCraft(SeedCraft.Find(MasterList, pastedStationLines[8]));
                }
                else
                {
                    SecondCraft = new SavedCraft();
                }
                if (craftCount == 3)
                {
                    ThirdCraft = new SavedCraft(SeedCraft.Find(MasterList, pastedStationLines[9]));
                }
                else
                {
                    ThirdCraft = new SavedCraft();
                }

                Note = ConverterUtil.GetNoteForCrafts(new SavedCraft[] { FirstCraft, SecondCraft, ThirdCraft });

                OnPropertyChanged("FirstCraft");
                OnPropertyChanged("SecondCraft");
                OnPropertyChanged("ThirdCraft");
                OnPropertyChanged("Note");
            }
            else
            {
                MessageBox.Show("Invalid Station-Code. Please copy / paste again from ingame!");
            }
        }
Ejemplo n.º 18
0
        internal void Start()
        {
            if (IsRunning)
            {
                return;
            }

            var paramGate = new Types.Gate.TestParameters {
                IsEnabled = false
            };
            var paramBvt = new Types.BVT.TestParameters {
                IsEnabled = false
            };
            var paramATU = new Types.ATU.TestParameters {
                IsEnabled = false
            };
            var paramQrrTq = new Types.QrrTq.TestParameters {
                IsEnabled = false
            };
            var paramIH = new Types.IH.TestParameters {
                IsEnabled = false
            };
            var paramRCC = new Types.RCC.TestParameters {
                IsEnabled = false
            };
            var paramTOU = new Types.TOU.TestParameters {
                IsEnabled = false
            };

            ClampParameters.SkipClamping = Cache.Clamp.ManualClamping;
            ClearStatus();

            if (!Cache.Net.Start(paramGate, Parameters, paramBvt, paramATU, paramQrrTq, paramIH, paramRCC,
                                 new Types.Commutation.TestParameters
            {
                BlockIndex = (!Cache.Clamp.UseTmax) ? Types.Commutation.HWBlockIndex.Block1 : Types.Commutation.HWBlockIndex.Block2,
                CommutationType = ConverterUtil.MapCommutationType(CommType),
                Position = ConverterUtil.MapModulePosition(ModPosition)
            }, ClampParameters, paramTOU))
            {
                return;
            }

            IsRunning = true;
        }
Ejemplo n.º 19
0
        public List <Dictionary <string, object> > SeeDogActivities(long idDog)
        {
            List <Activity> activities = activityDao.GetActivities(idDog);
            List <Dictionary <string, object> > result = ConverterUtil.ConvertActivities(activities);

            for (int i = 0; i < activities.Count(); ++i)
            {
                Activity a        = activities.ElementAt(i);
                long[]   idDogs   = ConverterUtil.ConvertIds(a.dogs);
                long[]   idLovers = ConverterUtil.ConvertIds(a.lovers);
                long[]   idAdmins = ConverterUtil.ConvertIds(a.admins);

                result[i].Add("dogs", ConverterUtil.ConvertBasicDogs(dogDao.GetAll(idDogs)));
                result[i].Add("lovers", ConverterUtil.ConvertBasicLovers(loverDao.GetAll(idLovers)));
                result[i].Add("admins", ConverterUtil.ConvertBasicAdmins(adminDao.GetAll(idAdmins)));
            }

            return(result);
        }
Ejemplo n.º 20
0
        public async Task <List <SelectListItem> > GetUsersAsSelectAsync(string user = "")
        {
            List <UserModel> list = new List <UserModel>();

            try
            {
                dynamic           content = new { };
                CancellationToken cancellationToken;
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, GetUserUrl))
                        using (var httpContent = HttpUtil.CreateHttpContent(content))
                        {
                            request.Content = httpContent;

                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
                                                  .ConfigureAwait(false))
                            {
                                if (response.StatusCode != HttpStatusCode.OK)
                                {
                                    LastError = "Error:" + response.StatusCode;
                                    throw new Exception();
                                }
                                else
                                {
                                    list = JsonConvert.DeserializeObject <List <UserModel> >(await response.Content.ReadAsStringAsync());
                                    return(ConverterUtil.GetUsersAsSelect(list, user));
                                    //return list;
                                    //LastMessage = await response.Content.ReadAsStringAsync();
                                    //LastMessage = serviceResponse.ToString();
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                LastError = "Error:" + ex.Message;
                throw new Exception();
            }
        }
Ejemplo n.º 21
0
        private void BtnStart_OnClick(object sender, RoutedEventArgs e)
        {
            UserSettings.Default.ShuntResistance = TextBoxResistance.Text;
            UserSettings.Default.Save();
            StartButtonEnabled(false);

            ClearStatus();
            CommType = Settings.Default.SinglePositionModuleMode ? Types.Commutation.ModuleCommutationType.Direct : Types.Commutation.ModuleCommutationType.MT3;
            var commPar = new Types.Commutation.TestParameters()
            {
                BlockIndex      = (!Cache.Clamp.UseTmax) ? Types.Commutation.HWBlockIndex.Block1 : Types.Commutation.HWBlockIndex.Block2,
                CommutationType = ConverterUtil.MapCommutationType(CommType),
                Position        = ConverterUtil.MapModulePosition(ModPosition)
            };

            //если пресс был зажат вручную - не стоит пробовать зажимать его ещё раз
            ClampParameters.SkipClamping = Cache.Clamp.ManualClamping;

            var parameters = new List <BaseTestParametersAndNormatives>(1);

            parameters.Add(Parameters);

            Cache.Net.Start(commPar, ClampParameters, parameters);
        }
        public static bool VerifyTaskLengthAndSplitTask(TASK Task)
        {
            // Si c'est une sous tache on ne split pas
            if (Task.FK_ID_PARENT_TASK != null)
            {
                return(false);
            }
            //On récupère la taille maximum sans split
            var listParamLength = new PARAM_LENGTH_Service().GetAll().ToList();
            //int.TryParse(MaxLengthString, out MaxLength);
            // Si la tache est trop lourde on la split
            int megabytes = (int)ConverterUtil.ConvertBytesToMegabytes((double)Task.LENGTH);

            if (listParamLength.Where(x => x.LENGTH <= megabytes).FirstOrDefault() != null)
            {
                VideoFile VideoFile = new VideoFile(Task.FILE_URL);
                VideoFile.GetVideoInfo();
                Task.STATUS = (int)EnumManager.PARAM_TASK_STATUS.SPLIT_EN_COURS;
                new TASK_Service().UpdateTask(Task);
                CreateSplits(Task, VideoFile);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 23
0
        private void OnDownloadSuccess(int serialId, string downloadPath, string downloadUri, int currentLength, object userData)
        {
            VersionListProcessor versionListProcessor = userData as VersionListProcessor;

            if (versionListProcessor == null || versionListProcessor != this)
            {
                return;
            }

            using (FileStream fileStream = new FileStream(downloadPath, FileMode.Open, FileAccess.ReadWrite))
            {
                int length = (int)fileStream.Length;
                if (length != m_VersionListZipLength)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Latest version list zip length error, need '{0}', downloaded '{1}'.", m_VersionListZipLength.ToString(), length.ToString());
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }

                if (m_UpdateFileCache == null || m_UpdateFileCache.Length < length)
                {
                    m_UpdateFileCache = new byte[(length / OneMegaBytes + 1) * OneMegaBytes];
                }

                int offset = 0;
                int count  = length;
                while (count > 0)
                {
                    int bytesRead = fileStream.Read(m_UpdateFileCache, offset, count);
                    if (bytesRead <= 0)
                    {
                        throw new Exception(TextUtil.Format("Unknown error when load file '{0}'.", downloadPath));
                    }

                    offset += bytesRead;
                    count  -= bytesRead;
                }

                int hashCode = ConverterUtil.GetInt32(VerifierUtil.GetCrc32(m_UpdateFileCache, 0, length));
                if (hashCode != m_VersionListZipHashCode)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Latest version list zip hash code error, need '{0}', downloaded '{1}'.", m_VersionListZipHashCode.ToString("X8"), hashCode.ToString("X8"));
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }

                try
                {
                    if (m_DecompressCache == null)
                    {
                        m_DecompressCache = new MemoryStream();
                    }

                    m_DecompressCache.Position = 0L;
                    m_DecompressCache.SetLength(0L);
                    if (!ZipUtil.Decompress(m_UpdateFileCache, 0, length, m_DecompressCache))
                    {
                        fileStream.Close();
                        string errorMessage = TextUtil.Format("Unable to decompress latest version list '{0}'.", downloadPath);
                        OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                        return;
                    }


                    if (m_DecompressCache.Length != m_VersionListLength)
                    {
                        fileStream.Close();
                        string errorMessage = TextUtil.Format("Latest version list length error, need '{0}', downloaded '{1}'.", m_VersionListLength.ToString(), m_DecompressCache.Length.ToString());
                        OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                        return;
                    }

                    fileStream.Position = 0L;
                    fileStream.SetLength(0L);
                    m_DecompressCache.Position = 0L;
                    int bytesRead = 0;
                    while ((bytesRead = m_DecompressCache.Read(m_UpdateFileCache, 0, m_UpdateFileCache.Length)) > 0)
                    {
                        fileStream.Write(m_UpdateFileCache, 0, bytesRead);
                    }
                }
                catch (Exception exception)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Unable to decompress latest version list '{0}' with error message '{1}'.", downloadPath, exception.Message);
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }
            }

            if (VersionListUpdateSuccess != null)
            {
                VersionListUpdateSuccess(downloadPath, downloadUri);
            }
        }
 private void UpdateNote()
 {
     Note = ConverterUtil.GetNoteForCrafts(new SavedCraft[] { FirstCraft, SecondCraft, ThirdCraft });
     OnPropertyChanged("Note");
 }
Ejemplo n.º 25
0
 public Dictionary <string, object> SeeDogBasic(long userId, long idDog)
 {
     return(ConverterUtil.ConvertDog(userId, dogDao.Get(idDog), ConverterUtil.ConvertInfo.SenderAdopter));
 }
Ejemplo n.º 26
0
 public List <Dictionary <String, Object> > GetAvailableDogs(long userId, int p)
 {
     return(ConverterUtil.ConvertDogs(userId, dogDao.GetFreeDogs(p), ConverterUtil.ConvertInfo.SenderOnly));
 }
Ejemplo n.º 27
0
        private void OnDownloadSuccess(int serialId, string downloadPath, string downloadUri, int currentLength, object userData)
        {
            UpdateInfo updateInfo = userData as UpdateInfo;

            if (updateInfo == null)
            {
                return;
            }

            using (FileStream fileStream = new FileStream(downloadPath, FileMode.Open, FileAccess.ReadWrite))
            {
                bool zip = (updateInfo.Length != updateInfo.ZipLength || updateInfo.HashCode != updateInfo.ZipHashCode);

                int length = (int)fileStream.Length;
                if (length != updateInfo.ZipLength)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Zip length error, need '{0}', downloaded '{1}'.", updateInfo.ZipLength.ToString(), length.ToString());
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }

                if (m_ResourceManager.UpdateFileCacheLength < length)
                {
                    m_ResourceManager.UpdateFileCacheLength = (length / OneMegaBytes + 1) * OneMegaBytes;
                }

                int offset = 0;
                int count  = length;
                while (count > 0)
                {
                    int bytesRead = fileStream.Read(m_ResourceManager.UpdateFileCache, offset, count);
                    if (bytesRead <= 0)
                    {
                        throw new Exception(TextUtil.Format("Unknown error when load file '{0}'.", downloadPath));
                    }

                    offset += bytesRead;
                    count  -= bytesRead;
                }

                int hashCode = ConverterUtil.GetInt32(VerifierUtil.GetCrc32(m_ResourceManager.UpdateFileCache, 0, length));
                if (hashCode != updateInfo.ZipHashCode)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Zip hash code error, need '{0}', downloaded '{1}'.", updateInfo.ZipHashCode.ToString("X8"), hashCode.ToString("X8"));
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }

                if (zip)
                {
                    try
                    {
                        if (m_ResourceManager.DecompressCache == null)
                        {
                            m_ResourceManager.DecompressCache = new MemoryStream();
                        }

                        m_ResourceManager.DecompressCache.Position = 0L;
                        m_ResourceManager.DecompressCache.SetLength(0L);
                        if (!ZipUtil.Decompress(m_ResourceManager.UpdateFileCache, 0, length, m_ResourceManager.DecompressCache))
                        {
                            fileStream.Close();
                            string errorMessage = TextUtil.Format("Unable to decompress from file '{0}'.", downloadPath);
                            OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                            return;
                        }

                        if (m_ResourceManager.DecompressCache.Length != updateInfo.Length)
                        {
                            fileStream.Close();
                            string errorMessage = TextUtil.Format("Resource length error, need '{0}', downloaded '{1}'.", updateInfo.Length.ToString(), m_ResourceManager.UpdateFileCache.Length.ToString());
                            OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                            return;
                        }

                        fileStream.Position = 0L;
                        fileStream.SetLength(0L);
                        m_ResourceManager.DecompressCache.Position = 0L;
                        int bytesRead = 0;
                        while ((bytesRead = m_ResourceManager.DecompressCache.Read(m_ResourceManager.UpdateFileCache, 0, m_ResourceManager.UpdateFileCache.Length)) > 0)
                        {
                            fileStream.Write(m_ResourceManager.UpdateFileCache, 0, bytesRead);
                        }
                    }
                    catch (Exception exception)
                    {
                        fileStream.Close();
                        string errorMessage = TextUtil.Format("Unable to decompress from file '{0}' with error message '{1}'.", downloadPath, exception.Message);
                        OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                        return;
                    }
                }
            }

            m_UpdatingCount--;

            if (m_ResourceManager.ResourceInfos.ContainsKey(updateInfo.ResourceName))
            {
                throw new Exception(TextUtil.Format("Resource info '{0}' is already exist.", updateInfo.ResourceName));
            }

            m_ResourceManager.ResourceInfos.Add(updateInfo.ResourceName, new ResourceInfo(updateInfo.ResourceName, updateInfo.Length, updateInfo.HashCode, false));
            m_ResourceManager.ResourceNames.Add(updateInfo.ResourceName);

            if (m_ResourceManager.ReadWriteResourceInfos.ContainsKey(updateInfo.ResourceName))
            {
                throw new Exception(TextUtil.Format("Read-write resource info '{0}' is already exist.", updateInfo.ResourceName));
            }

            m_ResourceManager.ReadWriteResourceInfos.Add(updateInfo.ResourceName, new ReadWriteResourceInfo(updateInfo.Length, updateInfo.HashCode));

            m_CurrentGenerateReadWriteListLength += updateInfo.ZipLength;
            if (m_UpdatingCount <= 0 || m_CurrentGenerateReadWriteListLength >= m_GenerateReadWriteListLength)
            {
                m_CurrentGenerateReadWriteListLength = 0;
                GenerateReadWriteList();
            }

            if (ResourceUpdateSuccess != null)
            {
                ResourceUpdateSuccess(updateInfo.ResourceName, downloadPath, downloadUri, updateInfo.Length, updateInfo.ZipLength);
            }
        }
            protected override void OnDrawScrollableWindow()
            {
                GUILayout.Label("<b>Screen Information</b>");
                GUILayout.BeginVertical("box");
                {
                    DrawItem("Current Resolution", GetResolutionString(Screen.currentResolution));
                    DrawItem("Screen Width", TextUtil.Format("{0} px / {1} in / {2} cm", Screen.width.ToString(), ConverterUtil.GetInchesFromPixels(Screen.width).ToString("F2"), ConverterUtil.GetCentimetersFromPixels(Screen.width).ToString("F2")));
                    DrawItem("Screen Height", TextUtil.Format("{0} px / {1} in / {2} cm", Screen.height.ToString(), ConverterUtil.GetInchesFromPixels(Screen.height).ToString("F2"), ConverterUtil.GetCentimetersFromPixels(Screen.height).ToString("F2")));
                    DrawItem("Screen DPI", Screen.dpi.ToString("F2"));
                    DrawItem("Screen Orientation", Screen.orientation.ToString());
                    DrawItem("Is Full Screen", Screen.fullScreen.ToString());
#if UNITY_2018_1_OR_NEWER
                    DrawItem("Full Screen Mode", Screen.fullScreenMode.ToString());
#endif
                    DrawItem("Sleep Timeout", GetSleepTimeoutDescription(Screen.sleepTimeout));
                    DrawItem("Cursor Visible", Cursor.visible.ToString());
                    DrawItem("Cursor Lock State", Cursor.lockState.ToString());
                    DrawItem("Auto Landscape Left", Screen.autorotateToLandscapeLeft.ToString());
                    DrawItem("Auto Landscape Right", Screen.autorotateToLandscapeRight.ToString());
                    DrawItem("Auto Portrait", Screen.autorotateToPortrait.ToString());
                    DrawItem("Auto Portrait Upside Down", Screen.autorotateToPortraitUpsideDown.ToString());
#if UNITY_2017_2_OR_NEWER && !UNITY_2017_2_0
                    DrawItem("Safe Area", Screen.safeArea.ToString());
#endif
                    DrawItem("Support Resolutions", GetResolutionsString(Screen.resolutions));
                }
                GUILayout.EndVertical();
            }
Ejemplo n.º 29
0
 public List <Dictionary <string, object> > SeeComments(long idDog, int page)
 {
     return(ConverterUtil.ConvertComments(commentDao.GetAll(idDog, page)));
 }