Beispiel #1
0
        public string Url()
        {
            string url = new Port(port).Url();

            if (LangExt.isblank(url, ""))
            {
                return(port == album ? "album.tier" : "");
            }
            return(url);
        }
Beispiel #2
0
 private void onSetDevice(object sender, RoutedEventArgs e)
 {
     if (LangExt.isblank(device.Text.Trim()))
     {
         MessageBox.Show("Device name can not be empty!", "Information",
                         MessageBoxButton.OK, MessageBoxImage.Exclamation);
         return;
     }
     else
     {
         savePrefs();
         turnOnDevice(true);
     }
 }
Beispiel #3
0
        private void toLogin(object sender, RoutedEventArgs e)
        {
            if (LangExt.isblank(jserv.Text.Trim()))
            {
                jserv.Text = "127.0.0.1";
            }
            if (LangExt.isblank(port.Text.Trim()))
            {
                port.Text = "8080";
            }

            AnClient.Init(string.Format("http://{0}:{1}/{2}", jserv.Text, port.Text, jservPath));

            // AlbumContext login(String uid, String pswd, TierCallback onOk, JProtocol.OnError onErr)
            singleton.login();
        }
Beispiel #4
0
        public DocsReq blockStart(IFileDescriptor file, SessionInf usr)
        {
            this.device = usr.device;
            if (LangExt.isblank(this.device, new string[] { ".", "/" }))
            {
                throw new SemanticException("File to be uploaded must come with user's device id - for distinguish files. {0}", file.fullpath());
            }

            this.clientpath = file.fullpath();
            this.docName    = file.clientname();
            this.createDate = file.Cdate();
            this.blockSeq   = 0;

            this.a = A.blockStart;
            return(this);
        }
Beispiel #5
0
        //public DocsReq blockUp(long sequence, DocsResp resp, StringBuilder b64, SessionInf usr) throws SemanticException {
        //	string uri64 = b64.toString();
        //	return blockUp(sequence, resp, uri64, usr);
        //}

        public DocsReq blockUp(long sequence, DocsResp resp, string s64, SessionInf usr)
        {
            this.device = usr.device;
            if (LangExt.isblank(this.device, new string[] { ".", "/" }))
            {
                throw new SemanticException("File to be uploaded must come with user's device id - for distinguish files");
            }

            this.blockSeq = sequence;

            this.docId      = resp.RecId();
            this.clientpath = resp.Fullpath();
            this.uri64      = s64;

            this.a = A.blockUp;
            return(this);
        }
Beispiel #6
0
        AlbumContext login(string uid, string pswd)
        {
            if (LangExt.isblank(photoUser.device, new string[] { "\\.", "/", "\\?", ":" }))
            {
                throw new Exception("Device Id is null.");
            }

            AnClient.Init(jserv + "/" + jdocbase, verbose);

            LoginHandler callback = new LoginHandler();

            AnClient.Login(uid, pswd, photoUser.device, callback, callback);

            /*
             *  (SessionClient client) =>
             *  {
             *      client.closeLink();
             *
             *      tier = new AlbumClientier(clientUri, client, errCtx);
             *
             *      client.openLink(clientUri, onHeartbeat, onLinkBroken, 19900); // 4 times failed in 3 min
             *              state = ConnState.Online;
             *              if (onOk != null)
             *                  onOk.ok(tier);
             *  },
             *  // Design Note: since error context don't have unified error message box,
             *  // error context pattern of React is not applicable.
             *  // errCtx.onError(c, r, (Object)v);
             *  (MsgCode c, string r, object v) => {
             *      state = ConnState.LoginFailed;
             *      if (onErr != null)
             *          onErr.err(c, r, v);
             *  }, photoUser.device);
             */
            return(this);
        }
Beispiel #7
0
        /// <summary>Use a special char to padd up to AES block.
        /// TODO upgrade the java side
        /// Reference:
        /// \u2020, ? , a char not easy to be keyed in
        /// https://www.unicode.org/charts/PDF/Unicode-3.2/U32-2000.pdf
        /// \u0000, Nil
        /// https://www.unicode.org/charts/PDF/U0000.pdf
        /// </summary>
        /// <param name="s"></param>
        /// <returns> 16 / 32 byte string
        /// </returns>
        /// <exception cref="Exception"></exception>
        private static byte[] pad16_32(string s)
        {
            int l = Encoding.Unicode.GetByteCount(s);

            if (l <= 16)
            {
                l = 16;
            }
            else if (l <= 32)
            {
                l = 32;
            }
            else
            {
                throw new Exception("Not supported block length(16B/32B): " + s);
            }

            byte[] buf = new byte[l];

            LangExt.Fill <byte>(buf, 0);

            Encoding.Unicode.GetBytes(s, 0, s.Length, buf, 0);
            return(buf);
        }
Beispiel #8
0
 public bool needSetup()
 {
     return(LangExt.isblank(jserv, new string[] { "/", ".", "http://", "https://" }) ||
            LangExt.isblank(photoUser.device, "/", ".") ||
            LangExt.isblank(photoUser.uid));
 }
Beispiel #9
0
 public void TestToStringIfSome()
 {
     Assert.IsTrue(Some(Distribution.GetDefault(DistributionType.Normal)).ToStringIfSome("x").IsAString());
     Assert.IsNull(LangExt.NoneOf <IDistribution>().ToStringIfSome("x"));
 }