Exemple #1
0
        public Stream GetConsumerStream(Guid consumerGuid, Guid viewGuid)
        {
            if (_workingDirectory == null)
            {
                throw new DirectoryNotFoundException("Working directory is not found.");
            }

            ConsumerData consumer = _consumers.FirstOrDefault <ConsumerData>(x => x.ConsumerGuid == consumerGuid &&
                                                                             x.ViewGuid == viewGuid);

            if (consumer != null && !String.IsNullOrEmpty(consumer.Hash))
            {
                FileInfo[] files = _workingDirectory.GetFiles(consumer.Hash + "*");
                if (files.Length > 0)
                {
                    // Just read the first match file, actually there should be only on match file as hash value is unique.
                    Stream stream = new MemoryStream();
                    using (FileStream fileStream = new FileStream(files[0].FullName, FileMode.Open, FileAccess.Read))
                    {
                        fileStream.CopyTo(stream);
                        stream.Position = 0;
                    }

                    return(stream);
                }
            }

            return(null);
        }
Exemple #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var cData = new ConsumerData(App.Current.Resources["ConsumerKey"].ToString(), App.Current.Resources["ConsumerSecret"].ToString());


            viewModel        = new NeuroniaViewModel(Window.Current.Dispatcher, cData);
            this.DataContext = viewModel;

            SettingsPane.GetForCurrentView().CommandsRequested += (s, arg) =>
            {
                arg.Request.ApplicationCommands.Add(new SettingsCommand("Setting", "設定", (a) =>
                {
                    this.Frame.Navigate(typeof(SettingPage), viewModel);
                }));

                arg.Request.ApplicationCommands.Add(new SettingsCommand("TwitterReport", "作者に直接文句をいう", async(a) =>
                {
                    await Launcher.LaunchUriAsync(new Uri("http://www.twitter.com/garicchi"));
                }));

                arg.Request.ApplicationCommands.Add(new SettingsCommand("ModeInformation", "MoreInformation", async(a) =>
                {
                    await Launcher.LaunchUriAsync(new Uri("http://neuronia.garicchi.com"));
                }));

                arg.Request.ApplicationCommands.Add(new SettingsCommand("PrivacyPolicy", "プライバシーポリシー", async(a) =>
                {
                    await Launcher.LaunchUriAsync(new Uri("http://garicchi.hatenablog.jp/entry/2014/02/08/151814"));
                }));
            };
        }
        public async Task <JsonResult> AjaxInitiate(
            decimal amount, int?numInstallments = null, bool?secure3d = false, bool?autoCapture = null,
            int numOptions = 6, bool pascalCase = false)
        {
            var billingAddress = new AddressData();
            var consumerModel  = new ConsumerData(isLocked: false, isDataRestricted: false);

            await this.TryUpdateModelAsync(billingAddress, "billingAddress");

            await this.TryUpdateModelAsync(consumerModel, "consumerModel");

            var loginApi = new LoginApi(this.FlexFieldsEnv);
            var request  = new LoginRequest(userName: SplititApiUsername, password: SplititApiPassword);

            var loginResult = await loginApi.LoginPostAsync(request);

            var installmentPlanApi = new InstallmentPlanApi(this.FlexFieldsEnv, sessionId: loginResult.SessionId);
            var initResponse       = installmentPlanApi.InstallmentPlanInitiate(new InitiateInstallmentPlanRequest()
            {
                PlanData = new PlanData(
                    amount: new MoneyWithCurrencyCode(amount, "USD"),
                    numberOfInstallments: numInstallments,
                    attempt3DSecure: secure3d,
                    autoCapture: autoCapture),
                BillingAddress    = billingAddress,
                ConsumerData      = consumerModel,
                PaymentWizardData = new PaymentWizardData(
                    requestedNumberOfInstallments: string.Join(",", Enumerable.Range(1, numOptions)))
            });

            return(new JsonResult(initResponse));
        }
        public TwitterClientBase(ConsumerData consumerData, AccessTokenData token)
        {
            this.consumerData = consumerData;

            this.accessToken = token;
            httpClient       = OAuthUtility.CreateOAuthClient(ConsumerData.ConsumerKey, ConsumerData.ConsumerSecret, new AccessToken(AccessToken.AccessToken, AccessToken.TokenSecret));

            httpClient.Timeout = System.Threading.Timeout.InfiniteTimeSpan;
        }
Exemple #5
0
 public FollowStream(ConsumerData consumer, AccessTokenData token, User user)
     : base(consumer, token, user, TwitterUrl.FilterStreamingUrl + "?follow=" + user.id_str)
 {
     GetStreamMe        += async(e) => { };
     GetStreamMention   += async(e) => { };
     GetStreamRetweet   += async(e) => { };
     GetStreamDelete    += async(e) => { };
     GetStreamRetweeted += async(e) => { };
 }
Exemple #6
0
        public TwitterAccount(ConsumerData consumerData, AccessTokenData accessToken, string screenName)
        {
            IsActive = false;

            friendsScreenNameList = new ObservableCollection <string>();
            TwitterClient         = new TwitterClient(consumerData, accessToken);

            ScreenName = screenName;
        }
 public TwitterStreamBase(ConsumerData consumerData, AccessTokenData token, User user, string streamingUrl)
     : base(consumerData, token)
 {
     this.UserInformation = user;
     this.streamingUrl    = streamingUrl;
     ConnectEndFlag       = false;
     ChangeStreamEvent   += (state) => { };
     OnStreamError       += e => { };
     StreamState          = StreamState.DisConnect;
 }
        public async Task <string> BeginAuthorizedAsync(ConsumerData data)
        {
            authorizer = new OAuthAuthorizer(data.ConsumerKey, data.ConsumerSecret);

            var tokenResponse = await authorizer.GetRequestToken(TwitterUrl.GetRequestTokenUrl);

            requestToken = tokenResponse.Token;

            var pinRequestUrl = authorizer.BuildAuthorizeUrl(TwitterUrl.AuthorizeUrl, requestToken);

            return(pinRequestUrl);
        }
Exemple #9
0
        public string GetConsumerStreamHash(Guid consumerGuid, Guid viewGuid)
        {
            ConsumerData consumer = _consumers.FirstOrDefault <ConsumerData>(x => x.ConsumerGuid == consumerGuid &&
                                                                             x.ViewGuid == viewGuid);

            if (consumer != null)
            {
                return(consumer.Hash);
            }
            else
            {
                return(String.Empty);
            }
        }
Exemple #10
0
    public int addConsumer()
    {
        //int ret = ConsumerData\
        int ret = consumerCount;

        //consumers.Add(new ConsumerData());
        consumerCount++;
        ConsumerData newStruct = new ConsumerData();

        newStruct.init(registerHeadState());

        consumers[ret] = newStruct;
        return(ret);
    }
Exemple #11
0
        /// <summary>启动</summary>
        /// <returns></returns>
        public override Boolean Start()
        {
            if (Active)
            {
                return(true);
            }

            var list = Data;

            if (list == null)
            {
                // 建立消费者数据,用于心跳
                var sd = new SubscriptionData
                {
                    Topic = Topic,
                };
                var cd = new ConsumerData
                {
                    GroupName           = Group,
                    SubscriptionDataSet = new[] { sd },
                };

                list = new List <ConsumerData> {
                    cd
                };

                Data = list;
            }

            if (!base.Start())
            {
                return(false);
            }

            // 默认自动开始调度
            if (AutoSchedule)
            {
                StartSchedule();
            }

            return(true);
        }
        private IList <ConsumerData> BuildConsumeDatas()
        {
            var subscriptData = new SubscriptionData
            {
                Topic          = Topic,
                ExpressionType = ExpressionType,
                SubString      = Subscription
            };

            if (ExpressionType == "TAG")
            {
                subscriptData.TagsSet = Subscription.Split(TagSeparator);
            }

            var consumeData = new ConsumerData
            {
                GroupName           = Group,
                ConsumeType         = ConsumeType,
                SubscriptionDataSet = new[] { subscriptData }
            };

            return(new[] { consumeData });
        }
Exemple #13
0
    void procTransfer()
    {
        // generator output
        for (int i = 0; i < generic[0].tempGenericUpdateOps.Length; ++i)
        {
            if (generic[0].tempGenericUpdateOps[i] != 0)
            {
                GeneratorData gen = generators[i];
                CanTakeState  cts = headStates[gen.tailArrayIdx];
                // check if this generator has space at its end?
                if (tubes[cts.tailIdx].hasSpace(gen.itemId))
                {
                    tubes[cts.tailIdx].push(gen.itemId);
                    // consume a unit of resource.
                    //Debug.LogFormat("generator {0} makes one at {1}", i, elapsedTime);
                    gen.pop();
                    generators[i] = gen;
                }
                else
                {
                    Debug.LogFormat("generator {0} got blocked.", i);
                    gen.block();
                    generators[i] = gen;
                }
            }
        }

        // tubes output
        for (int i = 0; i < arrayLength; ++i)
        {
            if (updateTubesJob.outputOps[i] != 0)
            {
                CanTakeState cts     = headStates[tubes[i].tailArrayIdx];
                TubeData     srcTube = tubes[i];
                if (cts.tailType == CTS_Tube) // tube
                {
                    if (tubes[cts.tailIdx].hasSpace(srcTube.itemId))
                    {
                        srcTube.pop();
                        tubes[cts.tailIdx].push(srcTube.itemId);
                        Debug.LogFormat("{0} Tube {1} pops into {2}.", elapsedTime, i, cts.tailIdx);
                        cts = headStates[srcTube.headArrayIdx];
                        cts.invokeUnblock();
                    }
                    else
                    {
                        Debug.LogFormat("{0} Tube {1} blocked", elapsedTime, i);
                        srcTube.block();
                    }
                }
                else if (cts.tailType == CTS_Converter) // converter
                {
                    ConverterData conv = converters[cts.tailIdx];
                    if (conv.hasSpace(srcTube.itemId))
                    {
                        srcTube.pop();
                        if (converters[cts.tailIdx].push(srcTube.itemId))
                        {
                            Debug.LogFormat("{0} Tube {1} pops into converter {2}.", elapsedTime, i, cts.tailIdx);
                            cts = headStates[srcTube.tailArrayIdx];
                            cts.invokeUnblock();
                        }
                    }
                    else
                    {
                        srcTube.block();
                        Debug.LogFormat("{0} Tube {1} got blocked by converter {2}.", elapsedTime, i, cts.tailIdx);
                    }
                    //Debug.LogFormat("{0} converter @ {1}, {2}", elapsedTime, conv.srcCurrent[0], conv.srcCurrent[1]);
                }
                else if (cts.tailType == CTS_Consumer)  // consumer
                {
                    ConsumerData consData = consumers[cts.tailIdx];
                    consData.attemptToTake(srcTube.itemId);
                    srcTube.pop();
                    consumers[cts.tailIdx] = consData;

                    Debug.LogFormat("{0} Tube {1} pops into consumer {2}.", elapsedTime, i, cts.tailIdx);
                    cts = headStates[srcTube.headArrayIdx];
                    cts.invokeUnblock();
                }
                tubes[i] = srcTube;
            }
        }

        // converter output
        for (int i = 0; i < generic[1].tempGenericUpdateOps.Length; ++i)
        {
            if (generic[1].tempGenericUpdateOps[i] != 0)
            {
                CanTakeState  cts  = headStates[converters[i].tailArrayIdx];
                ConverterData conv = converters[i];
                // check if this converter has space at its end?
                if (cts.tailType == CTS_Tube)   // the end entity of this converter is a tube
                {
                    if (tubes[cts.tailIdx].hasSpace(conv.targetId))
                    {
                        Debug.Log("converter out!");
                        tubes[cts.tailIdx].push(conv.targetId);

                        //headStates[conv.headArrayIdx].invokeUnblock();
                        Debug.LogFormat("{0} converter {1} pops into tube {2}.", elapsedTime, i, cts.tailIdx);
                    }
                    else
                    {
                        //head_cts
                        Debug.LogFormat("{0} converter {1} got blocked by tube {2}.", elapsedTime, i, cts.tailIdx);
                    }
                }
                else if (cts.tailType == CTS_Converter)  // converter
                {
                    Debug.LogFormat("{0} converter {1} pops into converter {2}.", elapsedTime, i, cts.tailIdx);
                }
                if (conv.allMet())
                {
                    converters[i].startUpdate();
                    headStates[conv.headArrayIdx].invokeUnblock();
                }
            }
        }

        sampler.End();
    }
Exemple #14
0
 public TrackStream(ConsumerData consumerData, AccessTokenData token, User user, string trackKeyword)
     : base(consumerData, token, user, TwitterUrl.FilterStreamingUrl + "?track=" + Uri.EscapeDataString(trackKeyword))
 {
     this.trackKeyword = trackKeyword;
     GetStreamTrack   += async(e) => { };
 }
Exemple #15
0
 public async void InsertData(ConsumerData consumerData)
 {
     _dbContext.ConsumerDatas.Add(consumerData);
     await _dbContext.SaveChangesAsync();
 }
Exemple #16
0
        public ConsumerData Produce(ProducerData data)
        {
            ConsumerData path = new ConsumerData(data.FilePath);

            return(path);
        }
Exemple #17
0
        public string SetConsumerStream(Guid consumerGuid, Guid viewGuid, Stream stream, string streamType)
        {
            if (_workingDirectory == null)
            {
                throw new DirectoryNotFoundException("Working directory is not found.");
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            long oldPostion = stream.Position;

            stream.Position = 0;

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] hash     = md5.ComputeHash(stream);
            string imageMD5 = BitConverter.ToString(hash);
            string fileHash = imageMD5.Replace("-", "").ToLower();

            ConsumerData consumer = _consumers.FirstOrDefault <ConsumerData>(x => x.ConsumerGuid == consumerGuid &&
                                                                             x.ViewGuid == viewGuid);

            if (consumer != null)
            {
                consumer.Hash = fileHash;
            }
            else
            {
                consumer = new ConsumerData(consumerGuid, viewGuid, fileHash);
                _consumers.Add(consumer);
            }

            FileInfo[] files = _workingDirectory.GetFiles(fileHash + "*");
            if (files.Length > 0)
            {
                // Image file already exist
                stream.Position = oldPostion;
                return(fileHash);
            }

            // Save the stream to file.
            string fileName = fileHash;

            if (!String.IsNullOrEmpty(streamType))
            {
                fileName += @".";
                fileName += streamType;
            }

            string fileFullName = Path.Combine(_workingDirectory.FullName, fileName);

            using (FileStream fileStream = new FileStream(fileFullName, FileMode.Create, FileAccess.Write))
            {
                stream.Position = 0;
                stream.CopyTo(fileStream);
                stream.Position = oldPostion;
            }

            return(fileHash);
        }
Exemple #18
0
        public NeuroniaViewModel(CoreDispatcher dispatcher, ConsumerData consumerData)
            : base(Messenger.Default)
        {
            SharedDispatcher.Dispatcher = dispatcher;
            twitterUIComponent          = new TwitterUIComponent();
            accountList              = new ObservableCollection <TwitterAccount>();
            TimelineListTab          = new ObservableCollection <TimelineTab>();
            NowTimelineList          = new ObservableCollection <TimelineBase>();
            SearchDetail             = new SearchDetail();
            Setting                  = new SettingData();
            TweetDetail              = new TweetDetail(new TimelineRow(Tweet.ZeroTweet, "", Setting, CallRowAction));
            DMDetail                 = new DirectMessageDetail();
            UserDetail               = new UserDetail();
            NotifyMessage            = new NotificationMessage();
            IsFirstNavigate          = true;
            this.consumerData        = consumerData;
            this.connectionStatusStr = "";
            Authorizer               = new TwitterAuthorizer();
            restTimerCounter         = 0;
            LicenseInfo              = CurrentApp.LicenseInformation;

            RestTimer          = new DispatcherTimer();
            RestTimer.Interval = TimeSpan.FromMinutes(1);
            RestTimer.Tick    += (s, e) => Task.Run(async() =>
            {
                await SharedDispatcher.RunAsync(() =>
                {
                    NowTime    = DateTime.Now;
                    NowTimeStr = NowTime.ToString("HH:mm");
                });

                if (restTimerCounter % 2 == 0)
                {
                    foreach (var tab in TimelineListTab)
                    {
                        foreach (var t in tab.TimelineList)
                        {
                            await t.RestUpdate();
                        }
                    }
                }
                if (restTimerCounter % 10 == 0)
                {
                    TwitterUIComponent.MentionSuggestSourceList.Clear();
                    TwitterUIComponent.HashSuggestSourceList.Clear();
                    foreach (var tab in TimelineListTab)
                    {
                        foreach (var t in tab.TimelineList)
                        {
                            foreach (var ac in (await t.GetTimelineAccountListAsync()))
                            {
                                TwitterUIComponent.MentionSuggestSourceList.Add(ac);
                            }
                            foreach (var ac in (await t.GetTimelineHashTagListAsync()))
                            {
                                TwitterUIComponent.HashSuggestSourceList.Add(ac);
                            }
                        }
                    }
                }
                restTimerCounter++;
                if (restTimerCounter > 100)
                {
                    restTimerCounter = 0;
                }
            });
            RestTimer.Start();
            CommandInitialize();
            timelineWidth = 320;
            IsFirstLaunch = true;
            if (LicenseInfo.ProductLicenses["ApplicationTheme"].IsActive)
            {
                IsPurchase = true;
            }
            else
            {
                IsPurchase = false;
            }
        }
Exemple #19
0
 public UserStream(ConsumerData consumerData, AccessTokenData token, User user)
     : base(consumerData, token, user, TwitterUrl.UserStreamingUrl)
 {
 }
Exemple #20
0
 public TwitterClient(ConsumerData consumerData, AccessTokenData token)
     : base(consumerData, token)
 {
 }