Пример #1
0
        /// <summary>
        ///     New Instance of Log Model
        /// </summary>
        /// <param name="obj">
        ///     Can be an Exception or any object (will be serialize to Json String and store in Message property)
        /// </param>
        /// <param name="httpContext">HttpContext of current request if have</param>
        public LogModel(object obj, HttpContext httpContext = null)
        {
            if (obj is Exception exception)
            {
                Initial(exception);
            }
            else
            {
                Message = obj.ToJsonString();
            }

            CreatedTime = DateTimeOffset.UtcNow;

            Type = LogType.Error;

            Runtime = RuntimeHelper.Get();

            EnvironmentModel = EnvironmentHelper.Get();

            Sdk = SdkHelper.Get(Assembly.GetCallingAssembly().GetName());

            if (httpContext != null)
            {
                HttpContext = new HttpContextModel(httpContext)
                {
                    Id = Id.ToString("N")
                };
            }
        }
Пример #2
0
        public Session Login(string ipAddress, int port, string userName, string password)
        {
            NET_DVR_DEVICEINFO_V30 deviceInfo = default(NET_DVR_DEVICEINFO_V30);
            int userId = SdkHelper.InvokeSDK(() => NET_DVR_Login_V30(ipAddress, port, userName, password, ref deviceInfo));

            return(new Session(userId, deviceInfo.byChanNum));
        }
Пример #3
0
 public ProfileCreated()
 {
     InitializeComponent();
     FaceSdkHelper = new SdkHelper();
     DataContext   = this;
     IsCalculating = true;
 }
Пример #4
0
        public async Task JobPreviewDefaultsToAll()
        {
            using (var service = await SdkHelper.CreateService())
            {
                JobArgs jobArgs = new JobArgs();

                var job = await service.Jobs.CreateAsync("search index=_* | head 101", args : jobArgs);

                for (int delay = 1000; delay < 5000; delay += 1000)
                {
                    try
                    {
                        await job.TransitionAsync(DispatchState.Done, delay);

                        break;
                    }
                    catch (TaskCanceledException)
                    { }
                }

                using (SearchResultStream stream = await job.GetSearchPreviewAsync())
                {
                    // Is the result preview count greater than the default of 100?
                    Assert.Equal(101, job.ResultPreviewCount);
                }

                await job.CancelAsync();
            }
        }
Пример #5
0
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     counter.Stop();
     counter.Tick -= counter_Tick;
     FaceSdkHelper = null;
     GC.Collect();
     base.OnNavigatedFrom(e);
 }
Пример #6
0
        protected override int FindNext(int findId, ref ISourceFile source)
        {
            NET_DVR_FINDDATA_V30 findData = default(NET_DVR_FINDDATA_V30);
            int res = SdkHelper.InvokeSDK(() => NET_DVR_FindNextFile_V30(findId, ref findData));

            source = findData;
            return(res);
        }
Пример #7
0
        public virtual int StartDownloadFile(int userId, string sourceFile, string destinationPath)
        {
            int downloadHandle = SdkHelper.InvokeSDK(() => NET_DVR_GetFileByName(userId, sourceFile, destinationPath));

            uint iOutValue = 0;

            SdkHelper.InvokeSDK(() => NET_DVR_PlayBackControl_V40(downloadHandle, HikConst.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue));
            return(downloadHandle);
        }
Пример #8
0
        public TakePhoto()
        {
            InitializeComponent();
            InitScene();
            FaceSdkHelper = new SdkHelper();
            DataContext   = this;

            Message       = string.Empty;
            IsCalculating = false;
        }
Пример #9
0
 public async Task TestContextThrowsOnForbidden()
 {
     using (var context = new Context(Scheme.Https, "localhost", 8089))
     {
         SdkHelper.ThrowsAsync <AuthenticationFailureException>(async() => {
             var response = await context.GetAsync(new Namespace("nobody", "search"), new ResourceName(new [] { "search", "jobs" }));
             await response.EnsureStatusCodeAsync(System.Net.HttpStatusCode.Forbidden);
         });
     }
 }
Пример #10
0
        protected override int FindNext(int findId, ref ISourceFile source)
        {
            NET_DVR_FIND_PICTURE_V50 findData = new NET_DVR_FIND_PICTURE_V50();

            int res = SdkHelper.InvokeSDK(() => NET_DVR_FindNextPicture_V50(findId, ref findData));

            source = findData;

            return(res);
        }
Пример #11
0
 public async Task TestContextThrowsOn404()
 {
     using (var context = new Context(Scheme.Https, "localhost", 8089))
     {
         SdkHelper.ThrowsAsync <ResourceNotFoundException>(async() =>
         {
             var response = await context.GetAsync(new Namespace("nobody", "search"), new ResourceName(new[] { "abc", "def", "ghi" }));
             await response.EnsureStatusCodeAsync(System.Net.HttpStatusCode.NotFound);
         });
     }
 }
Пример #12
0
 /// <summary>
 /// Run export for each enum value in an enum type.
 /// </summary>
 /// <param name="enumType">The enum type</param>
 /// <param name="getJobExportArgs">
 /// The funtion to get arguments to run a job.
 /// </param>
 async Task RunExportForEachEnum(string search, Type enumType, Func <string, SearchExportArgs> getJobExportArgs)
 {
     using (var service = await SdkHelper.CreateService())
     {
         await ForEachEnum(enumType, async @enum =>
         {
             using (SearchPreviewStream stream = await service.ExportSearchPreviewsAsync(search, getJobExportArgs(@enum)))
             { }
         });
     }
 }
Пример #13
0
 /// <summary>
 /// Run a job for each enum value in an enum type.
 /// </summary>
 /// <param name="enumType">The enum type</param>
 /// <param name="getJobArgs">
 /// The funtion to get arguments to run a job.
 /// </param>
 async Task RunJobForEachEnum(Type enumType, Func <string, JobArgs> getJobArgs)
 {
     using (var service = await SdkHelper.CreateService())
     {
         await ForEachEnum(enumType, async @enum =>
         {
             var job = await service.Jobs.CreateAsync(Search, args: getJobArgs(@enum));
             await job.CancelAsync();
         });
     }
 }
Пример #14
0
        private async Task startHardWork()
        {
            worker         = new BackgroundWorker();
            worker.DoWork += (sender, arg) =>
            {
                FaceSdkHelper.Initialize();
            };
            await worker.BeginWorkerAsync();

            var sdkImg = ImageConverter.SystemToSdk(imageBitmap);
            var result = FaceSdkHelper.Detect(sdkImg);

            if (SdkHelper.foundFace == true && SdkHelper.results.Count == 1)
            {
                var shape = SdkHelper.results.FirstOrDefault();

                var defaultFaceCalculations = Calculus.ReadDefaultFaceCalculations();
                var array = FaceCalculationsHelpers.FromFaceCalculationsToVector(defaultFaceCalculations);

                var calculatedFaceCalculations = Calculus.GetFaceCalculationsFromShape(shape);
                var resultArray = FaceCalculationsHelpers.FromFaceCalculationsToVector(calculatedFaceCalculations);

                var conditions         = new Conditions();
                var resultFromCalculus = conditions.GetLevelVerifierFunction(Level).Invoke(array, resultArray);

                if (resultFromCalculus != 0)
                {
                    using (var db = new GrimacizerContext(GrimacizerContext.ConnectionString))
                    {
                        var passedLevels = db.Settings.FirstOrDefault()._16_PassedLevels;
                        db.Settings.FirstOrDefault()._16_PassedLevels = Math.Max(passedLevels, Level);

                        var level = db.Levels.FirstOrDefault(t => t.Level == Level);
                        level.Stars = Math.Max(resultFromCalculus, level.Stars);

                        db.SubmitChanges();
                    }
                    MessageBox.Show("Level passed. You won " + resultFromCalculus + " point" + (resultFromCalculus > 1 ? "s!" : "!"));
                }
                else
                {
                    InGameLifeHelpers.LoseLife();
                    MessageBox.Show("Level failed");
                }
            }
            else
            {
                MessageBox.Show("Camera did not detect your face! Try again!");
            }

            NavigationService.Navigate(new Uri(Pages.GeneralGameplay_Adventure, UriKind.RelativeOrAbsolute));
            FaceSdkHelper = null;
            GC.Collect();
        }
Пример #15
0
        protected override int StartFind(int userId, DateTime periodStart, DateTime periodEnd, int channel)
        {
            NET_DVR_FIND_PICTURE_PARAM findConditions = new NET_DVR_FIND_PICTURE_PARAM
            {
                lChannel      = channel,
                byFileType    = 0xff, // all
                struStartTime = new NET_DVR_TIME(periodStart),
                struStopTime  = new NET_DVR_TIME(periodEnd)
            };

            return(SdkHelper.InvokeSDK(() => NET_DVR_FindPicture(userId, ref findConditions)));
        }
Пример #16
0
    void Start()
    {
        GlobalData.InitData();

        AssetManager.Initialize();
        AudioManager.Initialize();

#if UNITY_ANDROID
        GalaSDKBaseCallBack.Instance.GALASDKGameExitEvent += DoExitPopup;
#endif

        UiCamera        = GetComponent <Camera>();
        UiContainer     = gameObject.transform.Find("Canvas").gameObject;
        CommonContainer = gameObject.transform.Find("CommonCanvas").gameObject;
        GuideCanvas     = gameObject.transform.Find("GuideCanvas").GetComponent <Canvas>();

        I18NManager.LoadLanguageConfig((I18NManager.LanguageType)AppConfig.Instance.language);

        NetWorkManager.Instance.GlobalNetErrorHandler = NetworkErrorHandler;
        NetWorkManager.Instance.SetServer(AppConfig.Instance.logicServer);



        //屏幕适配
        Canvas canvas = UiContainer.GetComponent <Canvas>();

        ScaleX            = StageWidth / (float)Screen.width;
        ScaleY            = StageHeight / (float)Screen.height;
        ScaleFactor       = Mathf.Min(ScaleX, ScaleY);
        ScaleFactor      *= canvas.scaleFactor;
        CanvasScaleFactor = canvas.scaleFactor;

        int offY = SetOffsetOnPhone();
        ModuleManager.Instance.SetOffY(offY);

        ModuleManager.Instance.SetContainer(UiContainer);
        _backBtn = GameObject.Find("BackBtn");
        ReturnablePanel.SetBackBtn(_backBtn);


        ModuleManager.Instance.EnterModule(ModuleConfig.MODULE_UPDATE);

        ClientData.LoadErrorCode();

        SdkHelper.Initialize();

        //关闭多点触控
        Input.multiTouchEnabled = false;

        GameObject.Find("PromptLayer").AddComponent <FullScreenEffect>();

        HandleTest();
    }
Пример #17
0
        protected override int StartFind(int userId, DateTime periodStart, DateTime periodEnd, int channel)
        {
            NET_DVR_FILECOND_V40 findConditions = new NET_DVR_FILECOND_V40
            {
                lChannel      = channel,
                dwFileType    = 0xff, // all
                dwIsLocked    = 0xff, // all, locked and unlocked
                struStartTime = new NET_DVR_TIME(periodStart),
                struStopTime  = new NET_DVR_TIME(periodEnd),
            };

            return(SdkHelper.InvokeSDK(() => NET_DVR_FindFile_V40(userId, ref findConditions)));
        }
        public async Task ConfigurationCollection()
        {
            using (var service = await SdkHelper.CreateService())
            {
                ConfigurationCollection confs = service.Configurations;
                await confs.GetAllAsync();

                //// Make sure the collection contains some of the expected entries

                Assert.NotNull(confs.SingleOrDefault(a => a.Title == "eventtypes"));
                Assert.NotNull(confs.SingleOrDefault(a => a.Title == "searchbnf"));
                Assert.NotNull(confs.SingleOrDefault(a => a.Title == "indexes"));
                Assert.NotNull(confs.SingleOrDefault(a => a.Title == "inputs"));
                Assert.NotNull(confs.SingleOrDefault(a => a.Title == "props"));
                Assert.NotNull(confs.SingleOrDefault(a => a.Title == "transforms"));
                Assert.NotNull(confs.SingleOrDefault(a => a.Title == "savedsearches"));

                //// Iterate over the confs just to make sure we can read them

                foreach (Configuration conf in confs)
                {
                    string dummyString;

                    dummyString = conf.Name;
                    dummyString = conf.Title;

                    foreach (ConfigurationStanza stanza in conf)
                    {
                        dummyString = stanza.Name;
                        dummyString = stanza.Title;
                    }
                }

                for (int i = 0; i < confs.Count; i++)
                {
                    Configuration conf = confs[i];
                    string        dummyString;

                    dummyString = conf.Name;
                    dummyString = conf.Title;

                    foreach (ConfigurationStanza stanza in conf)
                    {
                        dummyString = stanza.Name;
                        dummyString = stanza.Title;
                    }
                }
            }
        }
 public async Task TestContextThrowsOn404()
 {
     using (var context = new Context(Scheme.Https, "localhost", 8089))
     {
         await SdkHelper.ThrowsAsync <ResourceNotFoundException>(async() =>
         {
             using (var service = new Service(context))
             {
                 await service.LogOnAsync(SdkHelper.Splunk.Username, SdkHelper.Splunk.Password);
                 var response = await service.Context.GetAsync(new Namespace("admin", "search"), new ResourceName(new[] { "abc", "def", "ghi" }));
                 await response.EnsureStatusCodeAsync(System.Net.HttpStatusCode.NotFound);
             }
         });
     }
 }
Пример #20
0
        public async Task Transmitter2()
        {
            string indexName = "main";

            using (var service = await SdkHelper.CreateService())
            {
                Index index = await service.Indexes.GetAsync(indexName);

                long currentEventCount = index.TotalEventCount;
                Assert.NotNull(index);

                Transmitter     transmitter     = service.Transmitter;
                IndexAttributes indexAttributes = GetIndexAttributes(index);
                Assert.NotNull(indexAttributes);

                // Submit event to default index using variable arguments

                await transmitter.SendAsync(
                    MockContext.GetOrElse(string.Format("{0}, DefaultIndexArgs string event Hello World 1", DateTime.Now)),
                    indexName);

                await transmitter.SendAsync(
                    MockContext.GetOrElse(string.Format("{0}, DefaultIndexArgs string event Hello World 2", DateTime.Now)),
                    indexName);

                await index.PollForUpdatedEventCount(currentEventCount + 2);

                currentEventCount += 2;

                using (MemoryStream stream = new MemoryStream())
                {
                    using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8, 4096, leaveOpen: true))
                    {
                        writer.WriteLine(
                            MockContext.GetOrElse(string.Format("{0}, DefaultIndexArgs stream events 1", DateTime.Now)));
                        writer.WriteLine(
                            MockContext.GetOrElse(string.Format("{0}, DefaultIndexArgs stream events 2", DateTime.Now)));
                    }

                    stream.Seek(0, SeekOrigin.Begin);
                    await transmitter.SendAsync(stream, indexName);
                }

                await index.PollForUpdatedEventCount(currentEventCount + 2);

                currentEventCount += 2;
            }
        }
Пример #21
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.Back)
            {
                return;
            }

            SystemTray.IsVisible = true;

            int width, height;

            using (var db = new GrimacizerContext(GrimacizerContext.ConnectionString))
            {
                var settings = db.Settings.FirstOrDefault();
                width  = settings.DefaultImagePixelWidth;
                height = settings.DefaultImagePixelHeight;
            }
            ImageSource = LocalImagesHelper.ReadImageFromIsolatedStorage(Constants.DEFAULT_FACE_PHOTO, width, height);

            var worker = new BackgroundWorker();

            worker.DoWork += (sender, arg) =>
            {
                FaceSdkHelper.Initialize();
            };
            await worker.BeginWorkerAsync();

            var sdkImg = ImageConverter.SystemToSdk(ImageSource);
            var result = FaceSdkHelper.Detect(sdkImg);

            ImageSource = ImageConverter.SdkToSystem(result);

            if (SdkHelper.foundFace == true && SdkHelper.results.Count == 1)
            {
                (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                (ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                IsCalculating = false;
            }
            else
            {
                MessageBox.Show("Camera did not detect your face! Try again!");
                NavigationService.GoBack();
            }

            FaceSdkHelper = null;
            GC.Collect();
        }
Пример #22
0
        public async Task JobResultsDefaultsToAll()
        {
            using (var service = await SdkHelper.CreateService())
            {
                JobArgs jobArgs = new JobArgs();

                var job = await service.Jobs.CreateAsync("search index=_* | head 101", args : jobArgs);

                using (SearchResultStream stream = await job.GetSearchResultsAsync())
                {
                    // Is the result count greater than the default of 100?
                    Assert.Equal(101, job.ResultCount);
                }

                await job.CancelAsync();
            }
        }
Пример #23
0
        private void OnUserLevelup()
        {
            view.SetLevel(GlobalData.PlayerModel.PlayerVo.Level);
            //玩家升级之后就要更新当前等级应援会规则能力。
            GlobalData.PlayerModel.BaseSupportPower = MyDepartmentData.GetDepartmentRule(DepartmentTypePB.Support
                                                                                         , GlobalData.PlayerModel.PlayerVo.Level).Power;

            // FlowText.ShowMessage(I18NManager.Get("GameMain_Hint1", GlobalData.PlayerModel.PlayerVo.Level));// ("应援会等级提升至" + GlobalData.PlayerModel.PlayerVo.Level);
            //弹出应援会升级弹窗
            var _levelupWindow = PopupManager.ShowWindow <LevelUpWindow>("GameMain/Prefabs/LevelupWindow/LevelUpWindow");

            _levelupWindow.SetData(GlobalData.DepartmentData);

            UpdateTopBar();
            view.HandleFunctionOpen();

            SdkHelper.SetSdkData(SdkHelper.TYPE_DATA_CHANGE);
        }
Пример #24
0
        public void DownloadFile(int userId, IRemoteFile remoteFile, string destinationPath)
        {
            if (remoteFile.Size > 0)
            {
                NET_DVR_PIC_PARAM temp = new NET_DVR_PIC_PARAM
                {
                    pDVRFileName  = remoteFile.Name,
                    pSavedFileBuf = Marshal.AllocHGlobal((int)remoteFile.Size),
                    dwBufLen      = (uint)remoteFile.Size
                };

                if (SdkHelper.InvokeSDK(() => NET_DVR_GetPicture_V50(userId, ref temp)))
                {
                    SdkHelper.InvokeSDK(() => NET_DVR_GetPicture(userId, temp.pDVRFileName, destinationPath));
                }

                Marshal.FreeHGlobal(temp.pSavedFileBuf);
            }
        }
Пример #25
0
        public async Task JobSearchMode()
        {
            using (var service = await SdkHelper.CreateService())
            {
                JobArgs jobArgs = new JobArgs();

                jobArgs.SearchMode = SearchMode.Normal;
                Job job = await service.Jobs.CreateAsync(Search, args : jobArgs);

                Assert.NotNull(job);

                jobArgs.SearchMode = SearchMode.RealTime;
                bool updatedSnapshot = await job.UpdateAsync(jobArgs);

                Assert.True(updatedSnapshot);

                await job.CancelAsync();
            }
        }
        public async Task TestApplications()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            using (var service = await SdkHelper.CreateService())
            {
                ApplicationCollection apps = service.Applications;
                await apps.GetAllAsync();

                foreach (Application app in apps)
                {
                    await CheckApplication(app);
                }

                for (int i = 0; i < apps.Count; i++)
                {
                    await CheckApplication(apps[i]);
                }
            }
        }
        public async Task QueuedSearchCreate()
        {
            const string searchPrefix = "search index=_internal ";
            int          i            = 0;

            using (var service = await SdkHelper.CreateService())
            {
                List <Job> jobs = new List <Job>();
                Job        job  = null;
                do
                {
                    JobArgs jobArgs = new JobArgs();
                    jobArgs.SearchMode = SearchMode.RealTime;

                    try
                    {
                        // Jobs should eventually be queued w/o waiting for them to get to running state
                        job = await service.Jobs.Create(searchPrefix + i.ToString(), args : jobArgs);

                        Assert.Equal(DispatchState.None, job.DispatchState);
                        await job.GetAsync();

                        jobs.Add(job);
                        i++;
                    } catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.GetBaseException().ToString());
                        break;
                    }
                } while (job.DispatchState != DispatchState.Queued);

                Assert.NotNull(job);
                Assert.Equal(DispatchState.Queued, job.DispatchState);

                // Cleanup
                foreach (Job j in jobs)
                {
                    await j.CancelAsync();
                }
            }
            Assert.True(i > 0);
        }
Пример #28
0
        public HdInfo GetHddStatus(int userId)
        {
            NET_DVR_HDCFG hdConfig     = default;
            uint          returned     = 0;
            int           sizeOfConfig = Marshal.SizeOf(hdConfig);
            IntPtr        ptrDeviceCfg = Marshal.AllocHGlobal(sizeOfConfig);

            Marshal.StructureToPtr(hdConfig, ptrDeviceCfg, false);
            SdkHelper.InvokeSDK(() => NET_DVR_GetDVRConfig(
                                    userId,
                                    HikConst.NET_DVR_GET_HDCFG,
                                    -1,
                                    ptrDeviceCfg,
                                    (uint)sizeOfConfig,
                                    ref returned));

            hdConfig = (NET_DVR_HDCFG)Marshal.PtrToStructure(ptrDeviceCfg, typeof(NET_DVR_HDCFG));
            Marshal.FreeHGlobal(ptrDeviceCfg);
            return(new HdInfo(hdConfig.struHDInfo[0]));
        }
Пример #29
0
        public async Task CanRefreshJob()
        {
            const string search = "search index=_internal * | head 1 | debug cmd=sleep param1=5";

            using (var service = await SdkHelper.CreateService())
            {
                var job = await service.Jobs.CreateAsync(search);

                await this.CheckJobAsync(job, service);

                Assert.True(job.DispatchState < DispatchState.Done);

                await job.TransitionAsync(DispatchState.Done, 10 * 1000);

                await this.CheckJobAsync(job, service);

                Assert.True(job.DispatchState == DispatchState.Done);

                await job.CancelAsync();
            }
        }
Пример #30
0
        public async Task JobExecutionMode()
        {
            using (var service = await SdkHelper.CreateService())
            {
                Job job;

                job = await service.Jobs.CreateAsync(Search, mode : ExecutionMode.Normal);

                Assert.NotNull(job);

                job = await service.Jobs.CreateAsync(Search, mode : ExecutionMode.OneShot);

                Assert.NotNull(job);

                job = await service.Jobs.CreateAsync(Search, mode : ExecutionMode.Blocking);

                Assert.NotNull(job);

                await job.CancelAsync();
            }
        }