Exemple #1
0
        /// <summary>
        /// 删除测点信息
        /// </summary>
        /// <param name="cd">测点信息</param>
        /// <returns>删除是否成功</returns>
        public bool Delete(CDInfo cd)
        {
            string sql = "Delete from `web`.`测点表` WHERE `测点编号` = " + cd.Id + ";";

            sql += "alter table `" + cd.JZId + "` drop `" + cd.Name + "`;";
            return(data.ExecSql(sql));
        }
Exemple #2
0
        /// <summary>
        /// 获取所有测点信息
        /// </summary>
        /// <returns>测点信息列表的json字符串形式</returns>
        public string GetAll(int page, int rows)
        {
            int           start = (page - 1) * rows;
            int           end   = page * rows;
            string        sql   = "SELECT * FROM `web`.`测点表`";
            List <CDInfo> cds   = new List <CDInfo>();

            string where = "limit " + start + "," + end;
            Dictionary <string, object> d = new Dictionary <string, object>();
            //获取数据总数(注意是总数,不是一页中数据的条数)
            DataTable dTable = data.GetTable(sql);

            d.Add("total", data.GetTable(sql).Rows.Count);
            //获取page页的数据
            dTable = dTable.AsEnumerable().Skip((page - 1) * rows).Take(rows).CopyToDataTable();
            for (int i = 0; i < dTable.Rows.Count; i++)
            {
                CDInfo cd = new CDInfo();
                cd.Id        = int.Parse(dTable.Rows[i]["测点编号"].ToString());
                cd.JZId      = dTable.Rows[i]["机组编号"].ToString();
                cd.Name      = dTable.Rows[i]["测点名称"].ToString();
                cd.Introduce = dTable.Rows[i]["测点描述"].ToString();
                cds.Add(cd);
            }
            d.Add("rows", cds);
            return(JsonConvert.SerializeObject(d));
        }
Exemple #3
0
        private void betoltes()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = @"C:\Temp";
            openFileDialog1.ShowDialog();
            CurrentPath = textBoxOpenFile.Text = openFileDialog1.FileName;

            var xDoc = new XmlDocument();

            xDoc.Load(CurrentPath);

            foreach (XmlElement element in xDoc.DocumentElement)
            {
                var CD = new CDInfo();
                CDList.Add(CD);

                var CDTitle = (XmlElement)element.ChildNodes[0];
                CD.Cim = CDTitle.InnerText;

                var CDArtist = (XmlElement)element.ChildNodes[1];
                CD.Eloado = CDArtist.InnerText;

                var CDYear = (XmlElement)element.ChildNodes[5];
                CD.KiadasEve = int.Parse(CDYear.InnerText);
            }
        }
Exemple #4
0
    // 更新TIPS 信息
    void UpdateTipsInfo(int skillId)
    {
        SkillInfo info = GameTable.SkillTableAsset.Lookup(skillId);

        if (null == info)
        {
            return;
        }

        CDInfo cdInfo = GameTable.CDTableAsset.Lookup(info.CoolDown);

        m_skillName.text = info.Name;
        m_skillDes.text  = info.Description;
        m_skillCD.text   = UICardDetail.GetInstance().GetTimeString(cdInfo.CDTime);

//        int needLevel = 0;
        // tips 位置
        float postionY = 98f;

        // 主动技能类型
        if (info.SkillType == (int)ENSkillType.enSkill)
        {
            postionY = 98f;
        }
        else
        {
            postionY = -17f;
        }

        // 设置位置
        m_tips.LocalPositionY(postionY);
    }
        private static async ETVoid StartCommonAttack(this CommonAttackComponent self)
        {
            self.CancellationTokenSource?.Cancel();
            self.CancellationTokenSource = new CancellationTokenSource();
            //如果有要执行攻击流程替换的内容,就执行替换流程
            if (self.HasAttackReplaceInfo())
            {
                NP_RuntimeTree npRuntimeTree = self.Entity.GetComponent <NP_RuntimeTreeManager>().GetTreeByRuntimeID(self.AttackReplaceNPTreeId);
                Blackboard     blackboard    = npRuntimeTree.GetBlackboard();

                blackboard.Set(self.AttackReplaceBB.BBKey, true);
                blackboard.Set(self.CancelAttackReplaceBB.BBKey, false);

                blackboard.Set("NormalAttackUnitIds", new List <long>()
                {
                    self.CachedUnitForAttack.Id
                });

                CDInfo commonAttackCDInfo = CDComponent.Instance.GetCDData(self.Entity.Id, "CommonAttack");
                await TimerComponent.Instance.WaitAsync(commonAttackCDInfo.Interval, self.CancellationTokenSource.Token);
            }
            else
            {
                await self.CommonAttack_Internal();
            }

            //此次攻击完成
            self.CancellationTokenSource.Dispose();
            self.CancellationTokenSource = null;
        }
Exemple #6
0
        /// <summary>
        /// 保存测点的信息
        /// </summary>
        /// <param name="cd"></param>
        public bool Add(CDInfo cd)
        {
            string sql = "INSERT INTO `web`.`测点表`(`机组编号`, `测点名称`, `测点描述`) VALUES ('" +
                         cd.JZId + "', '" +
                         cd.Name + "', '" +
                         cd.Introduce + "');";

            //alter table [表名] add 字段名 double default 0 增加数字字段,双精度型,缺省值为0
            sql += "alter table `" + cd.JZId + "` add `" + cd.Name + "` double default 0;";
            return(data.ExecSql(sql));
        }
        private static string CDProperties(CDInfo cd)
        {
            string year = "";

            if (cd.Year != null)
            {
                year = cd.Year;
            }
            return(@"[{""Key"":""Year"",""Value"":"""
                   + year + @""" ,""Type"":""text"",""Icon"":""info_outline""}]");
        }
Exemple #8
0
        /// <summary>
        /// 更新测点信息
        /// </summary>
        /// <param name="cd">新测点信息</param>
        /// <param name="old">旧测点名称</param>
        /// <returns></returns>
        public bool Update(CDInfo cd, string old)
        {
            string sql = "Update `web`.`测点表` SET " +
                         "`测点名称` = '" + cd.Name + "'," +
                         "`测点描述` = '" + cd.Introduce + "' " + " WHERE `测点编号` = " + cd.Id + ";";

            if (!old.Equals(cd.Name))
            {
                sql += "alter table `10001` change `" + old + "`  `" + cd.Name + "` double default 0;";
            }
            return(data.ExecSql(sql));
        }
Exemple #9
0
        /// <summary>
        /// 根据Id获取测点信息
        /// </summary>
        /// <param name="id">测点编号</param>
        /// <returns>测点信息</returns>
        public CDInfo GetCDInfo(int id)
        {
            string    sql    = "SELECT * FROM `web`.`测点表` where `测点编号`=" + id;
            DataTable dTable = data.GetTable(sql);
            CDInfo    cd     = new CDInfo();

            cd.Id        = int.Parse(dTable.Rows[0]["测点编号"].ToString());
            cd.JZId      = dTable.Rows[0]["机组编号"].ToString();
            cd.Name      = dTable.Rows[0]["测点名称"].ToString();
            cd.Introduce = dTable.Rows[0]["测点描述"].ToString();
            return(cd);
        }
Exemple #10
0
    public void Load(byte[] bytes)
    {
        BinaryHelper helper = new BinaryHelper(bytes);
        int          length = helper.ReadInt();

        CDInfoList = new SortedList <int, CDInfo>(length);
        for (int index = 0; index < length; ++index)
        {
            CDInfo info = new CDInfo();
            info.Load(helper);
            CDInfoList.Add(info.ID, info);
        }
    }
    public void RemoveSkillPreCD(int skillID, Actor actor)
    {
        Actor.ActorSkillInfo info = actor.SkillBag.Find(item => item.SkillTableInfo.ID == skillID);
        if (null == info || info.SkillTableInfo.PreCoolDown == 0)
        {
            return;
        }
        CDInfo cdInfo = GameTable.CDTableAsset.Lookup(info.SkillTableInfo.PreCoolDown);

        if (null != cdInfo)
        {
            actor.CDControl.CDList.RemoveAll(item => item.CDID == cdInfo.ID);
        }
    }
    public void AddSkill(int skillID, Actor actor)
    {
        Actor.ActorSkillInfo info = actor.SkillBag.Find(item => item.SkillTableInfo.ID == skillID);
        if (null == info)
        {
            return;
        }
        CDInfo cdInfo = GameTable.CDTableAsset.Lookup(info.SkillTableInfo.CoolDown);

        if (null != cdInfo)
        {
            actor.CDControl.AddCD(cdInfo.ID, actor.ID, skillID);
        }
    }
Exemple #13
0
    // 更新TIPS 信息
    void UpdateTipsInfo(int skillId)
    {
        SkillInfo info = GameTable.SkillTableAsset.Lookup(skillId);

        if (null == info)
        {
            return;
        }

        CDInfo cdInfo = GameTable.CDTableAsset.Lookup(info.CoolDown);

        m_skillName.text = info.Name;
        m_skillDes.text  = info.Description;
        m_skillCD.text   = GetTimeString(cdInfo.CDTime);
    }
    public static bool Apply(string id, GameObject caller, float cd, Func <bool> func)
    {
        id = id.ToLower();
        if (map.ContainsKey(new KeyValuePair <String, GameObject>(id, caller)))
        {
            return(false);
        }

        if (func())
        {
            CDInfo info = new CDInfo(Time.time, cd);
            map[new KeyValuePair <String, GameObject>(id, caller)] = info;
            return(true);
        }

        return(false);
    }
Exemple #15
0
    public virtual void OnEnter(Actor actor)
    {
        int   skillLevel  = 0;
        float cdGrowParma = 0;

        Actor.ActorSkillInfo info = actor.SkillBag.Find(item => item.SkillTableInfo.ID == m_skillID);
        if (info != null)
        {//获得技能等级和cd成长
            skillLevel  = info.SkillLevel;
            cdGrowParma = info.SkillTableInfo.CoolDownParam;
        }
        CDInfo cdinfo = GameTable.CDTableAsset.Lookup(CDID);
        float  timer  = cdinfo.CDTime + skillLevel * cdGrowParma;

        m_cdTime    = timer * (1 + actor.SkillCDModifyPercent) + actor.SkillCDModifyValue;
        m_startTime = Time.time;
    }
        private static async ETTask CommonAttack_Internal(this CommonAttackComponent self)
        {
            MessageHelper.Broadcast(new M2C_CommonAttack()
            {
                AttackCasterId = self.Entity.Id, TargetUnitId = self.CachedUnitForAttack.Id, CanAttack = true
            });
            HeroDataComponent heroDataComponent = self.Entity.GetComponent <HeroDataComponent>();
            float             attackPre         = heroDataComponent.NodeDataForHero.OriAttackPre / (1 + heroDataComponent.GetAttribute(NumericType.AttackSpeedAdd));
            float             attackSpeed       = heroDataComponent.GetAttribute(NumericType.AttackSpeed);

            //播放动画,如果动画播放完成还不能进行下一次普攻,则播放空闲动画
            await TimerComponent.Instance.WaitAsync((long)(attackPre * 1000), self.CancellationTokenSource.Token);

            DamageData damageData = ReferencePool.Acquire <DamageData>().InitData(BuffDamageTypes.PhysicalSingle | BuffDamageTypes.CommonAttack,
                                                                                  heroDataComponent.GetAttribute(NumericType.Attack), self.Entity as Unit, self.CachedUnitForAttack);

            self.Entity.GetComponent <CastDamageComponent>().BaptismDamageData(damageData);
            float finalDamage = self.CachedUnitForAttack.GetComponent <ReceiveDamageComponent>().BaptismDamageData(damageData);

            if (finalDamage >= 0)
            {
                self.CachedUnitForAttack.GetComponent <HeroDataComponent>().NumericComponent.ApplyChange(NumericType.Hp, -finalDamage);
                //抛出伤害事件,需要监听伤害的buff(比如吸血buff)需要监听此事件
                Game.Scene.GetComponent <BattleEventSystem>().Run($"{EventIdType.ExcuteDamage}{self.Entity.Id}", damageData);
                //抛出受伤事件,需要监听受伤的Buff(例如反甲)需要监听此事件
                Game.Scene.GetComponent <BattleEventSystem>().Run($"{EventIdType.TakeDamage}{self.CachedUnitForAttack.Id}", damageData);
            }

            CDComponent.Instance.TriggerCD(self.Entity.Id, "CommonAttack");
            CDInfo commonAttackCDInfo = CDComponent.Instance.GetCDData(self.Entity.Id, "CommonAttack");

            commonAttackCDInfo.Interval = (long)(1 / attackSpeed - attackPre) * 1000;

            List <NP_RuntimeTree> targetSkillCanvas = self.Entity.GetComponent <SkillCanvasManagerComponent>().GetSkillCanvas(10001);

            foreach (var skillCanva in targetSkillCanvas)
            {
                skillCanva.GetBlackboard().Set("CastNormalAttack", true);
                skillCanva.GetBlackboard().Set("NormalAttackUnitIds", new List <long>()
                {
                    self.CachedUnitForAttack.Id
                });
            }

            await TimerComponent.Instance.WaitAsync(commonAttackCDInfo.Interval, self.CancellationTokenSource.Token);
        }
Exemple #17
0
        private void ReadCDTextInformation(CDInfo cdInfo)
        {
            if (Settings.Current.DisableCDText)
            {
                return;
            }

            CDDrive cdDrive = new CDDrive();

            cdDrive.Open(CDEngine.DriveLetter);

            Ripper ripper = new Ripper(cdDrive);

            ripper.ReadCDText(CD);

            cdDrive.Close();
        }
 public void Awake()
 {
     this.heroTransformComponent = this.GetParent <HotfixUnit>().m_ModelUnit.GetComponent <HeroTransformComponent>();
     this.userInputComponent     = ETModel.Game.Scene.GetComponent <UserInputComponent>();
     this.m_CDComponent          = ETModel.Game.Scene.GetComponent <CDComponent>();
     m_QCDInfo          = ReferencePool.Acquire <CDInfo>();
     m_QCDInfo.Interval = 5000;
     m_QCDInfo.Name     = "QCD";
     m_WCDInfo          = ReferencePool.Acquire <CDInfo>();
     m_WCDInfo.Interval = 7000;
     m_WCDInfo.Name     = "WCD";
     m_ECDInfo          = ReferencePool.Acquire <CDInfo>();
     m_ECDInfo.Interval = 10000;
     m_ECDInfo.Name     = "ECD";
     m_CDComponent.AddCDData(this.Entity.Id, m_QCDInfo);
     m_CDComponent.AddCDData(this.Entity.Id, m_WCDInfo);
     m_CDComponent.AddCDData(this.Entity.Id, m_ECDInfo);
 }
Exemple #19
0
    private void updateSkillButtonText()
    {
        float timeNow = Time.unscaledTime;

        // 更新主武器按键文字和CD
        CDInfo mainCDInfo = cdInfoList[(int)SkillType.Main];
        float  mainCD     = mainCDInfo.timeStamp + mainCDInfo.cd - timeNow;

        if (mainCD > 0)
        {
            mainBtnText.text = Mathf.Ceil(mainCD).ToString();
        }
        else
        {
            mainBtnText.text = "M";
        }

        // 更新副武器按键文字和CD
        CDInfo secondCDInfo = cdInfoList[(int)SkillType.Second];
        float  secondCD     = secondCDInfo.timeStamp + secondCDInfo.cd - timeNow;

        if (secondCD > 0)
        {
            secondBtnText.text = Mathf.Ceil(secondCD).ToString();
        }
        else
        {
            secondBtnText.text = "S";
        }

        // 更新SSS武器按键和文字CD
        CDInfo sssCDInfo = cdInfoList[(int)SkillType.SSS];
        float  sssCD     = sssCDInfo.timeStamp + sssCDInfo.cd - timeNow;

        if (sssCD > 0)
        {
            sssBtnText.text = Mathf.Ceil(sssCD).ToString();
        }
        else
        {
            sssBtnText.text = "SSS";
        }
    }
        private const string discogs_token = "nruimgFCEQZXfqmqyFVXMrjKiIjoaPQwFvDNYaqe"; //Register and get token here: https://www.discogs.com/settings/developers

        public CDInfo GetCDInfo(string path)
        {
            string format = string.Empty;
            string code   = string.Empty;

            Zebra.GetBarcodeFromImageEmgu(path, out format, out code);

            string      jsondata = string.Empty;
            DiscogsInfo root     = null;
            CDInfo      cd       = new CDInfo();

            if (code != string.Empty)
            {
                try
                {
                    using (WebClient client = new WebClient())
                    {
                        client.Headers["User-Agent"] = "DitatUserAgent"; //If this header is omitted discogs throws protocol violation exception
                        client.Encoding = Encoding.UTF8;
                        jsondata        = client.DownloadString("https://api.discogs.com/database/search?token=" + discogs_token + "&barcode=" + code);
                    }
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    root = serializer.Deserialize <DiscogsInfo>(jsondata);
                    if ((root != null) && (root.results.Count > 0))
                    {
                        cd.Title   = root.results[0].title;
                        cd.Year    = root.results[0].year;
                        cd.Barcode = code;
                    }
                }
                catch (Exception ex)
                {
                    cd.ErrorMessage = "Could not find CD information";
                }
            }
            else
            {
                cd.ErrorMessage = "Could not find barcode";
            }
            cd.ProductProperties = CDProperties(cd);
            return(cd);
        }
Exemple #21
0
    public void PlayCD(float time, byte Indx)
    {
        CDInfo cdInfo = new CDInfo();

        cdInfo.m_CDIndx             = Indx;
        cdInfo.m_CDTime             = time;
        cdInfo.m_CurTime            = time;
        m_CDSprite[Indx].fillAmount = 1;
        //m_UIButton[Indx].isEnabled = false;
        if (m_bUseing[Indx])
        {
            cdInfo.m_bUseing = true;
            m_bUseing[Indx]  = false;
        }
        else
        {
            cdInfo.m_bUseing = false;
        }

        m_CDList.Add(cdInfo);
    }
    public bool IsSkillCDRunning(int skillID, Actor actor)
    {
        Actor.ActorSkillInfo info = actor.SkillBag.Find(item => item.SkillTableInfo.ID == skillID);
        if (null == info)
        {
            return(false);
        }
        CDInfo cdInfo = GameTable.CDTableAsset.Lookup(info.SkillTableInfo.CoolDown);

        if (null != cdInfo)
        {
            if (null == actor.CDControl.CDList.Find(item => item.CDID == cdInfo.ID))
            {
                if (info.SkillTableInfo.PreCoolDown != 0)
                {
                    cdInfo = GameTable.CDTableAsset.Lookup(info.SkillTableInfo.PreCoolDown);
                    if (null == actor.CDControl.CDList.Find(item => item.CDID == cdInfo.ID))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
        else
        {
            return(false);
        }
    }
Exemple #23
0
        private void CopyCDInfoToCD(CDInfo cdInfo)
        {
            CD.Tracks.ClearFromThread();

            int trackNumber = 1;

            foreach (CDInfoTrack track in cdInfo.Tracks)
            {
                Track cdTrack = new Track();
                cdTrack.TrackNumber   = trackNumber;
                cdTrack.Length        = track.Length;
                cdTrack.StartPosition = track.StartTime;
                cdTrack.CD            = CD;
                cdTrack.CDDriveLetter = CDEngine.DriveLetter;
                CD.Tracks.AddItemFromThread(cdTrack);

                trackNumber++;
            }

            CD.NumberOfTracks = cdInfo.Tracks.Count;
            CD.TotalLength    = cdInfo.TotalLength;
            CD.Identity       = cdInfo.Identity;
        }
Exemple #24
0
    // 更新TIPS 信息
    void UpdateTipsInfo(int skillId)
    {
        CSItem card = null;

        if (CardBag.Singleton.m_curOptinGuid.Equals(CSItemGuid.Zero))
        {
            card = CardBag.Singleton.m_cardForDetail;
        }
        else
        {
            card = CardBag.Singleton.itemBag.GetItemByGuid(CardBag.Singleton.m_curOptinGuid);
        }

        if (null == card)
        {
            return;
        }


        HeroInfo heroInfo = GameTable.HeroInfoTableAsset.Lookup(card.m_id);

        if (null == heroInfo)
        {
            return;
        }

        SkillInfo info = GameTable.SkillTableAsset.Lookup(skillId);

        if (null == info)
        {
            return;
        }
        HeroCardSkill heroSkillInfo = card.GetSkillInfo(skillId);

        CDInfo cdInfo = GameTable.CDTableAsset.Lookup(info.CoolDown);

        if (cdInfo == null)
        {
            m_tipsSkillCD.text = GetTimeString(0f);
        }
        else
        {
            m_tipsSkillCD.text = GetTimeString(cdInfo.CDTime);
        }


//        Debug.Log("m_tipsSkillDes:" + m_tipsSkillDes.height);

        int needLevel = 0;
        // tips 位置
        int offset = 50;

        needLevel = heroInfo.GetSkillNeedLevel(skillId);
        // 主动技能类型
        if (info.SkillType == (int)ENSkillType.enSkill)
        {
            offset = 100;
        }
        else
        {
            offset = 200;
        }

        // 是否有此技能
        if (!card.HaveSkill(skillId))
        {
            m_skillGetTips.text = string.Format(Localization.Get("SkillUnlockLevel"), needLevel);
            m_skillGetTips.gameObject.SetActive(true);
        }
        else
        {
            m_skillGetTips.gameObject.SetActive(false);
        }



        // 设置内容
        m_tipsSkillName.text  = info.Name;
        m_tipsSkillDes.text   = info.Description;
        m_tipsSkillLevel.text = heroSkillInfo.m_skillLevel.ToString();



        int height = 100;

        height = height + m_tipsSkillDes.height;

        int switchTipsHeight = 100;

        switchTipsHeight = switchTipsHeight + m_tipsSkillDes.height;


        m_comboItem.SetActive(false);

        for (int i = 0; i < m_comboList.Count; i++)
        {
            if (null != m_comboList[i])
            {
                GameObject.Destroy(m_comboList[i]);
            }
        }

        string strSkillType = "";

        // 终结技
        if (info.SkillConnectionType == (int)ENSkillConnectionType.enFinal)
        {
            strSkillType = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enFinalSkill).StringTypeValue;

            m_comboItem.SetActive(true);
            int minCombo = info.MinComboRequir + (int)(info.ComboRequirementParam * heroSkillInfo.m_skillLevel);
            m_comboItem.GetComponent <UILabel>().text = minCombo.ToString();
            WorldParamInfo worldInfo = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enActiveSkill);
            m_comboItem.transform.Find("ComboDes").GetComponent <UILabel>().text = Localization.Get(worldInfo.StringTypeValue);
            height = height + 60;


            Dictionary <int, string> list = GetComboList(skillId);
            int comboMax = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enMaxCombo).IntTypeValue;

            if (list != null)
            {
                int i = 1;
                foreach (KeyValuePair <int, string> item in list)
                {
                    if (i >= comboMax)
                    {
                        break;
                    }
                    GameObject copy = GameObject.Instantiate(m_comboItem) as GameObject;

                    copy.SetActive(true);
                    copy.transform.parent     = m_switchSkillTips.transform;
                    copy.name                 = copy.name + i;
                    copy.transform.localScale = Vector3.one;

                    copy.transform.localPosition = Vector3.zero;

                    copy.GetComponent <UILabel>().text = item.Key.ToString();
                    copy.transform.Find("ComboDes").GetComponent <UILabel>().text = item.Value;
                    height = height + 60;
                    i++;

                    m_comboList.Add(copy);
                }
            }
        }
        else if (info.SkillConnectionType == (int)ENSkillConnectionType.enConnect)
        {
            strSkillType = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enConectSkill).StringTypeValue;
        }
        else if (info.SkillConnectionType == (int)ENSkillConnectionType.enSpecial)
        {
            strSkillType = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enSpecialSkill).StringTypeValue;
        }


        m_tipsSkillType.GetComponent <UILabel>().text = Localization.Get(strSkillType);

        // 设置tips的 大小 主要是高度
        m_tips.GetComponent <UISprite>().height = height;

        // 设置位置
        m_tips.GetComponent <UISprite>().topAnchor.absolute = -offset;

        m_switchSkillTips.GetComponent <UILabel>().topAnchor.absolute = -switchTipsHeight;

        m_switchSkillTips.GetComponent <UIGrid>().Reposition();
    }
Exemple #25
0
        /// <summary>
        /// Die CD-Daten asynchron laden.
        /// </summary>
        public void ReadCDInformation()
        {
            cdUserControl.IsEnabled     = false;
            GridWaitProgress.Visibility = System.Windows.Visibility.Visible;

            CD.Clear();
            //CD = new DataBaseEngine.CD();
            //cdUserControl.CD = null;

            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                // CD-Informationen im Hintergrund einlesen, damit Hitbase nicht blockiert ist.
                CDInfo cdInfo = SoundEngine.SoundEngine.Instance.ReadCDInformation(CDEngine.DriveLetter);

                if (cdInfo != null)
                {
                    bool mp3AudioCD = false;

                    if (cdInfo.IsPureDataCD())
                    {
                        Dispatcher.Invoke((Action) delegate
                        {
                            WpfMessageBoxResult result = WPFMessageBox.Show(System.Windows.Application.Current.MainWindow,
                                                                            StringTable.PureDataCDTitle, StringTable.PureDataCD,
                                                                            "/Big3.Hitbase.SharedResources;component/Images/Info.png",
                                                                            WpfMessageBoxButtons.YesNo, "PureDataCDScanFiles", false, 300);

                            if (result == WpfMessageBoxResult.Yes)
                            {
                                ScanDataCD(CDEngine.DriveLetter.ToString() + ":\\");
                                mp3AudioCD = true;
                            }
                        });
                    }

                    if (!mp3AudioCD)
                    {
                        CopyCDInfoToCD(cdInfo);
                    }

                    if (!FindCDInDataBase())
                    {
                        ReadCDTextInformation(cdInfo);

                        if (CD.Tracks.Count > 0 && string.IsNullOrEmpty(CD.Artist) && string.IsNullOrEmpty(CD.Title) && CD.Tracks.All(x => string.IsNullOrEmpty(x.Artist)))
                        {
                            SearchCDInCDArchive();
                        }

                        if (Settings.Current.AutoDateToday && this.dataBase.Master.DateType != DateType.None)
                        {
                            CD.Date = Misc.GetDate();
                        }

                        if (Settings.Current.AutoSearchCover)
                        {
                            if (!string.IsNullOrEmpty(CD.Artist) && !string.IsNullOrEmpty(CD.Title))
                            {
                                CDCoverAmazon.GetCDCover(this.CD);
                            }
                        }

                        if (Settings.Current.AutoSearchLyrics)
                        {
                            Dispatcher.Invoke((Action) delegate
                            {
                                waitProgress.WaitText = StringTable.SearchLyrics;
                            });

                            foreach (var track in this.CD.Tracks)
                            {
                                if (!string.IsNullOrEmpty(track.Artist) && !string.IsNullOrEmpty(track.Title))
                                {
                                    string lyrics = LyricsSearch.Search(track.Artist, track.Title);
                                    if (!string.IsNullOrEmpty(lyrics))
                                    {
                                        track.Lyrics = lyrics;
                                    }
                                }
                            }
                        }
                    }
                }
            };
            bw.RunWorkerCompleted += delegate
            {
                cdUserControl.IsEnabled = true;

                GridWaitProgress.Visibility = System.Windows.Visibility.Collapsed;

                cdUserControl.CD = CD;

                // Automatisch CD kopieren?
                if (CDEngine.IsCDInDrive && Big3.Hitbase.Configuration.Settings.Current.RecordAutoCDCopy)
                {
                    int numsoundfile = 0;

                    foreach (Track track in CD.Tracks)
                    {
                        if (track.SoundFileExists)
                        {
                            numsoundfile += 1;
                        }
                    }

                    // Wenn bereits für alle Tracks ein Soudnfile vorhanden ist mache nix...
                    if (numsoundfile != CD.NumberOfTracks)
                    {
                        HitbaseCommands.StartRecord.Execute(null, this);
                    }
                }

                UpdateTabCaption();

                // Automatisch abspielen? Wenn im Explorer ein CD-Laufwerk doppelgeklickt wurde.
                if (autoPlayTrackNumber > 0)
                {
                    if (this.CD != null && this.CD.Tracks != null && this.CD.Tracks.Count >= autoPlayTrackNumber)
                    {
                        AddToPlaylist(this.CD.Tracks[autoPlayTrackNumber - 1].ID, AddTracksToPlaylistType.Now);
                    }

                    autoPlayTrackNumber = 0;
                }
            };

            bw.RunWorkerAsync();
        }
Exemple #26
0
    private void OnShowSkillTips(SkillInfo skillInfo, int lvl)
    {
        int skillId = skillInfo.ID;

        SkillInfo info = GameTable.SkillTableAsset.Lookup(skillId);

        if (null == info)
        {
            return;
        }

        CDInfo cdInfo = GameTable.CDTableAsset.Lookup(info.CoolDown);

        if (cdInfo == null)
        {
            m_tipsSkillCD.text = GetTimeString(0f);
        }
        else
        {
            m_tipsSkillCD.text = GetTimeString(cdInfo.CDTime);
        }


        //        Debug.Log("m_tipsSkillDes:" + m_tipsSkillDes.height);

//		int needLevel = 0;
        // tips 位置
        int offset = 50;

        // 主动技能类型
        if (info.SkillType == (int)ENSkillType.enSkill)
        {
            offset = 100;
        }
        else
        {
            offset = 200;
        }

        m_skillGetTips.gameObject.SetActive(false);



        // 设置内容
        m_tipsSkillName.text  = info.Name;
        m_tipsSkillDes.text   = info.Description;
        m_tipsSkillLevel.text = lvl.ToString();



        int height = 100;

        height = height + m_tipsSkillDes.height;

        int switchTipsHeight = 100;

        switchTipsHeight = switchTipsHeight + m_tipsSkillDes.height;


        m_comboItem.SetActive(false);

        for (int i = 0; i < m_comboList.Count; i++)
        {
            if (null != m_comboList[i])
            {
                GameObject.Destroy(m_comboList[i]);
            }
        }

        string strSkillType = "";

        // 终结技
        if (info.SkillConnectionType == (int)ENSkillConnectionType.enFinal)
        {
            strSkillType = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enFinalSkill).StringTypeValue;

            m_comboItem.SetActive(true);
            Actor.ActorSkillInfo actroSkillInfo = this.m_mainPlayer.SkillBag.Find(item => item.SkillTableInfo.ID == info.ID);
            m_comboItem.GetComponent <UILabel>().text = actroSkillInfo.MinComboRequir.ToString();
            WorldParamInfo worldInfo = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enActiveSkill);
            m_comboItem.transform.Find("ComboDes").GetComponent <UILabel>().text = Localization.Get(worldInfo.StringTypeValue);
            height = height + 60;


            Dictionary <int, string> list = GetComboList(skillId);
            int comboMax = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enMaxCombo).IntTypeValue;

            if (list != null)
            {
                int i = 1;
                foreach (KeyValuePair <int, string> item in list)
                {
                    if (i >= comboMax)
                    {
                        break;
                    }
                    GameObject copy = GameObject.Instantiate(m_comboItem) as GameObject;

                    copy.SetActive(true);
                    copy.transform.parent     = m_switchSkillTips.transform;
                    copy.name                 = copy.name + i;
                    copy.transform.localScale = Vector3.one;

                    copy.transform.localPosition = Vector3.zero;

                    copy.GetComponent <UILabel>().text = item.Key.ToString();
                    copy.transform.Find("ComboDes").GetComponent <UILabel>().text = item.Value;
                    height = height + 60;
                    i++;

                    m_comboList.Add(copy);
                }
            }
        }
        else if (info.SkillConnectionType == (int)ENSkillConnectionType.enConnect)
        {
            strSkillType = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enConectSkill).StringTypeValue;
        }
        else if (info.SkillConnectionType == (int)ENSkillConnectionType.enSpecial)
        {
            strSkillType = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enSpecialSkill).StringTypeValue;
        }


        m_tipsSkillType.GetComponent <UILabel>().text = Localization.Get(strSkillType);

        // 设置tips的 大小 主要是高度
        m_skillInfoTips.GetComponent <UISprite>().height = height;

        // 设置位置
        m_skillInfoTips.GetComponent <UISprite>().topAnchor.absolute = -offset;

        m_switchSkillTips.GetComponent <UILabel>().topAnchor.absolute = -switchTipsHeight;

        m_switchSkillTips.GetComponent <UIGrid>().Reposition();
    }
Exemple #27
0
    private void Start()
    {
        // actual XML file
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(xmlFile.text);

        /**
         * // get Root node
         * //XmlNode rootNode = xmlDoc.SelectSingleNode("ArrayOfQuizQuestion");
         *
         * // get all quiz questions
         * //XmlNodeList quizQuestions = rootNode.SelectNodes("QuizQuestion");
         *
         * // select the first question
         * //Debug.Log(quizQuestions[0].SelectSingleNode("Anwsers").InnerText);
         *
         * //XmlNodeList list = quizQuestions[0].SelectSingleNode("Anwsers").SelectNodes("string");
         *
         * //for (int i = 0; i < list.Count; i++)
         * //{
         * //  Debug.Log(list[i].InnerText);
         * //}
         *
         * //foreach (XmlNode node in quizQuestions[0].SelectSingleNode("Anwsers").SelectNodes("string"))
         * //  Debug.Log(node.InnerText);
         */

        /**
         * XmlNode colorsNode = xmlDoc.SelectSingleNode("SampleXML").SelectSingleNode("Colors");
         *
         * for (int i = 1; i <= 4; i++)
         * {
         * Debug.Log(colorsNode.SelectSingleNode("Color" + i).InnerText);
         * }
         */

        /**
         * //XmlNode rootNode = xmlDoc.SelectSingleNode("SampleXML");
         *
         * //XmlNodeList colorsLists = rootNode.SelectNodes("Colors");
         * //int colorsThatHaveGreen = 0, numberOfWhites = 0;
         *
         * //StringBuilder sb = new StringBuilder();
         *
         * //foreach (XmlNode node in colorsLists)
         * //{
         * //  bool checkedGreen = false;
         *
         * //  sb.AppendLine(node.Name);
         * //  for (int i = 1; i <= 4; i++)
         * //  {
         * //    string colorName = node.SelectSingleNode("Color" + i).InnerText;
         * //    sb.AppendLine("\t " + colorName);
         *
         * //    if (colorName == "White")
         * //      numberOfWhites++;
         *
         * //    if (!checkedGreen && colorName == "Green")
         * //    {
         * //      colorsThatHaveGreen++;
         * //      checkedGreen = true;
         * //    }
         * //  }
         * //}
         *
         * //Debug.Log(sb);
         * //Debug.Log($"Number of green in colors: {colorsThatHaveGreen}\n" +
         * //  $"Number of whites: {numberOfWhites}");
         */

        /**
         *
         */
        StringBuilder sb       = new StringBuilder();
        XmlNode       rootNode = xmlDoc.SelectSingleNode("CATALOG");

        #region Less than $9.00
        int lessThanNineDollars = 0;
        // get all the cds
        foreach (XmlNode cdNode in rootNode.ChildNodes)
        {
            // Get all the nodes in a cd
            foreach (XmlNode cdInfoNode in cdNode.SelectNodes("PRICE"))
            {
                float price; float.TryParse(cdInfoNode.InnerText, out price);

                if (price < 9.00F)
                {
                    lessThanNineDollars++;
                }
            }
        }
        #endregion

        #region CDs before 1990
        List <string> cdsAfter1990 = new List <string>();

        foreach (XmlNode cdNode in rootNode.SelectNodes("CD"))
        {
            string innerText = cdNode.SelectSingleNode("YEAR").InnerText;
            int    year; int.TryParse(innerText, out year);

            if (year > 1990)
            {
                string name = cdNode.SelectSingleNode("TITLE").InnerText;
                cdsAfter1990.Add(name);
            }
        }
        #endregion

        #region How many CDs in US, EU, UK
        int UsCDS = 0, UkCDS = 0, EuCDS = 0;
        foreach (XmlNode cdNode in rootNode.SelectNodes("CD"))
        {
            foreach (XmlNode countryNode in cdNode.SelectNodes("COUNTRY"))
            {
                if (countryNode.InnerText == "USA")
                {
                    UsCDS++;
                }
                if (countryNode.InnerText == "UK")
                {
                    UkCDS++;
                }
                if (countryNode.InnerText == "EU")
                {
                    EuCDS++;
                }
            }
        }
        #endregion

        #region Country with heighest average CD Cost
        List <float> ukPrices = new List <float>(), usPrices = new List <float>(), euPrices = new List <float>();
        float        ukAverage = 0, usAverage = 0, euAverage = 0;

        foreach (XmlNode cdNode in rootNode.ChildNodes)
        {
            float  currentPrice; float.TryParse(cdNode.SelectSingleNode("PRICE").InnerText, out currentPrice);
            string country = cdNode.SelectSingleNode("COUNTRY").InnerText;

            switch (country)
            {
            case "UK":
                ukPrices.Add(currentPrice);
                break;

            case "USA":
                usPrices.Add(currentPrice);
                break;

            case "EU":
                euPrices.Add(currentPrice);
                break;
            }
        }

        ukAverage = GetAverage(ukPrices);
        usAverage = GetAverage(usPrices);
        euAverage = GetAverage(euPrices);
        #endregion

        #region Print names of cds that were released after 1990 and more than 9.00
        List <string> cdsAfter1990LessThan9 = new List <string>();
        foreach (XmlNode cdNode in rootNode.ChildNodes)
        {
            int date; int.TryParse(cdNode.SelectSingleNode("YEAR").InnerText, out date);
            if (date > 1990)
            {
                float price; float.TryParse(cdNode.SelectSingleNode("PRICE").InnerText, out price);
                if (price > 9.00)
                {
                    cdsAfter1990LessThan9.Add(cdNode.SelectSingleNode("TITLE").InnerText);
                }
            }
        }
        #endregion

        #region Names of CDS that were released before 1980 or from polydor company
        foreach (XmlNode node in xmlDoc.SelectSingleNode("CATALOG").SelectNodes("CD"))
        {
            CDInfo newCD = new CDInfo(node);

            cds.Add(newCD);
        }

        List <string> before1980OrPolydor   = new List <string>();
        foreach (CDInfo cd in cds)
        {
            if (cd.year < 1980 || cd.company.ToLower() == "polydor".ToLower())
            {
                before1980OrPolydor.Add(cd.title);
            }
        }
        #endregion



        BuildStringBuilder(sb, lessThanNineDollars, cdsAfter1990, UsCDS, UkCDS, EuCDS,
                           ukAverage, usAverage, euAverage, cdsAfter1990LessThan9, before1980OrPolydor);

        Debug.Log(sb);
    }
Exemple #28
0
        public void ProcessRequest(HttpContext context)
        {
            ResultInfo result = new ResultInfo();
            CDInfo     cd     = new CDInfo();
            string     action = context.Request["action"].ToString();

            context.Response.ContentType = "text/plain";

            switch (action)
            {
            case "GetAll":
                int page = int.Parse(context.Request.Form["page"]);
                int rows = int.Parse(context.Request.Form["rows"]);
                context.Response.Write(GetAll(page, rows));
                break;

            case "Add":
                try
                {
                    cd.JZId      = context.Request.Form["JZId"];
                    cd.Name      = context.Request.Form["Name"];
                    cd.Introduce = context.Request.Form["Introduce"];
                    //保存数据到数据库中
                    result.Success = Add(cd);
                    result.Message = "插入测点信息" + ((result.Success == true) ? "成功" : "失败") + "!";
                }
                catch (Exception ex)
                {
                    result.Success = false;
                    result.Message = ex.Message;
                }
                //返回客户端信息
                context.Response.Write(JsonHelper <ResultInfo> .ObjectToJsonString(result));
                break;

            case "Update":
                try
                {
                    cd           = new CDInfo();
                    cd.Id        = int.Parse(context.Request.Form["Id"]);
                    cd.JZId      = context.Request.Form["JZId"];
                    cd.Name      = context.Request.Form["Name"];
                    cd.Introduce = context.Request.Form["Introduce"];
                    string oldName = GetCDInfo(cd.Id).Name;
                    result.Success = Update(cd, oldName);
                    result.Message = "更新测点[" + cd.Name + "]信息" + ((result.Success == true) ? "成功" : "失败") + "!";
                }
                catch (Exception ex)
                {
                    result.Success = false;
                    result.Message = ex.Message;
                }
                //返回客户端信息
                context.Response.Write(JsonHelper <ResultInfo> .ObjectToJsonString(result));
                break;

            case "Delete":
                try
                {
                    int      count = 0;
                    string   id    = context.Request["Id"];
                    string[] ids   = id.Split(',');
                    for (int i = 0; i < ids.Length; i++)
                    {
                        result.Success = Delete(GetCDInfo(int.Parse(ids[i])));
                        if (result.Success == false)
                        {
                            break;
                        }
                        count++;
                    }
                    result.Message = ((result.Success == true) ? "操作成功:" : "操作失败:") + "共删除" + count + "条信息!";
                }
                catch (Exception ex)
                {
                    result.Success = false;
                    result.Message = ex.Message;
                }
                //返回客户端信息
                context.Response.Write(JsonHelper <ResultInfo> .ObjectToJsonString(result));
                break;

            case "GetAllCDInfo":
                int       menuid = int.Parse(CheckLoginStatus.node);
                string    jzname = MenuHelper.GetMenuNameById(menuid);
                string    sql    = "SELECT * FROM `web`.`机组表` where `机组名称`='" + jzname + "'";
                DataTable dTable = data.GetTable(sql);
                string    jzid   = dTable.Rows[0]["机组编号"].ToString();
                string    ret    = "[" + GetAllCDInfo(jzid) + "]";
                context.Response.Write(ret);
                break;

            case "GetCDInfo":
                string   jzid2     = context.Request.Form["JZId"].ToString();
                string   cdname    = context.Request.Form["CDName"].ToString();
                string   startdate = context.Request.Form["Start"].ToString();
                string   enddate   = context.Request.Form["End"].ToString();
                string[] cdnames   = cdname.Split(',');  //测点名称
                sql    = "SELECT " + "测试日期,测试时间," + cdname + " FROM `web`.`" + jzid2 + "` where 测试日期 between '" + startdate + "' and '" + enddate + "'";
                dTable = data.GetTable(sql);
                List <GraphInfo> gs = new List <GraphInfo>();
                string[]         x  = new string[dTable.Rows.Count];
                for (int i = 0; i < dTable.Rows.Count; i++)
                {
                    x[i] = DateTime.Parse(dTable.Rows[i]["测试日期"].ToString()).ToShortDateString() + " " + dTable.Rows[i]["测试时间"].ToString();
                }
                //外层是各个测试点,内层是数据总数
                for (int j = 0; j < cdnames.Length; j++)
                {
                    GraphInfo g = new GraphInfo();
                    g.name = cdnames[j];
                    g.type = "line";
                    g.data = new double[dTable.Rows.Count];
                    for (int i = 0; i < dTable.Rows.Count; i++)
                    {
                        g.data[i] = double.Parse(dTable.Rows[i][cdnames[j]].ToString());
                    }
                    gs.Add(g);
                }
                GraphInfo2 gi = new GraphInfo2();
                gi.series = gs;
                gi.x      = x;
                string ret2 = JsonConvert.SerializeObject(gi);
                context.Response.Write(ret2);
                break;

            default:
                break;
            }
        }
Exemple #29
0
        public static ProductImageDTO InsertProductImage(Guid ProductId, HttpPostedFile file, bool PrimaryImage)
        {
            string ImagePath = Properties.Settings.Default.ImagePath;

            var dbProductImage  = new ProductImage();
            var productImageDTO = new ProductImageDTO();

            int categoryId = 0;
            ClassifierResponse classifierResponse = null;

            string ProductName = string.Empty;
            string imagePath   = "";

            string productProperties = "{}";

            //Save image to disk
            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);

                dbProductImage.Id                = Guid.NewGuid();
                dbProductImage.Inserted          = DateTime.Now;
                dbProductImage.SelectedForExport = true;

                var path = ImagePath + dbProductImage.Id + "_" + fileName;

                var inp = file.InputStream;

                var savedProduct = GetProduct(ProductId);

                SaveOriginalImage(file, ImagePath, savedProduct.Id);

                //Save with number
                var cvProvider = new CVProvider();
                cvProvider.SaveImageWithProductNumber(new FileInfo(path), savedProduct.ProductNumber, inp);

                dbProductImage.ProductId    = ProductId;
                dbProductImage.PrimaryImage = PrimaryImage;

                imagePath           = "Images/" + Path.GetFileName(path);
                dbProductImage.Path = imagePath;

                //Classify image if not classified

                var prevCategory = savedProduct.Category;

                if (prevCategory == null)
                {
                    var classifierProvider = new ClassifierProvider();
                    classifierResponse = classifierProvider.ClassifyImage(path);

                    dbProductImage.Category = classifierResponse.Category;
                    dbProductImage.ClassifierPropability = classifierResponse.CategoryPorpability;
                    //ToDo: Check i low propability
                }
                else
                {
                    dbProductImage.Category = prevCategory;
                    dbProductImage.ClassifierPropability = 0;
                }

                using (var db = new DitatEntities())
                {
                    db.ProductImages.Add(dbProductImage);
                    db.SaveChanges();

                    productImageDTO.Category = dbProductImage.Category;
                    switch (dbProductImage.Category)
                    {
                    case "DVD":
                        categoryId = 2;

                        var     eanAttributeProvider = new EANAttributeProvider();
                        EANInfo eanInfo = eanAttributeProvider.GetEANInfo(path);

                        productProperties = "[]";     //Only name is provided from ean-search.org
                        ProductName       = eanInfo.name;

                        productImageDTO.ProductProperties = productProperties;
                        productImageDTO.Name         = ProductName;
                        productImageDTO.ErrorMessage = eanInfo.ErrorMessage;

                        /*
                         * productProperties = @"[{""Property"":""Artist"",""Value"":""" + "Test" + @"""},{""Property"":""År"",""Value"":""" + "1234" + @"""}]";
                         * ProductName = dbProductImage.Category + " - " + (dbProductImage.ClassifierPropability * 100).ToString() + "%, ej klart";
                         * productImageDTO.ProductProperties = productProperties;
                         * productImageDTO.Name = ProductName;
                         */

                        break;

                    case "CD":
                        string format = string.Empty;
                        string code   = string.Empty;

                        categoryId = 3;

                        var    cdAttributeProvider = new CDAttributeProvider();
                        CDInfo cdInfo = cdAttributeProvider.GetCDInfo(path);

                        productProperties = cdInfo.ProductProperties;

                        ProductName = cdInfo.Title;

                        productImageDTO.ProductProperties = productProperties;
                        productImageDTO.Name         = ProductName;
                        productImageDTO.ErrorMessage = cdInfo.ErrorMessage;

                        break;

                    default:
                        if (savedProduct.Name == "")
                        {
                            ProductName = dbProductImage.Category + " - " + (dbProductImage.ClassifierPropability * 100).ToString() + "%, ej klart";
                        }
                        break;
                    }

                    if (dbProductImage.Category == "Bok" && (savedProduct.Name == "Bok" || savedProduct.Name == ""))
                    {
                        categoryId = 1; //Bok

                        var bookAttributeProvider = new BookAttributeProvider();
                        var bookInfo = bookAttributeProvider.GetBookInfo(path);

                        productProperties = bookInfo.ProductProperties;

                        ProductName = bookInfo.Title;

                        productImageDTO.ProductProperties = productProperties;
                        productImageDTO.Name         = bookInfo.Title;
                        productImageDTO.ErrorMessage = bookInfo.ErrorMessage;
                    }

                    if (dbProductImage.Category == "Kruka")
                    {
                        categoryId  = 7;
                        ProductName = "Kruka";

                        productProperties = @"[{ ""Key"":""Width"",""Value"":"""",""Type"":""number"",""Icon"":""panorama_horizontal""},{ ""Key"":""Height"",""Value"":"""",""Type"":""number"",""Icon"":""panorama_vertical""}]";

                        var imageDimensionResponse = ExtractDimensions(new FileInfo(path));

                        //Save processed images if they exists
                        if (imageDimensionResponse.ImageWithDimensions != null)
                        {
                            var dbProductImageWithDimensions = new ProductImage();

                            dbProductImageWithDimensions.Id = Guid.NewGuid();

                            path = ImagePath + dbProductImageWithDimensions.Id + "_" + fileName;

                            imageDimensionResponse.ImageWithDimensions.Save(path);

                            dbProductImageWithDimensions.ProductId         = ProductId;
                            dbProductImageWithDimensions.PrimaryImage      = false;
                            dbProductImageWithDimensions.Path              = "Images/" + Path.GetFileName(path);
                            dbProductImageWithDimensions.ProductId         = ProductId;
                            dbProductImageWithDimensions.PrimaryImage      = false;
                            dbProductImageWithDimensions.SelectedForExport = true;
                            db.ProductImages.Add(dbProductImageWithDimensions);
                            db.SaveChanges();

                            var dbProductImageCropped = new ProductImage();
                            dbProductImageCropped.Id = Guid.NewGuid();

                            path = ImagePath + dbProductImageCropped.Id + "_crop" + fileName;

                            //imageDimensionResponse.CroppedImage.Save(path);

                            //Save with number
                            cvProvider.SaveImageWithProductNumber(new FileInfo(path), savedProduct.ProductNumber, imageDimensionResponse.CroppedImage);

                            dbProductImageCropped.ProductId         = ProductId;
                            dbProductImageCropped.PrimaryImage      = true;
                            dbProductImageCropped.Path              = "Images/" + Path.GetFileName(path);
                            dbProductImageCropped.ProductId         = ProductId;
                            dbProductImageCropped.PrimaryImage      = false;
                            dbProductImageCropped.SelectedForExport = true;
                            db.ProductImages.Add(dbProductImageCropped);
                            db.SaveChanges();

                            //Todo: Set Primary image
                            SetPrimaryImage(dbProductImageCropped.Id);

                            //Return cropped image
                            imagePath = dbProductImageCropped.Path;

                            Decimal width  = Math.Round((Decimal)imageDimensionResponse.Width);
                            Decimal height = Math.Round((Decimal)imageDimensionResponse.Height);
                            //productProperties = @"[{""Property"":""Höjd"",""Value"":""" + height.ToString() + @" cm""},{""Property"":""Bredd"",""Value"":""" + width.ToString() + @" cm""}]";
                            //Höjd: "panorama_vertical" Bredd: "panorama_horizontal"
                            productProperties = @"[{ ""Key"":""Height"",""Value"":""" + height.ToString() + @""",""Type"":""number"",""Icon"":""panorama_vertical""},{ ""Key"":""Width"",""Value"":""" + width.ToString() + @""",""Type"":""number"",""Icon"":""panorama_horizontal""}]";
                        }
                        else
                        {
                            productImageDTO.ErrorMessage = imageDimensionResponse.ErrorMessage;
                        }
                    }
                }
            }

            //Update Product information
            using (var db = new DitatEntities())
            {
                Product dbProduct = db.Products.Single(p => p.Id == ProductId);

                productImageDTO.Id   = dbProductImage.Id;
                productImageDTO.Path = imagePath;
                //productImageDTO.PrimaryImage = dbProductImage.PrimaryImage;

                productImageDTO.ProductProperties = productProperties;
                productImageDTO.Name     = ProductName;
                productImageDTO.Category = dbProduct.Category;

                if (ProductName != null || ProductName != "" || ProductName != String.Empty)
                {
                    if (ProductName == null)
                    {
                        ProductName = "";
                    }
                    if (ProductName.Length > 1)
                    {
                        dbProduct.Name = ProductName;
                        if (!HasProperties(dbProduct.Properties))
                        {
                            dbProduct.Properties = productProperties;
                        }
                    }
                }
                if (dbProductImage.Category != null)
                {
                    dbProduct.Category = dbProductImage.Category;//classifierResponse.Category;
                }

                if (categoryId > 0)
                {
                    dbProduct.CategoryId = categoryId;
                }

                //Fel:  Skriver över properties om man lägger till en odefinierad bil till en befintlig bok:
                if (productImageDTO.ErrorMessage == null || dbProduct.Properties == null)
                {
                    if (HasProperties(dbProduct.Properties) == false)
                    {
                        dbProduct.Properties = productProperties;
                    }
                }
                db.SaveChanges();
            }

            return(productImageDTO);
        }
Exemple #30
0
 private static string GetDriveName(CDInfo cdInfo)
 {
     return(string.Format("{0} ({1}:\\)", cdInfo.Name, cdInfo.DriveLetter));
 }